@ -25,13 +25,17 @@ class TestPandad(unittest.TestCase):
def tearDown ( self ) :
def tearDown ( self ) :
managed_processes [ ' pandad ' ] . stop ( )
managed_processes [ ' pandad ' ] . stop ( )
def _wait_for_boardd ( self , timeout = 30 ) :
def _run_test ( self , timeout = 30 ) :
managed_processes [ ' pandad ' ] . start ( )
sm = messaging . SubMaster ( [ ' peripheralState ' ] )
sm = messaging . SubMaster ( [ ' peripheralState ' ] )
for _ in range ( timeout * 10 ) :
for _ in range ( timeout * 10 ) :
sm . update ( 100 )
sm . update ( 100 )
if sm [ ' peripheralState ' ] . pandaType != log . PandaState . PandaType . unknown :
if sm [ ' peripheralState ' ] . pandaType != log . PandaState . PandaType . unknown :
break
break
managed_processes [ ' pandad ' ] . stop ( )
if sm [ ' peripheralState ' ] . pandaType == log . PandaState . PandaType . unknown :
if sm [ ' peripheralState ' ] . pandaType == log . PandaState . PandaType . unknown :
raise Exception ( " boardd failed to start " )
raise Exception ( " boardd failed to start " )
@ -43,7 +47,11 @@ class TestPandad(unittest.TestCase):
HARDWARE . recover_internal_panda ( )
HARDWARE . recover_internal_panda ( )
assert Panda . wait_for_dfu ( None , 10 )
assert Panda . wait_for_dfu ( None , 10 )
def _flash_and_test ( self , fn , expect_mismatch = False ) :
def _assert_no_panda ( self ) :
assert not Panda . wait_for_dfu ( None , 3 )
assert not Panda . wait_for_panda ( None , 3 )
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,22 +69,19 @@ class TestPandad(unittest.TestCase):
with Panda ( ) as p :
with Panda ( ) as p :
assert p . bootstub
assert p . bootstub
managed_processes [ ' pandad ' ] . start ( )
self . _run_test ( 45 )
self . _wait_for_boardd ( 45 )
@phone_only
@phone_only
def test_in_dfu ( self ) :
def test_in_dfu ( self ) :
HARDWARE . recover_internal_panda ( )
HARDWARE . recover_internal_panda ( )
managed_processes [ ' pandad ' ] . start ( )
self . _run_test ( 60 )
self . _wait_for_boardd ( 60 )
@phone_only
@phone_only
def test_in_bootstub ( self ) :
def test_in_bootstub ( self ) :
with Panda ( ) as p :
with Panda ( ) as p :
p . reset ( enter_bootstub = True )
p . reset ( enter_bootstub = True )
assert p . bootstub
assert p . bootstub
managed_processes [ ' pandad ' ] . start ( )
self . _run_test ( )
self . _wait_for_boardd ( )
@phone_only
@phone_only
def test_internal_panda_reset ( self ) :
def test_internal_panda_reset ( self ) :
@ -84,22 +89,17 @@ class TestPandad(unittest.TestCase):
gpio_set ( GPIO . STM_RST_N , 1 )
gpio_set ( GPIO . STM_RST_N , 1 )
time . sleep ( 0.5 )
time . sleep ( 0.5 )
assert all ( not Panda ( s ) . is_internal ( ) for s in Panda . list ( ) )
assert all ( not Panda ( s ) . is_internal ( ) for s in Panda . list ( ) )
self . _run_test ( )
managed_processes [ ' pandad ' ] . start ( )
self . _wait_for_boardd ( )
assert any ( Panda ( s ) . is_internal ( ) for s in Panda . list ( ) )
assert any ( Panda ( s ) . is_internal ( ) for s in Panda . list ( ) )
@phone_only
@phone_only
def test_best_case_startup_time ( self ) :
def test_best_case_startup_time ( self ) :
# run once so we're setup
# run once so we're setup
managed_processes [ ' pandad ' ] . start ( )
self . _run_test ( )
self . _wait_for_boardd ( )
managed_processes [ ' pandad ' ] . stop ( )
# should be fast this time
# should be fast this time
managed_processes [ ' pandad ' ] . start ( )
self . _run_test ( 8 )
self . _wait_for_boardd ( 8 )
@phone_only
@phone_only
def test_protocol_version_check ( self ) :
def test_protocol_version_check ( self ) :
@ -108,11 +108,23 @@ class TestPandad(unittest.TestCase):
# flash old fw
# flash old fw
fn = os . path . join ( HERE , " bootstub.panda_h7_spiv0.bin " )
fn = os . path . join ( HERE , " bootstub.panda_h7_spiv0.bin " )
self . _flash_and_test ( fn , expect_mismatch = True )
self . _flash_bootstub_ and_test ( fn , expect_mismatch = True )
@phone_only
@phone_only
def test_release_to_devel_bootstub ( self ) :
def test_release_to_devel_bootstub ( self ) :
self . _flash_and_test ( None )
self . _flash_bootstub_and_test ( None )
@phone_only
def test_recover_from_bad_bootstub ( self ) :
self . _go_to_dfu ( )
with PandaDFU ( None ) as pd :
pd . program_bootstub ( b " \x00 " * 1024 )
pd . reset ( )
HARDWARE . reset_internal_panda ( )
self . _assert_no_panda ( )
self . _run_test ( 60 )
if __name__ == " __main__ " :
if __name__ == " __main__ " :
unittest . main ( )
unittest . main ( )