You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
2.3 KiB
78 lines
2.3 KiB
4 years ago
|
#!/usr/bin/env python3
|
||
|
import os
|
||
1 year ago
|
import pytest
|
||
4 years ago
|
import signal
|
||
|
import time
|
||
|
|
||
1 year ago
|
from parameterized import parameterized
|
||
|
|
||
2 years ago
|
from cereal import car
|
||
2 years ago
|
from openpilot.common.params import Params
|
||
11 months ago
|
import openpilot.system.manager.manager as manager
|
||
|
from openpilot.system.manager.process import ensure_running
|
||
|
from openpilot.system.manager.process_config import managed_processes
|
||
2 years ago
|
from openpilot.system.hardware import HARDWARE
|
||
4 years ago
|
|
||
|
os.environ['FAKEUPLOAD'] = "1"
|
||
4 years ago
|
|
||
3 years ago
|
MAX_STARTUP_TIME = 3
|
||
2 years ago
|
BLACKLIST_PROCS = ['manage_athenad', 'pandad', 'pigeond']
|
||
4 years ago
|
|
||
2 years ago
|
|
||
1 year ago
|
@pytest.mark.tici
|
||
11 months ago
|
class TestManager:
|
||
|
def setup_method(self):
|
||
3 years ago
|
HARDWARE.set_power_save(False)
|
||
4 years ago
|
|
||
2 years ago
|
# ensure clean CarParams
|
||
|
params = Params()
|
||
|
params.clear_all()
|
||
|
|
||
11 months ago
|
def teardown_method(self):
|
||
4 years ago
|
manager.manager_cleanup()
|
||
4 years ago
|
|
||
|
def test_manager_prepare(self):
|
||
|
os.environ['PREPAREONLY'] = '1'
|
||
|
manager.main()
|
||
|
|
||
2 years ago
|
def test_blacklisted_procs(self):
|
||
|
# TODO: ensure there are blacklisted procs until we have a dedicated test
|
||
11 months ago
|
assert len(BLACKLIST_PROCS), "No blacklisted procs to test not_run"
|
||
2 years ago
|
|
||
1 year ago
|
@parameterized.expand([(i,) for i in range(10)])
|
||
1 year ago
|
def test_startup_time(self, index):
|
||
|
start = time.monotonic()
|
||
|
os.environ['PREPAREONLY'] = '1'
|
||
|
manager.main()
|
||
|
t = time.monotonic() - start
|
||
|
assert t < MAX_STARTUP_TIME, f"startup took {t}s, expected <{MAX_STARTUP_TIME}s"
|
||
4 years ago
|
|
||
11 months ago
|
@pytest.mark.skip("this test is flaky the way it's currently written, should be moved to test_onroad")
|
||
|
def test_clean_exit(self, subtests):
|
||
3 years ago
|
"""
|
||
|
Ensure all processes exit cleanly when stopped.
|
||
|
"""
|
||
3 years ago
|
HARDWARE.set_power_save(False)
|
||
2 years ago
|
manager.manager_init()
|
||
2 years ago
|
|
||
|
CP = car.CarParams.new_message()
|
||
|
procs = ensure_running(managed_processes.values(), True, Params(), CP, not_run=BLACKLIST_PROCS)
|
||
4 years ago
|
|
||
4 years ago
|
time.sleep(10)
|
||
4 years ago
|
|
||
2 years ago
|
for p in procs:
|
||
11 months ago
|
with subtests.test(proc=p.name):
|
||
2 years ago
|
state = p.get_process_state_msg()
|
||
11 months ago
|
assert state.running, f"{p.name} not running"
|
||
2 years ago
|
exit_code = p.stop(retry=False)
|
||
4 years ago
|
|
||
11 months ago
|
assert p.name not in BLACKLIST_PROCS, f"{p.name} was started"
|
||
2 years ago
|
|
||
11 months ago
|
assert exit_code is not None, f"{p.name} failed to exit"
|
||
2 years ago
|
|
||
3 years ago
|
# TODO: interrupted blocking read exits with 1 in cereal. use a more unique return code
|
||
|
exit_codes = [0, 1]
|
||
2 years ago
|
if p.sigkill:
|
||
3 years ago
|
exit_codes = [-signal.SIGKILL]
|
||
11 months ago
|
assert exit_code in exit_codes, f"{p.name} died with {exit_code}"
|