aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/memory.c19
-rw-r--r--test/test.c4
2 files changed, 21 insertions, 2 deletions
diff --git a/test/memory.c b/test/memory.c
new file mode 100644
index 0000000..05db8a2
--- /dev/null
+++ b/test/memory.c
@@ -0,0 +1,19 @@
+
+#include "kpl_test.h"
+
+KPL_TEST(allocate) {
+ kpl_memory_allocator allocator = {};
+ kpl_memory_allocator_init(&allocator);
+ for (int32_t times = 0; times < 700; times++) {
+ kpl_object *objects[10] = {};
+ for (int32_t object = 0; object < 10; object++) {
+ objects[object] = kpl_memory_allocator_allocate(&allocator, 32, KPL_THREAD_MAIN_ID);
+ KPL_ASSERT(objects[object]->object_size == 32, "Invalid size for 32 byte object");
+ }
+ for (int32_t object = 0; object < 10; object++)
+ kpl_memory_allocator_return(&allocator, objects[object]);
+ }
+ kpl_memory_allocator_slab_group *slab_group32 = &allocator.slabs[5];
+ KPL_ASSERT(slab_group32->slab_head == slab_group32->slab_tail, "Only one slab should have been allocated");
+ kpl_memory_allocator_free(&allocator);
+}
diff --git a/test/test.c b/test/test.c
index 02a8730..0dcf302 100644
--- a/test/test.c
+++ b/test/test.c
@@ -29,7 +29,7 @@ static void kpl_test_report(const kpl_test *_test) {
_test->error_line_number, _test->error_message);
}
-static int32_t kpl_test_report_error(void) {
+static kpl_exit_code kpl_test_report_error(void) {
if (!error_head) {
printf(KPL_COLOR2(BOLD, GREEN) "PASSED\n" KPL_COLOR(RESET));
return KPL_EXIT_CODE_SUCCESS;
@@ -55,7 +55,7 @@ static void kpl_test_run_one(kpl_test *_test) {
error_tail = error_tail->list_next = _test;
}
-static int32_t kpl_test_run_all(void) {
+static kpl_exit_code kpl_test_run_all(void) {
while (test_head) {
kpl_test *_test = test_head;
test_head = test_head->list_next;