blob: 21a059d63234a70da7a03071bdd012be0971377a [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 *
Bryce Harrington2cc92972015-06-11 15:39:40 -07005 * 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:
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080012 *
Bryce Harrington2cc92972015-06-11 15:39:40 -070013 * 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.
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080025 */
26
27#ifndef _WESTON_TEST_RUNNER_H_
28#define _WESTON_TEST_RUNNER_H_
29
Andrew Wedgbury9cd661e2014-04-07 12:40:35 +010030#include "config.h"
31
Sam Spilsburyb5021262013-09-13 10:01:20 +080032#include <stdlib.h>
33
Jon Cruz35b2eaa2015-06-15 15:37:08 -070034#include "shared/helpers.h"
35
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080036#ifdef NDEBUG
37#error "Tests must not be built with NDEBUG defined, they rely on assert()."
38#endif
39
40struct weston_test {
41 const char *name;
Sam Spilsburyb5021262013-09-13 10:01:20 +080042 void (*run)(void *);
43 const void *table_data;
44 size_t element_size;
45 int n_elements;
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080046 int must_fail;
Sam Spilsburyb5021262013-09-13 10:01:20 +080047} __attribute__ ((aligned (32)));
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080048
Sam Spilsburyb5021262013-09-13 10:01:20 +080049#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 *); \
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080054 \
55 const struct weston_test test##name \
Sam Spilsburyb5021262013-09-13 10:01:20 +080056 __attribute__ ((section ("test_section"))) = \
57 { \
58 #name, func, data, size, n_elem, ret \
59 };
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080060
Sam Spilsburyb5021262013-09-13 10:01:20 +080061#define NO_ARG_TEST(name, ret) \
62 TEST_COMMON(wrap##name, name, ret, NULL, 0, 1) \
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080063 static void name(void); \
Sam Spilsburyb5021262013-09-13 10:01:20 +080064 static void wrap##name(void *data) \
65 { \
66 (void) data; \
67 name(); \
68 } \
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080069 \
Sam Spilsburyb5021262013-09-13 10:01:20 +080070 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]), \
Bryce Harrington22ea3062014-11-19 17:18:35 -080075 ARRAY_LENGTH(test_data)) \
Sam Spilsburyb5021262013-09-13 10:01:20 +080076 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)
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080082
Pekka Paalanenb5817832017-01-27 17:30:26 +010083/**
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 */
92const char *
93get_test_name(void);
94
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080095#endif