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 | * |
Bryce Harrington | 2cc9297 | 2015-06-11 15:39:40 -0700 | [diff] [blame] | 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: |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 12 | * |
Bryce Harrington | 2cc9297 | 2015-06-11 15:39:40 -0700 | [diff] [blame] | 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. |
| 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 Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 25 | */ |
| 26 | |
| 27 | #ifndef _WESTON_TEST_RUNNER_H_ |
| 28 | #define _WESTON_TEST_RUNNER_H_ |
| 29 | |
Andrew Wedgbury | 9cd661e | 2014-04-07 12:40:35 +0100 | [diff] [blame] | 30 | #include "config.h" |
| 31 | |
Sam Spilsbury | b502126 | 2013-09-13 10:01:20 +0800 | [diff] [blame] | 32 | #include <stdlib.h> |
| 33 | |
Jon Cruz | 35b2eaa | 2015-06-15 15:37:08 -0700 | [diff] [blame] | 34 | #include "shared/helpers.h" |
| 35 | |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 36 | #ifdef NDEBUG |
| 37 | #error "Tests must not be built with NDEBUG defined, they rely on assert()." |
| 38 | #endif |
| 39 | |
| 40 | struct weston_test { |
| 41 | const char *name; |
Sam Spilsbury | b502126 | 2013-09-13 10:01:20 +0800 | [diff] [blame] | 42 | void (*run)(void *); |
| 43 | const void *table_data; |
| 44 | size_t element_size; |
| 45 | int n_elements; |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 46 | int must_fail; |
Sam Spilsbury | b502126 | 2013-09-13 10:01:20 +0800 | [diff] [blame] | 47 | } __attribute__ ((aligned (32))); |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 48 | |
Sam Spilsbury | b502126 | 2013-09-13 10:01:20 +0800 | [diff] [blame] | 49 | #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 Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 54 | \ |
| 55 | const struct weston_test test##name \ |
Sam Spilsbury | b502126 | 2013-09-13 10:01:20 +0800 | [diff] [blame] | 56 | __attribute__ ((section ("test_section"))) = \ |
| 57 | { \ |
| 58 | #name, func, data, size, n_elem, ret \ |
| 59 | }; |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 60 | |
Sam Spilsbury | b502126 | 2013-09-13 10:01:20 +0800 | [diff] [blame] | 61 | #define NO_ARG_TEST(name, ret) \ |
| 62 | TEST_COMMON(wrap##name, name, ret, NULL, 0, 1) \ |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 63 | static void name(void); \ |
Sam Spilsbury | b502126 | 2013-09-13 10:01:20 +0800 | [diff] [blame] | 64 | static void wrap##name(void *data) \ |
| 65 | { \ |
| 66 | (void) data; \ |
| 67 | name(); \ |
| 68 | } \ |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 69 | \ |
Sam Spilsbury | b502126 | 2013-09-13 10:01:20 +0800 | [diff] [blame] | 70 | 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 Harrington | 22ea306 | 2014-11-19 17:18:35 -0800 | [diff] [blame] | 75 | ARRAY_LENGTH(test_data)) \ |
Sam Spilsbury | b502126 | 2013-09-13 10:01:20 +0800 | [diff] [blame] | 76 | 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 Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 82 | |
Pekka Paalanen | b581783 | 2017-01-27 17:30:26 +0100 | [diff] [blame] | 83 | /** |
| 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 | */ |
| 92 | const char * |
| 93 | get_test_name(void); |
| 94 | |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 95 | #endif |