aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDouglas B. Rumbaugh <doug@douglasrumbaugh.com>2025-11-02 15:51:24 -0500
committerDouglas B. Rumbaugh <doug@douglasrumbaugh.com>2025-11-02 15:51:24 -0500
commit3d2b1b82bd1bf016d6fc5091bcec5c61bacabd70 (patch)
tree5df8feb9c8c974be0d5370e28f641286a8a17b05
parenta66d9582a16eb3c15bf727db84431660ae20b2f2 (diff)
downloadliballoc-3d2b1b82bd1bf016d6fc5091bcec5c61bacabd70.tar.gz
Added an interface to access free list and updated tests to use it
-rw-r--r--include/alloc.h7
-rw-r--r--src/alloc.c4
-rw-r--r--tests/liballoc_tests.c8
3 files changed, 17 insertions, 2 deletions
diff --git a/include/alloc.h b/include/alloc.h
index cdbdb37..82a4b7b 100644
--- a/include/alloc.h
+++ b/include/alloc.h
@@ -35,4 +35,11 @@ void *allocate(size_t);
*/
void release(void *);
+/*
+ * Return a pointer to the head of the free list. I can't recall
+ * precisely what I wanted this function called in the assignment,
+ * so this name may change when I get the chance to check.
+ */
+free_nd *free_list_head();
+
#endif
diff --git a/src/alloc.c b/src/alloc.c
index 2f4aa03..dd1c8aa 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -83,3 +83,7 @@ void release(void *ptr) {
fl_add_node(&free_list, ptr);
fl_coalesce_nodes(free_list);
}
+
+free_nd *free_list_head() {
+ return free_list;
+}
diff --git a/tests/liballoc_tests.c b/tests/liballoc_tests.c
index ad9635f..cfd976a 100644
--- a/tests/liballoc_tests.c
+++ b/tests/liballoc_tests.c
@@ -51,7 +51,11 @@ START_TEST(basic_release) {
release(memory);
- // TODO: verify entry on the free list
+ free_nd *list_head = free_list_head();
+ ck_assert_ptr_nonnull(list_head);
+ ck_assert_ptr_eq(list_head, memory);
+ ck_assert_int_eq(list_head->size, ALIGNMENT*3);
+ ck_assert_ptr_null(list_head->next);
}
END_TEST
@@ -59,7 +63,7 @@ START_TEST(release_null) {
/* releasing NULL should take no action */
release(NULL);
- // TODO: verify no entry on free list
+ ck_assert_ptr_null(free_list_head());
}
END_TEST