Skip to content

Commit 4eed05f

Browse files
committed
Restart simulator and full system between tests
1 parent f60d642 commit 4eed05f

3 files changed

Lines changed: 29 additions & 1 deletion

File tree

src/software/gameplay_tests/fixture.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ class SessionContext:
6161
"""The RobotCommunication instance, only set for field tests"""
6262
estop_mode: Optional[Any] = None
6363
"""The EstopMode, only set for field tests"""
64+
simulator: Optional[Any] = None
65+
"""The Simulator context manager, only set for simulated tests"""
66+
blue_full_system: Optional[Any] = None
67+
"""The blue FullSystem context manager, only set for simulated tests"""
68+
yellow_full_system: Optional[Any] = None
69+
"""The yellow FullSystem context manager, only set for simulated tests"""
6470

6571

6672
@pytest.fixture
@@ -108,6 +114,13 @@ def bound_runner(session):
108114
owns_thunderscope=False,
109115
)
110116
else:
117+
# Relaunch the simulator and full systems so each test starts from clean state.
118+
# The ProtoUnixIOs reconnect automatically.
119+
context.simulator.restart()
120+
context.blue_full_system.restart()
121+
context.yellow_full_system.restart()
122+
time.sleep(LAUNCH_DELAY_S)
123+
111124
runner = SimulatedTestRunner(
112125
test_name,
113126
session.thunderscope,
@@ -178,7 +191,6 @@ def simulated_session(args, runtime_subpath):
178191
gamecontroller.setup_proto_unix_io(
179192
blue_full_system_proto_unix_io=blue_full_system_proto_unix_io,
180193
yellow_full_system_proto_unix_io=yellow_full_system_proto_unix_io,
181-
simulator_proto_unix_io=simulator_proto_unix_io,
182194
)
183195

184196
time.sleep(LAUNCH_DELAY_S)
@@ -188,6 +200,9 @@ def simulated_session(args, runtime_subpath):
188200
yellow_full_system_proto_unix_io=yellow_full_system_proto_unix_io,
189201
simulator_proto_unix_io=simulator_proto_unix_io,
190202
gamecontroller=gamecontroller,
203+
simulator=simulator,
204+
blue_full_system=blue_fs,
205+
yellow_full_system=yellow_fs,
191206
)
192207

193208

src/software/thunderscope/binary_context_managers/full_system.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,11 @@ def __exit__(self, type, value, traceback) -> None:
207207
except TimeoutExpired:
208208
self.full_system_proc.kill()
209209

210+
def restart(self) -> None:
211+
"""Kill and relaunch the full_system process at the same runtime dir."""
212+
kill_cmd_if_running(self.generic_command)
213+
self.full_system_proc = Popen(self.full_system.split(" "))
214+
210215
def setup_proto_unix_io(self, proto_unix_io: ProtoUnixIO) -> None:
211216
"""Helper to run full system and attach the appropriate unix senders/listeners
212217

src/software/thunderscope/binary_context_managers/simulator.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ def __enter__(self) -> Simulator:
6464
if self.enable_realism:
6565
simulator_command += " --enable_realism"
6666

67+
# Stored so the process can be relaunched via restart()
68+
self.simulator_command = simulator_command
69+
6770
if self.debug_simulator:
6871
# We don't want to check the exact command because this binary could
6972
# be debugged from clion or somewhere other than gdb
@@ -107,6 +110,11 @@ def __exit__(self, type, value, traceback) -> None:
107110
self.er_force_simulator_proc.kill()
108111
self.er_force_simulator_proc.wait()
109112

113+
def restart(self) -> None:
114+
"""Kill and relaunch the simulator process at the same runtime dir."""
115+
kill_cmd_if_running(self.generic_command)
116+
self.er_force_simulator_proc = Popen(self.simulator_command.split(" "))
117+
110118
def setup_proto_unix_io(
111119
self,
112120
simulator_proto_unix_io: ProtoUnixIO,

0 commit comments

Comments
 (0)