Debian Codegraph @

tests/test_dual_link.c

raw
1 /*
2 * Test that abPOA's internal allocator uses namespaced symbols.
3 *
4 * This program defines its own kmalloc/kfree. If abPOA still exports
5 * bare kmalloc/kfree, the linker will either error (multiple definitions)
6 * or silently pick one — both prove the collision problem.
7 *
8 * After namespacing, abPOA uses abpoa_kmalloc internally, so our
9 * kmalloc/kfree are never called and the flag stays 0.
10 *
11 * Compile:
12 * gcc tests/test_dual_link.c -Iinclude -Llib -labpoa -lz -lm -lpthread \
13 * -o tests/test_dual_link
14 * Run:
15 * ./tests/test_dual_link
16 */
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <assert.h>
20 #include "abpoa.h"
21
22 static int foreign_kmalloc_called = 0;
23
24 void *kmalloc(void *km, size_t size) {
25 foreign_kmalloc_called = 1;
26 (void)km;
27 return malloc(size);
28 }
29
30 void kfree(void *km, void *ptr) {
31 foreign_kmalloc_called = 1;
32 (void)km;
33 free(ptr);
34 }
35
36 int main(void) {
37 abpoa_t *ab = abpoa_init();
38 assert(ab != NULL);
39 abpoa_free(ab);
40
41 assert(foreign_kmalloc_called == 0 &&
42 "abPOA called bare kmalloc/kfree instead of abpoa_kmalloc/abpoa_kfree");
43
44 printf("PASS: abPOA uses namespaced klib symbols, no collision\n");
45 return 0;
46 }