lib/igt.cocci: Add stanza for for_each_pipe
[platform/upstream/intel-gpu-tools.git] / tests / igt_simulation.c
1 /*
2  * Copyright © 2014 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 <stdlib.h>
29 #include <sys/wait.h>
30 #include <sys/types.h>
31 #include <assert.h>
32 #include <errno.h>
33
34 #include "drmtest.h"
35 #include "igt_core.h"
36
37 bool simple;
38 bool list_subtests;
39 bool in_fixture;
40 bool in_subtest;
41
42 char test[] = "test";
43 char list[] = "--list-subtests";
44 char *argv_list[] = { test, list };
45 char *argv_run[] = { test };
46
47 static int do_fork(void)
48 {
49         int pid, status;
50
51         switch (pid = fork()) {
52         case -1:
53                 assert(0);
54         case 0:
55                 if (simple) {
56                         igt_simple_init();
57
58                         igt_skip_on_simulation();
59
60                         exit(0);
61                 } else {
62                         if (list_subtests)
63                                 igt_subtest_init(2, argv_list);
64                         else
65                                 igt_subtest_init(1, argv_run);
66
67                         if (in_fixture) {
68                                 igt_fixture
69                                         igt_skip_on_simulation();
70                         } if (in_subtest) {
71                                 igt_subtest("sim")
72                                         igt_skip_on_simulation();
73                         } else
74                                 igt_skip_on_simulation();
75
76                         if (!in_subtest)
77                                 igt_subtest("foo")
78                                         ;
79
80                         igt_exit();
81                 }
82         default:
83                 while (waitpid(pid, &status, 0) == -1 &&
84                        errno == EINTR)
85                         ;
86
87                 assert(WIFEXITED(status));
88
89                 return WEXITSTATUS(status);
90         }
91 }
92
93 int main(int argc, char **argv)
94 {
95         /* simple tests */
96         simple = true;
97         assert(setenv("INTEL_SIMULATION", "1", 1) == 0);
98         assert(do_fork() == IGT_EXIT_SKIP);
99
100         assert(setenv("INTEL_SIMULATION", "0", 1) == 0);
101         assert(do_fork() == IGT_EXIT_SUCCESS);
102
103         /* subtests, list mode */
104         simple = false;
105         list_subtests = true;
106
107         in_fixture = false;
108         assert(setenv("INTEL_SIMULATION", "1", 1) == 0);
109         assert(do_fork() == IGT_EXIT_SUCCESS);
110
111         assert(setenv("INTEL_SIMULATION", "0", 1) == 0);
112         assert(do_fork() == IGT_EXIT_SUCCESS);
113
114         in_fixture = true;
115         assert(setenv("INTEL_SIMULATION", "1", 1) == 0);
116         assert(do_fork() == IGT_EXIT_SUCCESS);
117
118         assert(setenv("INTEL_SIMULATION", "0", 1) == 0);
119         assert(do_fork() == IGT_EXIT_SUCCESS);
120
121         in_fixture = false;
122         in_subtest = true;
123         assert(setenv("INTEL_SIMULATION", "1", 1) == 0);
124         assert(do_fork() == IGT_EXIT_SUCCESS);
125
126         assert(setenv("INTEL_SIMULATION", "0", 1) == 0);
127         assert(do_fork() == IGT_EXIT_SUCCESS);
128
129         /* subtest, run mode */
130         simple = false;
131         list_subtests = false;
132
133         in_fixture = false;
134         assert(setenv("INTEL_SIMULATION", "1", 1) == 0);
135         assert(do_fork() == IGT_EXIT_SKIP);
136
137         assert(setenv("INTEL_SIMULATION", "0", 1) == 0);
138         assert(do_fork() == IGT_EXIT_SUCCESS);
139
140         in_fixture = true;
141         assert(setenv("INTEL_SIMULATION", "1", 1) == 0);
142         assert(do_fork() == IGT_EXIT_SKIP);
143
144         assert(setenv("INTEL_SIMULATION", "0", 1) == 0);
145         assert(do_fork() == IGT_EXIT_SUCCESS);
146
147         in_fixture = false;
148         in_subtest = true;
149         assert(setenv("INTEL_SIMULATION", "1", 1) == 0);
150         assert(do_fork() == IGT_EXIT_SKIP);
151
152         assert(setenv("INTEL_SIMULATION", "0", 1) == 0);
153         assert(do_fork() == IGT_EXIT_SUCCESS);
154
155         return 0;
156 }