#!/usr/bin/env python3
import unittest
from cereal import car
from selfdrive . car . fingerprints import FW_VERSIONS
from selfdrive . car . fw_versions import match_fw_to_car
from selfdrive . car . toyota . values import CAR as TOYOTA
CarFw = car . CarParams . CarFw
Ecu = car . CarParams . Ecu
ECU_NAME = { v : k for k , v in Ecu . schema . enumerants . items ( ) }
class TestFwFingerprint ( unittest . TestCase ) :
def assertFingerprints ( self , candidates , expected ) :
candidates = list ( candidates )
self . assertEqual ( len ( candidates ) , 1 )
self . assertEqual ( candidates [ 0 ] , TOYOTA . RAV4_TSS2 )
def test_rav4_tss2 ( self ) :
CP = car . CarParams . new_message ( )
CP . carFw = [
{ " ecu " : Ecu . esp ,
" fwVersion " : b " \x01 F15260R210 \x00 \x00 \x00 \x00 \x00 \x00 " ,
" address " : 1968 ,
" subAddress " : 0 } ,
{ " ecu " : Ecu . engine ,
" fwVersion " : b " \x02 8966342Y8000 \x00 \x00 \x00 \x00 897CF1201001 \x00 \x00 \x00 \x00 " ,
" address " : 1792 ,
" subAddress " : 0 } ,
{ " ecu " : Ecu . eps ,
" fwVersion " : b " \x02 8965B0R01200 \x00 \x00 \x00 \x00 8965B0R02200 \x00 \x00 \x00 \x00 " ,
" address " : 1953 ,
" subAddress " : 0 } ,
{ " ecu " : Ecu . fwdRadar ,
" fwVersion " : b " \x01 8821F3301200 \x00 \x00 \x00 \x00 " ,
" address " : 1872 ,
" subAddress " : 15 } ,
{ " ecu " : Ecu . fwdCamera ,
" fwVersion " : b " \x02 8646F4203300 \x00 \x00 \x00 \x00 8646G26011A0 \x00 \x00 \x00 \x00 " ,
" address " : 1872 ,
" subAddress " : 109 }
]
self . assertFingerprints ( match_fw_to_car ( CP . carFw ) , TOYOTA . RAV4_TSS2 )
def test_no_duplicate_fw_versions ( self ) :
passed = True
for car_name , ecus in FW_VERSIONS . items ( ) :
for ecu , ecu_fw in ecus . items ( ) :
duplicates = set ( [ fw for fw in ecu_fw if ecu_fw . count ( fw ) > 1 ] )
if len ( duplicates ) :
print ( car_name , ECU_NAME [ ecu [ 0 ] ] , duplicates )
passed = False
self . assertTrue ( passed , " Duplicate FW versions found " )
if __name__ == " __main__ " :
unittest . main ( )