summaryrefslogtreecommitdiff
path: root/test/test-main.c
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2021-03-08 03:35:04 +0300
committerTom Rini <trini@konsulko.com>2021-03-12 17:57:30 +0300
commitfe806861a98b4ad524d070c6d7b9d20fd475ec6f (patch)
tree59df6d3172d2ec6758deb6ee14fa872be5837b6a /test/test-main.c
parentd2281bb09b0ebf580f8efe23c84c240a2f3ea9bb (diff)
downloadu-boot-fe806861a98b4ad524d070c6d7b9d20fd475ec6f.tar.xz
test: Use a local variable for test state
At present we use a global test state for all driver-model tests. Make use of a local struct like we do with the other tests. To make this work, add functions to get and set this state. When a test starts, the state is set (so it can be used in the test). When a test finishes, the state is unset, so it cannot be used by mistake. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'test/test-main.c')
-rw-r--r--test/test-main.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/test/test-main.c b/test/test-main.c
index 4e17c9edb2..139fc1f6f1 100644
--- a/test/test-main.c
+++ b/test/test-main.c
@@ -16,6 +16,19 @@
DECLARE_GLOBAL_DATA_PTR;
+/* This is valid when a test is running, NULL otherwise */
+static struct unit_test_state *cur_test_state;
+
+struct unit_test_state *test_get_state(void)
+{
+ return cur_test_state;
+}
+
+void test_set_state(struct unit_test_state *uts)
+{
+ cur_test_state = uts;
+}
+
/**
* dm_test_pre_run() - Get ready to run a driver model test
*
@@ -180,6 +193,9 @@ static int ut_run_test(struct unit_test_state *uts, struct unit_test *test,
note = " (flat tree)";
printf("Test: %s: %s%s\n", test_name, fname, note);
+ /* Allow access to test state from drivers */
+ test_set_state(uts);
+
ret = test_pre_run(uts, test);
if (ret == -EAGAIN)
return -EAGAIN;
@@ -192,6 +208,8 @@ static int ut_run_test(struct unit_test_state *uts, struct unit_test *test,
if (ret)
return ret;
+ test_set_state( NULL);
+
return 0;
}