mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-06-29 10:32:10 +08:00
hypothesis: speed up test case reduction
old-commit-hash: 0c29adcc76ce115cc5c490595d15148810b35d30
This commit is contained in:
@@ -22,12 +22,13 @@ from selfdrive.manager.process_config import managed_processes
|
||||
# Numpy gives different results based on CPU features after version 19
|
||||
NUMPY_TOLERANCE = 1e-7
|
||||
CI = "CI" in os.environ
|
||||
TIMEOUT = 15
|
||||
|
||||
ProcessConfig = namedtuple('ProcessConfig', ['proc_name', 'pub_sub', 'ignore', 'init_callback', 'should_recv_callback', 'tolerance', 'fake_pubsubmaster'])
|
||||
|
||||
|
||||
def wait_for_event(evt):
|
||||
if not evt.wait(15):
|
||||
if not evt.wait(TIMEOUT):
|
||||
if threading.currentThread().getName() == "MainThread":
|
||||
# tested process likely died. don't let test just hang
|
||||
raise Exception("Timeout reached. Tested process likely crashed.")
|
||||
|
||||
@@ -1,20 +1,18 @@
|
||||
#!/usr/bin/env python3
|
||||
import sys
|
||||
import unittest
|
||||
from collections import Counter
|
||||
|
||||
import hypothesis.strategies as st
|
||||
import numpy as np
|
||||
from hypothesis import assume, given, settings
|
||||
from hypothesis import given, settings
|
||||
|
||||
from cereal import log
|
||||
from selfdrive.car.toyota.values import CAR as TOYOTA
|
||||
from selfdrive.test.process_replay.process_replay import (CONFIGS,
|
||||
replay_process)
|
||||
import selfdrive.test.process_replay.process_replay as pr
|
||||
|
||||
|
||||
def get_process_config(process):
|
||||
return [cfg for cfg in CONFIGS if cfg.proc_name == process][0]
|
||||
return [cfg for cfg in pr.CONFIGS if cfg.proc_name == process][0]
|
||||
|
||||
|
||||
def get_event_union_strategy(r, name):
|
||||
@@ -109,12 +107,6 @@ def convert_to_lr(msgs):
|
||||
return [log.Event.new_message(**m).as_reader() for m in msgs]
|
||||
|
||||
|
||||
def assume_all_services_present(cfg, lr):
|
||||
tps = Counter([m.which() for m in lr])
|
||||
for p in cfg.pub_sub:
|
||||
assume(tps[p] > 0)
|
||||
|
||||
|
||||
def is_finite(d, exclude=[], prefix=""): # pylint: disable=dangerous-default-value
|
||||
ret = True
|
||||
for k, v in d.items():
|
||||
@@ -136,8 +128,8 @@ def is_finite(d, exclude=[], prefix=""): # pylint: disable=dangerous-default-va
|
||||
def test_process(dat, name):
|
||||
cfg = get_process_config(name)
|
||||
lr = convert_to_lr(dat)
|
||||
assume_all_services_present(cfg, lr)
|
||||
return replay_process(cfg, lr, TOYOTA.COROLLA_TSS2)
|
||||
pr.TIMEOUT = 0.1
|
||||
return pr.replay_process(cfg, lr, TOYOTA.COROLLA_TSS2)
|
||||
|
||||
|
||||
class TestFuzzy(unittest.TestCase):
|
||||
@@ -149,7 +141,7 @@ class TestFuzzy(unittest.TestCase):
|
||||
assert is_finite(lp)
|
||||
|
||||
@given(get_strategy_for_process('locationd', finite=True))
|
||||
@settings(deadline=10000)
|
||||
@settings(deadline=1000)
|
||||
def test_locationd(self, dat):
|
||||
exclude = [
|
||||
'positionGeodetic.std',
|
||||
|
||||
Reference in New Issue
Block a user