From f4d17cbfdd8f2e1a50259d5d9776dd0d993d44a1 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Wed, 5 Mar 2025 16:54:35 -0800 Subject: [PATCH] camerad: sanity check tests (#34785) lil more --- system/camerad/sensors/os04c10.cc | 3 +++ system/camerad/test/test_camerad.py | 33 +++++++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/system/camerad/sensors/os04c10.cc b/system/camerad/sensors/os04c10.cc index b3a7e39bfb..d008e1d07b 100644 --- a/system/camerad/sensors/os04c10.cc +++ b/system/camerad/sensors/os04c10.cc @@ -43,6 +43,9 @@ OS04C10::OS04C10() { frame_data_type = 0x2c; mclk_frequency = 24000000; // Hz + // TODO: this was set from logs. actually calculate it out + readout_time_ns = 11000000; + ev_scale = 150.0; dc_gain_factor = 1; dc_gain_min_weight = 1; // always on is fine diff --git a/system/camerad/test/test_camerad.py b/system/camerad/test/test_camerad.py index e88a7bf4bf..0ab71bee46 100644 --- a/system/camerad/test/test_camerad.py +++ b/system/camerad/test/test_camerad.py @@ -64,7 +64,36 @@ class TestCamerad: laggy_frames = {k: v for k, v in diffs.items() if v > 1.1} assert len(laggy_frames) == 0, f"Frames not synced properly: {laggy_frames=}" + def test_sanity_checks(self, logs): + self._sanity_checks(logs) + + def _sanity_checks(self, ts): + for c in CAMERAS: + assert c in ts + assert len(ts[c]['t']) > 20 + + # not a valid request id + assert 0 not in ts[c]['requestId'] + + # should monotonically increase + assert np.all(np.diff(ts[c]['frameId']) >= 1) + assert np.all(np.diff(ts[c]['requestId']) >= 1) + + # EOF > SOF + assert np.all((ts[c]['timestampEof'] - ts[c]['timestampSof']) > 0) + + # logMonoTime > SOF + assert np.all((ts[c]['t'] - ts[c]['timestampSof']/1e9) > 0.001) + assert np.all((ts[c]['t'] - ts[c]['timestampEof']/1e9) > 0.001) + @pytest.mark.skip("TODO: enable this") - def test_stress_test(self, logs): + def test_stress_test(self): os.environ['SPECTRA_STRESS_TEST'] = '1' - run_and_log(["camerad", ], CAMERAS, 5) + logs = run_and_log(["camerad", ], CAMERAS, 15) + ts = msgs_to_time_series(logs) + + # we should see some jumps from introduced errors + assert np.max([ np.max(np.diff(ts[c]['frameId'])) for c in CAMERAS ]) > 1 + assert np.max([ np.max(np.diff(ts[c]['requestId'])) for c in CAMERAS ]) > 1 + + self._sanity_checks(ts)