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.
		
		
		
		
			
				
					76 lines
				
				1.6 KiB
			
		
		
			
		
	
	
					76 lines
				
				1.6 KiB
			| 
											4 years ago
										 | #!/usr/bin/env python3
 | ||
|  | import unittest
 | ||
|  | import time
 | ||
|  | import math
 | ||
| 
											4 years ago
										 | from dataclasses import dataclass
 | ||
| 
											3 years ago
										 | from tabulate import tabulate
 | ||
| 
											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),
 | ||
| 
											3 years ago
										 |   Proc('modeld', 0.93, atol=0.2),
 | ||
| 
											3 years ago
										 |   Proc('dmonitoringmodeld', 0.4),
 | ||
| 
											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)
 | ||
|  | 
 | ||
| 
											3 years ago
										 |     # wait a bit for power save to disable
 | ||
|  |     time.sleep(5)
 | ||
|  | 
 | ||
| 
											4 years ago
										 |   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()
 | ||
|  | 
 | ||
| 
											3 years ago
										 |     tab = []
 | ||
|  |     tab.append(['process', 'expected (W)', 'current (W)'])
 | ||
| 
											4 years ago
										 |     for proc in PROCS:
 | ||
|  |       cur = used[proc.name]
 | ||
|  |       expected = proc.power
 | ||
| 
											3 years ago
										 |       tab.append([proc.name, round(expected, 2), round(cur, 2)])
 | ||
| 
											4 years ago
										 |       with self.subTest(proc=proc.name):
 | ||
|  |         self.assertTrue(math.isclose(cur, expected, rel_tol=proc.rtol, abs_tol=proc.atol))
 | ||
| 
											3 years ago
										 |     print(tabulate(tab))
 | ||
|  |     print(f"Baseline {baseline:.2f}W\n")
 | ||
| 
											4 years ago
										 | 
 | ||
|  | 
 | ||
|  | if __name__ == "__main__":
 | ||
|  |   unittest.main()
 |