summaryrefslogtreecommitdiffstats
path: root/tests/alloc.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2023-06-19 12:11:36 -0400
committerTavian Barnes <tavianator@tavianator.com>2023-06-20 14:26:09 -0400
commit90ded13e589b0089167ef25ca3d26be599dfec9b (patch)
treed5a007948587f62fff62c851ddd3886b5a5e78ed /tests/alloc.c
parent9ceb2b27577f1be3f30edb40a45117066fc78c51 (diff)
downloadbfs-90ded13e589b0089167ef25ca3d26be599dfec9b.tar.xz
alloc: New header for memory allocation utilities
Diffstat (limited to 'tests/alloc.c')
-rw-r--r--tests/alloc.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/alloc.c b/tests/alloc.c
new file mode 100644
index 0000000..91b1b43
--- /dev/null
+++ b/tests/alloc.c
@@ -0,0 +1,24 @@
+// Copyright © Tavian Barnes <tavianator@tavianator.com>
+// SPDX-License-Identifier: 0BSD
+
+#include "../src/alloc.h"
+#include "../src/diag.h"
+#include <stdlib.h>
+
+int main(void) {
+ // Check sizeof_flex()
+ struct flexible {
+ alignas(64) int foo;
+ 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);
+ bfs_verify(sizeof_flex(struct flexible, bar, SIZE_MAX / sizeof(int) + 1)
+ == 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);
+
+ return EXIT_SUCCESS;
+}