summaryrefslogtreecommitdiffstats
path: root/tests/alloc.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2024-02-29 13:23:02 -0500
committerTavian Barnes <tavianator@tavianator.com>2024-02-29 13:41:46 -0500
commit4e2f094d29ff8140f2b46a059128c780560db0f1 (patch)
treec492f871db65857f106b755d21c413ff74357f03 /tests/alloc.c
parenta228788769d7e3c71154606609a13eafb03a5fc2 (diff)
downloadbfs-4e2f094d29ff8140f2b46a059128c780560db0f1.tar.xz
tests: New bfs_check() macro
We now report failures and continue, rather than aborting after the first failure.
Diffstat (limited to 'tests/alloc.c')
-rw-r--r--tests/alloc.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/tests/alloc.c b/tests/alloc.c
index e14f131..4ce23d4 100644
--- a/tests/alloc.c
+++ b/tests/alloc.c
@@ -9,30 +9,32 @@
#include <stdint.h>
bool check_alloc(void) {
+ bool ret = true;
+
// Check sizeof_flex()
struct flexible {
alignas(64) int foo[8];
int bar[];
};
- bfs_verify(sizeof_flex(struct flexible, bar, 0) >= sizeof(struct flexible));
- bfs_verify(sizeof_flex(struct flexible, bar, 16) % alignof(struct flexible) == 0);
+ 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);
size_t too_many = SIZE_MAX / sizeof(int) + 1;
- bfs_verify(sizeof_flex(struct flexible, bar, too_many) == align_floor(alignof(struct flexible), SIZE_MAX));
+ ret &= 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
- bfs_verify(flex_size(8, 16, 4, 4, 1) == 16);
+ ret &= 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
- bfs_verify(ALLOC_ARRAY(int, too_many) == NULL && errno == EOVERFLOW);
- bfs_verify(ZALLOC_ARRAY(int, too_many) == NULL && errno == EOVERFLOW);
- bfs_verify(ALLOC_FLEX(struct flexible, bar, too_many) == NULL && errno == EOVERFLOW);
- bfs_verify(ZALLOC_FLEX(struct flexible, bar, too_many) == NULL && errno == EOVERFLOW);
+ 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);
// varena tests
struct varena varena;
@@ -41,9 +43,9 @@ 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];
- bfs_verify(arena->size >= sizeof_flex(struct flexible, bar, i));
+ ret &= bfs_check(arena->size >= sizeof_flex(struct flexible, bar, i));
}
varena_destroy(&varena);
- return true;
+ return ret;
}