Example #1
0
from ppci.cli.pascal import pascal
from ppci.cli.yacc import yacc
from ppci import api
from ppci.common import DiagnosticsManager, SourceLocation
from ppci.binutils.objectfile import ObjectFile, Section, Image
from helper_util import relpath, do_long_tests


def new_temp_file(suffix):
    """ Generate a new temporary filename """
    handle, filename = tempfile.mkstemp(suffix=suffix)
    os.close(handle)
    return filename


@unittest.skipUnless(do_long_tests('any'), 'skipping slow tests')
class BuildTestCase(unittest.TestCase):
    """ Test the build command-line utility """
    @patch('sys.stdout', new_callable=io.StringIO)
    @patch('sys.stderr', new_callable=io.StringIO)
    def test_build_command(self, mock_stdout, mock_stderr):
        """ Test normal use """
        report_file = new_temp_file('.html')
        build_file = relpath('..', 'examples', 'lm3s6965evb', 'snake',
                             'build.xml')
        build(['-v', '--report', report_file, '-f', build_file])

    @patch('sys.stdout', new_callable=io.StringIO)
    def test_help(self, mock_stdout):
        """ Test help function """
        with self.assertRaises(SystemExit) as cm:
Example #2
0
import unittest
import io

from sample_helpers import add_samples, build_sample_to_ir
from helper_util import relpath, run_python
from helper_util import do_long_tests, make_filename

from ppci import api
from ppci.utils.reporting import HtmlReportGenerator
from ppci.irutils import print_module, read_module, to_json, from_json


@unittest.skipUnless(do_long_tests("python"), "skipping slow tests")
@add_samples("simple", "medium", "hard", "8bit", "fp", "double", "32bit")
class TestSamplesOnPython(unittest.TestCase):
    opt_level = 0

    def do(self, src, expected_output, lang="c3"):
        base_filename = make_filename(self.id())
        sample_filename = base_filename + ".py"
        list_filename = base_filename + ".html"

        bsp_c3 = io.StringIO("""
           module bsp;
           public function void putc(byte c);
           """)
        march = "arm"
        with HtmlReportGenerator(open(list_filename, "w")) as reporter:
            ir_modules = build_sample_to_ir(src, lang, bsp_c3, march, reporter)

            # Test roundtrip of ir_modules
import unittest

from sample_helpers import add_samples, build
from helper_util import has_qemu, qemu, relpath
from helper_util import do_long_tests, make_filename
from ppci.format import uboot_image


@unittest.skipUnless(do_long_tests('microblaze'), 'skipping slow tests')
@add_samples('simple', 'medium')
class MicroblazeSamplesTestCase(unittest.TestCase):
    march = "microblaze"
    opt_level = 2

    def do(self, src, expected_output, lang='c3'):
        base_filename = make_filename(self.id())
        bsp_c3 = relpath('..', 'examples', 'microblaze', 'bsp.c3')
        crt0 = relpath('..', 'examples', 'microblaze', 'crt0.asm')
        mmap = relpath('..', 'examples', 'microblaze', 'layout.mmp')
        build(base_filename,
              src,
              bsp_c3,
              crt0,
              self.march,
              self.opt_level,
              mmap,
              lang=lang,
              bin_format='bin',
              code_image='flash')
        bin_filename = base_filename + '.bin'
Example #4
0
import unittest

from sample_helpers import add_samples, build
from helper_util import has_qemu, qemu, relpath
from helper_util import do_long_tests, make_filename


@unittest.skipUnless(do_long_tests("xtensa"), "skipping slow tests")
@add_samples("simple")
class TestSamplesOnXtensa(unittest.TestCase):
    march = "xtensa"
    opt_level = 0

    def do(self, src, expected_output, lang="c3"):
        base_filename = make_filename(self.id())
        bsp_c3 = relpath("..", "examples", "xtensa", "bsp.c3")
        crt0 = relpath("..", "examples", "xtensa", "glue.asm")
        mmap = relpath("..", "examples", "xtensa", "layout.mmp")
        build(
            base_filename,
            src,
            bsp_c3,
            crt0,
            self.march,
            self.opt_level,
            mmap,
            lang=lang,
            bin_format="elf",
            code_image="flash",
        )
        elf_filename = base_filename + ".elf"
import io
import unittest

from sample_helpers import add_samples, build

from helper_util import has_iverilog, run_picorv32
from helper_util import do_long_tests, do_iverilog, make_filename
from ppci.binutils.objectfile import merge_memories
from helper_util import has_qemu, qemu


@unittest.skipUnless(do_long_tests("riscv"), "skipping slow tests")
@add_samples("simple", "medium", "8bit", "32bit")
class TestSamplesOnRiscv(unittest.TestCase):
    opt_level = 2
    maxDiff = None
    march = "riscv"
    startercode = """
    global main_main 
    global bsp_exit 
    LUI sp, 0x1F        ; setup stack pointer
    JAL ra, main_main    ; Branch to sample start LR
    JAL ra, bsp_exit     ; do exit stuff LR
    EBREAK
    """
    arch_mmap = """
    MEMORY flash LOCATION=0x0000 SIZE=0x4000 {
         SECTION(code)
    }
    MEMORY ram LOCATION=0x4000 SIZE=0x4000 {
        SECTION(data)
import unittest
import io

from sample_helpers import add_samples
from helper_util import run_nodejs, relpath
from helper_util import do_long_tests, make_filename

from ppci.api import c3_to_ir, bf_to_ir, optimize, c_to_ir
from ppci.utils.reporting import HtmlReportGenerator
from ppci.lang.c import COptions
from ppci.wasm import ir_to_wasm
from ppci.irutils import ir_link


@unittest.skipUnless(do_long_tests('wasm'), 'skipping slow tests')
@add_samples('simple', 'medium', 'fp')
class TestSamplesOnWasm(unittest.TestCase):
    opt_level = 0

    def do(self, src, expected_output, lang='c3'):
        base_filename = make_filename(self.id())
        list_filename = base_filename + '.html'

        bsp = io.StringIO("""
           module bsp;
           public function void putc(byte c);
           """)
        march = 'arm'  # TODO: this must be wasm!
        with HtmlReportGenerator(open(list_filename, 'w')) as reporter:
            if lang == 'c3':
                ir_modules = [
Example #7
0
import unittest
import io
import os
import platform
import subprocess
from tempfile import mkstemp

from sample_helpers import add_samples, build
from helper_util import do_long_tests, make_filename

from ppci.api import asm, link, objcopy


@unittest.skipUnless(do_long_tests('x86_64'), 'skipping slow tests')
@add_samples('simple', 'medium', 'hard', '8bit', 'fp', 'double')
class TestSamplesOnX86Linux(unittest.TestCase):
    opt_level = 0
    march = "x86_64"
    startercode = """
    section reset

    global bsp_putc
    global main_main

    start:
        call main_main
        call bsp_exit

    bsp_putc:
            mov [0x20000000], rdi ; store char passed in rdi
Example #8
0
import unittest

from sample_helpers import add_samples, build
from helper_util import has_avr_emulator, run_avr, relpath
from helper_util import do_long_tests, do_iverilog, make_filename


@unittest.skipUnless(do_long_tests("avr"), "skipping slow tests")
@add_samples("8bit", "simple")
class TestSamplesOnAvr(unittest.TestCase):
    march = "avr"
    opt_level = 0

    def do(self, src, expected_output, lang="c3"):
        base_filename = make_filename(self.id())
        bsp_c3 = relpath("..", "examples", "avr", "bsp.c3")
        crt0 = relpath("..", "examples", "avr", "glue.asm")
        mmap = relpath("..", "examples", "avr", "avr.mmap")
        build(
            base_filename,
            src,
            bsp_c3,
            crt0,
            self.march,
            self.opt_level,
            mmap,
            lang=lang,
            bin_format="hex",
            code_image="flash",
        )
        hexfile = base_filename + ".hex"
Example #9
0
import unittest

from sample_helpers import add_samples, build
from helper_util import has_qemu, qemu, relpath
from helper_util import do_long_tests, make_filename
from ppci.format import uboot_image


@unittest.skipUnless(do_long_tests("microblaze"), "skipping slow tests")
@add_samples("simple", "medium")
class MicroblazeSamplesTestCase(unittest.TestCase):
    march = "microblaze"
    opt_level = 2

    def do(self, src, expected_output, lang="c3"):
        base_filename = make_filename(self.id())
        bsp_c3 = relpath("..", "examples", "microblaze", "bsp.c3")
        crt0 = relpath("..", "examples", "microblaze", "crt0.asm")
        mmap = relpath("..", "examples", "microblaze", "layout.mmp")
        build(
            base_filename,
            src,
            bsp_c3,
            crt0,
            self.march,
            self.opt_level,
            mmap,
            lang=lang,
            bin_format="bin",
            code_image="flash",
        )
import unittest

from sample_helpers import add_samples, build
from helper_util import has_qemu, qemu, relpath
from helper_util import do_long_tests, make_filename


@unittest.skipUnless(do_long_tests('xtensa'), 'skipping slow tests')
@add_samples('simple')
class TestSamplesOnXtensa(unittest.TestCase):
    march = "xtensa"
    opt_level = 0

    def do(self, src, expected_output, lang='c3'):
        base_filename = make_filename(self.id())
        bsp_c3 = relpath('..', 'examples', 'xtensa', 'bsp.c3')
        crt0 = relpath('..', 'examples', 'xtensa', 'glue.asm')
        mmap = relpath('..', 'examples', 'xtensa', 'layout.mmp')
        build(base_filename,
              src,
              bsp_c3,
              crt0,
              self.march,
              self.opt_level,
              mmap,
              lang=lang,
              bin_format='bin',
              code_image='flash')
        binfile = base_filename + '.bin'
        img_filename = base_filename + '.img'
        self.make_image(binfile, img_filename)
import io
import unittest

from sample_helpers import add_samples, build
from helper_util import relpath
from helper_util import has_iverilog, run_msp430
from helper_util import do_long_tests, do_iverilog, make_filename
from ppci.binutils.objectfile import merge_memories


@unittest.skipUnless(do_long_tests("msp430"), "skipping slow tests")
@add_samples("simple", "8bit")
class TestSamplesOnMsp430(unittest.TestCase):
    opt_level = 0
    startercode = """
      section reset_vector
        dw 0 ; 0
        dw 0 ; 1
        dw 0 ; 2
        dw 0 ; 3
        dw 0 ; 4
        dw 0 ; 5
        dw 0 ; 6
        dw 0 ; 7
        dw 0 ; 8
        dw 0 ; 9
        dw 0 ; 10
        dw 0 ; 11
        dw 0 ; 12
        dw 0 ; 13
        dw 0 ; 14
import unittest
import io

from sample_helpers import add_samples
from helper_util import relpath, run_python
from helper_util import do_long_tests, make_filename

from ppci.api import c3_to_ir, bf_to_ir, ir_to_python, optimize, c_to_ir
from ppci.utils.reporting import HtmlReportGenerator
from ppci.lang.c import COptions


@unittest.skipUnless(do_long_tests('python'), 'skipping slow tests')
@add_samples('simple', 'medium', 'hard', '8bit', 'fp', 'double', '32bit')
class TestSamplesOnPython(unittest.TestCase):
    opt_level = 0

    def do(self, src, expected_output, lang='c3'):
        base_filename = make_filename(self.id())
        sample_filename = base_filename + '.py'
        list_filename = base_filename + '.html'

        bsp = io.StringIO("""
           module bsp;
           public function void putc(byte c);
           """)
        march = 'arm'
        with HtmlReportGenerator(open(list_filename, 'w')) as reporter:
            if lang == 'c3':
                ir_modules = [c3_to_ir([
                    relpath('..', 'librt', 'io.c3'), bsp,
Example #13
0
import io
import unittest

from sample_helpers import add_samples, build
from helper_util import relpath
from helper_util import has_iverilog, run_msp430
from helper_util import do_long_tests, do_iverilog, make_filename
from ppci.binutils.objectfile import merge_memories


@unittest.skipUnless(do_long_tests('msp430'), 'skipping slow tests')
@add_samples('simple', '8bit')
class TestSamplesOnMsp430(unittest.TestCase):
    opt_level = 0
    startercode = """
      section reset_vector
        dw 0 ; 0
        dw 0 ; 1
        dw 0 ; 2
        dw 0 ; 3
        dw 0 ; 4
        dw 0 ; 5
        dw 0 ; 6
        dw 0 ; 7
        dw 0 ; 8
        dw 0 ; 9
        dw 0 ; 10
        dw 0 ; 11
        dw 0 ; 12
        dw 0 ; 13
        dw 0 ; 14
Example #14
0
import unittest
import io
import os
import platform
import subprocess
from tempfile import mkstemp

from sample_helpers import add_samples, build
from helper_util import do_long_tests, make_filename

from ppci.api import asm, link, objcopy


@unittest.skipUnless(do_long_tests("x86_64"), "skipping slow tests")
@add_samples("simple", "medium", "hard", "8bit", "fp", "double")
class TestSamplesOnX86Linux(unittest.TestCase):
    opt_level = 0
    march = "x86_64"

    def do(self, src, expected_output, lang="c3"):
        bsp_c3 = io.StringIO(BSP_C3_SRC)
        base_filename = make_filename(self.id())
        build(
            base_filename,
            src,
            bsp_c3,
            io.StringIO(STARTERCODE),
            self.march,
            self.opt_level,
            io.StringIO(ARCH_MMAP),
            lang=lang,
Example #15
0
import io
import unittest

from sample_helpers import add_samples, build

from helper_util import has_iverilog, run_picorv32
from helper_util import do_long_tests, do_iverilog, make_filename
from ppci.binutils.objectfile import merge_memories


@unittest.skipUnless(do_long_tests('riscv'), 'skipping slow tests')
@add_samples('simple', 'medium', '8bit', '32bit')
class TestSamplesOnRiscv(unittest.TestCase):
    opt_level = 2
    maxDiff = None
    march = "riscv"
    startercode = """
    global main_main 
    global bsp_exit 
    LUI sp, 0x1F        ; setup stack pointer
    JAL ra, main_main    ; Branch to sample start LR
    JAL ra, bsp_exit     ; do exit stuff LR
    EBREAK
    """
    arch_mmap = """
    MEMORY flash LOCATION=0x0000 SIZE=0x4000 {
         SECTION(code)
    }
    MEMORY ram LOCATION=0x4000 SIZE=0x4000 {
        SECTION(data)
    }