camerad: stress test (#34735)

* refactor a bunch of stuff

* prob

* enable

* rm print

* cleanup

---------

Co-authored-by: Comma Device <device@comma.ai>
This commit is contained in:
Adeeb Shihadeh
2025-03-05 19:31:44 -08:00
committed by GitHub
parent 4bb0dfd59c
commit 8c2cd247f0
2 changed files with 7 additions and 8 deletions
+3 -3
View File
@@ -211,9 +211,9 @@ private:
inline static bool first_frame_synced = false;
// a mode for stressing edge cases: realignment, sync failures, etc.
inline bool stress_test(const char* log, float prob=0.02) {
static bool enable = getenv("SPECTRA_STRESS_TEST") != nullptr;
bool triggered = enable && ((static_cast<double>(rand()) / RAND_MAX) < prob);
inline bool stress_test(const char* log) {
static double prob = std::stod(util::getenv("SPECTRA_ERROR_PROB", "-1"));;
bool triggered = (prob > 0) && ((static_cast<double>(rand()) / RAND_MAX) < prob);
if (triggered) {
LOGE("stress test (cam %d): %s", cc.camera_num, log);
}
+4 -5
View File
@@ -83,13 +83,12 @@ class TestCamerad:
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)
assert np.all((ts[c]['t'] - ts[c]['timestampSof']/1e9) > 1e-7)
assert np.all((ts[c]['t'] - ts[c]['timestampEof']/1e9) > 1e-7)
@pytest.mark.skip("TODO: enable this")
def test_stress_test(self):
os.environ['SPECTRA_STRESS_TEST'] = '1'
logs = run_and_log(["camerad", ], CAMERAS, 15)
os.environ['SPECTRA_ERROR_PROB'] = '0.008'
logs = run_and_log(["camerad", ], CAMERAS, 10)
ts = msgs_to_time_series(logs)
# we should see some jumps from introduced errors