Пример #1
0
def ap_thread(ap_tty, ap_log, runtime, processor):
    baud_rate = 115200

    ap_serial = serial.Serial(ap_tty, baud_rate, timeout=3000000, bytesize=serial.EIGHTBITS,
                               parity=serial.PARITY_NONE, xonxoff=False, rtscts=False, dsrdtr=False)
    ap_expect = pexpect_serial.SerialSpawn(ap_serial, timeout=3000000, encoding='utf-8', codec_errors='ignore')
    ap_expect.logfile = ap_log

    ap_expect.expect(isp_utils.terminateMessage(runtime))
Пример #2
0
def launchQEMU(run_dir, runtime, env, options):
    global process_exit
    terminate_msg = isp_utils.terminateMessage(runtime)
    status_log = open(os.path.join(run_dir, status_log_file), "w+")

    try:
        logger.debug("Running qemu cmd: {}\n".format(
            qemuCommand(run_cmd, env, options)))
        rc = subprocess.Popen([run_cmd] + options,
                              env=env,
                              stdout=status_log,
                              stderr=subprocess.STDOUT)
        while rc.poll() is None and not process_exit:
            time.sleep(1)
            try:
                uart_log = open(os.path.join(run_dir, uart_log_file), 'r')
                uart_output = uart_log.read()
                uart_log.close()
                if terminate_msg in uart_output:
                    rc.terminate()
                    process_exit = True
                    return
            except IOError:
                #keep trying if fail to open uart log
                pass
            except UnicodeDecodeError:
                # TODO: is this really what we want to do on this exception?
                rc.terminate()
                process_exit = True
                return
        if rc.returncode != 0:
            raise Exception("exited with return code " + str(rc.returncode))
    except Exception as e:
        logger.error("QEMU run failed for exception {}.\n".format(e))
    finally:
        process_exit = True
        rc.terminate()

        # using grep because the pex log can get large when debug is on
        grep_cmd = [
            "grep", "Policy Violation\\|TMT miss",
            os.path.join(run_dir, status_log_file)
        ]
        grep_results = subprocess.run(grep_cmd,
                                      env=env,
                                      stdout=subprocess.PIPE)
        if "Policy Violation" in str(grep_results.stdout):
            logger.warn("Process exited due to policy violation")
        if "TMT miss" in str(grep_results.stdout):
            logger.warn("Process exited due to TMT miss")
Пример #3
0
def getProcessExitCode(run_dir, runtime):
    try:
        process_log = open(os.path.join(run_dir, "uart.log"))
    except:
        return
    process_out = process_log.readlines()
    hex_pattern = r"0x[0-9A-Fa-f]+$"
    for line in process_out:
        if isp_utils.terminateMessage(runtime.replace("stock_", '')) in line:
            matches = re.findall(hex_pattern, line)

            if len(matches) > 0:
                return int(matches[0], 0)

    return -1
Пример #4
0
def launchQEMU(exe_path, run_dir, policy_dir, runtime, extra, use_validator=True):
    global process_exit
    terminate_msg = isp_utils.terminateMessage(runtime)
    sim_log = open(os.path.join(run_dir, sim_log_file), "w+")

    opts = qemuOptions(exe_path, run_dir, extra, runtime, use_validator, gdb_port=0)

    env = qemuEnv(use_validator, policy_dir)

    try:
        logger.debug("Running qemu cmd:{}\n".format(str([run_cmd] + opts)))
        rc = subprocess.Popen([run_cmd] + opts, env=env, stdout=sim_log,
                              stderr=subprocess.STDOUT)
        while rc.poll() is None:
            time.sleep(1)
            try:
                if terminate_msg in open(os.path.join(run_dir, uart_log_file), 'r').read() or process_exit:
                    rc.terminate()
                    process_exit = True
                    return
                if "Policy Violation:" in open(os.path.join(run_dir, status_log_file), 'r').read() or process_exit:
                    rc.terminate()
                    process_exit = True
                    logger.warn("Process exited due to policy violation")
                    return
            except IOError:
                #keep trying if fail to open uart log
                pass
            except UnicodeDecodeError:
                # TODO: is this really what we want to do on this exception?
                rc.terminate()
                process_exit = True
                return;
        if rc.returncode != 0:
            raise Exception("exited with return code " + str(rc.returncode))
        process_exit = True
    except Exception as e:
        logger.error("QEMU run failed for exception {}.\n".format(e))
        raise
Пример #5
0
def logUart(run_dir, runtime):
    uart_log_path = os.path.join(run_dir, uart_log_file)
    logPort(isp_utils.terminateMessage(runtime), uart_log_path, uart_port)