Skip to content

Unittest That Stress-Tests the VMM and PMM #341

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions tests/unittests.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <console.h>
#include <cpuid.h>
#include <ktf.h>
#include <lib.h>
#include <mm/pmm.h>
#include <pagetable.h>
#include <real_mode.h>
Expand Down Expand Up @@ -72,6 +73,33 @@ static unsigned long test_kernel_task_func(void *arg) {
return _ul(arg);
}

static inline uint64_t rand47(void) {
return (_ul(rand()) << 16) ^ rand();
}

#define KT2_ROUNDS 100
#define KT2_CHUNKS 10
static unsigned long test_kernel_pmm_vmm_stress_test(void *arg) {
srand(rdtsc());

uint64_t blocks[KT2_CHUNKS] = {0};

for (size_t i = 0; i < KT2_ROUNDS; i++) {
for (size_t j = 0; j < KT2_CHUNKS; j++) {
blocks[j] = rand47() & ~(PAGE_SIZE - 1);
void *res = vmap_kern_4k(_ptr(blocks[j]), get_free_frame()->mfn, L1_PROT);
ASSERT(res == _ptr(blocks[j]));
}

for (int j = 0; j < KT2_CHUNKS; j++) {
mfn_t mfn;
ASSERT(!vunmap_kern(_ptr(blocks[j]), &mfn, PAGE_ORDER_4K));
put_free_frame(mfn);
}
}
return 0;
}

static unsigned long __user_text test_user_task_func1(void *arg) {

printf(USTR("printf: %u %x %d\n"), 1234, 0x41414141, 9);
Expand Down Expand Up @@ -203,11 +231,12 @@ int unit_tests(void *_unused) {
printk("PTE: 0x%lx\n", pte2->entry);
unmap_pagetables_va(&cr3, unit_tests);

task_t *task1, *task2, *task_user1, *task_user1_se, *task_user1_int80, *task_user2,
*task_user3, *task_user4;
task_t *task1, *task2, *task3, *task_user1, *task_user1_se, *task_user1_int80,
*task_user2, *task_user3, *task_user4;

task1 = new_kernel_task("test1", test_kernel_task_func, _ptr(98));
task2 = new_kernel_task("test2", test_kernel_task_func, _ptr(-99));
task3 = new_kernel_task("test3", test_kernel_pmm_vmm_stress_test, NULL);
task_user1 = new_user_task("test1 user", test_user_task_func1, NULL);
task_user1_se =
new_user_task("test1 user sysenter", test_user_task_func1_sysenter, NULL);
Expand All @@ -230,6 +259,7 @@ int unit_tests(void *_unused) {
set_task_repeat(task1, 10);
schedule_task(task1, get_bsp_cpu());
schedule_task(task2, get_cpu(1));
schedule_task(task3, get_cpu(1));
schedule_task(task_user1, get_bsp_cpu());
schedule_task(task_user1_se, get_bsp_cpu());
schedule_task(task_user1_int80, get_bsp_cpu());
Expand Down
Loading