mirror of
https://gitlab.freedesktop.org/libinput/libei.git
synced 2026-01-09 13:20:24 +01:00
util: add helper macros for the ELF section handling
This commit is contained in:
parent
19c949a46b
commit
6758b9970d
2 changed files with 18 additions and 7 deletions
|
|
@ -34,23 +34,20 @@
|
|||
* __start and __stop point to the start and end of that section. See the
|
||||
* __attribute__(section) documentation.
|
||||
*/
|
||||
extern const struct test_function __start_test_functions_section, __stop_test_functions_section;
|
||||
DECLARE_TEST_SECTION();
|
||||
|
||||
int
|
||||
munit_tests_run(int argc, char **argv)
|
||||
{
|
||||
size_t count = 1; /* For NULL-terminated entry */
|
||||
|
||||
for (const struct test_function *t = &__start_test_functions_section;
|
||||
t < &__stop_test_functions_section;
|
||||
t++)
|
||||
foreach_test(t) {
|
||||
count++;
|
||||
}
|
||||
|
||||
_cleanup_free_ MunitTest *tests = calloc(count, sizeof(*tests));
|
||||
size_t idx = 0;
|
||||
for (const struct test_function *t = &__start_test_functions_section;
|
||||
t < &__stop_test_functions_section;
|
||||
t++) {
|
||||
foreach_test(t) {
|
||||
MunitTest test = {
|
||||
.name = xaprintf("%s", t->name),
|
||||
.test = t->func,
|
||||
|
|
|
|||
|
|
@ -41,6 +41,20 @@
|
|||
|
||||
#include <munit.h>
|
||||
|
||||
/**
|
||||
* Put at the top of the file somewhere, declares the start/stop for the test section we need.
|
||||
*/
|
||||
#define DECLARE_TEST_SECTION() \
|
||||
extern const struct test_function __start_test_functions_section, __stop_test_functions_section
|
||||
|
||||
/**
|
||||
* Helper to loop through each test.
|
||||
*/
|
||||
#define foreach_test(t_) \
|
||||
for (const struct test_function *t_ = &__start_test_functions_section; \
|
||||
t_ < &__stop_test_functions_section; \
|
||||
t_++)
|
||||
|
||||
typedef MunitResult (*munit_test_func_t)(const MunitParameter params[], void *user_data);
|
||||
|
||||
struct test_function {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue