From: Pekka Paalanen Date: Fri, 27 Jan 2017 16:30:26 +0000 (+0100) Subject: tests: implement get_test_name() X-Git-Tag: upstream/5.0.0~629 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b581783b793862f6d5c13eebc416385718b8440d;p=platform%2Fupstream%2Fweston.git 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 Reviewed-by: Emilio Pozuelo Monfort Reviewed-by: Micah Fedke Reviewed-by: Quentin Glidic --- diff --git a/tests/weston-test-runner.c b/tests/weston-test-runner.c index b1e89bc..f197265 100644 --- a/tests/weston-test-runner.c +++ b/tests/weston-test-runner.c @@ -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"); diff --git a/tests/weston-test-runner.h b/tests/weston-test-runner.h index a443691..21a059d 100644 --- a/tests/weston-test-runner.h +++ b/tests/weston-test-runner.h @@ -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