U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2012 Intel Corporation |
Sam Spilsbury | b502126 | 2013-09-13 10:01:20 +0800 | [diff] [blame] | 3 | * Copyright © 2013 Sam Spilsbury <smspillaz@gmail.com> |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 4 | * |
| 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 Wedgbury | 9cd661e | 2014-04-07 12:40:35 +0100 | [diff] [blame] | 27 | #include "config.h" |
| 28 | |
Sam Spilsbury | b502126 | 2013-09-13 10:01:20 +0800 | [diff] [blame] | 29 | #include <stdlib.h> |
| 30 | |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 31 | #ifdef NDEBUG |
| 32 | #error "Tests must not be built with NDEBUG defined, they rely on assert()." |
| 33 | #endif |
| 34 | |
| 35 | struct weston_test { |
| 36 | const char *name; |
Sam Spilsbury | b502126 | 2013-09-13 10:01:20 +0800 | [diff] [blame] | 37 | void (*run)(void *); |
| 38 | const void *table_data; |
| 39 | size_t element_size; |
| 40 | int n_elements; |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 41 | int must_fail; |
Sam Spilsbury | b502126 | 2013-09-13 10:01:20 +0800 | [diff] [blame] | 42 | } __attribute__ ((aligned (32))); |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 43 | |
Bryce Harrington | 22ea306 | 2014-11-19 17:18:35 -0800 | [diff] [blame^] | 44 | #define ARRAY_LENGTH(a) ((int) (sizeof (a) / sizeof (a)[0])) |
| 45 | |
Sam Spilsbury | b502126 | 2013-09-13 10:01:20 +0800 | [diff] [blame] | 46 | #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 Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 51 | \ |
| 52 | const struct weston_test test##name \ |
Sam Spilsbury | b502126 | 2013-09-13 10:01:20 +0800 | [diff] [blame] | 53 | __attribute__ ((section ("test_section"))) = \ |
| 54 | { \ |
| 55 | #name, func, data, size, n_elem, ret \ |
| 56 | }; |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 57 | |
Sam Spilsbury | b502126 | 2013-09-13 10:01:20 +0800 | [diff] [blame] | 58 | #define NO_ARG_TEST(name, ret) \ |
| 59 | TEST_COMMON(wrap##name, name, ret, NULL, 0, 1) \ |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 60 | static void name(void); \ |
Sam Spilsbury | b502126 | 2013-09-13 10:01:20 +0800 | [diff] [blame] | 61 | static void wrap##name(void *data) \ |
| 62 | { \ |
| 63 | (void) data; \ |
| 64 | name(); \ |
| 65 | } \ |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 66 | \ |
Sam Spilsbury | b502126 | 2013-09-13 10:01:20 +0800 | [diff] [blame] | 67 | 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 Harrington | 22ea306 | 2014-11-19 17:18:35 -0800 | [diff] [blame^] | 72 | ARRAY_LENGTH(test_data)) \ |
Sam Spilsbury | b502126 | 2013-09-13 10:01:20 +0800 | [diff] [blame] | 73 | 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 Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 79 | |
| 80 | #endif |