From 324481a334f525b96bc6b66bf16a7e7fc71a6311 Mon Sep 17 00:00:00 2001 From: Bahadir Balban Date: Tue, 12 May 2009 12:31:25 +0300 Subject: [PATCH] Some more enhancements to test0 - Only the topmost parent prints pass messages. Any failed child can print fail message. - Added testing of 16 forked threads doing file create/read/write/close and 16 forked x 4 cloned = 64 threads spawning/exiting --- tasks/fs0/main.c | 2 +- tasks/libposix/open.c | 3 ++- tasks/mm0/main.c | 2 +- tasks/test0/include/tests.h | 4 +++- tasks/test0/main.c | 12 +++++++----- tasks/test0/src/clonetest.c | 6 +++++- tasks/test0/src/fileio.c | 3 ++- tasks/test0/src/forktest.c | 20 +++++++++++--------- tasks/test0/src/mmaptest.c | 2 +- 9 files changed, 33 insertions(+), 21 deletions(-) diff --git a/tasks/fs0/main.c b/tasks/fs0/main.c index ea16859..8bf4b13 100644 --- a/tasks/fs0/main.c +++ b/tasks/fs0/main.c @@ -135,7 +135,7 @@ void handle_fs_requests(void) void main(void) { - printf("\n%s: Started with thread id: %d\n", __TASKNAME__, self_tid()); + printf("\n%s: Started with thread id %d\n", __TASKNAME__, self_tid()); initialise(); diff --git a/tasks/libposix/open.c b/tasks/libposix/open.c index 1147628..f267709 100644 --- a/tasks/libposix/open.c +++ b/tasks/libposix/open.c @@ -36,7 +36,8 @@ static inline int l4_open(const char *pathname, int flags, mode_t mode) } /* Check if syscall itself was successful */ if ((fd = l4_get_retval()) < 0) { - printf("%s: OPEN Error: %d.\n", __FUNCTION__, fd); + printf("%s: OPEN Error: %d, for path %s\n", + __FUNCTION__, fd, pathname); return fd; } return fd; diff --git a/tasks/mm0/main.c b/tasks/mm0/main.c index 94a8a48..e2009d6 100644 --- a/tasks/mm0/main.c +++ b/tasks/mm0/main.c @@ -239,7 +239,7 @@ int self_spawn(void) void main(void) { - printf("\n%s: Started with thread id: %d\n", __TASKNAME__, self_tid()); + printf("\n%s: Started with thread id %d\n", __TASKNAME__, self_tid()); /* Initialise the memory, server tasks, mmap and start them. */ initialise(); diff --git a/tasks/test0/include/tests.h b/tasks/test0/include/tests.h index 16cd1e4..3818ce0 100644 --- a/tasks/test0/include/tests.h +++ b/tasks/test0/include/tests.h @@ -3,13 +3,15 @@ #define __TASKNAME__ "test0" -// #define TEST_VERBOSE_PRINT +//#define TEST_VERBOSE_PRINT #if defined (TEST_VERBOSE_PRINT) #define test_printf(...) printf(__VA_ARGS__) #else #define test_printf(...) #endif +#include +extern pid_t parent_of_all; int shmtest(void); int forktest(void); diff --git a/tasks/test0/main.c b/tasks/test0/main.c index 2f475b2..284677a 100644 --- a/tasks/test0/main.c +++ b/tasks/test0/main.c @@ -24,22 +24,24 @@ void wait_pager(l4id_t partner) void main(void) { - printf("\n%s: Started with tid %d.\n", __TASKNAME__, self_tid()); + printf("\n%s: Started with thread id %d\n", __TASKNAME__, self_tid()); wait_pager(0); - dirtest(); + printf("%s: Running POSIX API tests.\n", __TASKNAME__); - // exectest(); + dirtest(); mmaptest(); - fileio(); - forktest(); + fileio(); + clonetest(); + // exectest(); + while (1) wait_pager(0); } diff --git a/tasks/test0/src/clonetest.c b/tasks/test0/src/clonetest.c index 1695895..8cada04 100644 --- a/tasks/test0/src/clonetest.c +++ b/tasks/test0/src/clonetest.c @@ -11,6 +11,8 @@ int clone_global = 0; +extern pid_t parent_of_all; + int my_thread_func(void *arg) { for (int i = 0; i < 25; i++) @@ -46,7 +48,9 @@ int clonetest(void) /* TODO: Add wait() or something similar and check that global is 100 */ - printf("CLONE TEST -- PASSED --\n"); + if (getpid() == parent_of_all) + printf("CLONE TEST -- PASSED --\n"); + return 0; out_err: printf("CLONE TEST -- FAILED --\n"); diff --git a/tasks/test0/src/fileio.c b/tasks/test0/src/fileio.c index 9c2af27..253fd61 100644 --- a/tasks/test0/src/fileio.c +++ b/tasks/test0/src/fileio.c @@ -61,7 +61,8 @@ int fileio(void) goto out_err; } - printf("FILE IO TEST -- PASSED --\n"); + if (getpid() == parent_of_all) + printf("FILE IO TEST -- PASSED --\n"); return 0; out_err: diff --git a/tasks/test0/src/forktest.c b/tasks/test0/src/forktest.c index ab81ff5..72ed85d 100644 --- a/tasks/test0/src/forktest.c +++ b/tasks/test0/src/forktest.c @@ -10,12 +10,13 @@ int global = 0; -static pid_t pid; +pid_t parent_of_all; int forktest(void) { pid_t myid; - pid_t parent = getpid(); + + parent_of_all = getpid(); /* 16 forks */ for (int i = 0; i < 4; i++) @@ -23,7 +24,7 @@ int forktest(void) goto out_err; myid = getpid(); - pid = myid; + if (global != 0) { test_printf("Global not zero.\n"); test_printf("-- FAILED --\n"); @@ -35,14 +36,15 @@ int forktest(void) goto out_err; - if (getpid() != parent) { - /* Successful childs return here */ - _exit(0); - BUG(); + if (getpid() != parent_of_all) { + /* Exit here to exit successful children */ + //_exit(0); + //BUG(); } - /* Parent of all comes here if successful */ - printf("FORK TEST -- PASSED --\n"); + if (getpid() == parent_of_all) + printf("FORK TEST -- PASSED --\n"); + return 0; /* Any erroneous child or parent comes here */ diff --git a/tasks/test0/src/mmaptest.c b/tasks/test0/src/mmaptest.c index 3f1f64e..95e37dd 100644 --- a/tasks/test0/src/mmaptest.c +++ b/tasks/test0/src/mmaptest.c @@ -23,7 +23,7 @@ int mmaptest(void) void *base; int x = 0x1000; - if ((fd = open("./newfile3.txt", O_CREAT | O_TRUNC | O_RDWR, S_IRWXU)) < 0) + if ((fd = open("./mmapfile.txt", O_CREAT | O_TRUNC | O_RDWR, S_IRWXU)) < 0) goto out_err; /* Extend the file */