test_lisp_api: added sys_test

This commit is contained in:
2026-02-05 05:47:44 +00:00
parent b32f420cb9
commit 54e9edcba6
2 changed files with 49 additions and 3 deletions

View File

@@ -51,10 +51,10 @@ other state do we need to encode?
*** TODO Write a parser for vectors
*** TODO Write the general parser
** WIP Unit tests :tests:
*** TODO Test system registration of allocated units
*** TODO Test streams
*** DONE Test system registration of allocated units
In particular, does clean up work as we expect? Do we have situations
where we may double free or not clean up something we should've?
*** TODO Test streams
** Backlog
*** TODO Design Big Integers
We currently have 62 bit integers implemented via immediate values

View File

@@ -141,6 +141,51 @@ void cons_test(void)
TEST_PASSED();
}
void sys_test(void)
{
sys_t sys = {0};
sys_init(&sys);
u64 old_memory_size = sys.memory.size;
// Creating integers doesn't affect memory size
(void)make_int(2000);
TEST(sys.memory.size == old_memory_size,
"Making integers doesn't affect system memory size");
// Creating symbols won't affect memory size, but does affect the symbol table
(void)intern(&sys, SV("hello world!", 12));
TEST(sys.memory.size == old_memory_size,
"Interning doesn't affect system memory size");
TEST(sys.symtable.count > 0, "Interning affects symbol table");
// Creating cons' do affect memory size
(void)cons(&sys, make_int(1), make_int(2));
TEST(sys.memory.size > 0, "Creating cons' affects memory size");
old_memory_size = sys.memory.size;
(void)cons(&sys, intern(&sys, SV("test", 4)), NIL);
TEST(sys.memory.size > old_memory_size,
"Creating cons' back to back affects memory size");
old_memory_size = sys.memory.size;
// Creating vectors does affect memory size
(void)make_vec(&sys, 8);
TEST(sys.memory.size > old_memory_size,
"Creating vectors (size 8) affects memory size");
old_memory_size = sys.memory.size;
(void)make_vec(&sys, 1000);
TEST(sys.memory.size > old_memory_size,
"Creating vectors (size 1000) affects memory size");
old_memory_size = sys.memory.size;
sys_free(&sys);
TEST(sys.memory.size == 0, "sys_free cleans up memory (shallow check)");
TEST(sys.symtable.count == 0, "sys_free cleans up symtable (shallow check)");
TEST_PASSED();
}
const test_suite_t LISP_API_SUITE = {
.name = "Lisp API Tests",
.tests =
@@ -150,8 +195,9 @@ const test_suite_t LISP_API_SUITE = {
MAKE_TEST_FN(sym_fresh_test),
MAKE_TEST_FN(sym_unique_test),
MAKE_TEST_FN(cons_test),
MAKE_TEST_FN(sys_test),
},
.size = 5,
.size = 6,
};
/* Copyright (C) 2026 Aryadev Chavali