Skip to content

Commit 46913b3

Browse files
committed
tests/report.py: add average failure and match rate to result table
Signed-off-by: Tim Janik <timj@gnu.org>
1 parent 92d29aa commit 46913b3

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

tests/report.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ def generate_attack_statistics (n_input_files, acnf_matching, cs_matching, align
8989
n_cs_valid = {}
9090
n_acnf_valid = {}
9191
n_aligned = {}
92+
total_fail_perc = 0.0
93+
total_match_perc = 0.0
9294
# strip ATTACKNAMEseed123 to just ATTACKNAME
9395
strip_seed = lambda attack: re.sub(r'seed[0-9]+$', '', attack)
9496
# setup counters
@@ -98,6 +100,7 @@ def generate_attack_statistics (n_input_files, acnf_matching, cs_matching, align
98100
n_acnf_valid[attack] = 0
99101
n_cs_valid[attack] = 0
100102
n_aligned[attack] = 0
103+
num_attacks = len (n_input)
101104
# merge counts from different seeds of the same attack
102105
for attackdir in ATTACKS:
103106
attack = strip_seed (attackdir)
@@ -114,19 +117,29 @@ def generate_attack_statistics (n_input_files, acnf_matching, cs_matching, align
114117
s += 'Total input files: %d\n\n' % n_input_files
115118
s += '| **Attack** | **ACNF** | **CS** | **AO** | **Fail** | **Match** |\n'
116119
s += '|----------------------------|-----:|:----:|:----:|-----:|----:|\n'
120+
# Attack stats
117121
for attack in sorted (n_input.keys()):
118122
is_geometric_attack = bool (re.search (r'(?<![A-Za-z])g$', attack))
119123
cs_weight = 1 if is_geometric_attack else 0.5 # assume CS only catches 50% of leaks
120124
valid_count = n_acnf_valid[attack] + n_cs_valid[attack] * cs_weight
121125
mismatch_perc = (n_input[attack] - valid_count) * 100.0 / n_input[attack]
126+
match_perc = 100 - mismatch_perc
127+
total_fail_perc += mismatch_perc
128+
total_match_perc += match_perc
122129
H,E = ('**','') if mismatch_perc < 1e-9 else ('','**') # highlight matches <= 90%
123130
s += '| %s | %d/%d | %d | %d | %s%.1f%%%s | %s%.1f%%%s\n' % \
124131
(attack,
125132
n_acnf_valid[attack], n_input[attack],
126133
n_cs_valid[attack],
127134
n_aligned[attack],
128135
E, mismatch_perc, E,
129-
H, 100 - mismatch_perc, H)
136+
H, match_perc, H)
137+
# Add average row to the table
138+
if num_attacks > 0:
139+
avg_fail_perc = total_fail_perc / num_attacks
140+
avg_match_perc = total_match_perc / num_attacks
141+
s += '| **Average:** | | | | **%.1f%%** | **%.1f%%** |\n' % (avg_fail_perc, avg_match_perc)
142+
130143
print (s)
131144

132145
# Timings

0 commit comments

Comments
 (0)