@ -9,8 +9,32 @@ from parameterized import parameterized
from cereal import car
from cereal import car
from selfdrive . car import gen_empty_fingerprint
from selfdrive . car import gen_empty_fingerprint
from selfdrive . car . car_helpers import interfaces
from selfdrive . car . car_helpers import interfaces
from selfdrive . car . fingerprints import _FINGERPRINTS as FINGERPRINTS , all_known_cars
from selfdrive . car . fingerprints import all_known_cars
from selfdrive . test . fuzzy_generation import FuzzyGenerator
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 ) :
class TestCarInterfaces ( unittest . TestCase ) :
@ -19,19 +43,12 @@ class TestCarInterfaces(unittest.TestCase):
@settings ( max_examples = 5 )
@settings ( max_examples = 5 )
@given ( data = st . data ( ) )
@given ( data = st . data ( ) )
def test_car_interfaces ( self , car_name , 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 ]
CarInterface , CarController , CarState = interfaces [ car_name ]
fingerprints = gen_empty_fingerprint ( )
fingerprints . update ( { k : fingerprint for k in fingerprints . keys ( ) } )
car_fw = [ ]
args = get_fuzzy_car_interface_args ( data . draw )
experimental_long = data . draw ( st . booleans ( ) )
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 )
car_interface = CarInterface ( car_params , CarController , CarState )
assert car_params
assert car_params
assert car_interface
assert car_interface