77from typing import Optional
88
99
10+ from target .communication .otfi_test import OTFITest
11+
12+
1013class OTFI :
11- IP = ["Ibex" , "Otbn" , "Crypto" ]
14+ TESTS = []
15+ IP = ["Ibex" , "Otbn" , "Crypto" , "Rng" ]
16+
1217 def __init__ (self , target , ip ) -> None :
1318 self .target = target
1419 self .ip = ip
1520
16- assert self .ip in OTFI .IP , "ip ({self.ip} not in OTFI.IP ({OTFI.IP})"
21+ assert self .ip in OTFI .IP , f "ip ({ self .ip } not in OTFI.IP ({ OTFI .IP } )"
1722
1823 def _ujson_fi_cmd (self ) -> None :
1924 time .sleep (0.01 )
2025 self .target .write (json .dumps (f"{ self .ip } Fi" ).encode ("ascii" ))
2126 time .sleep (0.01 )
2227
2328 def init (self , test : Optional [str ] = "" ) -> None :
24- """ Initialize the FI code on the chip.
29+ """Initialize the FI code on the chip.
2530 Returns:
2631 The device ID of the device.
2732 """
@@ -33,20 +38,37 @@ def init(self, test: Optional[str] = "") -> None:
3338 # Read back device ID from device.
3439 return self .read_response (max_tries = 30 )
3540
36- def start_test (self , cfg : dict ) -> None :
37- """ Start the selected test.
41+ def start_test (
42+ self , cfg : Optional [dict ] = {}, testname : Optional [str ] = ""
43+ ) -> None :
44+ """Start the selected test.
3845
3946 Call the function selected in the config file. Uses the getattr()
4047 construct to call the function.
4148
4249 Args:
4350 cfg: Config dict containing the selected test.
4451 """
45- test_function = getattr (self , cfg ["test" ]["which_test" ])
46- test_function ()
52+ if cfg != {}:
53+ testname = cfg ["test" ]["which_test" ]
54+ tests = [test for test in self .TESTS if test .name == testname ]
55+ assert not len (tests ) == 0 , f"{ testname } not found in { self .TESTS } "
56+ assert len (tests ) == 1 , f"Test duplicates with name { testname } "
57+ self ._run_test (tests [0 ])
58+
59+ def _run_test (self , test : OTFITest ) -> None :
60+ # OTFIx Fi command.
61+ self ._ujson_fi_cmd ()
62+ # Test command.
63+ time .sleep (0.01 )
64+ self .target .write (json .dumps (test .cmd ).encode ("ascii" ))
65+ # Test mode.
66+ if test .mode is not None :
67+ time .sleep (0.01 )
68+ self .target .write (json .dumps (test .mode ).encode ("ascii" ))
4769
4870 def read_response (self , max_tries : Optional [int ] = 1 ) -> str :
49- """ Read response from Crypto FI framework.
71+ """Read response from Crypto FI framework.
5072 Args:
5173 max_tries: Maximum number of attempts to read from UART.
5274
0 commit comments