Skip to content

Commit

Permalink
[fi] Add evaluation log
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
nasahlpa committed Mar 28, 2024
1 parent 6c045b1 commit bd65070
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
23 changes: 23 additions & 0 deletions fault_injection/fi_ibex.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
Expand Down Expand Up @@ -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:
Expand Down
23 changes: 23 additions & 0 deletions fault_injection/fi_otbn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit bd65070

Please sign in to comment.