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
27 #include <sys/types.h>
33 #include "weston-test-runner.h"
35 extern const struct weston_test __start_test_section, __stop_test_section;
37 static const struct weston_test *
38 find_test(const char *name)
40 const struct weston_test *t;
42 for (t = &__start_test_section; t < &__stop_test_section; t++)
43 if (strcmp(t->name, name) == 0)
50 run_test(const struct weston_test *t, void *data)
59 const struct weston_test *t;
61 fprintf(stderr, "Available test names:\n");
62 for (t = &__start_test_section; t < &__stop_test_section; t++)
63 fprintf(stderr, " %s\n", t->name);
67 exec_and_report_test(const struct weston_test *t, void *test_data, int iteration)
77 run_test(t, test_data); /* never returns */
79 if (waitid(P_ALL, 0, &info, WEXITED)) {
80 fprintf(stderr, "waitid failed: %m\n");
85 fprintf(stderr, "test \"%s/%i\":\t", t->name, iteration);
87 fprintf(stderr, "test \"%s\":\t", t->name);
89 switch (info.si_code) {
91 fprintf(stderr, "exit status %d", info.si_status);
92 if (info.si_status == EXIT_SUCCESS)
97 fprintf(stderr, "signal %d", info.si_status);
98 if (info.si_status != SIGABRT)
106 if (success && !hardfail) {
107 fprintf(stderr, ", pass.\n");
110 fprintf(stderr, ", fail.\n");
115 /* Returns number of tests and number of pass / fail in param args */
117 iterate_test(const struct weston_test *t, int *passed)
120 void *current_test_data = (void *) t->table_data;
121 for (i = 0; i < t->n_elements; ++i, current_test_data += t->element_size)
123 if (exec_and_report_test(t, current_test_data, i))
127 return t->n_elements;
130 int main(int argc, char *argv[])
132 const struct weston_test *t;
137 const char *testname = argv[1];
138 if (strcmp(testname, "--help") == 0 ||
139 strcmp(testname, "-h") == 0) {
140 fprintf(stderr, "Usage: %s [test-name]\n", program_invocation_short_name);
145 t = find_test(argv[1]);
147 fprintf(stderr, "unknown test: \"%s\"\n", argv[1]);
152 int number_passed_in_test = 0;
153 total += iterate_test(t, &number_passed_in_test);
154 pass += number_passed_in_test;
156 for (t = &__start_test_section; t < &__stop_test_section; t++) {
157 int number_passed_in_test = 0;
158 total += iterate_test(t, &number_passed_in_test);
159 pass += number_passed_in_test;
163 fprintf(stderr, "%d tests, %d pass, %d fail\n",
164 total, pass, total - pass);
166 return pass == total ? EXIT_SUCCESS : EXIT_FAILURE;