Split the geometry information from weston_surface out into weston_view
[platform/upstream/weston.git] / tests / weston-test-runner.h
1 /*
2  * Copyright © 2012 Intel Corporation
3  * Copyright © 2013 Sam Spilsbury <smspillaz@gmail.com>
4  *
5  * Permission to use, copy, modify, distribute, and sell this software and
6  * its documentation for any purpose is hereby granted without fee, provided
7  * that the above copyright notice appear in all copies and that both that
8  * copyright notice and this permission notice appear in supporting
9  * documentation, and that the name of the copyright holders not be used in
10  * advertising or publicity pertaining to distribution of the software
11  * without specific, written prior permission.  The copyright holders make
12  * no representations about the suitability of this software for any
13  * purpose.  It is provided "as is" without express or implied warranty.
14  *
15  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
16  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17  * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
18  * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
19  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
20  * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22  */
23
24 #ifndef _WESTON_TEST_RUNNER_H_
25 #define _WESTON_TEST_RUNNER_H_
26
27 #include <stdlib.h>
28
29 #ifdef NDEBUG
30 #error "Tests must not be built with NDEBUG defined, they rely on assert()."
31 #endif
32
33 struct weston_test {
34         const char *name;
35         void (*run)(void *);
36         const void *table_data;
37         size_t element_size;
38         int n_elements;
39         int must_fail;
40 } __attribute__ ((aligned (32)));
41
42 #define TEST_BEGIN(name, arg)                                   \
43         static void name(arg)
44
45 #define TEST_COMMON(func, name, ret, data, size, n_elem)        \
46         static void func(void *);                               \
47                                                                 \
48         const struct weston_test test##name                     \
49                 __attribute__ ((section ("test_section"))) =    \
50         {                                                       \
51                 #name, func, data, size, n_elem, ret            \
52         };
53
54 #define NO_ARG_TEST(name, ret)                                  \
55         TEST_COMMON(wrap##name, name, ret, NULL, 0, 1)          \
56         static void name(void);                                 \
57         static void wrap##name(void *data)                      \
58         {                                                       \
59                 (void) data;                                    \
60                 name();                                         \
61         }                                                       \
62                                                                 \
63         TEST_BEGIN(name, void)
64
65 #define ARG_TEST(name, ret, test_data)                          \
66         TEST_COMMON(name, name, ret, test_data,                 \
67                     sizeof(test_data[0]),                       \
68                     sizeof(test_data) / sizeof (test_data[0]))  \
69         TEST_BEGIN(name, void *data)                            \
70
71 #define TEST(name) NO_ARG_TEST(name, 0)
72 #define FAIL_TEST(name) NO_ARG_TEST(name, 1)
73 #define TEST_P(name, data) ARG_TEST(name, 0, data)
74 #define FAIL_TEST_P(name, data) ARG_TEST(name, 1, data)
75
76 #endif