| 
						
						
							
								
							
						
						
					 | 
					 | 
					@ -5,8 +5,7 @@ import time | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					import cereal.messaging as messaging | 
					 | 
					 | 
					 | 
					import cereal.messaging as messaging | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					from cereal import log | 
					 | 
					 | 
					 | 
					from cereal import log | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					from openpilot.common.gpio import gpio_set, gpio_init | 
					 | 
					 | 
					 | 
					from openpilot.common.gpio import gpio_set, gpio_init | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					from panda import Panda, PandaDFU, PandaProtocolMismatch | 
					 | 
					 | 
					 | 
					from panda import Panda, PandaDFU | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					from openpilot.common.retry import retry | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					from openpilot.system.manager.process_config import managed_processes | 
					 | 
					 | 
					 | 
					from openpilot.system.manager.process_config import managed_processes | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					from openpilot.system.hardware import HARDWARE | 
					 | 
					 | 
					 | 
					from openpilot.system.hardware import HARDWARE | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					from openpilot.system.hardware.tici.pins import GPIO | 
					 | 
					 | 
					 | 
					from openpilot.system.hardware.tici.pins import GPIO | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
					 | 
					@ -50,8 +49,7 @@ class TestPandad: | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    assert not Panda.wait_for_dfu(None, 3) | 
					 | 
					 | 
					 | 
					    assert not Panda.wait_for_dfu(None, 3) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    assert not Panda.wait_for_panda(None, 3) | 
					 | 
					 | 
					 | 
					    assert not Panda.wait_for_panda(None, 3) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  @retry(attempts=3) | 
					 | 
					 | 
					 | 
					  def _flash_bootstub(self, fn): | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  def _flash_bootstub_and_test(self, fn, expect_mismatch=False): | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    self._go_to_dfu() | 
					 | 
					 | 
					 | 
					    self._go_to_dfu() | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    pd = PandaDFU(None) | 
					 | 
					 | 
					 | 
					    pd = PandaDFU(None) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    if fn is None: | 
					 | 
					 | 
					 | 
					    if fn is None: | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -61,16 +59,6 @@ class TestPandad: | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    pd.reset() | 
					 | 
					 | 
					 | 
					    pd.reset() | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    HARDWARE.reset_internal_panda() | 
					 | 
					 | 
					 | 
					    HARDWARE.reset_internal_panda() | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    assert Panda.wait_for_panda(None, 10) | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    if expect_mismatch: | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      with pytest.raises(PandaProtocolMismatch): | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        Panda() | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    else: | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      with Panda() as p: | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        assert p.bootstub | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    self._run_test(45) | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  def test_in_dfu(self): | 
					 | 
					 | 
					 | 
					  def test_in_dfu(self): | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    HARDWARE.recover_internal_panda() | 
					 | 
					 | 
					 | 
					    HARDWARE.recover_internal_panda() | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    self._run_test(60) | 
					 | 
					 | 
					 | 
					    self._run_test(60) | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
					 | 
					@ -106,13 +94,14 @@ class TestPandad: | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    print("startup times", ts, sum(ts) / len(ts)) | 
					 | 
					 | 
					 | 
					    print("startup times", ts, sum(ts) / len(ts)) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    assert 0.1 < (sum(ts)/len(ts)) < 0.7 | 
					 | 
					 | 
					 | 
					    assert 0.1 < (sum(ts)/len(ts)) < 0.7 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  def test_protocol_version_check(self): | 
					 | 
					 | 
					 | 
					  def test_old_spi_protocol(self): | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    # flash old fw | 
					 | 
					 | 
					 | 
					    # flash firmware with old SPI protocol | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    fn = os.path.join(HERE, "bootstub.panda_h7_spiv0.bin") | 
					 | 
					 | 
					 | 
					    self._flash_bootstub(os.path.join(HERE, "bootstub.panda_h7_spiv0.bin")) | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    self._flash_bootstub_and_test(fn, expect_mismatch=True) | 
					 | 
					 | 
					 | 
					    self._run_test(45) | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  def test_release_to_devel_bootstub(self): | 
					 | 
					 | 
					 | 
					  def test_release_to_devel_bootstub(self): | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    self._flash_bootstub_and_test(None) | 
					 | 
					 | 
					 | 
					    self._flash_bootstub(None) | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    self._run_test(45) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  def test_recover_from_bad_bootstub(self): | 
					 | 
					 | 
					 | 
					  def test_recover_from_bad_bootstub(self): | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    self._go_to_dfu() | 
					 | 
					 | 
					 | 
					    self._go_to_dfu() | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
					 | 
					
  |