From bd650700eddd3908641313e4a3833ba7a90e1b61 Mon Sep 17 00:00:00 2001 From: Pascal Nasahl Date: Tue, 12 Mar 2024 07:21:52 +0000 Subject: [PATCH] [fi] Add evaluation log This commit adds an evaluation log, i.e., the total number of faults, the number of expected results, no responses, and unexpected results. Signed-off-by: Pascal Nasahl --- fault_injection/fi_ibex.py | 23 +++++++++++++++++++++++ fault_injection/fi_otbn.py | 23 +++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/fault_injection/fi_ibex.py b/fault_injection/fi_ibex.py index b49ca1d8..36e279ad 100755 --- a/fault_injection/fi_ibex.py +++ b/fault_injection/fi_ibex.py @@ -66,6 +66,25 @@ def setup(cfg: dict, project: Path): return target, fi_gear, project +def print_fi_statistic(fi_results: list) -> None: + """ Print FI Statistic. + + Prints the number of FISuccess.SUCCESS, FISuccess.EXPRESPONSE, and + FISuccess.NORESPONSE. + + Args: + fi_results: The FI results. + """ + num_total = len(fi_results) + num_succ = round((fi_results.count(FISuccess.SUCCESS) / num_total) * 100, 2) + num_exp = round((fi_results.count(FISuccess.EXPRESPONSE) / num_total) * 100, 2) + num_no = round((fi_results.count(FISuccess.NORESPONSE) / num_total) * 100, 2) + logger.info(f"{num_total} faults, {fi_results.count(FISuccess.SUCCESS)}" + f"({num_succ}%) successful, {fi_results.count(FISuccess.EXPRESPONSE)}" + f"({num_exp}%) expected, and {fi_results.count(FISuccess.NORESPONSE)}" + f"({num_no}%) no response.") + + def fi_parameter_sweep(cfg: dict, target: Target, fi_gear, project: FIProject, ot_communication: OTFIIbex) -> None: """ Fault parameter sweep. @@ -81,6 +100,8 @@ def fi_parameter_sweep(cfg: dict, target: Target, fi_gear, """ # Configure the trigger. ot_communication.init_trigger() + # Store results in array for a quick access. + fi_results = [] # Start the parameter sweep. remaining_iterations = fi_gear.get_num_fault_injections() with tqdm(total=remaining_iterations, desc="Injecting", ncols=80, @@ -127,9 +148,11 @@ def fi_parameter_sweep(cfg: dict, target: Target, fi_gear, x_pos = fault_parameters.get("x_pos"), y_pos = fault_parameters.get("y_pos") ) + fi_results.append(fi_result) remaining_iterations -= 1 pbar.update(1) + print_fi_statistic(fi_results) def print_plot(project: FIProject, config: dict, file: Path) -> None: diff --git a/fault_injection/fi_otbn.py b/fault_injection/fi_otbn.py index 81987951..35c52e21 100755 --- a/fault_injection/fi_otbn.py +++ b/fault_injection/fi_otbn.py @@ -65,6 +65,25 @@ def setup(cfg: dict, project: Path): return target, fi_gear, project +def print_fi_statistic(fi_results: list) -> None: + """ Print FI Statistic. + + Prints the number of FISuccess.SUCCESS, FISuccess.EXPRESPONSE, and + FISuccess.NORESPONSE. + + Args: + fi_results: The FI results. + """ + num_total = len(fi_results) + num_succ = round((fi_results.count(FISuccess.SUCCESS) / num_total) * 100, 2) + num_exp = round((fi_results.count(FISuccess.EXPRESPONSE) / num_total) * 100, 2) + num_no = round((fi_results.count(FISuccess.NORESPONSE) / num_total) * 100, 2) + logger.info(f"{num_total} faults, {fi_results.count(FISuccess.SUCCESS)}" + f"({num_succ}%) successful, {fi_results.count(FISuccess.EXPRESPONSE)}" + f"({num_exp}%) expected, and {fi_results.count(FISuccess.NORESPONSE)}" + f"({num_no}%) no response.") + + def fi_parameter_sweep(cfg: dict, target: Target, fi_gear, project: FIProject, ot_communication: OTFIOtbn) -> None: """ Fault parameter sweep. @@ -82,6 +101,8 @@ def fi_parameter_sweep(cfg: dict, target: Target, fi_gear, ot_communication.init_keymgr(cfg["test"]["which_test"]) # Configure the trigger. ot_communication.init_trigger() + # Store results in array for a quick access. + fi_results = [] # Start the parameter sweep. remaining_iterations = fi_gear.get_num_fault_injections() with tqdm(total=remaining_iterations, desc="Injecting", ncols=80, @@ -128,9 +149,11 @@ def fi_parameter_sweep(cfg: dict, target: Target, fi_gear, x_pos = fault_parameters.get("x_pos"), y_pos = fault_parameters.get("y_pos") ) + fi_results.append(fi_result) remaining_iterations -= 1 pbar.update(1) + print_fi_statistic(fi_results) def print_plot(project: FIProject, config: dict, file: Path) -> None: