summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/alloc.c24
-rw-r--r--tests/bfstd.c13
2 files changed, 26 insertions, 11 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;
+}
diff --git a/tests/bfstd.c b/tests/bfstd.c
index 7fea9b5..fa854a8 100644
--- a/tests/bfstd.c
+++ b/tests/bfstd.c
@@ -24,17 +24,6 @@ static void check_base_dir(const char *path, const char *dir, const char *base)
}
int main(void) {
- // Check flex_sizeof()
- struct flexible {
- alignas(64) int foo;
- int bar[];
- };
- bfs_verify(flex_sizeof(struct flexible, bar, 0) >= sizeof(struct flexible));
- bfs_verify(flex_sizeof(struct flexible, bar, 16) % alignof(struct flexible) == 0);
- bfs_verify(flex_sizeof(struct flexible, bar, SIZE_MAX / sizeof(int) + 1)
- == align_floor(alignof(struct flexible), SIZE_MAX));
- bfs_verify(flex_sizeof_impl(8, 16, 4, 4, 1) == 16);
-
// From man 3p basename
check_base_dir("usr", ".", "usr");
check_base_dir("usr/", ".", "usr");
@@ -46,4 +35,6 @@ int main(void) {
check_base_dir("/usr/lib", "/usr", "lib");
check_base_dir("//usr//lib//", "//usr", "lib");
check_base_dir("/home//dwc//test", "/home//dwc", "test");
+
+ return EXIT_SUCCESS;
}