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.
		
		
		
		
			
				
					52 lines
				
				1.8 KiB
			
		
		
			
		
	
	
					52 lines
				
				1.8 KiB
			| 
								 
											4 years ago
										 
									 | 
							
								#!/usr/bin/env python3
							 | 
						||
| 
								 
											1 year ago
										 
									 | 
							
								import pytest
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											1 year ago
										 
									 | 
							
								from openpilot.system.thermald.fan_controller import TiciFanController
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											1 year ago
										 
									 | 
							
								ALL_CONTROLLERS = [TiciFanController]
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											1 year ago
										 
									 | 
							
								def patched_controller(mocker, controller_class):
							 | 
						||
| 
								 | 
							
								  mocker.patch("os.system", new=mocker.Mock())
							 | 
						||
| 
								 | 
							
								  return controller_class()
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											1 year ago
										 
									 | 
							
								class TestFanController:
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  def wind_up(self, controller, ignition=True):
							 | 
						||
| 
								 | 
							
								    for _ in range(1000):
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								      controller.update(100, ignition)
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 | 
							
								  def wind_down(self, controller, ignition=False):
							 | 
						||
| 
								 | 
							
								    for _ in range(1000):
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								      controller.update(10, ignition)
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											1 year ago
										 
									 | 
							
								  @pytest.mark.parametrize("controller_class", ALL_CONTROLLERS)
							 | 
						||
| 
								 | 
							
								  def test_hot_onroad(self, mocker, controller_class):
							 | 
						||
| 
								 | 
							
								    controller = patched_controller(mocker, controller_class)
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								    self.wind_up(controller)
							 | 
						||
| 
								 
											1 year ago
										 
									 | 
							
								    assert controller.update(100, True) >= 70
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											1 year ago
										 
									 | 
							
								  @pytest.mark.parametrize("controller_class", ALL_CONTROLLERS)
							 | 
						||
| 
								 | 
							
								  def test_offroad_limits(self, mocker, controller_class):
							 | 
						||
| 
								 | 
							
								    controller = patched_controller(mocker, controller_class)
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								    self.wind_up(controller)
							 | 
						||
| 
								 
											1 year ago
										 
									 | 
							
								    assert controller.update(100, False) <= 30
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											1 year ago
										 
									 | 
							
								  @pytest.mark.parametrize("controller_class", ALL_CONTROLLERS)
							 | 
						||
| 
								 | 
							
								  def test_no_fan_wear(self, mocker, controller_class):
							 | 
						||
| 
								 | 
							
								    controller = patched_controller(mocker, controller_class)
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								    self.wind_down(controller)
							 | 
						||
| 
								 
											1 year ago
										 
									 | 
							
								    assert controller.update(10, False) == 0
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											1 year ago
										 
									 | 
							
								  @pytest.mark.parametrize("controller_class", ALL_CONTROLLERS)
							 | 
						||
| 
								 | 
							
								  def test_limited(self, mocker, controller_class):
							 | 
						||
| 
								 | 
							
								    controller = patched_controller(mocker, controller_class)
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								    self.wind_up(controller, True)
							 | 
						||
| 
								 
											1 year ago
										 
									 | 
							
								    assert controller.update(100, True) == 100
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											1 year ago
										 
									 | 
							
								  @pytest.mark.parametrize("controller_class", ALL_CONTROLLERS)
							 | 
						||
| 
								 | 
							
								  def test_windup_speed(self, mocker, controller_class):
							 | 
						||
| 
								 | 
							
								    controller = patched_controller(mocker, controller_class)
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								    self.wind_down(controller, True)
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								    for _ in range(10):
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								      controller.update(90, True)
							 | 
						||
| 
								 
											1 year ago
										 
									 | 
							
								    assert controller.update(90, True) >= 60
							 |