blob: 193b76d314cc8bf7f3e6e918ea3a8c9b01da59ed [file] [log] [blame]
U. Artie Eoff1ba9b382012-12-07 13:50:32 -08001/*
2 * Copyright © 2012 Intel Corporation
Sam Spilsburyb5021262013-09-13 10:01:20 +08003 * Copyright © 2013 Sam Spilsbury <smspillaz@gmail.com>
U. Artie Eoff1ba9b382012-12-07 13:50:32 -08004 *
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
Andrew Wedgbury9cd661e2014-04-07 12:40:35 +010027#include "config.h"
28
Sam Spilsburyb5021262013-09-13 10:01:20 +080029#include <stdlib.h>
30
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080031#ifdef NDEBUG
32#error "Tests must not be built with NDEBUG defined, they rely on assert()."
33#endif
34
35struct weston_test {
36 const char *name;
Sam Spilsburyb5021262013-09-13 10:01:20 +080037 void (*run)(void *);
38 const void *table_data;
39 size_t element_size;
40 int n_elements;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080041 int must_fail;
Sam Spilsburyb5021262013-09-13 10:01:20 +080042} __attribute__ ((aligned (32)));
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080043
Bryce Harrington22ea3062014-11-19 17:18:35 -080044#define ARRAY_LENGTH(a) ((int) (sizeof (a) / sizeof (a)[0]))
45
Sam Spilsburyb5021262013-09-13 10:01:20 +080046#define TEST_BEGIN(name, arg) \
47 static void name(arg)
48
49#define TEST_COMMON(func, name, ret, data, size, n_elem) \
50 static void func(void *); \
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080051 \
52 const struct weston_test test##name \
Sam Spilsburyb5021262013-09-13 10:01:20 +080053 __attribute__ ((section ("test_section"))) = \
54 { \
55 #name, func, data, size, n_elem, ret \
56 };
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080057
Sam Spilsburyb5021262013-09-13 10:01:20 +080058#define NO_ARG_TEST(name, ret) \
59 TEST_COMMON(wrap##name, name, ret, NULL, 0, 1) \
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080060 static void name(void); \
Sam Spilsburyb5021262013-09-13 10:01:20 +080061 static void wrap##name(void *data) \
62 { \
63 (void) data; \
64 name(); \
65 } \
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080066 \
Sam Spilsburyb5021262013-09-13 10:01:20 +080067 TEST_BEGIN(name, void)
68
69#define ARG_TEST(name, ret, test_data) \
70 TEST_COMMON(name, name, ret, test_data, \
71 sizeof(test_data[0]), \
Bryce Harrington22ea3062014-11-19 17:18:35 -080072 ARRAY_LENGTH(test_data)) \
Sam Spilsburyb5021262013-09-13 10:01:20 +080073 TEST_BEGIN(name, void *data) \
74
75#define TEST(name) NO_ARG_TEST(name, 0)
76#define FAIL_TEST(name) NO_ARG_TEST(name, 1)
77#define TEST_P(name, data) ARG_TEST(name, 0, data)
78#define FAIL_TEST_P(name, data) ARG_TEST(name, 1, data)
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080079
80#endif