2020-12-29 22:32:03 -08:00
|
|
|
import os
|
2023-11-07 20:35:44 -05:00
|
|
|
import pytest
|
2020-12-29 22:32:03 -08:00
|
|
|
import signal
|
|
|
|
|
import time
|
|
|
|
|
|
2023-01-22 16:26:55 -06:00
|
|
|
from cereal import car
|
2023-08-20 20:49:55 -07:00
|
|
|
from openpilot.common.params import Params
|
2024-05-25 12:41:17 -07:00
|
|
|
import openpilot.system.manager.manager as manager
|
|
|
|
|
from openpilot.system.manager.process import ensure_running
|
2025-01-21 17:29:56 -08:00
|
|
|
from openpilot.system.manager.process_config import managed_processes, procs
|
2023-08-20 20:49:55 -07:00
|
|
|
from openpilot.system.hardware import HARDWARE
|
2021-03-05 11:03:23 +01:00
|
|
|
|
|
|
|
|
os.environ['FAKEUPLOAD'] = "1"
|
2020-12-29 22:32:03 -08:00
|
|
|
|
2022-06-12 18:00:00 -07:00
|
|
|
MAX_STARTUP_TIME = 3
|
2023-01-22 16:26:55 -06:00
|
|
|
BLACKLIST_PROCS = ['manage_athenad', 'pandad', 'pigeond']
|
2020-12-29 22:32:03 -08:00
|
|
|
|
2023-08-24 00:34:36 -07:00
|
|
|
|
2024-05-17 11:01:44 -07:00
|
|
|
class TestManager:
|
|
|
|
|
def setup_method(self):
|
2021-12-06 14:40:42 -08:00
|
|
|
HARDWARE.set_power_save(False)
|
2020-12-29 22:32:03 -08:00
|
|
|
|
2022-11-12 06:50:09 +01:00
|
|
|
# ensure clean CarParams
|
|
|
|
|
params = Params()
|
|
|
|
|
params.clear_all()
|
|
|
|
|
|
2024-05-17 11:01:44 -07:00
|
|
|
def teardown_method(self):
|
2021-03-05 11:03:23 +01:00
|
|
|
manager.manager_cleanup()
|
2020-12-29 22:32:03 -08:00
|
|
|
|
|
|
|
|
def test_manager_prepare(self):
|
|
|
|
|
os.environ['PREPAREONLY'] = '1'
|
|
|
|
|
manager.main()
|
|
|
|
|
|
2025-01-21 17:29:56 -08:00
|
|
|
def test_duplicate_procs(self):
|
|
|
|
|
assert len(procs) == len(managed_processes), "Duplicate process names"
|
|
|
|
|
|
2023-08-24 00:34:36 -07:00
|
|
|
def test_blacklisted_procs(self):
|
|
|
|
|
# TODO: ensure there are blacklisted procs until we have a dedicated test
|
2024-05-17 11:01:44 -07:00
|
|
|
assert len(BLACKLIST_PROCS), "No blacklisted procs to test not_run"
|
2023-08-24 00:34:36 -07:00
|
|
|
|
2024-05-17 11:01:44 -07:00
|
|
|
@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):
|
2022-08-07 18:41:54 -07:00
|
|
|
"""
|
|
|
|
|
Ensure all processes exit cleanly when stopped.
|
|
|
|
|
"""
|
2021-11-18 23:43:09 -08:00
|
|
|
HARDWARE.set_power_save(False)
|
2022-11-12 06:50:09 +01:00
|
|
|
manager.manager_init()
|
2023-01-22 16:26:55 -06:00
|
|
|
|
|
|
|
|
CP = car.CarParams.new_message()
|
|
|
|
|
procs = ensure_running(managed_processes.values(), True, Params(), CP, not_run=BLACKLIST_PROCS)
|
2021-02-01 15:15:29 -08:00
|
|
|
|
2021-07-02 16:29:57 -07:00
|
|
|
time.sleep(10)
|
2020-12-29 22:32:03 -08:00
|
|
|
|
2023-01-22 16:26:55 -06:00
|
|
|
for p in procs:
|
2024-05-17 11:01:44 -07:00
|
|
|
with subtests.test(proc=p.name):
|
2023-01-22 16:26:55 -06:00
|
|
|
state = p.get_process_state_msg()
|
2024-05-17 11:01:44 -07:00
|
|
|
assert state.running, f"{p.name} not running"
|
2023-01-22 16:26:55 -06:00
|
|
|
exit_code = p.stop(retry=False)
|
2021-04-08 23:46:20 -07:00
|
|
|
|
2024-05-17 11:01:44 -07:00
|
|
|
assert p.name not in BLACKLIST_PROCS, f"{p.name} was started"
|
2023-08-24 00:34:36 -07:00
|
|
|
|
2024-05-17 11:01:44 -07:00
|
|
|
assert exit_code is not None, f"{p.name} failed to exit"
|
2023-07-24 20:22:14 -07:00
|
|
|
|
2022-08-07 18:41:54 -07:00
|
|
|
# TODO: interrupted blocking read exits with 1 in cereal. use a more unique return code
|
|
|
|
|
exit_codes = [0, 1]
|
2023-01-22 16:26:55 -06:00
|
|
|
if p.sigkill:
|
2022-08-07 18:41:54 -07:00
|
|
|
exit_codes = [-signal.SIGKILL]
|
2024-05-17 11:01:44 -07:00
|
|
|
assert exit_code in exit_codes, f"{p.name} died with {exit_code}"
|