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.
		
		
		
		
			
				
					71 lines
				
				1.5 KiB
			
		
		
			
		
	
	
					71 lines
				
				1.5 KiB
			| 
											4 years ago
										 | #!/usr/bin/env python3
 | ||
|  | import unittest
 | ||
|  | import time
 | ||
|  | import math
 | ||
| 
											4 years ago
										 | from dataclasses import dataclass
 | ||
| 
											4 years ago
										 | 
 | ||
| 
											3 years ago
										 | from system.hardware import HARDWARE, TICI
 | ||
|  | from system.hardware.tici.power_monitor import get_power
 | ||
| 
											4 years ago
										 | from selfdrive.manager.process_config import managed_processes
 | ||
|  | from selfdrive.manager.manager import manager_cleanup
 | ||
|  | 
 | ||
| 
											4 years ago
										 | 
 | ||
|  | @dataclass
 | ||
|  | class Proc:
 | ||
|  |   name: str
 | ||
|  |   power: float
 | ||
|  |   rtol: float = 0.05
 | ||
|  |   atol: float = 0.1
 | ||
| 
											3 years ago
										 |   warmup: float = 6.
 | ||
| 
											4 years ago
										 | 
 | ||
|  | PROCS = [
 | ||
| 
											3 years ago
										 |   Proc('camerad', 2.15),
 | ||
|  |   Proc('modeld', 1.0),
 | ||
| 
											3 years ago
										 |   Proc('dmonitoringmodeld', 0.25),
 | ||
| 
											3 years ago
										 |   Proc('encoderd', 0.23),
 | ||
| 
											4 years ago
										 | ]
 | ||
| 
											4 years ago
										 | 
 | ||
|  | 
 | ||
|  | class TestPowerDraw(unittest.TestCase):
 | ||
|  | 
 | ||
|  |   @classmethod
 | ||
|  |   def setUpClass(cls):
 | ||
|  |     if not TICI:
 | ||
|  |       raise unittest.SkipTest
 | ||
|  | 
 | ||
|  |   def setUp(self):
 | ||
|  |     HARDWARE.initialize_hardware()
 | ||
|  |     HARDWARE.set_power_save(False)
 | ||
|  | 
 | ||
|  |   def tearDown(self):
 | ||
|  |     manager_cleanup()
 | ||
|  | 
 | ||
|  |   def test_camera_procs(self):
 | ||
|  |     baseline = get_power()
 | ||
|  | 
 | ||
|  |     prev = baseline
 | ||
|  |     used = {}
 | ||
| 
											4 years ago
										 |     for proc in PROCS:
 | ||
|  |       managed_processes[proc.name].start()
 | ||
|  |       time.sleep(proc.warmup)
 | ||
| 
											4 years ago
										 | 
 | ||
|  |       now = get_power(8)
 | ||
| 
											4 years ago
										 |       used[proc.name] = now - prev
 | ||
| 
											4 years ago
										 |       prev = now
 | ||
|  | 
 | ||
|  |     manager_cleanup()
 | ||
|  | 
 | ||
|  |     print("-"*35)
 | ||
|  |     print(f"Baseline {baseline:.2f}W\n")
 | ||
| 
											4 years ago
										 |     for proc in PROCS:
 | ||
|  |       cur = used[proc.name]
 | ||
|  |       expected = proc.power
 | ||
|  |       print(f"{proc.name.ljust(20)} {expected:.2f}W  {cur:.2f}W")
 | ||
|  |       with self.subTest(proc=proc.name):
 | ||
|  |         self.assertTrue(math.isclose(cur, expected, rel_tol=proc.rtol, abs_tol=proc.atol))
 | ||
| 
											4 years ago
										 |     print("-"*35)
 | ||
|  | 
 | ||
|  | 
 | ||
|  | if __name__ == "__main__":
 | ||
|  |   unittest.main()
 |