Skip to content

Commit c1a4488

Browse files
committed
Merge #51: Fix exhaustive test check
294b6c5 Use correct flags variable for c-i (Cory Fields) 8d52856 Fix exhaustive test check (Pieter Wuille) Pull request description: There were 3 issues: 1. The comparison between `counts[...]` and `Combination()` wasn't running at all (`(i >> bits)` is always 0 for i==0, so the loop would instantly exit). 2. The `counts` values were wrong (because it was counting a sum across all implementation), so if they would be compared to something, the test would incorrectly fail. 3. `(i >> bits)` is undefined when bits==64. (1) would be fixed by changing `i >> bits` to `(i >> bits) == 0`, but that leaves issue (3), so introduce a `mask` and use a different way of writing the same, that keeps working for bits==64. (2) is fixed by only incrementing counts[...] for impl==0. This was discovered through #50. ACKs for top commit: naumenkogs: ACK 294b6c5 Tree-SHA512: 770af770898fb82abf390b7cd21f6ac8657d16dbf391c1d5825c62a3c17c8d50a36481f91254020bd00bfdda493507406df2110292fe8edc396db28181ca94b5
2 parents ea986a8 + 294b6c5 commit c1a4488

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

.cirrus.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ env_matrix_snippet: &ENV_MATRIX_SAN
4242
- env:
4343
BUILD: distcheck
4444
- env:
45-
CFLAGS: "-fsanitize=undefined -fno-omit-frame-pointer"
45+
CXXFLAGS: "-fsanitize=undefined -fno-omit-frame-pointer"
4646
LDFLAGS: "-fsanitize=undefined -fno-omit-frame-pointer"
4747
UBSAN_OPTIONS: "print_stacktrace=1:halt_on_error=1"
4848
BENCH: no
@@ -57,7 +57,7 @@ env_matrix_snippet: &ENV_MATRIX_SAN_VALGRIND
5757
TESTRUNS: 1
5858
BUILD:
5959
- env:
60-
CFLAGS: "-fsanitize=undefined -fno-omit-frame-pointer"
60+
CXXFLAGS: "-fsanitize=undefined -fno-omit-frame-pointer"
6161
LDFLAGS: "-fsanitize=undefined -fno-omit-frame-pointer"
6262
UBSAN_OPTIONS: "print_stacktrace=1:halt_on_error=1"
6363
BENCH: no

src/test.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,15 @@ void TestExhaustive(uint32_t bits, size_t capacity) {
109109
// Compare
110110
CHECK(serialized == serialized_rebuild);
111111
// Count it
112-
if (elements_0.size() <= capacity) ++counts[elements_0.size()];
112+
if (impl == 0 && elements_0.size() <= capacity) ++counts[elements_0.size()];
113113
}
114114
}
115115
}
116116

117117
// Verify that the number of decodable sketches with given elements is expected.
118-
for (uint64_t i = 0; i <= capacity && i >> bits; ++i) {
119-
CHECK(counts[i] == Combination((uint64_t{1} << bits) - 1, i));
118+
uint64_t mask = bits == 64 ? UINT64_MAX : (uint64_t{1} << bits) - 1;
119+
for (uint64_t i = 0; i <= capacity && (i & mask) == i; ++i) {
120+
CHECK(counts[i] == Combination(mask, i));
120121
}
121122
}
122123

0 commit comments

Comments
 (0)