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