aboutsummaryrefslogtreecommitdiff
path: root/kernel/l0
diff options
context:
space:
mode:
authorAlex Auvolat <alex.auvolat@ens.fr>2014-12-16 21:21:46 +0100
committerAlex Auvolat <alex.auvolat@ens.fr>2014-12-16 21:21:46 +0100
commitab35e5fac02f11f0bd742020b112a09e5b1f2de5 (patch)
treec7b401662f8dabc1f9976cbd387a2b1abc32ac56 /kernel/l0
parentbafc8298c68dc1a631ef818710311c01eccec137 (diff)
downloadkogata-ab35e5fac02f11f0bd742020b112a09e5b1f2de5.tar.gz
kogata-ab35e5fac02f11f0bd742020b112a09e5b1f2de5.zip
Add simple hash table implementation.
Diffstat (limited to 'kernel/l0')
-rw-r--r--kernel/l0/kmain.c61
1 files changed, 51 insertions, 10 deletions
diff --git a/kernel/l0/kmain.c b/kernel/l0/kmain.c
index 140a09f..f0ce014 100644
--- a/kernel/l0/kmain.c
+++ b/kernel/l0/kmain.c
@@ -13,6 +13,7 @@
#include <thread.h>
#include <slab_alloc.h>
+#include <hashtbl.h>
extern const void k_end_addr; // defined in linker script : 0xC0000000 plus kernel stuff
@@ -100,25 +101,65 @@ void kmalloc_test(void* kernel_data_end) {
dbg_print_region_info();
}
+void test_hashtbl_1() {
+ // hashtable test
+ hashtbl_t *ht = create_hashtbl(str_key_eq_fun, str_hash_fun, 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");
+ 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"));
+ delete_hashtbl(ht);
+}
+
+void test_hashtbl_2() {
+ hashtbl_t *ht = create_hashtbl(id_key_eq_fun, id_hash_fun, 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");
+ 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));
+ delete_hashtbl(ht);
+}
+
void test_thread(void* a) {
- int i = 0;
- while(1) {
+ 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) {
- yield();
- i = 0;
- }
+ if (i % 8 == 0) yield();
}
}
void kernel_init_stage2(void* data) {
- thread_t *tb = new_thread(test_thread);
- resume_thread_with_result(tb, 0, false);
-
dbg_print_region_info();
dbg_print_frame_stats();
- while(1) {
+ test_hashtbl_1();
+ test_hashtbl_2();
+
+ thread_t *tb = new_thread(test_thread);
+ resume_thread_with_result(tb, 0, false);
+
+ for (int i = 0; i < 120; i++) {
dbg_printf("a");
for (int x = 0; x < 100000; x++) asm volatile("xor %%ebx, %%ebx":::"%ebx");
}