blob: fea478da9659cebeb7b19cedb9d405152fe7e903 [file] [log] [blame]
nstraze3219812003-07-14 17:06:37 +00001/*
2 * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved.
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +08003 * Copyright (c) 2012 Wanlong Gao <gaowanlong@cn.fujitsu.com>
nstraze3219812003-07-14 17:06:37 +00004 *
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
Wanlong Gaofed96412012-10-24 10:10:29 +080014 * with this program; if not, write the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
nstraze3219812003-07-14 17:06:37 +000016 *
17 */
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +080018
19/*
20 * This is a test for the clone(2) system call.
nstraze3219812003-07-14 17:06:37 +000021 * It is intended to provide a limited exposure of the system call.
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +080022 */
nstraze3219812003-07-14 17:06:37 +000023
robbiewd34d5812005-07-11 22:28:09 +000024#if defined UCLINUX && !__THROW
25/* workaround for libc bug */
26#define __THROW
27#endif
28
nstraze3219812003-07-14 17:06:37 +000029#include <errno.h>
30#include <sched.h>
31#include <sys/wait.h>
32#include "test.h"
nstraz882ee2d2003-07-16 17:40:32 +000033#include "clone_platform.h"
nstraze3219812003-07-14 17:06:37 +000034
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +080035static void setup(void);
36static void cleanup(void);
nstraze3219812003-07-14 17:06:37 +000037static int do_child();
38
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +080039char *TCID = "clone01";
40int TST_TOTAL = 1;
nstraze3219812003-07-14 17:06:37 +000041
subrata_modak56207ce2009-03-23 13:35:39 +000042int main(int ac, char **av)
nstraze3219812003-07-14 17:06:37 +000043{
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020044 const char *msg;
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +080045 void *child_stack;
nstraze3219812003-07-14 17:06:37 +000046 int status, child_pid;
subrata_modak56207ce2009-03-23 13:35:39 +000047
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +080048 msg = parse_opts(ac, av, NULL, NULL);
49 if (msg != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -080050 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
nstraze3219812003-07-14 17:06:37 +000051
nstraze3219812003-07-14 17:06:37 +000052 setup();
53
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +080054 child_stack = malloc(CHILD_STACK_SIZE);
55 if (child_stack == NULL)
nstraze3219812003-07-14 17:06:37 +000056 tst_brkm(TBROK, cleanup, "Cannot allocate stack for child");
nstraze3219812003-07-14 17:06:37 +000057
Caspar Zhangd59a6592013-03-07 14:59:12 +080058 tst_count = 0;
nstraze3219812003-07-14 17:06:37 +000059
Garrett Cooperfbb20142010-12-17 01:57:48 -080060 TEST(ltp_clone(SIGCHLD, do_child, NULL, CHILD_STACK_SIZE, child_stack));
Jan Stancek443d16e2012-12-03 13:19:57 +010061 if (TEST_RETURN == -1)
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +080062 tst_resm(TFAIL | TTERRNO, "clone failed");
nstraze3219812003-07-14 17:06:37 +000063
Garrett Cooperfbb20142010-12-17 01:57:48 -080064 child_pid = wait(&status);
Jan Stancek443d16e2012-12-03 13:19:57 +010065 if (child_pid == -1)
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +080066 tst_brkm(TBROK | TERRNO, cleanup, "wait failed, status: %d",
67 status);
subrata_modakbdbaec52009-02-26 12:14:51 +000068
Garrett Cooperfbb20142010-12-17 01:57:48 -080069 if (TEST_RETURN == child_pid)
70 tst_resm(TPASS, "clone returned %ld", TEST_RETURN);
Garrett Cooperfbb20142010-12-17 01:57:48 -080071 else
Jan Stancek443d16e2012-12-03 13:19:57 +010072 tst_resm(TFAIL, "clone returned %ld, wait returned %d",
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +080073 TEST_RETURN, child_pid);
nstraze3219812003-07-14 17:06:37 +000074
75 free(child_stack);
76
nstraze3219812003-07-14 17:06:37 +000077 cleanup();
78
Garrett Cooperfbb20142010-12-17 01:57:48 -080079 tst_exit();
Garrett Cooper2c282152010-12-16 00:55:50 -080080}
nstraze3219812003-07-14 17:06:37 +000081
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +080082static void setup(void)
nstraze3219812003-07-14 17:06:37 +000083{
nstraze3219812003-07-14 17:06:37 +000084 tst_sig(FORK, DEF_HANDLER, cleanup);
nstraze3219812003-07-14 17:06:37 +000085 TEST_PAUSE;
Garrett Cooper2c282152010-12-16 00:55:50 -080086}
nstraze3219812003-07-14 17:06:37 +000087
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +080088static void cleanup(void)
nstraze3219812003-07-14 17:06:37 +000089{
Garrett Cooper2c282152010-12-16 00:55:50 -080090}
nstraze3219812003-07-14 17:06:37 +000091
Mike Frysingerc57fba52014-04-09 18:56:30 -040092static int do_child(void)
nstraze3219812003-07-14 17:06:37 +000093{
robbiewb8bd30c2003-07-31 20:41:11 +000094 exit(0);
Chris Dearmanec6edca2012-10-17 19:54:01 -070095}