From 1eb30468ea2c4e7558b04443c20133dd87f36fe2 Mon Sep 17 00:00:00 2001 From: Pekka Paalanen Date: Wed, 22 Jan 2020 13:37:20 +0200 Subject: [PATCH] tests: add get_test_fixture_index() A future test wants to access the fixture data array for the currently running fixture index to log the test description. This patch provides access to the array index. Rather than adding more gloabl variables, I changed the type of the existing one which feels slightly cleaner. Signed-off-by: Pekka Paalanen --- tests/weston-test-runner.c | 37 ++++++++++++++++++++++++++++++------- tests/weston-test-runner.h | 3 +++ 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/tests/weston-test-runner.c b/tests/weston-test-runner.c index 8f945f94..c10f286f 100644 --- a/tests/weston-test-runner.c +++ b/tests/weston-test-runner.c @@ -46,7 +46,12 @@ extern const struct weston_test_entry __start_test_section, __stop_test_section; -static const char *test_name_; +struct weston_test_run_info { + char name[512]; + int fixture_nr; +}; + +static const struct weston_test_run_info *test_run_info_; /** Get the test name string with counter * @@ -62,7 +67,23 @@ static const char *test_name_; const char * get_test_name(void) { - return test_name_; + return test_run_info_->name; +} + +/** Get the current fixture index + * + * Returns the current fixture index which can be used directly as an index + * into the array passed as an argument to DECLARE_FIXTURE_SETUP_WITH_ARG(). + * + * This is only usable from code paths inside TEST(), TEST_P(), PLUGIN_TEST() + * etc. defined functions. + * + * \ingroup testharness + */ +int +get_test_fixture_index(void) +{ + return test_run_info_->fixture_nr - 1; } /** Print into test log @@ -100,18 +121,20 @@ static enum test_result_code run_test(int fixture_nr, const struct weston_test_entry *t, void *data, int iteration) { - char str[512]; + struct weston_test_run_info info; if (data) { - snprintf(str, sizeof(str), "f%d-%s-e%d", + snprintf(info.name, sizeof(info.name), "f%d-%s-e%d", fixture_nr, t->name, iteration); } else { - snprintf(str, sizeof(str), "f%d-%s", fixture_nr, t->name); + snprintf(info.name, sizeof(info.name), "f%d-%s", + fixture_nr, t->name); } + info.fixture_nr = fixture_nr; - test_name_ = str; + test_run_info_ = &info; t->run(data); - test_name_ = NULL; + test_run_info_ = NULL; /* * XXX: We should return t->run(data); but that requires changing diff --git a/tests/weston-test-runner.h b/tests/weston-test-runner.h index c47deba9..9e545cd9 100644 --- a/tests/weston-test-runner.h +++ b/tests/weston-test-runner.h @@ -143,6 +143,9 @@ testlog(const char *fmt, ...) WL_PRINTF(1, 2); const char * get_test_name(void); +int +get_test_fixture_index(void); + /** Fixture setup array record * * Helper to store the attributes of the data array passed in to