7
7
from typing import Optional
8
8
9
9
10
+ from target .communication .otfi_test import OTFITest
11
+
12
+
10
13
class OTFI :
11
- IP = ["Ibex" , "Otbn" , "Crypto" ]
14
+ TESTS = []
15
+ IP = ["Ibex" , "Otbn" , "Crypto" , "Rng" ]
16
+
12
17
def __init__ (self , target , ip ) -> None :
13
18
self .target = target
14
19
self .ip = ip
15
20
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 } )"
17
22
18
23
def _ujson_fi_cmd (self ) -> None :
19
24
time .sleep (0.01 )
20
25
self .target .write (json .dumps (f"{ self .ip } Fi" ).encode ("ascii" ))
21
26
time .sleep (0.01 )
22
27
23
28
def init (self , test : Optional [str ] = "" ) -> None :
24
- """ Initialize the FI code on the chip.
29
+ """Initialize the FI code on the chip.
25
30
Returns:
26
31
The device ID of the device.
27
32
"""
@@ -33,20 +38,37 @@ def init(self, test: Optional[str] = "") -> None:
33
38
# Read back device ID from device.
34
39
return self .read_response (max_tries = 30 )
35
40
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.
38
45
39
46
Call the function selected in the config file. Uses the getattr()
40
47
construct to call the function.
41
48
42
49
Args:
43
50
cfg: Config dict containing the selected test.
44
51
"""
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" ))
47
69
48
70
def read_response (self , max_tries : Optional [int ] = 1 ) -> str :
49
- """ Read response from Crypto FI framework.
71
+ """Read response from Crypto FI framework.
50
72
Args:
51
73
max_tries: Maximum number of attempts to read from UART.
52
74
0 commit comments