Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ci] Test stepping function of tvla in CI #151

Merged
merged 1 commit into from
Aug 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[ci] Test stepping function of tvla in CI
This commit modifies `test_general_nonleaking_project()` to run
TVLA with `--number-of-steps 10` and compare the produced result
with the checked-in numerical value, rather than just checking for
leakage.

Signed-off-by: Vladimir Rozic <vrozic@lowrisc.org>
vrozic committed Aug 15, 2023
commit 6256f65e047e4ec98e6e1468e75c38c8eecf1336
12 changes: 6 additions & 6 deletions cw/tvla.py
Original file line number Diff line number Diff line change
@@ -817,12 +817,12 @@ def run_tvla(ctx: typer.Context):
if save_to_disk_ttest:
if num_steps > 1:
log.info("Saving T-test Step")
np.savez('tmp/ttest-step.npy',
ttest_step=ttest_step,
trace_end_vec=trace_end_vec,
rnd_list=rnd_list,
byte_list=byte_list,
single_trace=traces[1])
np.savez_compressed('tmp/ttest-step.npy',
ttest_step=ttest_step,
trace_end_vec=trace_end_vec,
rnd_list=rnd_list,
byte_list=byte_list,
single_trace=traces[1])
else:
log.info("Saving T-test")
np.save('tmp/ttest.npy', ttest_trace)
3 changes: 3 additions & 0 deletions test/data/tvla_general/ttest-step-golden.npy.npz
Git LFS file not shown
28 changes: 25 additions & 3 deletions test/tvla_test.py
Original file line number Diff line number Diff line change
@@ -28,12 +28,34 @@ def ttest_significant(ttest_trace) -> bool:
return np.any(abs_max > threshold)


def ttest_compare_results(expected, received, delta) -> bool:
"""
Determine if the numerical values of two ttest traces match.

Checks if all nan values are in the same positions in both arrays.
Checks if all numerical values match within precision delta.
"""
nan_match = np.all(np.isnan(expected) == np.isnan(received))
numbers_match = np.all(np.logical_or(np.isnan(expected), np.abs(expected - received) < delta))
return nan_match and numbers_match


def test_general_nonleaking_project():
project_path = TestDataPath('tvla_general/ci_opentitan_simple_kmac.cwp')
tvla = TvlaCmd(Args(['--project-file', str(project_path),
'--mode', 'kmac', '--save-to-disk-ttest', 'run-tvla'])).run()
assert not ttest_significant(np.load('tmp/ttest.npy')), (
f"{tvla} did find significant leakage, which is unexpected")
'--mode', 'kmac', '--save-to-disk-ttest',
'--number-of-steps', '10', 'run-tvla'])).run()
expected_path = TestDataPath('tvla_general/ttest-step-golden.npy.npz')
expected_file = np.load(str(expected_path))
expected_trace = expected_file['ttest_step']
received_file = np.load('tmp/ttest-step.npy.npz')
received_trace = received_file['ttest_step']
# Expected and received traces should be equal within precision delta.
# Small mismatch is possible due to the differences in floating point operations
# on different machines.
delta = 0.001
assert ttest_compare_results(expected_trace, received_trace, delta), (
f"{tvla} generated ttest_step values that don't match the expected ones")


def test_general_leaking_histogram():