| 1 |
/* |
| 2 |
* Copyright © 2014 Ran Benita <[email protected]> |
| 3 |
* Copyright © 2023 Pierre Le Marre <[email protected]> |
| 4 |
* SPDX-License-Identifier: MIT |
| 5 |
*/ |
| 6 |
|
| 7 |
/* |
| 8 |
*This is a wrapper around X11 tests to make it faster to use for the simple |
| 9 |
* type of test cases. |
| 10 |
* |
| 11 |
* Use with the X11_TEST macro like this: |
| 12 |
* |
| 13 |
* X11_TEST(some_test) { |
| 14 |
* return 0; |
| 15 |
* } |
| 16 |
* |
| 17 |
* int main(void) { |
| 18 |
* return x11_tests_run(void); |
| 19 |
* } |
| 20 |
* |
| 21 |
*/ |
| 22 |
|
| 23 |
#pragma once |
| 24 |
|
| 25 |
#include "config.h" |
| 26 |
|
| 27 |
typedef int (* x11_test_func_t)(const char* display, void *private); |
| 28 |
|
| 29 |
int xvfb_wrapper(x11_test_func_t f, void *private); |
| 30 |
|
| 31 |
int x11_tests_run(void); |
| 32 |
|
| 33 |
|
| 34 |
struct test_function { |
| 35 |
const char *name; /* function name */ |
| 36 |
const char *file; /* file name */ |
| 37 |
x11_test_func_t func; /* test function */ |
| 38 |
} __attribute__((aligned(16))); |
| 39 |
|
| 40 |
/** |
| 41 |
* Defines a struct test_function in a custom ELF section that we can then |
| 42 |
* loop over in x11_tests_run() to extract the tests. This removes the |
| 43 |
* need of manually adding the tests to a suite or listing them somewhere. |
| 44 |
*/ |
| 45 |
#define TEST_ELF_SECTION test_func_sec |
| 46 |
|
| 47 |
#if defined(__APPLE__) && defined(__MACH__) |
| 48 |
#define SET_TEST_ELF_SECTION(_section) \ |
| 49 |
__attribute__((retain,used)) \ |
| 50 |
__attribute__((section("__DATA," STRINGIFY(_section)))) |
| 51 |
|
| 52 |
/* Custom section pointers. See: https://stackoverflow.com/a/22366882 */ |
| 53 |
#define DECLARE_TEST_ELF_SECTION_POINTERS(_section) \ |
| 54 |
extern const struct test_function CONCAT2(__start_, _section) \ |
| 55 |
__asm("section$start$__DATA$" STRINGIFY2(_section)); \ |
| 56 |
extern const struct test_function CONCAT2(__stop_, _section) \ |
| 57 |
__asm("section$end$__DATA$" STRINGIFY2(_section)) |
| 58 |
|
| 59 |
#else |
| 60 |
|
| 61 |
#define SET_TEST_ELF_SECTION(_section) \ |
| 62 |
__attribute__((retain,used)) \ |
| 63 |
__attribute__((section(STRINGIFY(_section)))) |
| 64 |
|
| 65 |
#define DECLARE_TEST_ELF_SECTION_POINTERS(_section) \ |
| 66 |
extern const struct test_function \ |
| 67 |
CONCAT2(__start_, _section), CONCAT2(__stop_, _section) |
| 68 |
#endif |
| 69 |
|
| 70 |
#define X11_TEST(_func) \ |
| 71 |
static int _func(const char* display, void *private); \ |
| 72 |
static const struct test_function _test_##_func \ |
| 73 |
SET_TEST_ELF_SECTION(TEST_ELF_SECTION) = { \ |
| 74 |
.name = #_func, \ |
| 75 |
.func = (_func), \ |
| 76 |
.file = __FILE__, \ |
| 77 |
}; \ |
| 78 |
static int _func(const char* display, void *private) |