camerad: stress test (#34735)

* refactor a bunch of stuff

* prob

* enable

* rm print

* cleanup

---------

Co-authored-by: Comma Device <device@comma.ai>
notmaster30
Adeeb Shihadeh 2 months ago committed by GitHub
parent 4bb0dfd59c
commit 8c2cd247f0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 6
      system/camerad/cameras/spectra.h
  2. 9
      system/camerad/test/test_camerad.py

@ -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);
}

@ -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

Loading…
Cancel
Save