Skip to content

Commit

Permalink
Pytest: consistent hardware state for tici tests (commaai#31279)
Browse files Browse the repository at this point in the history
* consistent hardware

* consistent hardware

* moved

* this too

* ruff

* s

* duplicated

---------

Co-authored-by: Comma Device <device@comma.ai>
  • Loading branch information
jnewb1 and Comma Device authored Feb 2, 2024
1 parent a5766e2 commit 0277fc5
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ node {
deviceStage("tici", "tici-common", ["UNSAFE=1"], [
["build", "cd selfdrive/manager && ./build.py"],
["test pandad", "pytest selfdrive/boardd/tests/test_pandad.py", ["panda/", "selfdrive/boardd/"]],
["test power draw", "./system/hardware/tici/tests/test_power_draw.py"],
["test power draw", "pytest -s system/hardware/tici/tests/test_power_draw.py"],
["test encoder", "LD_LIBRARY_PATH=/usr/local/lib pytest system/loggerd/tests/test_encoder.py"],
["test pigeond", "pytest system/sensord/tests/test_pigeond.py"],
["test manager", "pytest selfdrive/manager/test/test_manager.py"],
Expand Down
18 changes: 15 additions & 3 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from openpilot.common.prefix import OpenpilotPrefix
from openpilot.selfdrive.manager import manager
from openpilot.system.hardware import TICI
from openpilot.system.hardware import TICI, HARDWARE


def pytest_sessionstart(session):
Expand Down Expand Up @@ -57,12 +57,24 @@ def openpilot_class_fixture():
os.environ.update(starting_env)


@pytest.fixture(scope="class")
def tici_setup_fixture():
"""Ensure a consistent state for tests on-device"""
HARDWARE.initialize_hardware()
HARDWARE.set_power_save(False)
os.system("pkill -9 -f athena")
os.system("rm /dev/shm/*")


@pytest.hookimpl(tryfirst=True)
def pytest_collection_modifyitems(config, items):
skipper = pytest.mark.skip(reason="Skipping tici test on PC")
for item in items:
if not TICI and "tici" in item.keywords:
item.add_marker(skipper)
if "tici" in item.keywords:
if not TICI:
item.add_marker(skipper)
else:
item.fixturenames.append('tici_setup_fixture')

if "xdist_group_class_property" in item.keywords:
class_property_name = item.get_closest_marker('xdist_group_class_property').args[0]
Expand Down
8 changes: 1 addition & 7 deletions selfdrive/test/test_onroad.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,11 @@ def setUpClass(cls):

# setup env
params = Params()
if "CI" in os.environ:
params.clear_all()
params.remove("CurrentRoute")
set_params_enabled()
os.environ['TESTING_CLOSET'] = '1'
if os.path.exists(Paths.log_root()):
shutil.rmtree(Paths.log_root())
os.system("rm /dev/shm/*")

# Make sure athena isn't running
os.system("pkill -9 -f athena")

# start manager and run openpilot for a minute
proc = None
Expand Down Expand Up @@ -429,4 +423,4 @@ def test_engagable(self):


if __name__ == "__main__":
unittest.main()
pytest.main()
7 changes: 1 addition & 6 deletions system/hardware/tici/tests/test_hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@
@pytest.mark.tici
class TestHardware(unittest.TestCase):

@classmethod
def setUpClass(cls):
HARDWARE.initialize_hardware()
HARDWARE.set_power_save(False)

def test_power_save_time(self):
ts = []
for _ in range(5):
Expand All @@ -30,4 +25,4 @@ def test_power_save_time(self):


if __name__ == "__main__":
unittest.main()
pytest.main()
5 changes: 1 addition & 4 deletions system/hardware/tici/tests/test_power_draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from cereal.services import SERVICE_LIST
from openpilot.common.mock import mock_messages
from openpilot.selfdrive.car.car_helpers import write_car_param
from openpilot.system.hardware import HARDWARE
from openpilot.system.hardware.tici.power_monitor import get_power
from openpilot.selfdrive.manager.process_config import managed_processes
from openpilot.selfdrive.manager.manager import manager_cleanup
Expand Down Expand Up @@ -41,8 +40,6 @@ class Proc:
class TestPowerDraw(unittest.TestCase):

def setUp(self):
HARDWARE.initialize_hardware()
HARDWARE.set_power_save(False)
write_car_param()

# wait a bit for power save to disable
Expand Down Expand Up @@ -88,4 +85,4 @@ def test_camera_procs(self):


if __name__ == "__main__":
unittest.main()
pytest.main()

0 comments on commit 0277fc5

Please sign in to comment.