1 /* 2 * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved. 3 * Copyright (c) 2012 Wanlong Gao <gaowanlong@cn.fujitsu.com> 4 * 5 * This program is free software; you can redistribute it and/or modify it 6 * under the terms of version 2 of the GNU General Public License as 7 * published by the Free Software Foundation. 8 * 9 * This program is distributed in the hope that it would be useful, but 10 * WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 * 13 * You should have received a copy of the GNU General Public License along 14 * with this program; if not, write the Free Software Foundation, Inc., 15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 16 * 17 */ 18 19 /* 20 * This is a test for the clone(2) system call. 21 * It is intended to provide a limited exposure of the system call. 22 */ 23 24 #if defined UCLINUX && !__THROW 25 /* workaround for libc bug */ 26 #define __THROW 27 #endif 28 29 #include <errno.h> 30 #include <sched.h> 31 #include <sys/wait.h> 32 #include "test.h" 33 #include "safe_macros.h" 34 #include "clone_platform.h" 35 36 static void setup(void); 37 static void cleanup(void); 38 static int do_child(); 39 40 char *TCID = "clone01"; 41 int TST_TOTAL = 1; 42 43 int main(int ac, char **av) 44 { 45 void *child_stack; 46 int status, child_pid; 47 48 tst_parse_opts(ac, av, NULL, NULL); 49 50 setup(); 51 52 child_stack = malloc(CHILD_STACK_SIZE); 53 if (child_stack == NULL) 54 tst_brkm(TBROK, cleanup, "Cannot allocate stack for child"); 55 56 tst_count = 0; 57 58 TEST(ltp_clone(SIGCHLD, do_child, NULL, CHILD_STACK_SIZE, child_stack)); 59 if (TEST_RETURN == -1) 60 tst_resm(TFAIL | TTERRNO, "clone failed"); 61 62 child_pid = SAFE_WAIT(cleanup, &status); 63 64 if (TEST_RETURN == child_pid) 65 tst_resm(TPASS, "clone returned %ld", TEST_RETURN); 66 else 67 tst_resm(TFAIL, "clone returned %ld, wait returned %d", 68 TEST_RETURN, child_pid); 69 70 free(child_stack); 71 72 cleanup(); 73 74 tst_exit(); 75 } 76 77 static void setup(void) 78 { 79 tst_sig(FORK, DEF_HANDLER, cleanup); 80 TEST_PAUSE; 81 } 82 83 static void cleanup(void) 84 { 85 } 86 87 static int do_child(void) 88 { 89 exit(0); 90 } 91