diff options
author | David 'Digit' Turner <digit@google.com> | 2010-01-28 10:53:00 -0800 |
---|---|---|
committer | David 'Digit' Turner <digit@google.com> | 2010-01-28 10:53:00 -0800 |
commit | 84a66d0c8d79857586bad4e3d3010ee44f8f6971 (patch) | |
tree | 0c3d80930cf0238a12748adffe58f18d34880467 /tests/bionic/libc/common/test_clone.c | |
parent | 5b805c490e90b9702fb1010415db3994aba85798 (diff) | |
download | extras-84a66d0c8d79857586bad4e3d3010ee44f8f6971.tar.gz |
Add clone() test.
This also refreshes the tests to properly compile with the latest
host toolchain.
Diffstat (limited to 'tests/bionic/libc/common/test_clone.c')
-rw-r--r-- | tests/bionic/libc/common/test_clone.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/tests/bionic/libc/common/test_clone.c b/tests/bionic/libc/common/test_clone.c new file mode 100644 index 00000000..afbb9c17 --- /dev/null +++ b/tests/bionic/libc/common/test_clone.c @@ -0,0 +1,56 @@ +/* Check that clone() is implemented and properly works + */ +#define __GNU_SOURCE 1 +#include <stdio.h> +#include <errno.h> +#include <sched.h> +#include <unistd.h> +#include <signal.h> +#include <stdlib.h> +#include <sys/ptrace.h> +#include <sys/wait.h> +#include <stdarg.h> +#include <string.h> + +static int +clone_child (void *arg) +{ + errno = 0; + ptrace (PTRACE_TRACEME, 0, 0, 0); + if (errno != 0) + perror ("ptrace"); + if (kill (getpid (), SIGSTOP) < 0) + perror ("kill"); + return 0; +} + +#define PAGE_SIZE 4096 +#define STACK_SIZE (4 * PAGE_SIZE) + +char clone_stack[STACK_SIZE] __attribute__ ((aligned (PAGE_SIZE))); + +int +main () +{ + int pid,child; + int status; + + pid = clone (clone_child, clone_stack + 3 * PAGE_SIZE, + CLONE_VM | SIGCHLD, NULL); + if (pid < 0) + { + perror ("clone"); + exit (1); + } + printf ("child pid %d\n", pid); + + //sleep(20); + child = waitpid (pid, &status, 0); + printf("waitpid returned %d\n", child); + if (child < 0) { + perror ("waitpid"); + return 1; + } + printf ("child %d, status 0x%x\n", child, status); + return 0; +} |