tests: add test_seat_release() for symmetry
[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 is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sublicense, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice (including the
14  * next paragraph) shall be included in all copies or substantial
15  * portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20  * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
21  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
22  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24  * SOFTWARE.
25  */
26
27 #ifndef _WESTON_TEST_RUNNER_H_
28 #define _WESTON_TEST_RUNNER_H_
29
30 #include "config.h"
31
32 #include <stdlib.h>
33
34 #include "shared/helpers.h"
35
36 #ifdef NDEBUG
37 #error "Tests must not be built with NDEBUG defined, they rely on assert()."
38 #endif
39
40 struct weston_test {
41         const char *name;
42         void (*run)(void *);
43         const void *table_data;
44         size_t element_size;
45         int n_elements;
46         int must_fail;
47 } __attribute__ ((aligned (32)));
48
49 #define TEST_BEGIN(name, arg)                                           \
50         static void name(arg)
51
52 #define TEST_COMMON(func, name, ret, data, size, n_elem)                \
53         static void func(void *);                                       \
54                                                                         \
55         const struct weston_test test##name                             \
56                 __attribute__ ((used, section ("test_section"))) =      \
57         {                                                               \
58                 #name, func, data, size, n_elem, ret                    \
59         };
60
61 #define NO_ARG_TEST(name, ret)                                          \
62         TEST_COMMON(wrap##name, name, ret, NULL, 0, 1)                  \
63         static void name(void);                                         \
64         static void wrap##name(void *data)                              \
65         {                                                               \
66                 (void) data;                                            \
67                 name();                                                 \
68         }                                                               \
69                                                                         \
70         TEST_BEGIN(name, void)
71
72 #define ARG_TEST(name, ret, test_data)                                  \
73         TEST_COMMON(name, name, ret, test_data,                         \
74                     sizeof(test_data[0]),                               \
75                     ARRAY_LENGTH(test_data))                            \
76         TEST_BEGIN(name, void *data)                                    \
77
78 #define TEST(name) NO_ARG_TEST(name, 0)
79 #define FAIL_TEST(name) NO_ARG_TEST(name, 1)
80 #define TEST_P(name, data) ARG_TEST(name, 0, data)
81 #define FAIL_TEST_P(name, data) ARG_TEST(name, 1, data)
82
83 /**
84  * Get the test name string with counter
85  *
86  * \return The test name. For an iterated test, e.g. defined with TEST_P(),
87  * the name has a '[%d]' suffix to indicate the iteration.
88  *
89  * This is only usable from code paths inside TEST(), TEST_P(), etc.
90  * defined functions.
91  */
92 const char *
93 get_test_name(void);
94
95 #endif