tests: drop the custom ELF section

With DECLARE_TEST_LIST(), there is no need for the custom ELF section.
We can use a plain variable to refer to the list of test functions.

This makes the test harness more reliable as we are no longer relying on
internal compiler behavior on laying out objects in sections. This is
also obvious to memory access checkers that the accesses are valid.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
This commit is contained in:
Pekka Paalanen 2026-05-28 15:07:12 +03:00
parent 807245bce6
commit 4db67f1eac
2 changed files with 23 additions and 14 deletions

View file

@ -52,8 +52,6 @@
* \defgroup testharness_private Test harness private
*/
extern const struct weston_test_entry __start_test_section, __stop_test_section;
struct weston_test_run_info {
char name[512];
int fixture_nr;
@ -158,9 +156,10 @@ fixture_setup_array_get_name(const struct fixture_setup_array *fsa, int findex)
static const struct weston_test_entry *
find_test(const char *name)
{
const struct weston_test_entry_list *list = &weston_test_entry_list_;
const struct weston_test_entry *t;
for (t = &__start_test_section; t < &__stop_test_section; t++)
for (t = list->array; t < list->array + list->len; t++)
if (strcmp(t->name, name) == 0)
return t;
@ -203,6 +202,7 @@ run_test(struct wet_testsuite_data *suite_data, int fixture_nr,
static void
list_tests(void)
{
const struct weston_test_entry_list *list = &weston_test_entry_list_;
const struct fixture_setup_array *fsa;
const struct weston_test_entry *t;
int i;
@ -220,7 +220,7 @@ list_tests(void)
}
printf("Test names:\n");
for (t = &__start_test_section; t < &__stop_test_section; t++) {
for (t = list->array; t < list->array + list->len; t++) {
printf(" %s\n", t->name);
if (t->n_elements > 1)
printf(" with array of %d cases\n", t->n_elements);
@ -518,9 +518,8 @@ weston_test_harness_create(int argc, char **argv)
harness->data.tests_count = 1;
harness->data.case_index = harness->case_ind;
} else {
harness->data.tests = &__start_test_section;
harness->data.tests_count =
&__stop_test_section - &__start_test_section;
harness->data.tests = weston_test_entry_list_.array;
harness->data.tests_count = weston_test_entry_list_.len;
harness->data.case_index = -1;
}

View file

@ -52,10 +52,10 @@ typedef enum test_result_code (*weston_test_run_plugin_fn)(struct wet_testsuite_
/** Test program entry
*
* Each invocation of TEST(), TEST_P(), or PLUGIN_TEST() will create one
* more weston_test_entry in a custom named section in the final binary.
* Iterating through the section then allows to iterate through all
* the defined tests.
* Arrays of entries are created with macros \c TESTFN(), \c TESTFN_ARG()
* and \c TESTFN_PLUGIN() inside a \c DECLARE_TEST_LIST() arguments.
* The array of entries lists all test functions in a test program for the
* test harness to iterate through.
*
* \ingroup testharness_private
*/
@ -69,7 +69,7 @@ struct weston_test_entry {
const void *table_data;
size_t element_size;
int n_elements;
} __attribute__ ((aligned (64)));
};
/** Add a test function with no parameters
*
@ -157,6 +157,13 @@ struct weston_test_entry {
.n_elements = 1, \
}
struct weston_test_entry_list {
const struct weston_test_entry *array;
size_t len;
};
extern const struct weston_test_entry_list weston_test_entry_list_;
/** Declare the list of tests in a test program
*
* When the fixture setup is using \c weston_test_harness_execute_standalone()
@ -170,9 +177,12 @@ struct weston_test_entry {
* \ingroup testharness
*/
#define DECLARE_TEST_LIST(...) \
__attribute__ ((used, section ("test_section"))) \
const struct weston_test_entry test_list[] = { \
static const struct weston_test_entry test_list[] = { \
__VA_ARGS__ \
}; \
const struct weston_test_entry_list weston_test_entry_list_ = { \
.array = test_list, \
.len = ARRAY_LENGTH(test_list), \
}
void