MCPcopy
hub / github.com/commaai/openpilot / test_driving

Method test_driving

tools/sim/tests/test_sim_bridge.py:23–84  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

21 self.processes = []
22
23 def test_driving(self):
24 # Startup manager and bridge.py. Check processes are running, then engage and verify.
25 p_manager = subprocess.Popen("./launch_openpilot.sh", cwd=SIM_DIR)
26 self.processes.append(p_manager)
27
28 sm = messaging.SubMaster(['selfdriveState', 'onroadEvents', 'managerState'])
29 q = Queue()
30 bridge = self.create_bridge()
31 p_bridge = bridge.run(q, retries=10)
32 self.processes.append(p_bridge)
33
34 max_time_per_step = 60
35
36 # Wait for bridge to startup
37 start_waiting = time.monotonic()
38 while not bridge.started.value and time.monotonic() < start_waiting + max_time_per_step:
39 time.sleep(0.1)
40 assert p_bridge.exitcode is None, f"Bridge process should be running, but exited with code {p_bridge.exitcode}"
41
42 start_time = time.monotonic()
43 no_car_events_issues_once = False
44 car_event_issues = []
45 not_running = []
46 while time.monotonic() < start_time + max_time_per_step:
47 sm.update()
48
49 not_running = [p.name for p in sm['managerState'].processes if not p.running and p.shouldBeRunning]
50 car_event_issues = [event.name for event in sm['onroadEvents'] if any([event.noEntry, event.softDisable, event.immediateDisable])]
51
52 if sm.all_alive() and len(car_event_issues) == 0 and len(not_running) == 0:
53 no_car_events_issues_once = True
54 break
55
56 assert no_car_events_issues_once, \
57 f"Failed because no messages received, or CarEvents '{car_event_issues}' or processes not running '{not_running}'"
58
59 start_time = time.monotonic()
60 min_counts_control_active = 100
61 control_active = 0
62
63 while time.monotonic() < start_time + max_time_per_step:
64 sm.update()
65
66 if sm.all_alive() and sm['selfdriveState'].active:
67 control_active += 1
68
69 if control_active == min_counts_control_active:
70 break
71
72 assert min_counts_control_active == control_active, f"Simulator did not engage a minimal of {min_counts_control_active} steps was {control_active}"
73
74 failure_states = []
75 while bridge.started.value:
76 continue
77
78 while not q.empty():
79 state = q.get()
80 if state.type == QueueMessageType.TERMINATION_INFO:

Callers

nothing calls this directly

Calls 7

updateMethod · 0.95
all_aliveMethod · 0.95
appendMethod · 0.80
create_bridgeMethod · 0.80
sleepMethod · 0.80
runMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected