1
0
Fork 0
mirror of https://github.com/tailix/libkernaux.git synced 2024-11-13 11:04:27 -05:00
libkernaux/tests/test_pfa.c

71 lines
1.8 KiB
C
Raw Normal View History

2020-12-06 23:47:53 -05:00
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
2020-11-30 13:32:27 -05:00
#include <kernaux/pfa.h>
#include <assert.h>
int main()
{
struct KernAux_PFA pfa;
KernAux_PFA_initialize(&pfa);
for (unsigned int index = 0; index < KERNAUX_PFA_PAGES_COUNT_MAX; ++index) {
2020-12-06 05:16:15 -05:00
assert(pfa.pages[index] == false);
}
KernAux_PFA_mark_available(&pfa, 0, 654335);
KernAux_PFA_mark_available(&pfa, 1048576, 134086655);
KernAux_PFA_mark_unavailable(&pfa, 4194304, 6291455); // [4 MB, 6 MB)
for (unsigned int index = 0; index < 159; ++index) {
2020-12-06 05:16:15 -05:00
assert(pfa.pages[index] == true);
}
for (unsigned int index = 159; index < 256; ++index) {
2020-12-06 05:16:15 -05:00
assert(pfa.pages[index] == false);
}
for (unsigned int index = 256; index < 1024; ++index) { // [1 MB, 4 MB)
2020-12-06 05:16:15 -05:00
assert(pfa.pages[index] == true);
}
for (unsigned int index = 1024; index < 1536; ++index) { // [4 MB, 6 MB)
2020-12-06 05:16:15 -05:00
assert(pfa.pages[index] == false);
}
for (unsigned int index = 1536; index < 32736; ++index) { // [6 MB, ~127 MB)
2020-12-06 05:16:15 -05:00
assert(pfa.pages[index] == true);
}
for (
unsigned int index = 32736;
index < KERNAUX_PFA_PAGES_COUNT_MAX;
++index
) {
2020-12-06 05:16:15 -05:00
assert(pfa.pages[index] == false);
}
2020-11-30 18:38:55 -05:00
unsigned int page_addr = KernAux_PFA_alloc_page(&pfa);
assert(page_addr != 0);
assert(page_addr % KERNAUX_PFA_PAGE_SIZE == 0);
assert(!pfa.pages[page_addr / KERNAUX_PFA_PAGE_SIZE]);
KernAux_PFA_free_page(&pfa, page_addr);
assert(pfa.pages[page_addr / KERNAUX_PFA_PAGE_SIZE]);
2020-11-30 18:41:17 -05:00
for (unsigned int index = 0; index < KERNAUX_PFA_PAGES_COUNT_MAX; ++index) {
if (pfa.pages[index]) {
assert(KernAux_PFA_alloc_page(&pfa) != 0);
}
}
assert(KernAux_PFA_alloc_page(&pfa) == 0);
2020-11-30 13:32:27 -05:00
return 0;
}