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.
		
		
		
		
			
				
					77 lines
				
				2.3 KiB
			
		
		
			
		
	
	
					77 lines
				
				2.3 KiB
			| 
											5 years ago
										 | import os
 | ||
| 
											2 years ago
										 | import pytest
 | ||
| 
											5 years ago
										 | import signal
 | ||
|  | import time
 | ||
|  | 
 | ||
| 
											2 years ago
										 | from parameterized import parameterized
 | ||
|  | 
 | ||
| 
											3 years ago
										 | from cereal import car
 | ||
| 
											2 years ago
										 | from openpilot.common.params import Params
 | ||
| 
											1 year 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
 | ||
| 
											5 years ago
										 | 
 | ||
|  | os.environ['FAKEUPLOAD'] = "1"
 | ||
| 
											5 years ago
										 | 
 | ||
| 
											3 years ago
										 | MAX_STARTUP_TIME = 3
 | ||
| 
											3 years ago
										 | BLACKLIST_PROCS = ['manage_athenad', 'pandad', 'pigeond']
 | ||
| 
											5 years ago
										 | 
 | ||
| 
											2 years ago
										 | 
 | ||
| 
											2 years ago
										 | @pytest.mark.tici
 | ||
| 
											1 year ago
										 | class TestManager:
 | ||
|  |   def setup_method(self):
 | ||
| 
											4 years ago
										 |     HARDWARE.set_power_save(False)
 | ||
| 
											5 years ago
										 | 
 | ||
| 
											3 years ago
										 |     # ensure clean CarParams
 | ||
|  |     params = Params()
 | ||
|  |     params.clear_all()
 | ||
|  | 
 | ||
| 
											1 year ago
										 |   def teardown_method(self):
 | ||
| 
											5 years ago
										 |     manager.manager_cleanup()
 | ||
| 
											5 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
 | ||
| 
											1 year ago
										 |     assert len(BLACKLIST_PROCS), "No blacklisted procs to test not_run"
 | ||
| 
											2 years ago
										 | 
 | ||
| 
											2 years ago
										 |   @parameterized.expand([(i,) for i in range(10)])
 | ||
| 
											2 years 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"
 | ||
| 
											5 years ago
										 | 
 | ||
| 
											1 year 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.
 | ||
|  |     """
 | ||
| 
											4 years ago
										 |     HARDWARE.set_power_save(False)
 | ||
| 
											3 years ago
										 |     manager.manager_init()
 | ||
| 
											3 years ago
										 | 
 | ||
|  |     CP = car.CarParams.new_message()
 | ||
|  |     procs = ensure_running(managed_processes.values(), True, Params(), CP, not_run=BLACKLIST_PROCS)
 | ||
| 
											5 years ago
										 | 
 | ||
| 
											4 years ago
										 |     time.sleep(10)
 | ||
| 
											5 years ago
										 | 
 | ||
| 
											3 years ago
										 |     for p in procs:
 | ||
| 
											1 year ago
										 |       with subtests.test(proc=p.name):
 | ||
| 
											3 years ago
										 |         state = p.get_process_state_msg()
 | ||
| 
											1 year ago
										 |         assert state.running, f"{p.name} not running"
 | ||
| 
											3 years ago
										 |         exit_code = p.stop(retry=False)
 | ||
| 
											5 years ago
										 | 
 | ||
| 
											1 year ago
										 |         assert p.name not in BLACKLIST_PROCS, f"{p.name} was started"
 | ||
| 
											2 years ago
										 | 
 | ||
| 
											1 year 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]
 | ||
| 
											3 years ago
										 |         if p.sigkill:
 | ||
| 
											3 years ago
										 |           exit_codes = [-signal.SIGKILL]
 | ||
| 
											1 year ago
										 |         assert exit_code in exit_codes, f"{p.name} died with {exit_code}"
 |