summaryrefslogtreecommitdiff
path: root/src/user/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/user/test')
-rw-r--r--src/user/test/main.c65
1 files changed, 62 insertions, 3 deletions
diff --git a/src/user/test/main.c b/src/user/test/main.c
index ec14c21..a7df667 100644
--- a/src/user/test/main.c
+++ b/src/user/test/main.c
@@ -1,9 +1,14 @@
#include <tce/syscall.h>
#include <stdlib.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,6 +30,41 @@ void thread_cascade(void* d) {
//printk("{#} Thread cascade element finished.\n");
printk(".");
}
+
+ threads--;
+}
+
+void list_dir(FILE f, int lv) {
+ char buf[256];
+ int i = 0, k;
+ int r;
+ file_info info;
+
+ while ((r = read(f, i, 256, buf)) > 0) {
+ for (k = 0; k < lv; k++) printk(" ");
+ printk(buf); printk("\t\t");
+
+ stat_relative(f, buf, &info);
+ printk_hex(info.type);
+ if (info.type & FT_DIR) {
+ printk("\t");
+ if (strcmp(buf, ".") != 0 && strcmp(buf, "..") != 0) {
+ FILE ff = open_relative(f, buf, 0);
+ if (ff <= 0) {
+ printk("error: "); printk_int(ff); printk("\n");
+ } else {
+ printk("fd: "); printk_int(ff); printk("\n");
+ list_dir(ff, lv+1);
+ close(ff);
+ }
+ } else {
+ printk("\n");
+ }
+ } else {
+ printk("\n");
+ }
+ i++;
+ }
}
int main() {
@@ -32,12 +72,31 @@ int main() {
printk_hex((uint32_t)malloc(42));
printk("\n");
- printk("(test app) Creating thread cascade (total 2**8 = 256 threads)\n");
- thread_new(thread_cascade, (void*)8);
+ printk(" -> Creating thread cascade (total 2**4 = 16 threads)\n");
+ thread_new(thread_cascade, (void*)4);
- printk("(test app) Main thread now sleeping... forever...\n");
+ printk(" -> Main thread now sleeping...\n");
while (1) {
+ thread_sleep(100);
+ if (threads == 0) break;
+ }
+ printk("\n -> Ok, let's try something else.\n");
+
+ FILE f = open("/", 0);
+ if (f <= 0) {
+ printk(" -> Could not open '/', error #");
+ printk_int(f);
+ printk("...\n");
+ } else {
+ printk("Now enumerating '/' (fd "); printk_int(f); printk(") :\n");
+ list_dir(f, 1);
+ close(f);
+ }
+
+ printk(" -> Now sleeping, forever and ever...\n");
+ while(1) {
thread_sleep(1000);
}
+
return 0;
}