diff --git a/system/camerad/cameras/spectra.h b/system/camerad/cameras/spectra.h index 2070363a16..fb1bbf874a 100644 --- a/system/camerad/cameras/spectra.h +++ b/system/camerad/cameras/spectra.h @@ -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(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(rand()) / RAND_MAX) < prob); if (triggered) { LOGE("stress test (cam %d): %s", cc.camera_num, log); } diff --git a/system/camerad/test/test_camerad.py b/system/camerad/test/test_camerad.py index 0ab71bee46..ab76985972 100644 --- a/system/camerad/test/test_camerad.py +++ b/system/camerad/test/test_camerad.py @@ -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