diff options
Diffstat (limited to 'src/kernel/core/kmain.c')
-rw-r--r-- | src/kernel/core/kmain.c | 122 |
1 files changed, 74 insertions, 48 deletions
diff --git a/src/kernel/core/kmain.c b/src/kernel/core/kmain.c index 57d49e5..774174f 100644 --- a/src/kernel/core/kmain.c +++ b/src/kernel/core/kmain.c @@ -27,7 +27,14 @@ void breakpoint_handler(registers_t *regs) { BOCHS_BREAKPOINT; } +void breakpoint_test() { + dbg_printf("(BEGIN-TEST 'breakpoint-test)\n"); + asm volatile("int $0x3"); // test breakpoint + dbg_printf("(TEST-OK)\n"); +} + void region_test1() { + dbg_printf("(BEGIN-TEST 'region-test-1)\n"); void* p = region_alloc(0x1000, "Test region", 0); dbg_printf("Allocated one-page region: 0x%p\n", p); dbg_print_region_info(); @@ -52,11 +59,13 @@ void region_test1() { region_free(s); dbg_printf("Freed region 0x%p\n", s); dbg_print_region_info(); + + dbg_printf("(TEST-OK)\n"); } void region_test2() { // allocate a big region and try to write into it - dbg_printf("Begin region test 2..."); + dbg_printf("(BEGIN-TEST 'region-test-2)\n"); const size_t n = 200; void* p0 = region_alloc(n * PAGE_SIZE, "Test big region", default_allocator_pf_handler); for (size_t i = 0; i < n; i++) { @@ -78,13 +87,14 @@ void region_test2() { frame_free(f, 1); } region_free(p0); - dbg_printf("OK\n"); + + dbg_printf("(TEST-OK)\n"); } void kmalloc_test(void* kernel_data_end) { + dbg_printf("(BEGIN-TEST 'kmalloc-test)\n"); // Test kmalloc ! dbg_print_region_info(); - dbg_printf("Begin kmalloc test...\n"); const int m = 200; uint16_t** ptr = malloc(m * sizeof(uint32_t)); for (int i = 0; i < m; i++) { @@ -104,55 +114,78 @@ void kmalloc_test(void* kernel_data_end) { free(ptr); dbg_printf("Kmalloc test OK.\n"); dbg_print_region_info(); + + dbg_printf("(TEST-OK)\n"); } void test_hashtbl_1() { + dbg_printf("(BEGIN-TEST 'test-hashtbl-1)\n"); // hashtable test hashtbl_t *ht = create_hashtbl(str_key_eq_fun, str_hash_fun, 0, 0); - hashtbl_add(ht, "test1", "Hello, world [test1]"); - hashtbl_add(ht, "test2", "Hello, world [test2]"); - dbg_printf("ht[test1] = %s\n", hashtbl_find(ht, "test1")); - dbg_printf("ht[test] = %s\n", hashtbl_find(ht, "test")); - dbg_printf("ht[test2] = %s\n", hashtbl_find(ht, "test2")); - dbg_printf("adding test...\n"); - hashtbl_add(ht, "test", "Forever alone"); - dbg_printf("ht[test1] = %s\n", hashtbl_find(ht, "test1")); - dbg_printf("ht[test] = %s\n", hashtbl_find(ht, "test")); - dbg_printf("ht[test2] = %s\n", hashtbl_find(ht, "test2")); - dbg_printf("removing test1...\n"); + ASSERT(ht != 0); + + ASSERT(hashtbl_add(ht, "test1", "STRTEST1")); + ASSERT(hashtbl_add(ht, "test2", "STRTEST2")); + ASSERT(hashtbl_find(ht, "test1") != 0 && + strcmp(hashtbl_find(ht, "test1"), "STRTEST1") == 0); + ASSERT(hashtbl_find(ht, "test2") != 0 && + strcmp(hashtbl_find(ht, "test2"), "STRTEST2") == 0); + ASSERT(hashtbl_find(ht, "test") == 0); + + ASSERT(hashtbl_add(ht, "test", "Forever alone")); + ASSERT(hashtbl_find(ht, "test1") != 0 && + strcmp(hashtbl_find(ht, "test1"), "STRTEST1") == 0); + ASSERT(hashtbl_find(ht, "test2") != 0 && + strcmp(hashtbl_find(ht, "test2"), "STRTEST2") == 0); + ASSERT(hashtbl_find(ht, "test") != 0 && + strcmp(hashtbl_find(ht, "test"), "Forever alone") == 0); + hashtbl_remove(ht, "test1"); - dbg_printf("ht[test1] = %s\n", hashtbl_find(ht, "test1")); - dbg_printf("ht[test] = %s\n", hashtbl_find(ht, "test")); - dbg_printf("ht[test2] = %s\n", hashtbl_find(ht, "test2")); + ASSERT(hashtbl_find(ht, "test1") == 0); + ASSERT(hashtbl_find(ht, "test2") != 0 && + strcmp(hashtbl_find(ht, "test2"), "STRTEST2") == 0); + ASSERT(hashtbl_find(ht, "test") != 0 && + strcmp(hashtbl_find(ht, "test"), "Forever alone") == 0); + delete_hashtbl(ht, 0); + + dbg_printf("(TEST-OK)\n"); } void test_hashtbl_2() { + dbg_printf("(BEGIN-TEST 'test-hashtbl-2)\n"); + hashtbl_t *ht = create_hashtbl(id_key_eq_fun, id_hash_fun, 0, 0); - hashtbl_add(ht, (void*)12, "Hello, world [12]"); - hashtbl_add(ht, (void*)777, "Hello, world [777]"); - dbg_printf("ht[12] = %s\n", hashtbl_find(ht, (void*)12)); - dbg_printf("ht[144] = %s\n", hashtbl_find(ht, (void*)144)); - dbg_printf("ht[777] = %s\n", hashtbl_find(ht, (void*)777)); - dbg_printf("adding 144...\n"); - hashtbl_add(ht, (void*)144, "Forever alone"); - dbg_printf("ht[12] = %s\n", hashtbl_find(ht, (void*)12)); - dbg_printf("ht[144] = %s\n", hashtbl_find(ht, (void*)144)); - dbg_printf("ht[777] = %s\n", hashtbl_find(ht, (void*)777)); - dbg_printf("removing 12...\n"); + ASSERT(ht != 0); + + ASSERT(hashtbl_add(ht, (void*)12, "TESTSTR12")); + ASSERT(hashtbl_add(ht, (void*)777, "TESTSTR777")); + + ASSERT(hashtbl_find(ht, (void*)12) != 0 && + strcmp(hashtbl_find(ht, (void*)12), "TESTSTR12") == 0); + ASSERT(hashtbl_find(ht, (void*)777) != 0 && + strcmp(hashtbl_find(ht, (void*)777), "TESTSTR777") == 0); + ASSERT(hashtbl_find(ht, (void*)144) == 0); + + ASSERT(hashtbl_add(ht, (void*)144, "Forever alone")); + + ASSERT(hashtbl_find(ht, (void*)12) != 0 && + strcmp(hashtbl_find(ht, (void*)12), "TESTSTR12") == 0); + ASSERT(hashtbl_find(ht, (void*)144) != 0 && + strcmp(hashtbl_find(ht, (void*)144), "Forever alone") == 0); + ASSERT(hashtbl_find(ht, (void*)777) != 0 && + strcmp(hashtbl_find(ht, (void*)777), "TESTSTR777") == 0); + hashtbl_remove(ht, (void*)12); - dbg_printf("ht[12] = %s\n", hashtbl_find(ht, (void*)12)); - dbg_printf("ht[144] = %s\n", hashtbl_find(ht, (void*)144)); - dbg_printf("ht[777] = %s\n", hashtbl_find(ht, (void*)777)); + ASSERT(hashtbl_find(ht, (void*)12) == 0); + ASSERT(hashtbl_find(ht, (void*)144) != 0 && + strcmp(hashtbl_find(ht, (void*)144), "Forever alone") == 0); + ASSERT(hashtbl_find(ht, (void*)777) != 0 && + strcmp(hashtbl_find(ht, (void*)777), "TESTSTR777") == 0); + delete_hashtbl(ht, 0); -} -void test_thread(void* a) { - for(int i = 0; i < 120; i++) { - dbg_printf("b"); - for (int x = 0; x < 100000; x++) asm volatile("xor %%ebx, %%ebx":::"%ebx"); - if (i % 8 == 0) yield(); - } + dbg_printf("(TEST-OK)\n"); } void kernel_init_stage2(void* data); @@ -192,7 +225,8 @@ void kmain(multiboot_info_t *mbd, int32_t mb_magic) { idt_init(); dbg_printf("IDT set up.\n"); idt_set_ex_handler(EX_BREAKPOINT, breakpoint_handler); - asm volatile("int $0x3"); // test breakpoint + + breakpoint_test(); size_t total_ram = ((mbd->mem_upper + mbd->mem_lower) * 1024); dbg_printf("Total ram: %d Kb\n", total_ram / 1024); @@ -230,14 +264,6 @@ void kernel_init_stage2(void* data) { test_hashtbl_1(); test_hashtbl_2(); - thread_t *tb = new_thread(test_thread, 0); - resume_thread(tb, false); - - for (int i = 0; i < 120; i++) { - dbg_printf("a"); - for (int x = 0; x < 100000; x++) asm volatile("xor %%ebx, %%ebx":::"%ebx"); - } - // Create devfs register_nullfs_driver(); fs_t *devfs = make_fs("nullfs", 0, "cd"); @@ -303,7 +329,7 @@ void kernel_init_stage2(void* data) { // - launch it // - just return, this thread is done - PANIC("Reached kmain end! Falling off the edge."); + dbg_printf("Reached kmain end! I'll just stop here and do nothing.\n"); } /* vim: set ts=4 sw=4 tw=0 noet :*/ |