From 7f40dd92d6f1091a77516b43ecfb4e075c2c4a68 Mon Sep 17 00:00:00 2001 From: Randy Jordan Date: Sat, 18 Oct 2025 11:33:31 -0500 Subject: [PATCH] Added other tests --- tests/05_arena_new.c | 12 ++++++++++++ tests/06_arena_nozero.c | 12 ++++++++++++ tests/07_arena_softfail.c | 11 +++++++++++ tests/08_arena_exception.c | 28 ++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+) create mode 100644 tests/05_arena_new.c create mode 100644 tests/06_arena_nozero.c create mode 100644 tests/07_arena_softfail.c create mode 100644 tests/08_arena_exception.c diff --git a/tests/05_arena_new.c b/tests/05_arena_new.c new file mode 100644 index 0000000..b3662a6 --- /dev/null +++ b/tests/05_arena_new.c @@ -0,0 +1,12 @@ +#define DEBUG +#include +#include "../include/mem.h" + +int main(void){ + size_t nbytes = 20; + Arena a = ARENA(0,nbytes); + ASSERTED(a.beg != NULL); + ASSERTED( mem_is_zero(a.beg, nbytes)); + FREE(a.beg); + return EXIT_SUCCESS; +} diff --git a/tests/06_arena_nozero.c b/tests/06_arena_nozero.c new file mode 100644 index 0000000..b1cd812 --- /dev/null +++ b/tests/06_arena_nozero.c @@ -0,0 +1,12 @@ +#define DEBUG +#include +#include "../include/mem.h" + +int main(void){ + size_t nbytes = 20; + Arena a = ARENA(NOZERO,nbytes); + ASSERTED(a.beg != NULL); + ASSERTED( !mem_is_zero(a.beg, nbytes)); + FREE(a.beg); + return EXIT_SUCCESS; +} diff --git a/tests/07_arena_softfail.c b/tests/07_arena_softfail.c new file mode 100644 index 0000000..ffa2cfc --- /dev/null +++ b/tests/07_arena_softfail.c @@ -0,0 +1,11 @@ +#define DEBUG +#include +#include +#include "../include/mem.h" + +int main(void){ + size_t nbytes = MEM_GB(1024); + Arena a = ARENA(SOFT_FAIL, nbytes); + ASSERTED(a.beg == NULL); + return EXIT_SUCCESS; +} diff --git a/tests/08_arena_exception.c b/tests/08_arena_exception.c new file mode 100644 index 0000000..238a9db --- /dev/null +++ b/tests/08_arena_exception.c @@ -0,0 +1,28 @@ +#define DEBUG +#include +#include +#include +#include "../include/mem.h" + +int main(void){ + size_t nbytes = MEM_GB(1024); + Arena a; + TRY { + a = ARENA(0,nbytes); /* try 1GB */ + if (!a.beg) + RAISE(OOM); + free(a.beg); + } + EXCEPT(OOM) { + /* handle memory failure gracefully */ + fprintf(stderr, "Caught: %s\n", OOM.reason); + return EXIT_SUCCESS; /* requested behavior */ + } + FINALLY { + /* cleanup if needed, runs always */ + if (a.beg) free(a.beg); + } + END_TRY; + + return EXIT_FAILURE; /* shouldn't reach here for this example */ + }