1 /*
2  * Copyright © 2013 Intel Corporation
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21  * IN THE SOFTWARE.
22  *
23  * Authors:
24  *    Daniel Vetter <daniel.vetter@ffwll.ch>
25  *
26  */
27 
28 #include <sys/wait.h>
29 
30 #include "drmtest.h"
31 
32 #include "igt_tests_common.h"
33 
no_exit_list_only(void)34 static void no_exit_list_only(void)
35 {
36 	char prog[] = "igt_list_only";
37 	char arg[] = "--list-subtests";
38 	char *fake_argv[] = {prog, arg};
39 	int fake_argc = ARRAY_SIZE(fake_argv);
40 
41 	igt_subtest_init(fake_argc, fake_argv);
42 
43 	igt_subtest("A")
44 		;
45 }
46 
no_exit(void)47 static void no_exit(void)
48 {
49 	char prog[] = "igt_no_exit";
50 	char *fake_argv[] = {prog};
51 	int fake_argc = ARRAY_SIZE(fake_argv);
52 
53 	igt_subtest_init(fake_argc, fake_argv);
54 
55 	igt_subtest("A")
56 		;
57 }
58 
do_fork(void (* test_to_run)(void))59 static int do_fork(void (*test_to_run)(void))
60 {
61 	int pid, status;
62 
63 	switch (pid = fork()) {
64 	case -1:
65 		internal_assert(0);
66 	case 0:
67 		test_to_run();
68 	default:
69 		while (waitpid(pid, &status, 0) == -1 &&
70 		       errno == EINTR)
71 			;
72 
73 		return status;
74 	}
75 }
76 
main(int argc,char ** argv)77 int main(int argc, char **argv)
78 {
79 	int ret;
80 
81 	ret = do_fork(no_exit);
82 	internal_assert_wsignaled(ret, SIGABRT);
83 
84 	ret = do_fork(no_exit_list_only);
85 	internal_assert_wsignaled(ret, SIGABRT);
86 
87 	return 0;
88 }
89