tests: Fix leftover wl_client_add_versioned_object()
[platform/upstream/weston.git] / tests / weston-test-runner.c
1 /*
2  * Copyright © 2012 Intel Corporation
3  *
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.
13  *
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
20  * OF THIS SOFTWARE.
21  */
22
23 #include <unistd.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <sys/types.h>
27 #include <sys/wait.h>
28 #include <string.h>
29 #include <assert.h>
30 #include <errno.h>
31 #include <signal.h>
32 #include "weston-test-runner.h"
33
34 extern const struct weston_test __start_test_section, __stop_test_section;
35
36 static const struct weston_test *
37 find_test(const char *name)
38 {
39         const struct weston_test *t;
40
41         for (t = &__start_test_section; t < &__stop_test_section; t++)
42                 if (strcmp(t->name, name) == 0)
43                         return t;
44
45         return NULL;
46 }
47
48 static void
49 run_test(const struct weston_test *t)
50 {
51         t->run();
52         exit(EXIT_SUCCESS);
53 }
54
55 int main(int argc, char *argv[])
56 {
57         const struct weston_test *t;
58         pid_t pid;
59         int total, pass;
60         siginfo_t info;
61
62         if (argc == 2) {
63                 t = find_test(argv[1]);
64                 if (t == NULL) {
65                         fprintf(stderr, "unknown test: \"%s\"\n", argv[1]);
66                         exit(EXIT_FAILURE);
67                 }
68
69                 run_test(t);
70         }
71
72         pass = 0;
73         for (t = &__start_test_section; t < &__stop_test_section; t++) {
74                 int success = 0;
75                 int hardfail = 0;
76
77                 pid = fork();
78                 assert(pid >= 0);
79
80                 if (pid == 0)
81                         run_test(t); /* never returns */
82
83                 if (waitid(P_ALL, 0, &info, WEXITED)) {
84                         fprintf(stderr, "waitid failed: %m\n");
85                         abort();
86                 }
87
88                 fprintf(stderr, "test \"%s\":\t", t->name);
89                 switch (info.si_code) {
90                 case CLD_EXITED:
91                         fprintf(stderr, "exit status %d", info.si_status);
92                         if (info.si_status == EXIT_SUCCESS)
93                                 success = 1;
94                         break;
95                 case CLD_KILLED:
96                 case CLD_DUMPED:
97                         fprintf(stderr, "signal %d", info.si_status);
98                         if (info.si_status != SIGABRT)
99                                 hardfail = 1;
100                         break;
101                 }
102
103                 if (t->must_fail)
104                         success = !success;
105
106                 if (success && !hardfail) {
107                         pass++;
108                         fprintf(stderr, ", pass.\n");
109                 } else
110                         fprintf(stderr, ", fail.\n");
111         }
112
113         total = &__stop_test_section - &__start_test_section;
114         fprintf(stderr, "%d tests, %d pass, %d fail\n",
115                 total, pass, total - pass);
116
117         return pass == total ? EXIT_SUCCESS : EXIT_FAILURE;
118 }