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.
		
		
		
		
			
				
					65 lines
				
				1.7 KiB
			
		
		
			
		
	
	
					65 lines
				
				1.7 KiB
			| 
								 
											5 years ago
										 
									 | 
							
								#!/usr/bin/env python3
							 | 
						||
| 
								 | 
							
								import os
							 | 
						||
| 
								 | 
							
								import signal
							 | 
						||
| 
								 | 
							
								import time
							 | 
						||
| 
								 | 
							
								import unittest
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								import selfdrive.manager.manager as manager
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								from selfdrive.hardware import EON
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								from selfdrive.manager.process import DaemonProcess
							 | 
						||
| 
								 | 
							
								from selfdrive.manager.process_config import managed_processes
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								os.environ['FAKEUPLOAD'] = "1"
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 | 
							
								# TODO: make eon fast
							 | 
						||
| 
								 | 
							
								MAX_STARTUP_TIME = 30 if EON else 15
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								ALL_PROCESSES = [p.name for p in managed_processes.values() if type(p) is not DaemonProcess]
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								class TestManager(unittest.TestCase):
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								  def setUp(self):
							 | 
						||
| 
								 | 
							
								    os.environ['PASSIVE'] = '0'
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  def tearDown(self):
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								    manager.manager_cleanup()
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 | 
							
								  def test_manager_prepare(self):
							 | 
						||
| 
								 | 
							
								    os.environ['PREPAREONLY'] = '1'
							 | 
						||
| 
								 | 
							
								    manager.main()
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  def test_startup_time(self):
							 | 
						||
| 
								 | 
							
								    for _ in range(10):
							 | 
						||
| 
								 | 
							
								      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"
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  # ensure all processes exit cleanly
							 | 
						||
| 
								 | 
							
								  def test_clean_exit(self):
							 | 
						||
| 
								 | 
							
								    manager.manager_prepare()
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								    for p in ALL_PROCESSES:
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								      managed_processes[p].start()
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								    time.sleep(10)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    for p in reversed(ALL_PROCESSES):
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								      exit_code = managed_processes[p].stop(retry=False)
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								      if (not EON and p == 'ui') or (EON and p == 'logcatd'):
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								        # TODO: make Qt UI exit gracefully and fix OMX encoder exiting
							 | 
						||
| 
								 | 
							
								        continue
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								      # Make sure the process is actually dead
							 | 
						||
| 
								 | 
							
								      managed_processes[p].stop()
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								      # TODO: interrupted blocking read exits with 1 in cereal. use a more unique return code
							 | 
						||
| 
								 | 
							
								      exit_codes = [0, 1]
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								      if managed_processes[p].sigkill:
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								        exit_codes = [-signal.SIGKILL]
							 | 
						||
| 
								 | 
							
								      assert exit_code in exit_codes, f"{p} died with {exit_code}"
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								if __name__ == "__main__":
							 | 
						||
| 
								 | 
							
								  unittest.main()
							 |