pandad: ensure panda is in a good state before each test case (#30151)

* pandad: ensure panda is in a good state before each test case

* less overhead

* fix pc

* update that

* Update selfdrive/boardd/tests/test_pandad.py

* update
pull/30160/head
Adeeb Shihadeh 2 years ago committed by GitHub
parent 377722fd5e
commit 4f769d0a38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 32
      selfdrive/boardd/tests/test_pandad.py

@ -1,21 +1,26 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import os import os
import time import time
import unittest import pytest
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, PandaProtocolMismatch
from openpilot.selfdrive.test.helpers import phone_only
from openpilot.selfdrive.manager.process_config import managed_processes from openpilot.selfdrive.manager.process_config import managed_processes
from openpilot.system.hardware import HARDWARE from openpilot.system.hardware import HARDWARE, PC
from openpilot.system.hardware.tici.pins import GPIO from openpilot.system.hardware.tici.pins import GPIO
HERE = os.path.dirname(os.path.realpath(__file__)) HERE = os.path.dirname(os.path.realpath(__file__))
class TestPandad(unittest.TestCase): @pytest.mark.skipif(PC, reason="needs a panda")
class TestPandad:
def setUp(self):
# ensure panda is up
if len(Panda.list()) == 0:
self._run_test(60)
def tearDown(self): def tearDown(self):
managed_processes['pandad'].stop() managed_processes['pandad'].stop()
@ -54,7 +59,7 @@ class TestPandad(unittest.TestCase):
assert Panda.wait_for_panda(None, 10) assert Panda.wait_for_panda(None, 10)
if expect_mismatch: if expect_mismatch:
with self.assertRaises(PandaProtocolMismatch): with pytest.raises(PandaProtocolMismatch):
Panda() Panda()
else: else:
with Panda() as p: with Panda() as p:
@ -62,19 +67,16 @@ class TestPandad(unittest.TestCase):
self._run_test(45) self._run_test(45)
@phone_only
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)
@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
self._run_test() self._run_test()
@phone_only
def test_internal_panda_reset(self): def test_internal_panda_reset(self):
gpio_init(GPIO.STM_RST_N, True) gpio_init(GPIO.STM_RST_N, True)
gpio_set(GPIO.STM_RST_N, 1) gpio_set(GPIO.STM_RST_N, 1)
@ -84,28 +86,22 @@ class TestPandad(unittest.TestCase):
assert any(Panda(s).is_internal() for s in Panda.list()) assert any(Panda(s).is_internal() for s in Panda.list())
@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
self._run_test() self._run_test(60)
# should be fast this time # should be fast this time
self._run_test(8) self._run_test(8)
@phone_only @pytest.mark.skipif(HARDWARE.get_device_type() == 'tici', reason="SPI test")
def test_protocol_version_check(self): def test_protocol_version_check(self):
if HARDWARE.get_device_type() == 'tici':
self.skipTest("")
# 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_bootstub_and_test(fn, expect_mismatch=True) self._flash_bootstub_and_test(fn, expect_mismatch=True)
@phone_only
def test_release_to_devel_bootstub(self): def test_release_to_devel_bootstub(self):
self._flash_bootstub_and_test(None) self._flash_bootstub_and_test(None)
@phone_only
def test_recover_from_bad_bootstub(self): def test_recover_from_bad_bootstub(self):
self._go_to_dfu() self._go_to_dfu()
with PandaDFU(None) as pd: with PandaDFU(None) as pd:
@ -115,7 +111,3 @@ class TestPandad(unittest.TestCase):
self._assert_no_panda() self._assert_no_panda()
self._run_test(60) self._run_test(60)
if __name__ == "__main__":
unittest.main()

Loading…
Cancel
Save