2021-12-14 17:10:28 -05:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2022-11-28 20:19:35 -05:00
|
|
|
#include <kernaux/macro.h>
|
2021-12-14 17:10:28 -05:00
|
|
|
#include <kernaux/pfa.h>
|
2022-12-21 03:59:18 -05:00
|
|
|
#include <kernaux/runtime.h>
|
2021-12-14 17:10:28 -05:00
|
|
|
|
|
|
|
#include <assert.h>
|
2022-06-13 12:28:00 -04:00
|
|
|
#include <setjmp.h>
|
2021-12-14 17:10:28 -05:00
|
|
|
#include <stddef.h>
|
2022-06-13 12:28:00 -04:00
|
|
|
#include <stdlib.h>
|
2021-12-14 17:10:28 -05:00
|
|
|
|
|
|
|
static unsigned int count = 0;
|
2022-06-13 12:28:00 -04:00
|
|
|
static jmp_buf jmpbuf;
|
2021-12-14 17:10:28 -05:00
|
|
|
|
|
|
|
static void assert_cb(
|
2022-11-28 20:19:35 -05:00
|
|
|
const char *const file KERNAUX_UNUSED,
|
|
|
|
const int line KERNAUX_UNUSED,
|
|
|
|
const char *const str KERNAUX_UNUSED
|
2021-12-14 17:10:28 -05:00
|
|
|
) {
|
|
|
|
++count;
|
2022-06-13 12:28:00 -04:00
|
|
|
longjmp(jmpbuf, 1);
|
2021-12-14 17:10:28 -05:00
|
|
|
}
|
|
|
|
|
2022-06-20 14:01:56 -04:00
|
|
|
void test_main()
|
2021-12-14 17:10:28 -05:00
|
|
|
{
|
2022-06-13 12:28:00 -04:00
|
|
|
if (setjmp(jmpbuf) != 0) abort();
|
2021-12-14 17:10:28 -05:00
|
|
|
|
|
|
|
kernaux_assert_cb = assert_cb;
|
2022-01-22 15:36:05 -05:00
|
|
|
|
2021-12-14 17:10:28 -05:00
|
|
|
struct KernAux_PFA pfa;
|
|
|
|
|
2022-06-13 12:28:00 -04:00
|
|
|
if (setjmp(jmpbuf) == 0) {
|
|
|
|
KernAux_PFA_initialize(&pfa);
|
|
|
|
} else {
|
|
|
|
assert(count == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (setjmp(jmpbuf) == 0) {
|
|
|
|
KernAux_PFA_initialize(NULL);
|
|
|
|
} else {
|
|
|
|
assert(count == 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (setjmp(jmpbuf) == 0) {
|
|
|
|
assert(!KernAux_PFA_is_available(NULL, KERNAUX_PFA_PAGE_SIZE));
|
|
|
|
} else {
|
|
|
|
assert(count == 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (setjmp(jmpbuf) == 0) {
|
|
|
|
assert(!KernAux_PFA_is_available(&pfa, 123));
|
|
|
|
} else {
|
|
|
|
assert(count == 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (setjmp(jmpbuf) == 0) {
|
|
|
|
KernAux_PFA_mark_available(NULL, 0, KERNAUX_PFA_PAGE_SIZE);
|
|
|
|
} else {
|
|
|
|
assert(count == 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (setjmp(jmpbuf) == 0) {
|
|
|
|
KernAux_PFA_mark_available(&pfa, KERNAUX_PFA_PAGE_SIZE, 0);
|
|
|
|
} else {
|
|
|
|
assert(count == 5);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (setjmp(jmpbuf) == 0) {
|
|
|
|
KernAux_PFA_mark_unavailable(NULL, 0, KERNAUX_PFA_PAGE_SIZE);
|
|
|
|
} else {
|
|
|
|
assert(count == 6);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (setjmp(jmpbuf) == 0) {
|
|
|
|
KernAux_PFA_mark_unavailable(&pfa, KERNAUX_PFA_PAGE_SIZE, 0);
|
|
|
|
} else {
|
|
|
|
assert(count == 7);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (setjmp(jmpbuf) == 0) {
|
|
|
|
assert(KernAux_PFA_alloc_pages(NULL, KERNAUX_PFA_PAGE_SIZE) == 0);
|
|
|
|
} else {
|
|
|
|
assert(count == 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (setjmp(jmpbuf) == 0) {
|
|
|
|
KernAux_PFA_free_pages(NULL, KERNAUX_PFA_PAGE_SIZE, KERNAUX_PFA_PAGE_SIZE);
|
|
|
|
} else {
|
|
|
|
assert(count == 9);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (setjmp(jmpbuf) == 0) {
|
|
|
|
KernAux_PFA_free_pages(&pfa, 123, KERNAUX_PFA_PAGE_SIZE);
|
|
|
|
} else {
|
|
|
|
assert(count == 10);
|
|
|
|
}
|
2021-12-14 17:10:28 -05:00
|
|
|
}
|