diff options
Diffstat (limited to 'src/user/test/main.c')
-rw-r--r-- | src/user/test/main.c | 69 |
1 files changed, 65 insertions, 4 deletions
diff --git a/src/user/test/main.c b/src/user/test/main.c index 945c530..f8fec48 100644 --- a/src/user/test/main.c +++ b/src/user/test/main.c @@ -1,9 +1,15 @@ #include <tce/syscall.h> #include <stdlib.h> +#include <tce/Folder.h> +#include <stdio.h> + +int threads = 0; void thread_cascade(void* d) { int n = (int)d; + threads++; + if (d == 0) { //printk("{#} 0 cascade element started => end\n"); printk("*"); @@ -25,16 +31,71 @@ void thread_cascade(void* d) { //printk("{#} Thread cascade element finished.\n"); printk("."); } + + threads--; +} + +void read_dir(Object o, int l) { + int i = 0, j; + char name[FILENAME_MAX_LEN]; + while (1) { + for (j = 0; j < l; j++) printk(" "); + j = Folder_GetChildNameAt(o, i, name); + if (j <= 0) { + printk(" - reached end : "); + printk_int(j); + printk("\n"); + break; + } + printk(" - '"); + printk(name); + + if (strcmp(name, ".") == 0) { + printk("', skipping -_-'\n"); + } else { + Object oo = open_relative(name, o); + if (oo <= 0) { + printk("', failed to open, error "); + printk_int(oo); + printk("...\n"); + } else { + printk("', opened as "); + printk_int(oo); + printk(", content:\n"); + read_dir(oo, l+1); + } + } + i++; + } } + int main() { - printk("Hi world from test module !\n"); + printk("Test starts. "); - printk(" -> Creating thread cascade (total 2**8 = 256 threads)\n"); - thread_new(thread_cascade, (void*)8); + printk("Create thread cascade (2**5 = 32 threads). "); + thread_new(thread_cascade, (void*)5); - printk(" -> Main thread now sleeping... forever...\n"); + printk("Main thread waits.\n"); while (1) { + thread_sleep(100); + if (threads == 0) break; + } + printk("\nOk, that was fine. Now trying something else...\n"); + Object o = open("/"); + if (o <= 0) { + printk("Cannot open '/', error "); + printk_int(o); + printk("...\n"); + } else { + printk("Reading '/' ("); + printk_int(o); + printk(") :\n"); + read_dir(o, 0); + } + + printk("Ok. Now sleeping, forever and ever."); + while(1) { thread_sleep(1000); } return 0; |