1 /*
2 * Copyright © 2017 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
25 #include <stdlib.h>
26 #include <signal.h>
27 #include "igt.h"
28
29 /*
30 * The purpose of this test is to test the CI system that we have
31 * for running the tests. The test should generate all possible
32 * exit states for igt tests.
33 *
34 * Possible exit-states of igt tests:
35 * 1. pass - subtest: pass-result
36 * 2. fail - subtest: fail-result
37 * 3. dmesg warn - subtest: dmesg-pass
38 * - subtest: dmesg-warn
39 * The purpose is to check that certain kernel log activity
40 * gets correctly reported in the test result, and that normal
41 * activity doesn't.
42 * 4. crash - subtest: user-crash
43 * 5. piglit timeout - subtest: piglit-timeout
44 * 6. incomplete - subtest: generate-panic
45 * NOTE: inorder for this to generate the incomplete state
46 * the kernel must be configured to reboot on panic.
47 * NOTE: if the tested CI system have features such as
48 * PSTORE and/or kexec/kdump enabled. This test could be
49 * used to make sure that the CI system stores the generated
50 * log/dumps as expected.
51 * 7. incomplete - where user hang is not caught by piglit timeout.
52 * This would be caught by a user-side softdog daemon,
53 * such as owatch by ezbench. However, I don't know
54 * how to trigger this state, so it will not be tested.
55 * 8. incomplete - system requires hard reboot :
56 * This state could be triggered by calling an evil kernel
57 * module that was developed hang the system. Such
58 * a module will not be developed for this purpose,
59 * so this "exit state" will not be tested.
60 *
61 * TODO: If this test was deployed on a CI system that
62 * was able to pick up testing again after reboot,
63 * such as ezbench, a post-analyze test should be added
64 * that collected and analyzed the result of the tests
65 * run before reboot.
66 */
67
68 __attribute__((format(printf, 1, 2)))
kmsg(const char * format,...)69 static void kmsg(const char *format, ...)
70 #define KERN_EMER "<0>"
71 #define KERN_ALERT "<1>"
72 #define KERN_CRIT "<2>"
73 #define KERN_ERR "<3>"
74 #define KERN_WARNING "<4>"
75 #define KERN_NOTICE "<5>"
76 #define KERN_INFO "<6>"
77 #define KERN_DEBUG "<7>"
78 {
79 va_list ap;
80 FILE *file;
81
82 file = fopen("/dev/kmsg", "w");
83 if (file == NULL)
84 return;
85
86 va_start(ap, format);
87 vfprintf(file, format, ap);
88 va_end(ap);
89 fclose(file);
90 }
91
test_result(bool result)92 static void test_result(bool result)
93 {
94 igt_assert_eq(result, true);
95 }
96
test_dmesg(bool pass)97 static void test_dmesg(bool pass)
98 {
99 if (pass)
100 kmsg(KERN_DEBUG "[drm: IGT inserted string.");
101 else
102 kmsg(KERN_WARNING "[drm: IGT inserted string.");
103 }
104
test_user_crash(void)105 static void test_user_crash(void)
106 {
107 raise(SIGSEGV);
108 }
109
test_piglit_timeout(void)110 static void test_piglit_timeout(void)
111 {
112 sleep(605);
113 }
114
test_panic(void)115 static void test_panic(void)
116 {
117 system("echo c > /proc/sysrq-trigger");
118 }
119
120 igt_main
121 {
122
123 igt_fixture {
124 igt_skip_on_f(!getenv("IGT_CI_META_TEST"),
125 "Only for meta-testing of CI systems");
126 }
127
128 igt_subtest("pass-result")
129 test_result(true);
130
131 igt_subtest("warn") {
132 igt_warn("This is a test that should fail with a warning\n");
133
134 test_result(true);
135 }
136
137 igt_subtest("fail-result")
138 test_result(false);
139
140 igt_subtest("dmesg-pass")
141 test_dmesg(true);
142
143 igt_subtest("dmesg-warn")
144 test_dmesg(false);
145
146 igt_subtest("user-crash")
147 test_user_crash();
148
149 igt_subtest("piglit-timeout")
150 test_piglit_timeout();
151
152 igt_subtest("generate-panic")
153 test_panic();
154 }
155
156