mirror of
https://github.com/brain-hackers/u-boot-brain
synced 2024-09-27 23:20:26 +09:00
test: Move test running into a separate function
Add a function to handle the preparation for running a test and the post-test clean-up. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
e77615d3a7
commit
99a88fe1bd
@ -387,6 +387,22 @@ int test_pre_run(struct unit_test_state *uts, struct unit_test *test);
|
|||||||
*/
|
*/
|
||||||
int test_post_run(struct unit_test_state *uts, struct unit_test *test);
|
int test_post_run(struct unit_test_state *uts, struct unit_test *test);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ut_run_test() - Run a single test
|
||||||
|
*
|
||||||
|
* This runs the test, handling any preparation and clean-up needed. It prints
|
||||||
|
* the name of each test before running it.
|
||||||
|
*
|
||||||
|
* @uts: Test state to update. The caller should ensure that this is zeroed for
|
||||||
|
* the first call to this function. On exit, @uts->fail_count is
|
||||||
|
* incremented by the number of failures (0, one hopes)
|
||||||
|
* @test: Test to run
|
||||||
|
* @name: Name of test, possibly skipping a prefix that should not be displayed
|
||||||
|
* @return 0 if all tests passed, -EAGAIN if the test should be skipped, -1 if
|
||||||
|
* any failed
|
||||||
|
*/
|
||||||
|
int ut_run_test(struct unit_test_state *uts, struct unit_test *test,
|
||||||
|
const char *name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ut_run_tests() - Run a set of tests
|
* ut_run_tests() - Run a set of tests
|
||||||
|
@ -121,6 +121,28 @@ int test_post_run(struct unit_test_state *uts, struct unit_test *test)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ut_run_test(struct unit_test_state *uts, struct unit_test *test,
|
||||||
|
const char *test_name)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
printf("Test: %s\n", test_name);
|
||||||
|
|
||||||
|
ret = test_pre_run(uts, test);
|
||||||
|
if (ret == -EAGAIN)
|
||||||
|
return -EAGAIN;
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
test->func(uts);
|
||||||
|
|
||||||
|
ret = test_post_run(uts, test);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int ut_run_tests(struct unit_test_state *uts, const char *prefix,
|
int ut_run_tests(struct unit_test_state *uts, const char *prefix,
|
||||||
struct unit_test *tests, int count, const char *select_name)
|
struct unit_test *tests, int count, const char *select_name)
|
||||||
{
|
{
|
||||||
@ -138,20 +160,12 @@ int ut_run_tests(struct unit_test_state *uts, const char *prefix,
|
|||||||
|
|
||||||
if (select_name && strcmp(select_name, test_name))
|
if (select_name && strcmp(select_name, test_name))
|
||||||
continue;
|
continue;
|
||||||
printf("Test: %s\n", test_name);
|
ret = ut_run_test(uts, test, test_name);
|
||||||
found++;
|
found++;
|
||||||
|
|
||||||
ret = test_pre_run(uts, test);
|
|
||||||
if (ret == -EAGAIN)
|
if (ret == -EAGAIN)
|
||||||
continue;
|
continue;
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
test->func(uts);
|
|
||||||
|
|
||||||
ret = test_post_run(uts, test);
|
|
||||||
if (ret)
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
if (select_name && !found)
|
if (select_name && !found)
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
|
Loading…
Reference in New Issue
Block a user