diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2024-07-07 12:59:39 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2024-07-07 13:12:56 -0400 |
commit | 3206124fb3af2481fc45e705f7bba3ea56016433 (patch) | |
tree | 994f03b0d9d1db2e410a7bef155f0e5b4e03fe28 /tests/alloc.c | |
parent | 144353ab004bcd3e85f4cdd0a848add7811df2fe (diff) | |
download | bfs-3206124fb3af2481fc45e705f7bba3ea56016433.tar.xz |
tests: Simplify unit tests with a global variable
It's a little awkward to thread the test result through manually; much
easier to just make bfs_check() update a global variable.
Diffstat (limited to 'tests/alloc.c')
-rw-r--r-- | tests/alloc.c | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/tests/alloc.c b/tests/alloc.c index 6c0defd..2d3077d 100644 --- a/tests/alloc.c +++ b/tests/alloc.c @@ -9,33 +9,31 @@ #include <stdlib.h> #include <stdint.h> -bool check_alloc(void) { - bool ret = true; - +void check_alloc(void) { // Check sizeof_flex() struct flexible { alignas(64) int foo[8]; int bar[]; }; - ret &= bfs_check(sizeof_flex(struct flexible, bar, 0) >= sizeof(struct flexible)); - ret &= bfs_check(sizeof_flex(struct flexible, bar, 16) % alignof(struct flexible) == 0); + bfs_check(sizeof_flex(struct flexible, bar, 0) >= sizeof(struct flexible)); + bfs_check(sizeof_flex(struct flexible, bar, 16) % alignof(struct flexible) == 0); size_t too_many = SIZE_MAX / sizeof(int) + 1; - ret &= bfs_check(sizeof_flex(struct flexible, bar, too_many) == align_floor(alignof(struct flexible), SIZE_MAX)); + bfs_check(sizeof_flex(struct flexible, bar, too_many) == align_floor(alignof(struct flexible), SIZE_MAX)); // Corner case: sizeof(type) > align_ceil(alignof(type), offsetof(type, member)) // Doesn't happen in typical ABIs - ret &= bfs_check(flex_size(8, 16, 4, 4, 1) == 16); + bfs_check(flex_size(8, 16, 4, 4, 1) == 16); // Make sure we detect allocation size overflows #if __GNUC__ && !__clang__ # pragma GCC diagnostic ignored "-Walloc-size-larger-than=" #endif - ret &= bfs_check(ALLOC_ARRAY(int, too_many) == NULL && errno == EOVERFLOW); - ret &= bfs_check(ZALLOC_ARRAY(int, too_many) == NULL && errno == EOVERFLOW); - ret &= bfs_check(ALLOC_FLEX(struct flexible, bar, too_many) == NULL && errno == EOVERFLOW); - ret &= bfs_check(ZALLOC_FLEX(struct flexible, bar, too_many) == NULL && errno == EOVERFLOW); + bfs_check(ALLOC_ARRAY(int, too_many) == NULL && errno == EOVERFLOW); + bfs_check(ZALLOC_ARRAY(int, too_many) == NULL && errno == EOVERFLOW); + bfs_check(ALLOC_FLEX(struct flexible, bar, too_many) == NULL && errno == EOVERFLOW); + bfs_check(ZALLOC_FLEX(struct flexible, bar, too_many) == NULL && errno == EOVERFLOW); // varena tests struct varena varena; @@ -44,9 +42,8 @@ bool check_alloc(void) { for (size_t i = 0; i < 256; ++i) { bfs_verify(varena_alloc(&varena, i)); struct arena *arena = &varena.arenas[varena.narenas - 1]; - ret &= bfs_check(arena->size >= sizeof_flex(struct flexible, bar, i)); + bfs_check(arena->size >= sizeof_flex(struct flexible, bar, i)); } varena_destroy(&varena); - return ret; } |