Skip to content

Commit

Permalink
more unit test speedup (commaai#30997)
Browse files Browse the repository at this point in the history
* that's super slow

* fix startup test

* fix
  • Loading branch information
adeebshihadeh authored Jan 14, 2024
1 parent e17e661 commit fe6aff0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
27 changes: 14 additions & 13 deletions selfdrive/controls/tests/test_startup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
import time
import os
import unittest
from parameterized import parameterized

Expand All @@ -11,7 +11,7 @@
from openpilot.selfdrive.car.toyota.values import CAR as TOYOTA
from openpilot.selfdrive.car.mazda.values import CAR as MAZDA
from openpilot.selfdrive.controls.lib.events import EVENT_NAME
from openpilot.selfdrive.test.helpers import with_processes
from openpilot.selfdrive.manager.process_config import managed_processes

EventName = car.CarEvent.EventName
Ecu = car.CarParams.Ecu
Expand All @@ -38,6 +38,9 @@

class TestStartup(unittest.TestCase):

def tearDown(self):
managed_processes['controlsd'].stop()

@parameterized.expand([
# TODO: test EventName.startup for release branches
Expand All @@ -61,15 +64,11 @@ class TestStartup(unittest.TestCase):
(EventName.startupMaster, TOYOTA.COROLLA, COROLLA_FW_VERSIONS_FUZZY, "toyota"),
(EventName.startupMaster, TOYOTA.COROLLA, COROLLA_FW_VERSIONS_FUZZY, "toyota"),
])
@with_processes(['controlsd'])
def test_startup_alert(self, expected_event, car_model, fw_versions, brand):

# TODO: this should be done without any real sockets
controls_sock = messaging.sub_sock("controlsState")
pm = messaging.PubMaster(['can', 'pandaStates'])

params = Params()
params.clear_all()
params.put_bool("Passive", False)
params.put_bool("OpenpilotEnabledToggle", True)

Expand All @@ -91,11 +90,13 @@ def test_startup_alert(self, expected_event, car_model, fw_versions, brand):
cp.carVin = "1" * 17
cp.carFw = car_fw
params.put("CarParamsCache", cp.to_bytes())
else:
os.environ['SKIP_FW_QUERY'] = '1'

time.sleep(2) # wait for controlsd to be ready
managed_processes['controlsd'].start()

assert pm.wait_for_readers_to_update('can', 5)
pm.send('can', can_list_to_can_capnp([[0, 0, b"", 0]]))
time.sleep(0.1)

msg = messaging.new_message('pandaStates', 1)
msg.pandaStates[0].pandaType = log.PandaState.PandaType.uno
Expand All @@ -107,18 +108,18 @@ def test_startup_alert(self, expected_event, car_model, fw_versions, brand):
else:
finger = _FINGERPRINTS[car_model][0]

msgs = [[addr, 0, b'\x00'*length, 0] for addr, length in finger.items()]
for _ in range(1000):
# controlsd waits for boardd to echo back that it has changed the multiplexing mode
if not params.get_bool("ObdMultiplexingChanged"):
params.put_bool("ObdMultiplexingChanged", True)

msgs = [[addr, 0, b'\x00'*length, 0] for addr, length in finger.items()]
pm.send('can', can_list_to_can_capnp(msgs))
assert pm.wait_for_readers_to_update('can', 2, dt=0.001)

time.sleep(0.01)
msgs = messaging.drain_sock(controls_sock)
if len(msgs):
event_name = msgs[0].controlsState.alertType.split("/")[0]
ctrls = messaging.drain_sock(controls_sock)
if len(ctrls):
event_name = ctrls[0].controlsState.alertType.split("/")[0]
self.assertEqual(EVENT_NAME[expected_event], event_name,
f"expected {EVENT_NAME[expected_event]} for '{car_model}', got {event_name}")
break
Expand Down
6 changes: 2 additions & 4 deletions tools/replay/tests/test_replay.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,6 @@ std::string download_demo_route() {
std::string log_path = util::string_format("%s/%s--%d/", data_dir.c_str(), route_name.c_str(), i);
util::create_directories(log_path, 0755);
REQUIRE(download_to_file(remote_route.at(i).rlog.toStdString(), log_path + "rlog.bz2"));
REQUIRE(download_to_file(remote_route.at(i).driver_cam.toStdString(), log_path + "dcamera.hevc"));
REQUIRE(download_to_file(remote_route.at(i).wide_road_cam.toStdString(), log_path + "ecamera.hevc"));
REQUIRE(download_to_file(remote_route.at(i).qcamera.toStdString(), log_path + "qcamera.ts"));
}
}
Expand All @@ -139,7 +137,7 @@ std::string download_demo_route() {
TEST_CASE("Local route") {
std::string data_dir = download_demo_route();

auto flags = GENERATE(REPLAY_FLAG_DCAM | REPLAY_FLAG_ECAM, REPLAY_FLAG_QCAMERA);
auto flags = GENERATE(0, REPLAY_FLAG_QCAMERA);
Route route(DEMO_ROUTE, QString::fromStdString(data_dir));
REQUIRE(route.load());
REQUIRE(route.segments().size() == 2);
Expand All @@ -149,7 +147,7 @@ TEST_CASE("Local route") {
}

TEST_CASE("Remote route") {
auto flags = GENERATE(REPLAY_FLAG_DCAM | REPLAY_FLAG_ECAM, REPLAY_FLAG_QCAMERA);
auto flags = GENERATE(0, REPLAY_FLAG_QCAMERA);
Route route(DEMO_ROUTE);
REQUIRE(route.load());
REQUIRE(route.segments().size() == 13);
Expand Down

0 comments on commit fe6aff0

Please sign in to comment.