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 "clone_platform.h" 34 35static void setup(void); 36static void cleanup(void); 37static int do_child(); 38 39char *TCID = "clone01"; 40int TST_TOTAL = 1; 41 42int main(int ac, char **av) 43{ 44 void *child_stack; 45 int status, child_pid; 46 47 tst_parse_opts(ac, av, NULL, NULL); 48 49 setup(); 50 51 child_stack = malloc(CHILD_STACK_SIZE); 52 if (child_stack == NULL) 53 tst_brkm(TBROK, cleanup, "Cannot allocate stack for child"); 54 55 tst_count = 0; 56 57 TEST(ltp_clone(SIGCHLD, do_child, NULL, CHILD_STACK_SIZE, child_stack)); 58 if (TEST_RETURN == -1) 59 tst_resm(TFAIL | TTERRNO, "clone failed"); 60 61 child_pid = wait(&status); 62 if (child_pid == -1) 63 tst_brkm(TBROK | TERRNO, cleanup, "wait failed, status: %d", 64 status); 65 66 if (TEST_RETURN == child_pid) 67 tst_resm(TPASS, "clone returned %ld", TEST_RETURN); 68 else 69 tst_resm(TFAIL, "clone returned %ld, wait returned %d", 70 TEST_RETURN, child_pid); 71 72 free(child_stack); 73 74 cleanup(); 75 76 tst_exit(); 77} 78 79static void setup(void) 80{ 81 tst_sig(FORK, DEF_HANDLER, cleanup); 82 TEST_PAUSE; 83} 84 85static void cleanup(void) 86{ 87} 88 89static int do_child(void) 90{ 91 exit(0); 92} 93