Example #1
0
def filesystem(_, target):
    '''
    Filesystem tests. This creates a filesystem image with the test file fstest.txt
    in it, the compiles the program fs.c to perform operations on it. The program
    will print 'PASS' if it is successful.
    '''

    test_harness.build_program(['fs.c'])
    subprocess.check_output([
        test_harness.BIN_DIR + 'mkfs', test_harness.WORK_DIR + '/fsimage.bin',
        'fstest.txt'
    ],
                            stderr=subprocess.STDOUT)
    result = test_harness.run_program(target=target,
                                      block_device=test_harness.WORK_DIR +
                                      '/fsimage.bin')
    if 'PASS' not in result or 'FAIL' in result:
        raise test_harness.TestException(
            'test program did not indicate pass\n' + result)
Example #2
0
    def recv_serial(self):
        """Receive a single byte from the serial loader program.

        The byte is meant to be sent to the dev board.
        Args:
            None

        Returns:
            integer byte value

        Raises:
            TestException if nothing can be read for over RECEIVE_TIMEOUT_S
            seconds.
        """
        r, _w, _e = select.select([self.pipe], [], [], RECEIVE_TIMEOUT_S)
        if self.pipe in r:
            return ord(os.read(self.pipe, 1))
        else:
            raise test_harness.TestException('serial read timed out')
Example #3
0
def uart_echo_test(*unused):
    '''Validate UART transfers  in both directions.

    The emulator direct all UART traffic through the terminal that
    it is launched from.
    '''
    executable = test_harness.build_program(['uart_echo_test.c'])

    args = [test_harness.EMULATOR_PATH, executable]

    in_str = 'THE QUICK brOwn FOX jumPED Over THE LAZY DOG\n'
    process = subprocess.Popen(args,
                               stdin=subprocess.PIPE,
                               stdout=subprocess.PIPE)
    out_str, _ = test_harness.TimedProcessRunner().communicate(
        process=process, timeout=10, input=in_str.encode('ascii'))
    out_str = out_str.decode()
    if 'the quick brown fox jumped over the lazy dog' not in out_str:
        raise test_harness.TestException(
            'Subprocess returned incorrect result \"' + out_str + '"')
Example #4
0
def filesystem(_, target):
    """Test the filesystem implementation in libos.

    This creates a filesystem image with the test file fstest.txt
    in it, the compiles the program fs.c to perform operations on it. The program
    will print 'PASS' if it is successful.
    """

    hex_file = test_harness.build_program(['fs.c'])
    subprocess.check_output([
        os.path.join(test_harness.TOOL_BIN_DIR, 'mkfs'), FS_IMAGE_PATH,
        'fstest.txt'
    ],
                            stderr=subprocess.STDOUT)
    result = test_harness.run_program(hex_file,
                                      target,
                                      block_device=FS_IMAGE_PATH)
    if 'PASS' not in result or 'FAIL' in result:
        raise test_harness.TestException(
            'test program did not indicate pass\n' + result)
Example #5
0
    def expect_serial_bytes(self, expect_sequence):
        """Receive a sequence of bytes from the serial loader and check them.

        Args:
            expect_sequence: list of int
                The sequence of byte values that are expected to be received.

        Returns:
            Nothing

        Raises:
            TestException if the program doesn't send_serial this sequence of bytes
        """
        if test_harness.DEBUG:
            print('expect bytes: ' + str(expect_sequence))

        for index, expect_byte in enumerate(expect_sequence):
            got = self.recv_serial()
            if got != expect_byte:
                raise test_harness.TestException('serial mismatch @{}: expected {} got {}'.format(
                    index, expect_byte, got))
Example #6
0
def recv_host_interrupt(_, target):
    try:
        os.remove(RECV_PIPE_NAME)
    except OSError:
        pass  # Ignore if pipe doesn't exist

    test_harness.build_program(['recv_host_interrupt.S'])

    os.mknod(RECV_PIPE_NAME, stat.S_IFIFO | 0o666)

    args = [
        test_harness.BIN_DIR + 'emulator', '-i', RECV_PIPE_NAME,
        test_harness.HEX_FILE
    ]
    emulator_process = subprocess.Popen(args,
                                        stdout=subprocess.PIPE,
                                        stderr=subprocess.STDOUT)

    try:
        interrupt_pipe = os.open(RECV_PIPE_NAME, os.O_WRONLY)

        # Send periodic interrupts to process'
        try:
            for intnum in range(5):
                os.write(interrupt_pipe, str.encode(chr(intnum)))
                time.sleep(0.2)
        except OSError:
            # Broken pipe will occur if the emulator exits early.
            # We'll flag an error after communicate if we don't see a PASS.
            pass

        # Wait for completion
        result, _ = test_harness.TimedProcessRunner().communicate(
            emulator_process, 60)
        strresult = str(result)
        if 'PASS' not in strresult or 'FAIL' in strresult:
            raise test_harness.TestException('Test failed ' + strresult)
    finally:
        os.close(interrupt_pipe)
        os.unlink(RECV_PIPE_NAME)
Example #7
0
    def expect_serial_int(self, expected):
        """Check a 32-bit value received from the serial port.

        The value is four bytes in little endian order.
        Args:
            expected: int
                The value that should be received

        Returns:
            Nothing

        Raises:
            TestException if the number doesn't match.
        """
        if test_harness.DEBUG:
            print('expect int: ' + str(expected))

        intval = self.recv_serial()
        intval |= self.recv_serial() << 8
        intval |= self.recv_serial() << 16
        intval |= self.recv_serial() << 24
        if intval != expected:
            raise test_harness.TestException('Int value mismatch: wanted {} got {}'.format(
                expected, intval))
Example #8
0
def perf_counters(_):
    test_harness.build_program(['perf_counters.c'])
    result = test_harness.run_program(environment='verilator')
    if 'PASS' not in result:
        raise test_harness.TestException(
            'test program did not indicate pass\n' + result)
Example #9
0
def ps2(_, target):
    test_harness.build_program(['ps2.c'])
    result = test_harness.run_program(target)
    if 'PASS' not in result:
        raise test_harness.TestException('program did not indicate pass\n' +
                                         result)
Example #10
0
def multicore(_):
    test_harness.build_program(['multicore.c'])
    result = test_harness.run_program(environment='verilator')
    if '012345678910111213141516171819202122232425262728293031' not in result.replace('\n', ''):
        raise test_harness.TestException('Output mismatch:\n' + result)
Example #11
0
def test_fill_emulator(name):
    test_harness.compile_test(['fill_test.c', 'wrap_tlb_miss_handler.s'])
    result = test_harness.run_emulator()
    if result.find('FAIL') != -1 or result.find('PASS') == -1:
        raise test_harness.TestException(result + '\ntest did not signal pass')
Example #12
0
def uart_hw_test(*unused):
    test_harness.build_program(['uart_hw_test.c'])
    result = test_harness.run_program(target='verilator')
    if 'PASS' not in result:
        raise test_harness.TestException('test did not indicate pass\n' +
                                         result)
Example #13
0
def iinvalidate(_, target):
    hex_file = test_harness.build_program(['iinvalidate.S'])
    output = test_harness.run_program(hex_file, target)
    if 'PASS' not in output:
        raise test_harness.TestException('Test did not signal pass: ' + output)
Example #14
0
def dflush_wait(_, target):
    hex_file = test_harness.build_program(['dflush_wait.S'])
    output = test_harness.run_program(hex_file, target)
    if 'PASS' not in output:
        raise test_harness.TestException('Test did not signal pass: ' + output)
Example #15
0
def perf_counters(_, target):
    test_harness.build_program(['perf_counters.c'])
    result = test_harness.run_program(target)
    if 'PASS' not in result:
        raise test_harness.TestException(
            'test program did not indicate pass\n' + result)
Example #16
0
def multicore(_, target):
    hex_file = test_harness.build_program(['multicore.S'])
    result = test_harness.run_program(hex_file, target)
    if 'ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`' not in result:
        raise test_harness.TestException('Output mismatch:\n' + result)
Example #17
0
def uart(_):
    test_harness.build_program(['uart.c'])
    result = test_harness.run_program(environment='verilator')
    if 'PASS' not in result:
        raise test_harness.TestException(
            'test did not indicate pass\n' + result)
Example #18
0
def iinvalidate(_):
    test_harness.build_program(['iinvalidate.S'])
    output = test_harness.run_program(environment='verilator')
    if 'PASS' not in output:
        raise test_harness.TestException('Test did not signal pass: ' + output)
Example #19
0
def dflush_wait(_):
    test_harness.build_program(['dflush_wait.S'])
    output = test_harness.run_program(environment='verilator')
    if 'PASS' not in output:
        raise test_harness.TestException('Test did not signal pass: ' + output)