2021-12-14 17:10:28 -05:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <kernaux/assert.h>
|
|
|
|
#include <kernaux/pfa.h>
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
|
|
|
|
static unsigned int count = 0;
|
|
|
|
|
|
|
|
static void test();
|
|
|
|
|
2021-12-14 17:14:03 -05:00
|
|
|
#ifdef ENABLE_ASSERT
|
2021-12-14 17:10:28 -05:00
|
|
|
static void assert_cb(
|
|
|
|
__attribute__((unused))
|
|
|
|
const char *const file,
|
|
|
|
__attribute__((unused))
|
|
|
|
const int line,
|
|
|
|
__attribute__((unused))
|
|
|
|
const char *const str
|
|
|
|
) {
|
|
|
|
++count;
|
|
|
|
}
|
2021-12-14 17:14:03 -05:00
|
|
|
#endif
|
2021-12-14 17:10:28 -05:00
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
kernaux_assert_cb = NULL;
|
|
|
|
test();
|
|
|
|
|
2021-12-15 09:28:29 -05:00
|
|
|
#if defined(ENABLE_ASSERT) || defined(ENABLE_NULL_GUARD)
|
2021-12-14 17:10:28 -05:00
|
|
|
#ifdef ENABLE_ASSERT
|
|
|
|
kernaux_assert_cb = assert_cb;
|
2021-12-15 09:28:29 -05:00
|
|
|
#endif
|
2021-12-14 17:10:28 -05:00
|
|
|
test();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void test()
|
|
|
|
{
|
2021-12-15 09:28:29 -05:00
|
|
|
unsigned int acc = 0;
|
2021-12-14 17:10:28 -05:00
|
|
|
struct KernAux_PFA pfa;
|
|
|
|
KernAux_PFA_initialize(&pfa);
|
|
|
|
|
2021-12-15 09:28:29 -05:00
|
|
|
#ifdef ENABLE_NULL_GUARD
|
2021-12-14 17:10:28 -05:00
|
|
|
KernAux_PFA_initialize(NULL);
|
2021-12-15 09:28:29 -05:00
|
|
|
if (kernaux_assert_cb) assert(count == ++acc);
|
|
|
|
#endif
|
2021-12-14 17:10:28 -05:00
|
|
|
|
2021-12-15 09:28:29 -05:00
|
|
|
#ifdef ENABLE_NULL_GUARD
|
2021-12-14 17:10:28 -05:00
|
|
|
assert(!KernAux_PFA_is_available(NULL, KERNAUX_PFA_PAGE_SIZE));
|
2021-12-15 09:28:29 -05:00
|
|
|
if (kernaux_assert_cb) assert(count == ++acc);
|
|
|
|
#endif
|
2021-12-14 17:10:28 -05:00
|
|
|
|
|
|
|
assert(!KernAux_PFA_is_available(&pfa, 123));
|
2021-12-15 09:28:29 -05:00
|
|
|
if (kernaux_assert_cb) assert(count == ++acc);
|
2021-12-14 17:10:28 -05:00
|
|
|
|
2021-12-15 09:28:29 -05:00
|
|
|
#ifdef ENABLE_NULL_GUARD
|
2021-12-14 17:10:28 -05:00
|
|
|
KernAux_PFA_mark_available(NULL, 0, KERNAUX_PFA_PAGE_SIZE);
|
2021-12-15 09:28:29 -05:00
|
|
|
if (kernaux_assert_cb) assert(count == ++acc);
|
|
|
|
#endif
|
2021-12-14 17:10:28 -05:00
|
|
|
|
|
|
|
KernAux_PFA_mark_available(&pfa, KERNAUX_PFA_PAGE_SIZE, 0);
|
2021-12-15 09:28:29 -05:00
|
|
|
if (kernaux_assert_cb) assert(count == ++acc);
|
2021-12-14 17:10:28 -05:00
|
|
|
|
2021-12-15 09:28:29 -05:00
|
|
|
#ifdef ENABLE_NULL_GUARD
|
2021-12-14 17:10:28 -05:00
|
|
|
KernAux_PFA_mark_unavailable(NULL, 0, KERNAUX_PFA_PAGE_SIZE);
|
2021-12-15 09:28:29 -05:00
|
|
|
if (kernaux_assert_cb) assert(count == ++acc);
|
|
|
|
#endif
|
2021-12-14 17:10:28 -05:00
|
|
|
|
|
|
|
KernAux_PFA_mark_unavailable(&pfa, KERNAUX_PFA_PAGE_SIZE, 0);
|
2021-12-15 09:28:29 -05:00
|
|
|
if (kernaux_assert_cb) assert(count == ++acc);
|
2021-12-14 17:10:28 -05:00
|
|
|
|
2021-12-15 09:28:29 -05:00
|
|
|
#ifdef ENABLE_NULL_GUARD
|
2021-12-14 17:10:28 -05:00
|
|
|
assert(KernAux_PFA_alloc_pages(NULL, KERNAUX_PFA_PAGE_SIZE) == 0);
|
2021-12-15 09:28:29 -05:00
|
|
|
if (kernaux_assert_cb) assert(count == ++acc);
|
|
|
|
#endif
|
2021-12-14 17:10:28 -05:00
|
|
|
|
2021-12-15 09:28:29 -05:00
|
|
|
#ifdef ENABLE_NULL_GUARD
|
2021-12-14 17:10:28 -05:00
|
|
|
KernAux_PFA_free_pages(NULL, KERNAUX_PFA_PAGE_SIZE, KERNAUX_PFA_PAGE_SIZE);
|
2021-12-15 09:28:29 -05:00
|
|
|
if (kernaux_assert_cb) assert(count == ++acc);
|
|
|
|
#endif
|
2021-12-14 17:10:28 -05:00
|
|
|
|
|
|
|
KernAux_PFA_free_pages(&pfa, 123, KERNAUX_PFA_PAGE_SIZE);
|
2021-12-15 09:28:29 -05:00
|
|
|
if (kernaux_assert_cb) assert(count == ++acc);
|
2021-12-14 17:10:28 -05:00
|
|
|
}
|