diff options
author | Simon Glass <sjg@chromium.org> | 2021-03-07 17:35:04 -0700 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2021-03-12 09:57:30 -0500 |
commit | fe806861a98b4ad524d070c6d7b9d20fd475ec6f (patch) | |
tree | 59df6d3172d2ec6758deb6ee14fa872be5837b6a /test/test-main.c | |
parent | d2281bb09b0ebf580f8efe23c84c240a2f3ea9bb (diff) | |
download | u-boot-fe806861a98b4ad524d070c6d7b9d20fd475ec6f.tar.gz u-boot-fe806861a98b4ad524d070c6d7b9d20fd475ec6f.tar.bz2 u-boot-fe806861a98b4ad524d070c6d7b9d20fd475ec6f.zip |
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.c | 18 |
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; } |