blob: 33a8c6100d839d78d8528c8d254121b559b050f1 [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>
Cyril Hrubisb6a56572012-12-11 20:58:12 +01004 * Copyright (c) 2012 Cyril Hrubis <chrubis@suse.cz>
nstraze3219812003-07-14 17:06:37 +00005 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of version 2 of the GNU General Public License as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it would be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 *
14 * You should have received a copy of the GNU General Public License along
Wanlong Gaofed96412012-10-24 10:10:29 +080015 * with this program; if not, write the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
nstraze3219812003-07-14 17:06:37 +000017 *
18 */
nstraze3219812003-07-14 17:06:37 +000019
Cyril Hrubisc91af2f2012-11-28 18:02:01 +010020/*
21 * Call clone() with CLONE_VFORK flag set. verify that
22 * execution of parent is suspended until child finishes
23 */
robbiewd34d5812005-07-11 22:28:09 +000024
Cyril Hrubis019ed6c2011-08-26 12:59:32 +020025#define _GNU_SOURCE
26
nstraze3219812003-07-14 17:06:37 +000027#include <errno.h>
28#include <sched.h>
29#include <sys/wait.h>
30#include "test.h"
nstraz882ee2d2003-07-16 17:40:32 +000031#include "clone_platform.h"
robbiew666adf12003-10-01 16:10:49 +000032
Cyril Hrubisc91af2f2012-11-28 18:02:01 +010033char *TCID = "clone05";
34int TST_TOTAL = 1;
nstraze3219812003-07-14 17:06:37 +000035
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +080036static void setup(void);
37static void cleanup(void);
Cyril Hrubisc91af2f2012-11-28 18:02:01 +010038static int child_fn(void *);
nstraze3219812003-07-14 17:06:37 +000039
Cyril Hrubisc91af2f2012-11-28 18:02:01 +010040static int child_exited = 0;
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{
44
Jan Stancek443d16e2012-12-03 13:19:57 +010045 int lc, status;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020046 const char *msg;
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +080047 void *child_stack;
nstraze3219812003-07-14 17:06:37 +000048
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +080049 msg = parse_opts(ac, av, NULL, NULL);
Cyril Hrubisb6a56572012-12-11 20:58:12 +010050 if (msg != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -080051 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
nstraze3219812003-07-14 17:06:37 +000052
nstraze3219812003-07-14 17:06:37 +000053 setup();
54
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +080055 child_stack = malloc(CHILD_STACK_SIZE);
56 if (child_stack == NULL)
nstraze3219812003-07-14 17:06:37 +000057 tst_brkm(TBROK, cleanup, "Cannot allocate stack for child");
nstraze3219812003-07-14 17:06:37 +000058
subrata_modak56207ce2009-03-23 13:35:39 +000059 for (lc = 0; TEST_LOOPING(lc); lc++) {
Caspar Zhangd59a6592013-03-07 14:59:12 +080060 tst_count = 0;
nstraze3219812003-07-14 17:06:37 +000061
Wanlong Gao79b77292012-12-12 10:38:05 +080062 TEST(ltp_clone(CLONE_VM | CLONE_VFORK | SIGCHLD, child_fn, NULL,
Cyril Hrubisc91af2f2012-11-28 18:02:01 +010063 CHILD_STACK_SIZE, child_stack));
subrata_modakbdbaec52009-02-26 12:14:51 +000064
Cyril Hrubisb6a56572012-12-11 20:58:12 +010065 if ((TEST_RETURN != -1) && (child_exited))
nstraze3219812003-07-14 17:06:37 +000066 tst_resm(TPASS, "Test Passed");
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +080067 else
nstraze3219812003-07-14 17:06:37 +000068 tst_resm(TFAIL, "Test Failed");
nstraze3219812003-07-14 17:06:37 +000069
Jan Stancek443d16e2012-12-03 13:19:57 +010070 if ((wait(&status)) == -1)
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +080071 tst_brkm(TBROK | TERRNO, cleanup,
72 "wait failed, status: %d", status);
Jan Stancek443d16e2012-12-03 13:19:57 +010073
Cyril Hrubisc91af2f2012-11-28 18:02:01 +010074 child_exited = 0;
Garrett Cooper2c282152010-12-16 00:55:50 -080075 }
nstraze3219812003-07-14 17:06:37 +000076
subrata_modak56207ce2009-03-23 13:35:39 +000077 free(child_stack);
nstraze3219812003-07-14 17:06:37 +000078
nstraze3219812003-07-14 17:06:37 +000079 cleanup();
Garrett Coopera2e42482010-12-17 01:58:55 -080080 tst_exit();
Garrett Cooper2c282152010-12-16 00:55:50 -080081}
nstraze3219812003-07-14 17:06:37 +000082
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +080083static void setup(void)
nstraze3219812003-07-14 17:06:37 +000084{
Jan Stancek443d16e2012-12-03 13:19:57 +010085 tst_sig(FORK, DEF_HANDLER, cleanup);
nstraze3219812003-07-14 17:06:37 +000086
nstraze3219812003-07-14 17:06:37 +000087 TEST_PAUSE;
Garrett Cooper2c282152010-12-16 00:55:50 -080088}
nstraze3219812003-07-14 17:06:37 +000089
Wanlong Gao3dd0c6a2012-12-04 15:16:50 +080090static void cleanup(void)
nstraze3219812003-07-14 17:06:37 +000091{
Garrett Cooper2c282152010-12-16 00:55:50 -080092}
nstraze3219812003-07-14 17:06:37 +000093
Cyril Hrubisc91af2f2012-11-28 18:02:01 +010094static int child_fn(void *unused __attribute__((unused)))
nstraze3219812003-07-14 17:06:37 +000095{
Cyril Hrubisc91af2f2012-11-28 18:02:01 +010096 int i;
97
98 /* give the kernel scheduler chance to run the parent */
99 for (i = 0; i < 100; i++) {
100 sched_yield();
101 usleep(1000);
102 }
103
104 child_exited = 1;
robbiewb8bd30c2003-07-31 20:41:11 +0000105 exit(1);
Cyril Hrubis019ed6c2011-08-26 12:59:32 +0200106}