1*d83cc019SAndroid Build Coastguard Worker /*
2*d83cc019SAndroid Build Coastguard Worker * Copyright © 2017 Intel Corporation
3*d83cc019SAndroid Build Coastguard Worker *
4*d83cc019SAndroid Build Coastguard Worker * Permission is hereby granted, free of charge, to any person obtaining a
5*d83cc019SAndroid Build Coastguard Worker * copy of this software and associated documentation files (the "Software"),
6*d83cc019SAndroid Build Coastguard Worker * to deal in the Software without restriction, including without limitation
7*d83cc019SAndroid Build Coastguard Worker * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8*d83cc019SAndroid Build Coastguard Worker * and/or sell copies of the Software, and to permit persons to whom the
9*d83cc019SAndroid Build Coastguard Worker * Software is furnished to do so, subject to the following conditions:
10*d83cc019SAndroid Build Coastguard Worker *
11*d83cc019SAndroid Build Coastguard Worker * The above copyright notice and this permission notice (including the next
12*d83cc019SAndroid Build Coastguard Worker * paragraph) shall be included in all copies or substantial portions of the
13*d83cc019SAndroid Build Coastguard Worker * Software.
14*d83cc019SAndroid Build Coastguard Worker *
15*d83cc019SAndroid Build Coastguard Worker * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16*d83cc019SAndroid Build Coastguard Worker * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17*d83cc019SAndroid Build Coastguard Worker * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18*d83cc019SAndroid Build Coastguard Worker * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19*d83cc019SAndroid Build Coastguard Worker * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20*d83cc019SAndroid Build Coastguard Worker * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21*d83cc019SAndroid Build Coastguard Worker * IN THE SOFTWARE.
22*d83cc019SAndroid Build Coastguard Worker *
23*d83cc019SAndroid Build Coastguard Worker */
24*d83cc019SAndroid Build Coastguard Worker
25*d83cc019SAndroid Build Coastguard Worker #include <stdlib.h>
26*d83cc019SAndroid Build Coastguard Worker #include <signal.h>
27*d83cc019SAndroid Build Coastguard Worker #include "igt.h"
28*d83cc019SAndroid Build Coastguard Worker
29*d83cc019SAndroid Build Coastguard Worker /*
30*d83cc019SAndroid Build Coastguard Worker * The purpose of this test is to test the CI system that we have
31*d83cc019SAndroid Build Coastguard Worker * for running the tests. The test should generate all possible
32*d83cc019SAndroid Build Coastguard Worker * exit states for igt tests.
33*d83cc019SAndroid Build Coastguard Worker *
34*d83cc019SAndroid Build Coastguard Worker * Possible exit-states of igt tests:
35*d83cc019SAndroid Build Coastguard Worker * 1. pass - subtest: pass-result
36*d83cc019SAndroid Build Coastguard Worker * 2. fail - subtest: fail-result
37*d83cc019SAndroid Build Coastguard Worker * 3. dmesg warn - subtest: dmesg-pass
38*d83cc019SAndroid Build Coastguard Worker * - subtest: dmesg-warn
39*d83cc019SAndroid Build Coastguard Worker * The purpose is to check that certain kernel log activity
40*d83cc019SAndroid Build Coastguard Worker * gets correctly reported in the test result, and that normal
41*d83cc019SAndroid Build Coastguard Worker * activity doesn't.
42*d83cc019SAndroid Build Coastguard Worker * 4. crash - subtest: user-crash
43*d83cc019SAndroid Build Coastguard Worker * 5. piglit timeout - subtest: piglit-timeout
44*d83cc019SAndroid Build Coastguard Worker * 6. incomplete - subtest: generate-panic
45*d83cc019SAndroid Build Coastguard Worker * NOTE: inorder for this to generate the incomplete state
46*d83cc019SAndroid Build Coastguard Worker * the kernel must be configured to reboot on panic.
47*d83cc019SAndroid Build Coastguard Worker * NOTE: if the tested CI system have features such as
48*d83cc019SAndroid Build Coastguard Worker * PSTORE and/or kexec/kdump enabled. This test could be
49*d83cc019SAndroid Build Coastguard Worker * used to make sure that the CI system stores the generated
50*d83cc019SAndroid Build Coastguard Worker * log/dumps as expected.
51*d83cc019SAndroid Build Coastguard Worker * 7. incomplete - where user hang is not caught by piglit timeout.
52*d83cc019SAndroid Build Coastguard Worker * This would be caught by a user-side softdog daemon,
53*d83cc019SAndroid Build Coastguard Worker * such as owatch by ezbench. However, I don't know
54*d83cc019SAndroid Build Coastguard Worker * how to trigger this state, so it will not be tested.
55*d83cc019SAndroid Build Coastguard Worker * 8. incomplete - system requires hard reboot :
56*d83cc019SAndroid Build Coastguard Worker * This state could be triggered by calling an evil kernel
57*d83cc019SAndroid Build Coastguard Worker * module that was developed hang the system. Such
58*d83cc019SAndroid Build Coastguard Worker * a module will not be developed for this purpose,
59*d83cc019SAndroid Build Coastguard Worker * so this "exit state" will not be tested.
60*d83cc019SAndroid Build Coastguard Worker *
61*d83cc019SAndroid Build Coastguard Worker * TODO: If this test was deployed on a CI system that
62*d83cc019SAndroid Build Coastguard Worker * was able to pick up testing again after reboot,
63*d83cc019SAndroid Build Coastguard Worker * such as ezbench, a post-analyze test should be added
64*d83cc019SAndroid Build Coastguard Worker * that collected and analyzed the result of the tests
65*d83cc019SAndroid Build Coastguard Worker * run before reboot.
66*d83cc019SAndroid Build Coastguard Worker */
67*d83cc019SAndroid Build Coastguard Worker
68*d83cc019SAndroid Build Coastguard Worker __attribute__((format(printf, 1, 2)))
kmsg(const char * format,...)69*d83cc019SAndroid Build Coastguard Worker static void kmsg(const char *format, ...)
70*d83cc019SAndroid Build Coastguard Worker #define KERN_EMER "<0>"
71*d83cc019SAndroid Build Coastguard Worker #define KERN_ALERT "<1>"
72*d83cc019SAndroid Build Coastguard Worker #define KERN_CRIT "<2>"
73*d83cc019SAndroid Build Coastguard Worker #define KERN_ERR "<3>"
74*d83cc019SAndroid Build Coastguard Worker #define KERN_WARNING "<4>"
75*d83cc019SAndroid Build Coastguard Worker #define KERN_NOTICE "<5>"
76*d83cc019SAndroid Build Coastguard Worker #define KERN_INFO "<6>"
77*d83cc019SAndroid Build Coastguard Worker #define KERN_DEBUG "<7>"
78*d83cc019SAndroid Build Coastguard Worker {
79*d83cc019SAndroid Build Coastguard Worker va_list ap;
80*d83cc019SAndroid Build Coastguard Worker FILE *file;
81*d83cc019SAndroid Build Coastguard Worker
82*d83cc019SAndroid Build Coastguard Worker file = fopen("/dev/kmsg", "w");
83*d83cc019SAndroid Build Coastguard Worker if (file == NULL)
84*d83cc019SAndroid Build Coastguard Worker return;
85*d83cc019SAndroid Build Coastguard Worker
86*d83cc019SAndroid Build Coastguard Worker va_start(ap, format);
87*d83cc019SAndroid Build Coastguard Worker vfprintf(file, format, ap);
88*d83cc019SAndroid Build Coastguard Worker va_end(ap);
89*d83cc019SAndroid Build Coastguard Worker fclose(file);
90*d83cc019SAndroid Build Coastguard Worker }
91*d83cc019SAndroid Build Coastguard Worker
test_result(bool result)92*d83cc019SAndroid Build Coastguard Worker static void test_result(bool result)
93*d83cc019SAndroid Build Coastguard Worker {
94*d83cc019SAndroid Build Coastguard Worker igt_assert_eq(result, true);
95*d83cc019SAndroid Build Coastguard Worker }
96*d83cc019SAndroid Build Coastguard Worker
test_dmesg(bool pass)97*d83cc019SAndroid Build Coastguard Worker static void test_dmesg(bool pass)
98*d83cc019SAndroid Build Coastguard Worker {
99*d83cc019SAndroid Build Coastguard Worker if (pass)
100*d83cc019SAndroid Build Coastguard Worker kmsg(KERN_DEBUG "[drm: IGT inserted string.");
101*d83cc019SAndroid Build Coastguard Worker else
102*d83cc019SAndroid Build Coastguard Worker kmsg(KERN_WARNING "[drm: IGT inserted string.");
103*d83cc019SAndroid Build Coastguard Worker }
104*d83cc019SAndroid Build Coastguard Worker
test_user_crash(void)105*d83cc019SAndroid Build Coastguard Worker static void test_user_crash(void)
106*d83cc019SAndroid Build Coastguard Worker {
107*d83cc019SAndroid Build Coastguard Worker raise(SIGSEGV);
108*d83cc019SAndroid Build Coastguard Worker }
109*d83cc019SAndroid Build Coastguard Worker
test_piglit_timeout(void)110*d83cc019SAndroid Build Coastguard Worker static void test_piglit_timeout(void)
111*d83cc019SAndroid Build Coastguard Worker {
112*d83cc019SAndroid Build Coastguard Worker sleep(605);
113*d83cc019SAndroid Build Coastguard Worker }
114*d83cc019SAndroid Build Coastguard Worker
test_panic(void)115*d83cc019SAndroid Build Coastguard Worker static void test_panic(void)
116*d83cc019SAndroid Build Coastguard Worker {
117*d83cc019SAndroid Build Coastguard Worker system("echo c > /proc/sysrq-trigger");
118*d83cc019SAndroid Build Coastguard Worker }
119*d83cc019SAndroid Build Coastguard Worker
120*d83cc019SAndroid Build Coastguard Worker igt_main
121*d83cc019SAndroid Build Coastguard Worker {
122*d83cc019SAndroid Build Coastguard Worker
123*d83cc019SAndroid Build Coastguard Worker igt_fixture {
124*d83cc019SAndroid Build Coastguard Worker igt_skip_on_f(!getenv("IGT_CI_META_TEST"),
125*d83cc019SAndroid Build Coastguard Worker "Only for meta-testing of CI systems");
126*d83cc019SAndroid Build Coastguard Worker }
127*d83cc019SAndroid Build Coastguard Worker
128*d83cc019SAndroid Build Coastguard Worker igt_subtest("pass-result")
129*d83cc019SAndroid Build Coastguard Worker test_result(true);
130*d83cc019SAndroid Build Coastguard Worker
131*d83cc019SAndroid Build Coastguard Worker igt_subtest("warn") {
132*d83cc019SAndroid Build Coastguard Worker igt_warn("This is a test that should fail with a warning\n");
133*d83cc019SAndroid Build Coastguard Worker
134*d83cc019SAndroid Build Coastguard Worker test_result(true);
135*d83cc019SAndroid Build Coastguard Worker }
136*d83cc019SAndroid Build Coastguard Worker
137*d83cc019SAndroid Build Coastguard Worker igt_subtest("fail-result")
138*d83cc019SAndroid Build Coastguard Worker test_result(false);
139*d83cc019SAndroid Build Coastguard Worker
140*d83cc019SAndroid Build Coastguard Worker igt_subtest("dmesg-pass")
141*d83cc019SAndroid Build Coastguard Worker test_dmesg(true);
142*d83cc019SAndroid Build Coastguard Worker
143*d83cc019SAndroid Build Coastguard Worker igt_subtest("dmesg-warn")
144*d83cc019SAndroid Build Coastguard Worker test_dmesg(false);
145*d83cc019SAndroid Build Coastguard Worker
146*d83cc019SAndroid Build Coastguard Worker igt_subtest("user-crash")
147*d83cc019SAndroid Build Coastguard Worker test_user_crash();
148*d83cc019SAndroid Build Coastguard Worker
149*d83cc019SAndroid Build Coastguard Worker igt_subtest("piglit-timeout")
150*d83cc019SAndroid Build Coastguard Worker test_piglit_timeout();
151*d83cc019SAndroid Build Coastguard Worker
152*d83cc019SAndroid Build Coastguard Worker igt_subtest("generate-panic")
153*d83cc019SAndroid Build Coastguard Worker test_panic();
154*d83cc019SAndroid Build Coastguard Worker }
155*d83cc019SAndroid Build Coastguard Worker
156