aboutsummaryrefslogtreecommitdiff
path: root/c/main.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/main.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/main.c')
-rw-r--r--c/main.c19
1 files changed, 16 insertions, 3 deletions
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);