mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-07-01 03:22:07 +08:00
test car interface: fuzzy CarParams (#28931)
* bump * should be bytes * draft fuzzy car params * stash * bump * bump * this is explored! * some clean up * more clean up * clean up * can't easily * clean up * no import * Apply suggestions from code review * move into a function * Update selfdrive/car/tests/test_car_interfaces.py * Update selfdrive/car/tests/test_car_interfaces.py * Update selfdrive/car/tests/test_car_interfaces.py * come onn * we know it will return a dict here old-commit-hash: c9f80e89b7ab837b9a5402723e4e028155354dde
This commit is contained in:
@@ -9,8 +9,32 @@ from parameterized import parameterized
|
||||
from cereal import car
|
||||
from selfdrive.car import gen_empty_fingerprint
|
||||
from selfdrive.car.car_helpers import interfaces
|
||||
from selfdrive.car.fingerprints import _FINGERPRINTS as FINGERPRINTS, all_known_cars
|
||||
from selfdrive.test.fuzzy_generation import FuzzyGenerator
|
||||
from selfdrive.car.fingerprints import all_known_cars
|
||||
from selfdrive.test.fuzzy_generation import DrawType, FuzzyGenerator
|
||||
|
||||
|
||||
def get_fuzzy_car_interface_args(draw: DrawType) -> dict:
|
||||
# Fuzzy CAN fingerprints and FW versions to test more states of the CarInterface
|
||||
fingerprint_strategy = st.fixed_dictionaries({key: st.dictionaries(st.integers(min_value=0, max_value=0x800),
|
||||
st.integers(min_value=0, max_value=64)) for key in
|
||||
gen_empty_fingerprint()})
|
||||
|
||||
# just the most important fields
|
||||
car_fw_strategy = st.lists(st.fixed_dictionaries({
|
||||
'ecu': st.sampled_from(list(car.CarParams.Ecu.schema.enumerants.keys())),
|
||||
# TODO: only use reasonable addrs for the paired ecu and brand/platform
|
||||
'address': st.integers(min_value=0, max_value=0x800),
|
||||
}))
|
||||
|
||||
params_strategy = st.fixed_dictionaries({
|
||||
'fingerprints': fingerprint_strategy,
|
||||
'car_fw': car_fw_strategy,
|
||||
'experimental_long': st.booleans(),
|
||||
})
|
||||
|
||||
params: dict = draw(params_strategy)
|
||||
params['car_fw'] = [car.CarParams.CarFw(**fw) for fw in params['car_fw']]
|
||||
return params
|
||||
|
||||
|
||||
class TestCarInterfaces(unittest.TestCase):
|
||||
@@ -19,19 +43,12 @@ class TestCarInterfaces(unittest.TestCase):
|
||||
@settings(max_examples=5)
|
||||
@given(data=st.data())
|
||||
def test_car_interfaces(self, car_name, data):
|
||||
if car_name in FINGERPRINTS:
|
||||
fingerprint = FINGERPRINTS[car_name][0]
|
||||
else:
|
||||
fingerprint = {}
|
||||
|
||||
CarInterface, CarController, CarState = interfaces[car_name]
|
||||
fingerprints = gen_empty_fingerprint()
|
||||
fingerprints.update({k: fingerprint for k in fingerprints.keys()})
|
||||
|
||||
car_fw = []
|
||||
experimental_long = data.draw(st.booleans())
|
||||
args = get_fuzzy_car_interface_args(data.draw)
|
||||
|
||||
car_params = CarInterface.get_params(car_name, fingerprints, car_fw, experimental_long=experimental_long, docs=False)
|
||||
car_params = CarInterface.get_params(car_name, args['fingerprints'], args['car_fw'],
|
||||
experimental_long=args['experimental_long'], docs=False)
|
||||
car_interface = CarInterface(car_params, CarController, CarState)
|
||||
assert car_params
|
||||
assert car_interface
|
||||
|
||||
Reference in New Issue
Block a user