2 * Copyright © 2012 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial
14 * portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
37 #include "weston-test-runner.h"
41 char __attribute__((weak)) *server_parameters="";
43 extern const struct weston_test __start_test_section, __stop_test_section;
45 static const char *test_name_;
53 static const struct weston_test *
54 find_test(const char *name)
56 const struct weston_test *t;
58 for (t = &__start_test_section; t < &__stop_test_section; t++)
59 if (strcmp(t->name, name) == 0)
66 run_test(const struct weston_test *t, void *data, int iteration)
71 snprintf(str, sizeof(str), "%s[%d]", t->name, iteration);
84 const struct weston_test *t;
86 fprintf(stderr, "Available test names:\n");
87 for (t = &__start_test_section; t < &__stop_test_section; t++)
88 fprintf(stderr, " %s\n", t->name);
92 exec_and_report_test(const struct weston_test *t, void *test_data, int iteration)
103 run_test(t, test_data, iteration); /* never returns */
105 if (waitid(P_ALL, 0, &info, WEXITED)) {
106 fprintf(stderr, "waitid failed: %m\n");
111 fprintf(stderr, "test \"%s/%i\":\t", t->name, iteration);
113 fprintf(stderr, "test \"%s\":\t", t->name);
115 switch (info.si_code) {
117 fprintf(stderr, "exit status %d", info.si_status);
118 if (info.si_status == EXIT_SUCCESS)
120 else if (info.si_status == SKIP)
125 fprintf(stderr, "signal %d", info.si_status);
126 if (info.si_status != SIGABRT)
134 if (success && !hardfail) {
135 fprintf(stderr, ", pass.\n");
138 fprintf(stderr, ", skip.\n");
141 fprintf(stderr, ", fail.\n");
146 /* Returns number of tests and number of pass / fail in param args */
148 iterate_test(const struct weston_test *t, int *passed, int *skipped)
151 void *current_test_data = (void *) t->table_data;
152 for (i = 0; i < t->n_elements; ++i, current_test_data += t->element_size)
154 ret = exec_and_report_test(t, current_test_data, i);
161 return t->n_elements;
164 int main(int argc, char *argv[])
166 const struct weston_test *t;
172 const char *testname = argv[1];
173 if (strcmp(testname, "--help") == 0 ||
174 strcmp(testname, "-h") == 0) {
175 fprintf(stderr, "Usage: %s [test-name]\n", program_invocation_short_name);
180 if (strcmp(testname, "--params") == 0 ||
181 strcmp(testname, "-p") == 0) {
182 printf("%s", server_parameters);
186 t = find_test(argv[1]);
188 fprintf(stderr, "unknown test: \"%s\"\n", argv[1]);
193 int number_passed_in_test = 0, number_skipped_in_test = 0;
194 total += iterate_test(t, &number_passed_in_test, &number_skipped_in_test);
195 pass += number_passed_in_test;
196 skip += number_skipped_in_test;
198 for (t = &__start_test_section; t < &__stop_test_section; t++) {
199 int number_passed_in_test = 0, number_skipped_in_test = 0;
200 total += iterate_test(t, &number_passed_in_test, &number_skipped_in_test);
201 pass += number_passed_in_test;
202 skip += number_skipped_in_test;
206 fprintf(stderr, "%d tests, %d pass, %d skip, %d fail\n",
207 total, pass, skip, total - pass - skip);
211 else if (pass + skip == total)