2021-10-27 00:50:05 -06:00
|
|
|
import os
|
2020-08-25 19:31:49 -06:00
|
|
|
import time
|
2020-07-05 18:56:24 -06:00
|
|
|
from functools import wraps
|
|
|
|
|
2020-12-16 22:30:23 -07:00
|
|
|
from selfdrive.hardware import PC
|
2021-03-05 03:03:23 -07:00
|
|
|
from selfdrive.manager.process_config import managed_processes
|
2021-10-25 10:44:04 -06:00
|
|
|
from selfdrive.version import training_version, terms_version
|
2021-03-05 03:03:23 -07:00
|
|
|
|
2020-07-05 18:56:24 -06:00
|
|
|
|
2020-07-25 03:12:19 -06:00
|
|
|
def set_params_enabled():
|
2020-10-13 08:23:23 -06:00
|
|
|
from common.params import Params
|
2020-07-25 03:12:19 -06:00
|
|
|
params = Params()
|
2020-08-08 21:59:32 -06:00
|
|
|
params.put("HasAcceptedTerms", terms_version)
|
2020-07-25 03:12:19 -06:00
|
|
|
params.put("CompletedTrainingVersion", training_version)
|
2021-04-07 07:36:37 -06:00
|
|
|
params.put_bool("OpenpilotEnabledToggle", True)
|
|
|
|
params.put_bool("CommunityFeaturesToggle", True)
|
|
|
|
params.put_bool("Passive", False)
|
2020-07-25 03:12:19 -06:00
|
|
|
|
2021-03-05 03:03:23 -07:00
|
|
|
|
2021-10-25 10:44:04 -06:00
|
|
|
def phone_only(f):
|
|
|
|
@wraps(f)
|
|
|
|
def wrap(self, *args, **kwargs):
|
|
|
|
if PC:
|
|
|
|
self.skipTest("This test is not meant to run on PC")
|
|
|
|
f(self, *args, **kwargs)
|
|
|
|
return wrap
|
2020-07-05 18:56:24 -06:00
|
|
|
|
2021-10-27 00:50:05 -06:00
|
|
|
def release_only(f):
|
|
|
|
@wraps(f)
|
|
|
|
def wrap(self, *args, **kwargs):
|
|
|
|
if "RELEASE" not in os.environ:
|
|
|
|
self.skipTest("This test is only for release branches")
|
|
|
|
f(self, *args, **kwargs)
|
|
|
|
return wrap
|
2021-03-05 03:03:23 -07:00
|
|
|
|
2021-04-08 09:48:57 -06:00
|
|
|
def with_processes(processes, init_time=0, ignore_stopped=None):
|
|
|
|
ignore_stopped = [] if ignore_stopped is None else ignore_stopped
|
|
|
|
|
2020-07-05 18:56:24 -06:00
|
|
|
def wrapper(func):
|
|
|
|
@wraps(func)
|
2020-08-25 19:31:49 -06:00
|
|
|
def wrap(*args, **kwargs):
|
2020-07-05 18:56:24 -06:00
|
|
|
# start and assert started
|
2020-10-01 19:42:43 -06:00
|
|
|
for n, p in enumerate(processes):
|
2021-03-05 03:03:23 -07:00
|
|
|
managed_processes[p].start()
|
|
|
|
if n < len(processes) - 1:
|
2020-10-01 19:42:43 -06:00
|
|
|
time.sleep(init_time)
|
2021-03-05 03:03:23 -07:00
|
|
|
assert all(managed_processes[name].proc.exitcode is None for name in processes)
|
2020-07-05 18:56:24 -06:00
|
|
|
|
|
|
|
# call the function
|
|
|
|
try:
|
2020-08-25 19:31:49 -06:00
|
|
|
func(*args, **kwargs)
|
2020-07-05 18:56:24 -06:00
|
|
|
# assert processes are still started
|
2021-04-08 09:48:57 -06:00
|
|
|
assert all(managed_processes[name].proc.exitcode is None for name in processes if name not in ignore_stopped)
|
2020-07-05 18:56:24 -06:00
|
|
|
finally:
|
2020-08-25 19:31:49 -06:00
|
|
|
for p in processes:
|
2021-03-05 03:03:23 -07:00
|
|
|
managed_processes[p].stop()
|
|
|
|
|
2020-07-05 18:56:24 -06:00
|
|
|
return wrap
|
|
|
|
return wrapper
|