summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPekka Paalanen <pekka.paalanen@collabora.co.uk>2017-01-27 17:30:26 +0100
committerPekka Paalanen <pekka.paalanen@collabora.co.uk>2017-02-07 14:25:12 +0200
commitb581783b793862f6d5c13eebc416385718b8440d (patch)
tree928dfb95a357726ef7d89a13d27414b7c45f55a9 /tests
parenta21b5ebf85f385dadc817c908f808fedaa4334d5 (diff)
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>
Diffstat (limited to 'tests')
-rw-r--r--tests/weston-test-runner.c21
-rw-r--r--tests/weston-test-runner.h12
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