aboutsummaryrefslogtreecommitdiff
path: root/c
diff options
context:
space:
mode:
authorJack O'Connor <[email protected]>2020-01-22 20:22:15 -0500
committerJack O'Connor <[email protected]>2020-01-22 21:19:47 -0500
commit92d421dea1a89e2f079f4dbd93b0dab41234b279 (patch)
tree97bf168a1cfe853e164de5524f92029d75a7f500 /c
parent78e858d0506d6dfa72b5b690cf4203e90af64b8a (diff)
add a larger test case
One thing I like to test is that, if I hack simd_degree to be higher than MAX_SIMD_DEGREE, assertions fire. This requires a test case long enough to exceed that number of chunks.
Diffstat (limited to 'c')
-rw-r--r--c/blake3_c_rust_bindings/src/test.rs7
-rw-r--r--c/main.c19
2 files changed, 20 insertions, 6 deletions
diff --git a/c/blake3_c_rust_bindings/src/test.rs b/c/blake3_c_rust_bindings/src/test.rs
index 21b5745..abfab42 100644
--- a/c/blake3_c_rust_bindings/src/test.rs
+++ b/c/blake3_c_rust_bindings/src/test.rs
@@ -36,11 +36,12 @@ pub const TEST_CASES: &[usize] = &[
7 * CHUNK_LEN + 1,
8 * CHUNK_LEN,
8 * CHUNK_LEN + 1,
- 16 * CHUNK_LEN, // AVX512's bandwidth
- 31 * CHUNK_LEN, // 16 + 8 + 4 + 2 + 1
+ 16 * CHUNK_LEN, // AVX512's bandwidth
+ 31 * CHUNK_LEN, // 16 + 8 + 4 + 2 + 1
+ 100 * CHUNK_LEN, // subtrees larger than MAX_SIMD_DEGREE chunks
];
-pub const TEST_CASES_MAX: usize = 31 * CHUNK_LEN;
+pub const TEST_CASES_MAX: usize = 100 * CHUNK_LEN;
// There's a test to make sure these two are equal below.
pub const TEST_KEY: [u8; 32] = *b"whats the Elvish word for friend";
diff --git a/c/main.c b/c/main.c
index 6abd4f3..59d7b32 100644
--- a/c/main.c
+++ b/c/main.c
@@ -103,8 +103,21 @@ int main(int argc, char **argv) {
argv += 2;
}
- uint8_t buf[65536] = {0};
- size_t n = fread(buf, 1, sizeof(buf), stdin);
+ // We're going to hash the input multiple times, so we need to buffer it all.
+ // This is just for test cases, so go ahead and assume that the input is less
+ // than 1 MiB.
+ size_t buf_capacity = 1 << 20;
+ uint8_t *buf = malloc(buf_capacity);
+ assert(buf != NULL);
+ size_t buf_len = 0;
+ while (1) {
+ size_t n = fread(&buf[buf_len], 1, buf_capacity - buf_len, stdin);
+ if (n == 0) {
+ break;
+ }
+ buf_len += n;
+ assert(buf_len < buf_capacity);
+ }
const int mask = get_cpu_features();
int feature = 0;
@@ -126,7 +139,7 @@ int main(int argc, char **argv) {
abort();
}
- blake3_hasher_update(&hasher, buf, n);
+ blake3_hasher_update(&hasher, buf, buf_len);
// TODO: An incremental output reader API to avoid this allocation.
uint8_t *out = malloc(out_len);