1*49cdfc7eSAndroid Build Coastguard Worker // SPDX-License-Identifier: GPL-2.0-or-later
2*49cdfc7eSAndroid Build Coastguard Worker /*
3*49cdfc7eSAndroid Build Coastguard Worker * Copyright (c) 2016 Cyril Hrubis <[email protected]>
4*49cdfc7eSAndroid Build Coastguard Worker */
5*49cdfc7eSAndroid Build Coastguard Worker
6*49cdfc7eSAndroid Build Coastguard Worker /*
7*49cdfc7eSAndroid Build Coastguard Worker * Tests tst_run_as_child()
8*49cdfc7eSAndroid Build Coastguard Worker */
9*49cdfc7eSAndroid Build Coastguard Worker
10*49cdfc7eSAndroid Build Coastguard Worker #include "tst_test.h"
11*49cdfc7eSAndroid Build Coastguard Worker
child_fn(unsigned int i)12*49cdfc7eSAndroid Build Coastguard Worker static void child_fn(unsigned int i)
13*49cdfc7eSAndroid Build Coastguard Worker {
14*49cdfc7eSAndroid Build Coastguard Worker switch (i) {
15*49cdfc7eSAndroid Build Coastguard Worker case 0:
16*49cdfc7eSAndroid Build Coastguard Worker tst_res(TPASS, "PASSED message");
17*49cdfc7eSAndroid Build Coastguard Worker break;
18*49cdfc7eSAndroid Build Coastguard Worker case 1:
19*49cdfc7eSAndroid Build Coastguard Worker tst_brk(TBROK, "BROKEN message");
20*49cdfc7eSAndroid Build Coastguard Worker break;
21*49cdfc7eSAndroid Build Coastguard Worker }
22*49cdfc7eSAndroid Build Coastguard Worker }
23*49cdfc7eSAndroid Build Coastguard Worker
setup(void)24*49cdfc7eSAndroid Build Coastguard Worker static void setup(void)
25*49cdfc7eSAndroid Build Coastguard Worker {
26*49cdfc7eSAndroid Build Coastguard Worker tst_res(TINFO, "setup() executed by pid %i", getpid());
27*49cdfc7eSAndroid Build Coastguard Worker }
28*49cdfc7eSAndroid Build Coastguard Worker
cleanup(void)29*49cdfc7eSAndroid Build Coastguard Worker static void cleanup(void)
30*49cdfc7eSAndroid Build Coastguard Worker {
31*49cdfc7eSAndroid Build Coastguard Worker tst_res(TINFO, "cleanup() executed by pid %i", getpid());
32*49cdfc7eSAndroid Build Coastguard Worker }
33*49cdfc7eSAndroid Build Coastguard Worker
do_test(unsigned int i)34*49cdfc7eSAndroid Build Coastguard Worker static void do_test(unsigned int i)
35*49cdfc7eSAndroid Build Coastguard Worker {
36*49cdfc7eSAndroid Build Coastguard Worker if (SAFE_FORK() == 0)
37*49cdfc7eSAndroid Build Coastguard Worker child_fn(i);
38*49cdfc7eSAndroid Build Coastguard Worker }
39*49cdfc7eSAndroid Build Coastguard Worker
40*49cdfc7eSAndroid Build Coastguard Worker static struct tst_test test = {
41*49cdfc7eSAndroid Build Coastguard Worker .tcnt = 2,
42*49cdfc7eSAndroid Build Coastguard Worker .test = do_test,
43*49cdfc7eSAndroid Build Coastguard Worker .setup = setup,
44*49cdfc7eSAndroid Build Coastguard Worker .cleanup = cleanup,
45*49cdfc7eSAndroid Build Coastguard Worker .forks_child = 1,
46*49cdfc7eSAndroid Build Coastguard Worker };
47