Added a clone() test to test0.

This commit is contained in:
Bahadir Balban
2008-11-10 12:51:01 +02:00
parent a96a8bb6d9
commit 9a9b8d2701
3 changed files with 46 additions and 0 deletions

View File

@@ -9,5 +9,6 @@ int mmaptest(void);
int dirtest(void);
int fileio(void);
int fileio2(void);
int clonetest(void);
#endif /* __TEST0_TESTS_H__ */

View File

@@ -62,6 +62,9 @@ void main(void)
printf("-- FAILED --\n");
}
printf("Testing clone syscall...\n");
clonetest();
while (1)
wait_pager(0);
#if 0

42
tasks/test0/src/clone.c Normal file
View File

@@ -0,0 +1,42 @@
/*
* Clone test.
*/
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <sched.h>
#include <errno.h>
int my_thread_func(void *arg)
{
printf("Cloned child running...\n");
printf("PID: %d\n", getpid());
_exit(0);
}
int clonetest(void)
{
pid_t childid;
void *child_stack;
if ((child_stack = mmap(0, 0x1000, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE | MAP_GROWSDOWN, 0, 0)) == MAP_FAILED) {
printf("MMAP failed.\n");
_exit(1);
} else {
printf("Mapped area starting at %p\n", child_stack);
}
((int *)child_stack)[-1] = 5; /* Test mapped area */
printf("Cloning...\n");
if ((childid = clone(my_thread_func, child_stack,
CLONE_PARENT | CLONE_FS | CLONE_VM | CLONE_THREAD | CLONE_SIGHAND, 0)) < 0) {
perror("CLONE failed.\n");
} else {
printf("Cloned a new thread with child pid %d\n", childid);
}
return 0;
}