summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/bpf/veristat.c
diff options
context:
space:
mode:
authorAndrii Nakryiko <andrii@kernel.org>2022-10-05 19:14:49 +0300
committerAlexei Starovoitov <ast@kernel.org>2022-10-06 02:55:11 +0300
commit6df2eb45e378f38ca42776276e7bb5b5078c12cf (patch)
tree3c04a3c7e55fd98857faae8eaffcf55ded9633fc /tools/testing/selftests/bpf/veristat.c
parent2a72f5951ac6d613216a93ae3e172cabb04aaefc (diff)
downloadlinux-6df2eb45e378f38ca42776276e7bb5b5078c12cf.tar.xz
selftests/bpf: avoid reporting +100% difference in veristat for actual 0%
In special case when both base and comparison values are 0, veristat currently reports "+0 (+100%)" difference, which is quite confusing. Fix it up to be "+0 (+0%)". Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/r/20221005161450.1064469-2-andrii@kernel.org Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'tools/testing/selftests/bpf/veristat.c')
-rw-r--r--tools/testing/selftests/bpf/veristat.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/tools/testing/selftests/bpf/veristat.c b/tools/testing/selftests/bpf/veristat.c
index b0d83a28e348..38f678122a7d 100644
--- a/tools/testing/selftests/bpf/veristat.c
+++ b/tools/testing/selftests/bpf/veristat.c
@@ -1104,17 +1104,21 @@ static void output_comp_stats(const struct verif_stats *base, const struct verif
else
snprintf(diff_buf, sizeof(diff_buf), "%s", "MISMATCH");
} else {
+ double p = 0.0;
+
snprintf(base_buf, sizeof(base_buf), "%ld", base_val);
snprintf(comp_buf, sizeof(comp_buf), "%ld", comp_val);
diff_val = comp_val - base_val;
if (base == &fallback_stats || comp == &fallback_stats || base_val == 0) {
- snprintf(diff_buf, sizeof(diff_buf), "%+ld (%+.2lf%%)",
- diff_val, comp_val < base_val ? -100.0 : 100.0);
+ if (comp_val == base_val)
+ p = 0.0; /* avoid +0 (+100%) case */
+ else
+ p = comp_val < base_val ? -100.0 : 100.0;
} else {
- snprintf(diff_buf, sizeof(diff_buf), "%+ld (%+.2lf%%)",
- diff_val, diff_val * 100.0 / base_val);
+ p = diff_val * 100.0 / base_val;
}
+ snprintf(diff_buf, sizeof(diff_buf), "%+ld (%+.2lf%%)", diff_val, p);
}
switch (fmt) {