-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR adds a new CI job to automatically compare a generated trace to a golden reference trace. This helps to quickly identify CI issues. Signed-off-by: Pascal Nasahl <[email protected]>
- Loading branch information
Showing
6 changed files
with
174 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/bin/bash | ||
|
||
# Copyright lowRISC contributors. | ||
# Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# Simple script to test AES capture. | ||
mkdir -p tmp | ||
|
||
# AES | ||
MODE="aes" | ||
BOARD=cw310 | ||
declare -A aes_test_list | ||
aes_test_list["aes-static"]=100 | ||
|
||
ARGS="--force-program-bitstream" | ||
for test in ${!aes_test_list[@]}; do | ||
echo Testing ${test} on CW310 - `date` | ||
NUM_TRACES=${aes_test_list[${test}]} | ||
../cw/capture.py --cfg-file ci_capture_aes_cw310.yaml capture ${test} \ | ||
--num-traces ${NUM_TRACES} ${ARGS} &>> "tmp/test_capture.log" | ||
|
||
mv ./ci_projects/sample_traces_${MODE}.html tmp/${test}_traces.html | ||
ARGS="" | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright lowRISC contributors. | ||
# Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
import argparse | ||
import sys | ||
|
||
import chipwhisperer as cw | ||
import numpy as np | ||
import scipy.stats | ||
|
||
|
||
def analyze_traces(file_proj, file_gold_proj, corr_coeff) -> bool: | ||
"""Performs a correlation between golden and new traces. | ||
This function: | ||
- Computes the mean of the golden and new traces, | ||
- Computes the pearson coefficient of these means, | ||
- Compares the coefficient with the user provided threshold. | ||
Args: | ||
file_proj: The new Chipwhisperer project file. | ||
file_gold_proj: The golden Chipwhisperer project file. | ||
corr_coeff: User defined correlation threshold. | ||
Returns: | ||
True if trace comparison succeeds, False otherwise. | ||
""" | ||
# Open the current project | ||
proj_curr = cw.open_project(file_proj) | ||
# Calculate mean of new traces | ||
curr_trace = np.mean(proj_curr.waves, axis=0) | ||
|
||
# Import the golden project | ||
proj_gold = cw.import_project(file_gold_proj) | ||
# Calculate mean of golden traces | ||
gold_trace = np.mean(proj_gold.waves, axis=0) | ||
|
||
# Pearson correlation: golden trace vs. mean of new traces | ||
calc_coeff = scipy.stats.pearsonr(gold_trace, curr_trace).correlation | ||
print(f'Correlation={round(calc_coeff,3)},') | ||
# Fail / pass | ||
if calc_coeff < corr_coeff: | ||
return False | ||
else: | ||
return True | ||
|
||
|
||
def parse_args(): | ||
"""Parses command-line arguments.""" | ||
parser = argparse.ArgumentParser( | ||
description="""Calculate Pearson correlation between golden | ||
traces and captured traces. Failes when correlation | ||
coefficient is below user threshold.""" | ||
) | ||
parser.add_argument( | ||
"-f", | ||
"--file_proj", | ||
required=True, | ||
help="chipwhisperer project file" | ||
) | ||
parser.add_argument( | ||
"-g", | ||
"--file_gold_proj", | ||
required=True, | ||
help="chipwhisperergolden project file" | ||
) | ||
parser.add_argument( | ||
"-c", | ||
"--corr_coeff", | ||
type=float, | ||
required=True, | ||
help="specifies the correlation coefficient threshold" | ||
) | ||
return parser.parse_args() | ||
|
||
|
||
def main() -> int: | ||
"""Parses command-line arguments and TODO""" | ||
args = parse_args() | ||
|
||
if analyze_traces(**vars(args)): | ||
print('Traces OK.') | ||
else: | ||
print('Traces correlation below threshold.') | ||
sys.exit(1) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters