2727PROC_REPLAY_DIR = os .path .dirname (os .path .abspath (__file__ ))
2828FAKEDATA = os .path .join (PROC_REPLAY_DIR , "fakedata/" )
2929
30- ProcessConfig = namedtuple ('ProcessConfig' , ['proc_name' , 'pub_sub' , 'ignore' , 'init_callback' , 'should_recv_callback' , 'tolerance' , 'fake_pubsubmaster' , 'submaster_config' ], defaults = ({},))
30+ ProcessConfig = namedtuple ('ProcessConfig' , ['proc_name' , 'pub_sub' , 'ignore' , 'init_callback' , 'should_recv_callback' , 'tolerance' , 'fake_pubsubmaster' , 'submaster_config' , 'environ' , 'subtest_name' ], defaults = ({}, {}, "" ))
3131
3232
3333def wait_for_event (evt ):
3434 if not evt .wait (TIMEOUT ):
3535 if threading .currentThread ().getName () == "MainThread" :
3636 # tested process likely died. don't let test just hang
37- raise Exception ("Timeout reached. Tested process likely crashed." )
37+ raise Exception (f "Timeout reached. Tested process { os . environ [ 'PROC_NAME' ] } likely crashed." )
3838 else :
3939 # done testing this process, let it die
4040 sys .exit (0 )
@@ -190,6 +190,7 @@ def get_car_params(msgs, fsm, can_sock, fingerprint):
190190 _ , CP = get_car (can , sendcan )
191191 Params ().put ("CarParams" , CP .to_bytes ())
192192
193+
193194def controlsd_rcv_callback (msg , CP , cfg , fsm ):
194195 # no sendcan until controlsd is initialized
195196 socks = [s for s in cfg .pub_sub [msg .which ()] if
@@ -198,6 +199,7 @@ def controlsd_rcv_callback(msg, CP, cfg, fsm):
198199 socks .remove ("sendcan" )
199200 return socks , len (socks ) > 0
200201
202+
201203def radar_rcv_callback (msg , CP , cfg , fsm ):
202204 if msg .which () != "can" :
203205 return [], False
@@ -240,7 +242,7 @@ def laika_rcv_callback(msg, CP, cfg, fsm):
240242 if msg .ubloxGnss .which () == "measurementReport" :
241243 return ["gnssMeasurements" ], True
242244 else :
243- return [], False
245+ return [], True
244246
245247
246248CONFIGS = [
@@ -345,6 +347,19 @@ def laika_rcv_callback(msg, CP, cfg, fsm):
345347 tolerance = None ,
346348 fake_pubsubmaster = False ,
347349 ),
350+ ProcessConfig (
351+ proc_name = "laikad" ,
352+ subtest_name = "Offline" ,
353+ pub_sub = {
354+ "ubloxGnss" : ["gnssMeasurements" ],
355+ },
356+ ignore = ["logMonoTime" ],
357+ init_callback = get_car_params ,
358+ should_recv_callback = laika_rcv_callback ,
359+ tolerance = NUMPY_TOLERANCE ,
360+ fake_pubsubmaster = True ,
361+ environ = {"LAIKAD_NO_INTERNET" : "1" },
362+ ),
348363 ProcessConfig (
349364 proc_name = "laikad" ,
350365 pub_sub = {
@@ -366,7 +381,8 @@ def replay_process(cfg, lr, fingerprint=None):
366381 else :
367382 return cpp_replay_process (cfg , lr , fingerprint )
368383
369- def setup_env (simulation = False , CP = None ):
384+
385+ def setup_env (simulation = False , CP = None , cfg = None ):
370386 params = Params ()
371387 params .clear_all ()
372388 params .put_bool ("OpenpilotEnabledToggle" , True )
@@ -380,6 +396,16 @@ def setup_env(simulation=False, CP=None):
380396 os .environ ['SKIP_FW_QUERY' ] = ""
381397 os .environ ['FINGERPRINT' ] = ""
382398
399+ if cfg is not None :
400+ # Clear all custom processConfig environment variables
401+ for cfg in CONFIGS :
402+ for k , _ in cfg .environ .items ():
403+ if k in os .environ :
404+ del os .environ [k ]
405+
406+ os .environ .update (cfg .environ )
407+ os .environ ['PROC_NAME' ] = cfg .proc_name
408+
383409 if simulation :
384410 os .environ ["SIMULATION" ] = "1"
385411 elif "SIMULATION" in os .environ :
@@ -396,6 +422,7 @@ def setup_env(simulation=False, CP=None):
396422 os .environ ['SKIP_FW_QUERY' ] = "1"
397423 os .environ ['FINGERPRINT' ] = CP .carFingerprint
398424
425+
399426def python_replay_process (cfg , lr , fingerprint = None ):
400427 sub_sockets = [s for _ , sub in cfg .pub_sub .items () for s in sub ]
401428 pub_sockets = [s for s in cfg .pub_sub .keys () if s != 'can' ]
@@ -413,10 +440,10 @@ def python_replay_process(cfg, lr, fingerprint=None):
413440 if fingerprint is not None :
414441 os .environ ['SKIP_FW_QUERY' ] = "1"
415442 os .environ ['FINGERPRINT' ] = fingerprint
416- setup_env ()
443+ setup_env (cfg = cfg )
417444 else :
418445 CP = [m for m in lr if m .which () == 'carParams' ][0 ].carParams
419- setup_env (CP = CP )
446+ setup_env (CP = CP , cfg = cfg )
420447
421448 assert (type (managed_processes [cfg .proc_name ]) is PythonProcess )
422449 managed_processes [cfg .proc_name ].prepare ()
@@ -477,7 +504,7 @@ def cpp_replay_process(cfg, lr, fingerprint=None):
477504 log_msgs = []
478505
479506 # We need to fake SubMaster alive since we can't inject a fake clock
480- setup_env (simulation = True )
507+ setup_env (simulation = True , cfg = cfg )
481508
482509 managed_processes [cfg .proc_name ].prepare ()
483510 managed_processes [cfg .proc_name ].start ()
0 commit comments