1 /*
2 * Copyright © 2015 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
24 #include <errno.h>
25 #include <sys/wait.h>
26
27 #include "igt_core.h"
28 #include "drmtest.h"
29
30 #include "igt_tests_common.h"
31
invalid_subtest_name(void)32 static void invalid_subtest_name(void)
33 {
34 char prog[] = "igt_no_exit";
35 char *fake_argv[] = {prog};
36 int fake_argc = ARRAY_SIZE(fake_argv);
37
38 igt_subtest_init(fake_argc, fake_argv);
39
40 igt_subtest("# invalid name !") {
41 igt_info("Invalid subtest name test\n");
42 }
43
44 igt_exit();
45 }
46
nonexisting_subtest(void)47 static void nonexisting_subtest(void)
48 {
49 char prog[] = "igt_no_exit";
50 char arg1[] = "--run-subtest";
51 char arg2[] = "invalid-subtest";
52 char *fake_argv[] = {prog, arg1, arg2};
53 int fake_argc = ARRAY_SIZE(fake_argv);
54
55 igt_subtest_init(fake_argc, fake_argv);
56
57 igt_subtest("some-subtest")
58 ;
59
60 igt_exit();
61 }
62
do_fork(void (* test_to_run)(void))63 static int do_fork(void (*test_to_run)(void))
64 {
65 int pid, status;
66
67 switch (pid = fork()) {
68 case -1:
69 internal_assert(0);
70 case 0:
71 test_to_run();
72 default:
73 while (waitpid(pid, &status, 0) == -1 &&
74 errno == EINTR)
75 ;
76
77 return status;
78 }
79 }
80
main(int argc,char ** argv)81 int main(int argc, char **argv)
82 {
83 int ret;
84
85 ret = do_fork(invalid_subtest_name);
86 internal_assert_wsignaled(ret, SIGABRT);
87
88 ret = do_fork(nonexisting_subtest);
89 internal_assert_wexited(ret, IGT_EXIT_INVALID);
90
91 return 0;
92 }
93