예제 #1
0
def send_host_interrupt(*unused):
    try:
        os.remove(SEND_PIPE_NAME)
    except OSError:
        pass  # Ignore if pipe doesn't exist

    hex_file = test_harness.build_program(['send_host_interrupt.S'])

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

    args = [test_harness.EMULATOR_PATH, '-o', SEND_PIPE_NAME, hex_file]
    emulator_process = subprocess.Popen(args,
                                        stdout=subprocess.PIPE,
                                        stderr=subprocess.STDOUT)

    try:
        interrupt_pipe = os.open(SEND_PIPE_NAME, os.O_RDONLY | os.O_NONBLOCK)
        test_harness.TimedProcessRunner().communicate(emulator_process, 60)

        # Interrupts should be in pipe now
        interrupts = os.read(interrupt_pipe, 5)
        if interrupts != b'\x05\x06\x07\x08\x09':
            raise test_harness.TestException(
                'Did not receive proper host interrupts')
    finally:
        os.close(interrupt_pipe)
        os.unlink(SEND_PIPE_NAME)
예제 #2
0
    def get_result(self):
        """Wait for the process to exit and return its output.

        This does not check the exit value of the program.

        Args:
            None

        Returns:
            (string, string) Standard out and standard error

        Raises:
            TestException if the program does not exit in
            RECEIVE_TIMEOUT_S seconds.
        """
        out, err = test_harness.TimedProcessRunner().communicate(
            self.serial_boot_process, RECEIVE_TIMEOUT_S)
        return out.decode('ascii'), err.decode('ascii')
예제 #3
0
def uart_echo_test(*unused):
    '''
    The emulator direct all UART traffic through the terminal that
    it is launched from. This validates transfers in both directions.
    '''
    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 + '"')
예제 #4
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)