2 * Copyright © 2012 Intel Corporation
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that copyright
7 * notice and this permission notice appear in supporting documentation, and
8 * that the name of the copyright holders not be used in advertising or
9 * publicity pertaining to distribution of the software without specific,
10 * written prior permission. The copyright holders make no representations
11 * about the suitability of this software for any purpose. It is provided "as
12 * is" without express or implied warranty.
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
34 #include "weston-test-runner.h"
38 char __attribute__((weak)) *server_parameters="";
40 extern const struct weston_test __start_test_section, __stop_test_section;
42 static const struct weston_test *
43 find_test(const char *name)
45 const struct weston_test *t;
47 for (t = &__start_test_section; t < &__stop_test_section; t++)
48 if (strcmp(t->name, name) == 0)
55 run_test(const struct weston_test *t, void *data)
64 const struct weston_test *t;
66 fprintf(stderr, "Available test names:\n");
67 for (t = &__start_test_section; t < &__stop_test_section; t++)
68 fprintf(stderr, " %s\n", t->name);
72 exec_and_report_test(const struct weston_test *t, void *test_data, int iteration)
83 run_test(t, test_data); /* never returns */
85 if (waitid(P_ALL, 0, &info, WEXITED)) {
86 fprintf(stderr, "waitid failed: %m\n");
91 fprintf(stderr, "test \"%s/%i\":\t", t->name, iteration);
93 fprintf(stderr, "test \"%s\":\t", t->name);
95 switch (info.si_code) {
97 fprintf(stderr, "exit status %d", info.si_status);
98 if (info.si_status == EXIT_SUCCESS)
100 else if (info.si_status == SKIP)
105 fprintf(stderr, "signal %d", info.si_status);
106 if (info.si_status != SIGABRT)
114 if (success && !hardfail) {
115 fprintf(stderr, ", pass.\n");
118 fprintf(stderr, ", skip.\n");
121 fprintf(stderr, ", fail.\n");
126 /* Returns number of tests and number of pass / fail in param args */
128 iterate_test(const struct weston_test *t, int *passed, int *skipped)
131 void *current_test_data = (void *) t->table_data;
132 for (i = 0; i < t->n_elements; ++i, current_test_data += t->element_size)
134 ret = exec_and_report_test(t, current_test_data, i);
141 return t->n_elements;
144 int main(int argc, char *argv[])
146 const struct weston_test *t;
152 const char *testname = argv[1];
153 if (strcmp(testname, "--help") == 0 ||
154 strcmp(testname, "-h") == 0) {
155 fprintf(stderr, "Usage: %s [test-name]\n", program_invocation_short_name);
160 if (strcmp(testname, "--params") == 0 ||
161 strcmp(testname, "-p") == 0) {
162 printf("%s", server_parameters);
166 t = find_test(argv[1]);
168 fprintf(stderr, "unknown test: \"%s\"\n", argv[1]);
173 int number_passed_in_test = 0, number_skipped_in_test = 0;
174 total += iterate_test(t, &number_passed_in_test, &number_skipped_in_test);
175 pass += number_passed_in_test;
176 skip += number_skipped_in_test;
178 for (t = &__start_test_section; t < &__stop_test_section; t++) {
179 int number_passed_in_test = 0, number_skipped_in_test = 0;
180 total += iterate_test(t, &number_passed_in_test, &number_skipped_in_test);
181 pass += number_passed_in_test;
182 skip += number_skipped_in_test;
186 fprintf(stderr, "%d tests, %d pass, %d skip, %d fail\n",
187 total, pass, skip, total - pass - skip);
191 else if (pass + skip == total)