2 * Copyright © 2012 Intel Corporation
3 * Copyright © 2013 Sam Spilsbury <smspillaz@gmail.com>
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:
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.
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
27 #ifndef _WESTON_TEST_RUNNER_H_
28 #define _WESTON_TEST_RUNNER_H_
34 #include "shared/helpers.h"
37 #error "Tests must not be built with NDEBUG defined, they rely on assert()."
43 const void *table_data;
47 } __attribute__ ((aligned (32)));
49 #define TEST_BEGIN(name, arg) \
52 #define TEST_COMMON(func, name, ret, data, size, n_elem) \
53 static void func(void *); \
55 const struct weston_test test##name \
56 __attribute__ ((used, section ("test_section"))) = \
58 #name, func, data, size, n_elem, ret \
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) \
70 TEST_BEGIN(name, void)
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) \
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)
84 * Get the test name string with counter
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.
89 * This is only usable from code paths inside TEST(), TEST_P(), etc.