Skip to content

Commit 2eff57d

Browse files
committed
[fi] OTFI: Use OTFITest
1 parent 2f30aaf commit 2eff57d

File tree

1 file changed

+31
-8
lines changed

1 file changed

+31
-8
lines changed

target/communication/otfi.py

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,26 @@
77
from typing import Optional
88

99

10+
from target.communication.otfi_test import OTFITest
11+
12+
1013
class 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,38 @@ 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+
testname = testname.replace(f"{self.ip}_", "", 1)
55+
tests = [test for test in self.TESTS if test.name == testname]
56+
assert not len(tests) == 0, f"{testname} not found in {self.TESTS}"
57+
assert len(tests) == 1, f"Test duplicates with name {testname}"
58+
self._run_test(tests[0])
59+
60+
def _run_test(self, test: OTFITest) -> None:
61+
# OTFIx Fi command.
62+
self._ujson_fi_cmd()
63+
# Test command.
64+
time.sleep(0.01)
65+
self.target.write(json.dumps(test.cmd).encode("ascii"))
66+
# Test mode.
67+
if test.mode is not None:
68+
time.sleep(0.01)
69+
self.target.write(json.dumps(test.mode).encode("ascii"))
4770

4871
def read_response(self, max_tries: Optional[int] = 1) -> str:
49-
""" Read response from Crypto FI framework.
72+
"""Read response from Crypto FI framework.
5073
Args:
5174
max_tries: Maximum number of attempts to read from UART.
5275

0 commit comments

Comments
 (0)