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()
|
|
|
|
{
|
2020-11-30 17:54:09 -05:00
|
|
|
struct KernAux_PFA pfa;
|
|
|
|
|
|
|
|
KernAux_PFA_initialize(&pfa);
|
|
|
|
|
2021-12-13 17:59:51 -05:00
|
|
|
for (size_t index = 0; index < KERNAUX_PFA_PAGES_COUNT_MAX; ++index) {
|
2021-12-13 18:10:05 -05:00
|
|
|
assert(!KernAux_PFA_is_available(&pfa, index * KERNAUX_PFA_PAGE_SIZE));
|
2020-11-30 17:54:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
KernAux_PFA_mark_available(&pfa, 0, 654335);
|
|
|
|
KernAux_PFA_mark_available(&pfa, 1048576, 134086655);
|
2020-12-03 22:04:42 -05:00
|
|
|
KernAux_PFA_mark_unavailable(&pfa, 4194304, 6291455); // [4 MB, 6 MB)
|
2020-11-30 17:54:09 -05:00
|
|
|
|
2021-12-13 17:59:51 -05:00
|
|
|
for (size_t index = 0; index < 159; ++index) {
|
2021-12-13 18:10:05 -05:00
|
|
|
assert(KernAux_PFA_is_available(&pfa, index * KERNAUX_PFA_PAGE_SIZE));
|
2020-11-30 17:54:09 -05:00
|
|
|
}
|
|
|
|
|
2021-12-13 17:59:51 -05:00
|
|
|
for (size_t index = 159; index < 256; ++index) {
|
2021-12-13 18:10:05 -05:00
|
|
|
assert(!KernAux_PFA_is_available(&pfa, index * KERNAUX_PFA_PAGE_SIZE));
|
2020-11-30 17:54:09 -05:00
|
|
|
}
|
|
|
|
|
2021-12-13 17:59:51 -05:00
|
|
|
for (size_t index = 256; index < 1024; ++index) { // [1 MB, 4 MB)
|
2021-12-13 18:10:05 -05:00
|
|
|
assert(KernAux_PFA_is_available(&pfa, index * KERNAUX_PFA_PAGE_SIZE));
|
2020-12-03 22:04:42 -05:00
|
|
|
}
|
|
|
|
|
2021-12-13 17:59:51 -05:00
|
|
|
for (size_t index = 1024; index < 1536; ++index) { // [4 MB, 6 MB)
|
2021-12-13 18:10:05 -05:00
|
|
|
assert(!KernAux_PFA_is_available(&pfa, index * KERNAUX_PFA_PAGE_SIZE));
|
2020-12-03 22:04:42 -05:00
|
|
|
}
|
|
|
|
|
2021-12-13 17:59:51 -05:00
|
|
|
for (size_t index = 1536; index < 32736; ++index) { // [6 MB, ~127 MB)
|
2021-12-13 18:10:05 -05:00
|
|
|
assert(KernAux_PFA_is_available(&pfa, index * KERNAUX_PFA_PAGE_SIZE));
|
2020-11-30 17:54:09 -05:00
|
|
|
}
|
|
|
|
|
2021-12-13 17:59:51 -05:00
|
|
|
for (size_t index = 32736; index < KERNAUX_PFA_PAGES_COUNT_MAX; ++index) {
|
2021-12-13 18:10:05 -05:00
|
|
|
assert(!KernAux_PFA_is_available(&pfa, index * KERNAUX_PFA_PAGE_SIZE));
|
2020-11-30 17:54:09 -05:00
|
|
|
}
|
|
|
|
|
2021-12-13 19:39:54 -05:00
|
|
|
{
|
|
|
|
const size_t page_addr = KernAux_PFA_alloc_page(&pfa);
|
2020-11-30 18:38:55 -05:00
|
|
|
|
2021-12-13 19:39:54 -05:00
|
|
|
assert(page_addr != 0);
|
|
|
|
assert(page_addr % KERNAUX_PFA_PAGE_SIZE == 0);
|
|
|
|
assert(!KernAux_PFA_is_available(&pfa, page_addr));
|
2020-11-30 18:38:55 -05:00
|
|
|
|
2021-12-13 19:39:54 -05:00
|
|
|
KernAux_PFA_free_page(&pfa, page_addr);
|
2020-11-30 18:38:55 -05:00
|
|
|
|
2021-12-13 19:39:54 -05:00
|
|
|
assert(KernAux_PFA_is_available(&pfa, page_addr));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const size_t page_addr =
|
|
|
|
KernAux_PFA_alloc_pages(&pfa, 10 * KERNAUX_PFA_PAGE_SIZE);
|
|
|
|
|
|
|
|
assert(page_addr != 0);
|
|
|
|
assert(page_addr % KERNAUX_PFA_PAGE_SIZE == 0);
|
|
|
|
|
|
|
|
for (size_t index = 0, addr = page_addr; index < 10; ++index) {
|
|
|
|
assert(!KernAux_PFA_is_available(&pfa, addr));
|
|
|
|
addr += KERNAUX_PFA_PAGE_SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
KernAux_PFA_free_pages(&pfa, page_addr, 10 * KERNAUX_PFA_PAGE_SIZE);
|
|
|
|
|
|
|
|
for (size_t index = 0, addr = page_addr; index < 10; ++index) {
|
|
|
|
assert(KernAux_PFA_is_available(&pfa, addr));
|
|
|
|
addr += KERNAUX_PFA_PAGE_SIZE;
|
|
|
|
}
|
|
|
|
}
|
2020-11-30 18:38:55 -05:00
|
|
|
|
2021-12-13 17:59:51 -05:00
|
|
|
for (size_t index = 0; index < KERNAUX_PFA_PAGES_COUNT_MAX; ++index) {
|
2021-12-13 18:10:05 -05:00
|
|
|
if (KernAux_PFA_is_available(&pfa, index * KERNAUX_PFA_PAGE_SIZE)) {
|
2020-11-30 18:41:17 -05:00
|
|
|
assert(KernAux_PFA_alloc_page(&pfa) != 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(KernAux_PFA_alloc_page(&pfa) == 0);
|
|
|
|
|
2020-11-30 13:32:27 -05:00
|
|
|
return 0;
|
|
|
|
}
|