blob: 7cc1cbe5116dc6fdafa0bd61032496752e1aa823 [file] [log] [blame]
U. Artie Eoff1ba9b382012-12-07 13:50:32 -08001/*
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
Peter Huttererd8ca8902013-09-11 16:08:04 +100023#include "config.h"
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080024#include <unistd.h>
25#include <stdio.h>
26#include <stdlib.h>
27#include <sys/types.h>
28#include <sys/wait.h>
29#include <string.h>
30#include <assert.h>
31#include <errno.h>
Pekka Paalanen585c27c2012-12-18 17:30:16 +020032#include <signal.h>
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080033#include "weston-test-runner.h"
34
35extern const struct weston_test __start_test_section, __stop_test_section;
36
37static const struct weston_test *
38find_test(const char *name)
39{
40 const struct weston_test *t;
41
42 for (t = &__start_test_section; t < &__stop_test_section; t++)
43 if (strcmp(t->name, name) == 0)
44 return t;
45
46 return NULL;
47}
48
49static void
50run_test(const struct weston_test *t)
51{
52 t->run();
53 exit(EXIT_SUCCESS);
54}
55
56int main(int argc, char *argv[])
57{
58 const struct weston_test *t;
59 pid_t pid;
60 int total, pass;
61 siginfo_t info;
62
63 if (argc == 2) {
64 t = find_test(argv[1]);
65 if (t == NULL) {
66 fprintf(stderr, "unknown test: \"%s\"\n", argv[1]);
67 exit(EXIT_FAILURE);
68 }
69
70 run_test(t);
71 }
72
73 pass = 0;
74 for (t = &__start_test_section; t < &__stop_test_section; t++) {
75 int success = 0;
Pekka Paalanen585c27c2012-12-18 17:30:16 +020076 int hardfail = 0;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080077
78 pid = fork();
79 assert(pid >= 0);
80
81 if (pid == 0)
82 run_test(t); /* never returns */
83
84 if (waitid(P_ALL, 0, &info, WEXITED)) {
85 fprintf(stderr, "waitid failed: %m\n");
86 abort();
87 }
88
89 fprintf(stderr, "test \"%s\":\t", t->name);
90 switch (info.si_code) {
91 case CLD_EXITED:
92 fprintf(stderr, "exit status %d", info.si_status);
93 if (info.si_status == EXIT_SUCCESS)
94 success = 1;
95 break;
96 case CLD_KILLED:
97 case CLD_DUMPED:
98 fprintf(stderr, "signal %d", info.si_status);
Pekka Paalanen585c27c2012-12-18 17:30:16 +020099 if (info.si_status != SIGABRT)
100 hardfail = 1;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800101 break;
102 }
103
104 if (t->must_fail)
105 success = !success;
106
Pekka Paalanen585c27c2012-12-18 17:30:16 +0200107 if (success && !hardfail) {
U. Artie Eoff1ba9b382012-12-07 13:50:32 -0800108 pass++;
109 fprintf(stderr, ", pass.\n");
110 } else
111 fprintf(stderr, ", fail.\n");
112 }
113
114 total = &__stop_test_section - &__start_test_section;
115 fprintf(stderr, "%d tests, %d pass, %d fail\n",
116 total, pass, total - pass);
117
118 return pass == total ? EXIT_SUCCESS : EXIT_FAILURE;
119}