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 * Authors:
24 * Derek Morton <[email protected]>
25 *
26 */
27
28 /*
29 * Testcase: Test the framework catches a segfault and returns an error.
30 *
31 * 1. Test a crashing simple test is reported.
32 * 2. Test a crashing subtest is reported.
33 * 3. Test a crashing subtest following a passing subtest is reported.
34 * 4. Test a crashing subtest preceeding a passing subtest is reported.
35 */
36
37 #include <signal.h>
38 #include <stdlib.h>
39 #include <sys/wait.h>
40 #include <sys/types.h>
41 #include <errno.h>
42
43 #include "drmtest.h"
44 #include "igt_core.h"
45
46 #include "igt_tests_common.h"
47
48 bool simple;
49 bool runa;
50 bool runc;
51 char test[] = "test";
52 char *argv_run[] = { test };
53
crashme(void)54 static void crashme(void)
55 {
56 raise(SIGSEGV);
57 }
58
do_fork(void)59 static int do_fork(void)
60 {
61 int pid, status;
62 int argc;
63
64 switch (pid = fork()) {
65 case -1:
66 internal_assert(0);
67 case 0:
68 argc = ARRAY_SIZE(argv_run);
69 if (simple) {
70 igt_simple_init(argc, argv_run);
71 crashme();
72
73 igt_exit();
74 } else {
75 igt_subtest_init(argc, argv_run);
76
77 if(runa)
78 igt_subtest("A")
79 ;
80
81 igt_subtest("B")
82 crashme();
83
84 if(runc)
85 igt_subtest("C")
86 ;
87
88 igt_exit();
89 }
90 default:
91 while (waitpid(pid, &status, 0) == -1 &&
92 errno == EINTR)
93 ;
94
95 return status;
96 }
97 }
98
main(int argc,char ** argv)99 int main(int argc, char **argv)
100 {
101 /* Test Crash in simple test is reported */
102 simple = true;
103 runa=false;
104 runc=false;
105 igt_info("Simple test.\n");
106 fflush(stdout);
107 internal_assert_wsignaled(do_fork(), SIGSEGV);
108
109 /* Test crash in a single subtest is reported */
110 simple = false;
111 igt_info("Single subtest.\n");
112 fflush(stdout);
113 internal_assert_wexited(do_fork(), SIGSEGV + 128);
114
115 /* Test crash in a subtest following a pass is reported */
116 simple = false;
117 runa=true;
118 igt_info("Passing then crashing subtest.\n");
119 fflush(stdout);
120 internal_assert_wexited(do_fork(), SIGSEGV + 128);
121
122 /* Test crash in a subtest preceeding a pass is reported */
123 simple = false;
124 runa=false;
125 runc=true;
126 igt_info("Crashing then passing subtest.\n");
127 fflush(stdout);
128 internal_assert_wexited(do_fork(), SIGSEGV + 128);
129
130 return 0;
131 }
132