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>
diff --git a/test/test-main.c b/test/test-main.c
index 4e17c9e..139fc1f 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 @@
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 @@
if (ret)
return ret;
+ test_set_state( NULL);
+
return 0;
}