[PATCH weston 4/7] tests: implement get_test_name()
Emilio Pozuelo Monfort
pochu27 at gmail.com
Fri Jan 27 16:30:26 UTC 2017
From: Pekka Paalanen <pekka.paalanen at collabora.co.uk>
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 at collabora.co.uk>
Reviewed-by: Emilio Pozuelo Monfort <emilio.pozuelo at collabora.co.uk>
---
tests/weston-test-runner.c | 21 +++++++++++++++++++--
tests/weston-test-runner.h | 12 ++++++++++++
2 files changed, 31 insertions(+), 2 deletions(-)
diff --git a/tests/weston-test-runner.c b/tests/weston-test-runner.c
index b1e89bc2..f197265d 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 a4436919..21a059d6 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
--
2.11.0
More information about the wayland-devel
mailing list