blob: 457cf31c8442ffad1be576fcb182a5291fb3a124 [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
Sam Spilsburyb5021262013-09-13 10:01:20 +080027#include <stdlib.h>
28
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080029#ifdef NDEBUG
30#error "Tests must not be built with NDEBUG defined, they rely on assert()."
31#endif
32
33struct weston_test {
34 const char *name;
Sam Spilsburyb5021262013-09-13 10:01:20 +080035 void (*run)(void *);
36 const void *table_data;
37 size_t element_size;
38 int n_elements;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080039 int must_fail;
Sam Spilsburyb5021262013-09-13 10:01:20 +080040} __attribute__ ((aligned (32)));
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080041
Sam Spilsburyb5021262013-09-13 10:01:20 +080042#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 *); \
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080047 \
48 const struct weston_test test##name \
Sam Spilsburyb5021262013-09-13 10:01:20 +080049 __attribute__ ((section ("test_section"))) = \
50 { \
51 #name, func, data, size, n_elem, ret \
52 };
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080053
Sam Spilsburyb5021262013-09-13 10:01:20 +080054#define NO_ARG_TEST(name, ret) \
55 TEST_COMMON(wrap##name, name, ret, NULL, 0, 1) \
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080056 static void name(void); \
Sam Spilsburyb5021262013-09-13 10:01:20 +080057 static void wrap##name(void *data) \
58 { \
59 (void) data; \
60 name(); \
61 } \
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080062 \
Sam Spilsburyb5021262013-09-13 10:01:20 +080063 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)
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080075
76#endif