def test_no_timeout(self, mock_time, mock_sleep): with Timeout(0.05) as to: cnt = 0 while to.check(): mock_sleep(0.01) cnt += 1 if cnt == 2: break else: assert False assert not to.did_time_out
def test_timeout_b(self, mock_time, mock_sleep): timedout = False print(repr(time)) with Timeout(0.05) as to: cnt = 0 while cnt < 10: if to.did_time_out: timedout = True mock_sleep(0.02) cnt += 1 assert timedout assert to.did_time_out
def test_timeout_b(self): timedout = False s = time() with Timeout(0.05) as to: cnt = 0 while cnt < 10: if to.did_time_out: timedout = True sleep(0.02) cnt += 1 assert timedout assert to.did_time_out assert (time() - s) >= 0.05
def run_til_halt(tgt, semihostagent): with Timeout(2.0) as t: logging.info("Resuming target") tgt.resume() while True: if not t.check(): tgt.halt() return False if tgt.get_state() == Target.State.HALTED: logging.info("Target halted") didHandle = semihostagent.check_and_handle_semihost_request() if didHandle: logging.info("Semihost request handled") else: logging.info("Non-semihost break") return didHandle
def test_timeout_reset(self, mock_time, mock_sleep): cnt = 0 cnta = 0 with Timeout(0.05) as to: cnta = 0 while cnta < 3: cnt = 0 while to.check(): mock_sleep(0.01) if cnta > 1: break cnt += 1 else: assert to.did_time_out to.clear() to.start() cnta += 1 assert cnta == 3 and cnt == 0 assert not to.did_time_out
def test_timeout_a(self, mock_time, mock_sleep): with Timeout(0.05) as to: while to.check(): mock_sleep(0.01) assert to.did_time_out
def test_probeserver(board_id=None, n=0): test_port = 5555 + n temp_test_elf_name = None result = ProbeserverTestResult() print("Connecting to identify target") with ConnectHelper.session_with_chosen_probe( unique_id=board_id, **get_session_options()) as session: board = session.board target_test_params = get_target_test_params(session) binary_file = get_test_binary_path(board.test_binary) if board_id is None: board_id = board.unique_id target_type = board.target_type # Run the test. We can't kill the server thread, so LOG.info('Starting server on port %d', test_port) server_args = [ 'pyocd', 'server', '-v', '--port=%i' % test_port, "--uid=%s" % board_id, ] server_program = Popen(server_args, stdout=PIPE, stderr=STDOUT) try: # Read server output waiting for it to report that the server is running. with Timeout(TEST_TIMEOUT_SECONDS) as time_out: while time_out.check(): ln = server_program.stdout.readline().decode('ascii') print("Server:", ln, end='') if "Serving debug probe" in ln: break if ln == '': raise TestError("no more output from server") else: raise TestError("server failed to start") server_thread = threading.Thread( target=wait_with_deadline, args=[server_program, TEST_TIMEOUT_SECONDS]) server_thread.daemon = True server_thread.start() # Start client in a thread. client_args = [ 'flash', "--frequency=%i" % target_test_params['test_clock'], "--uid=remote:localhost:%d" % test_port, "--target=%s" % target_type, binary_file ] client = PyOCDTool() client._setup_logging = lambda: None # Disable logging setup so we don't have duplicate log output. LOG.info('Starting client: %s', ' '.join(client_args)) client_thread = threading.Thread(target=client.run, args=[client_args]) client_thread.daemon = True client_thread.start() LOG.info('Waiting for client to finish...') client_thread.join(timeout=TEST_TIMEOUT_SECONDS) did_complete = not client_thread.is_alive() if not did_complete: LOG.error("Test timed out!") LOG.info("killing probe server process") server_program.kill() except TestError as err: LOG.info("test failed: %s", err) did_complete = False if server_program.returncode is None: server_program.kill() # Read back the result result.passed = did_complete if result.passed: print("PROBESERVER TEST PASSED") else: print("PROBESERVER TEST FAILED") return result