tests: implement get_test_name()

Screenshot tests often want to use the test name for writing out images.
This is a helper to get the test name without writing it multiple times
in the source.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Reviewed-by: Emilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk>
Reviewed-by: Micah Fedke <micah.fedke@collabora.co.uk>
Reviewed-by: Quentin Glidic <sardemff7+git@sardemff7.net>
This commit is contained in:
Pekka Paalanen 2017-01-27 17:30:26 +01:00
parent a21b5ebf85
commit b581783b79
2 changed files with 31 additions and 2 deletions

View File

@ -42,6 +42,14 @@ char __attribute__((weak)) *server_parameters="";
extern const struct weston_test __start_test_section, __stop_test_section;
static const char *test_name_;
const char *
get_test_name(void)
{
return test_name_;
}
static const struct weston_test *
find_test(const char *name)
{
@ -55,8 +63,17 @@ find_test(const char *name)
}
static void
run_test(const struct weston_test *t, void *data)
run_test(const struct weston_test *t, void *data, int iteration)
{
char str[512];
if (data) {
snprintf(str, sizeof(str), "%s[%d]", t->name, iteration);
test_name_ = str;
} else {
test_name_ = t->name;
}
t->run(data);
exit(EXIT_SUCCESS);
}
@ -83,7 +100,7 @@ exec_and_report_test(const struct weston_test *t, void *test_data, int iteration
assert(pid >= 0);
if (pid == 0)
run_test(t, test_data); /* never returns */
run_test(t, test_data, iteration); /* never returns */
if (waitid(P_ALL, 0, &info, WEXITED)) {
fprintf(stderr, "waitid failed: %m\n");

View File

@ -80,4 +80,16 @@ struct weston_test {
#define TEST_P(name, data) ARG_TEST(name, 0, data)
#define FAIL_TEST_P(name, data) ARG_TEST(name, 1, data)
/**
* Get the test name string with counter
*
* \return The test name. For an iterated test, e.g. defined with TEST_P(),
* the name has a '[%d]' suffix to indicate the iteration.
*
* This is only usable from code paths inside TEST(), TEST_P(), etc.
* defined functions.
*/
const char *
get_test_name(void);
#endif