2021-10-26 23:50:05 -07:00
|
|
|
import os
|
2020-08-25 18:31:49 -07:00
|
|
|
import time
|
2020-07-05 17:56:24 -07:00
|
|
|
from functools import wraps
|
|
|
|
|
|
2020-12-16 21:30:23 -08:00
|
|
|
from selfdrive.hardware import PC
|
2021-03-05 11:03:23 +01:00
|
|
|
from selfdrive.manager.process_config import managed_processes
|
2021-10-25 09:44:04 -07:00
|
|
|
from selfdrive.version import training_version, terms_version
|
2021-03-05 11:03:23 +01:00
|
|
|
|
2020-07-05 17:56:24 -07:00
|
|
|
|
2020-07-25 02:12:19 -07:00
|
|
|
def set_params_enabled():
|
2020-10-13 16:23:23 +02:00
|
|
|
from common.params import Params
|
2020-07-25 02:12:19 -07:00
|
|
|
params = Params()
|
2020-08-08 20:59:32 -07:00
|
|
|
params.put("HasAcceptedTerms", terms_version)
|
2020-07-25 02:12:19 -07:00
|
|
|
params.put("CompletedTrainingVersion", training_version)
|
2021-04-07 15:36:37 +02:00
|
|
|
params.put_bool("OpenpilotEnabledToggle", True)
|
|
|
|
|
params.put_bool("CommunityFeaturesToggle", True)
|
|
|
|
|
params.put_bool("Passive", False)
|
2020-07-25 02:12:19 -07:00
|
|
|
|
2021-03-05 11:03:23 +01:00
|
|
|
|
2021-10-25 09:44:04 -07: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 17:56:24 -07:00
|
|
|
|
2021-10-26 23:50:05 -07: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 11:03:23 +01:00
|
|
|
|
2021-04-08 17:48:57 +02:00
|
|
|
def with_processes(processes, init_time=0, ignore_stopped=None):
|
|
|
|
|
ignore_stopped = [] if ignore_stopped is None else ignore_stopped
|
|
|
|
|
|
2020-07-05 17:56:24 -07:00
|
|
|
def wrapper(func):
|
|
|
|
|
@wraps(func)
|
2020-08-25 18:31:49 -07:00
|
|
|
def wrap(*args, **kwargs):
|
2020-07-05 17:56:24 -07:00
|
|
|
# start and assert started
|
2020-10-01 18:42:43 -07:00
|
|
|
for n, p in enumerate(processes):
|
2021-03-05 11:03:23 +01:00
|
|
|
managed_processes[p].start()
|
|
|
|
|
if n < len(processes) - 1:
|
2020-10-01 18:42:43 -07:00
|
|
|
time.sleep(init_time)
|
2021-03-05 11:03:23 +01:00
|
|
|
assert all(managed_processes[name].proc.exitcode is None for name in processes)
|
2020-07-05 17:56:24 -07:00
|
|
|
|
|
|
|
|
# call the function
|
|
|
|
|
try:
|
2020-08-25 18:31:49 -07:00
|
|
|
func(*args, **kwargs)
|
2020-07-05 17:56:24 -07:00
|
|
|
# assert processes are still started
|
2021-04-08 17:48:57 +02:00
|
|
|
assert all(managed_processes[name].proc.exitcode is None for name in processes if name not in ignore_stopped)
|
2020-07-05 17:56:24 -07:00
|
|
|
finally:
|
2020-08-25 18:31:49 -07:00
|
|
|
for p in processes:
|
2021-03-05 11:03:23 +01:00
|
|
|
managed_processes[p].stop()
|
|
|
|
|
|
2020-07-05 17:56:24 -07:00
|
|
|
return wrap
|
|
|
|
|
return wrapper
|