mirror of
https://github.com/u-boot/u-boot.git
synced 2025-04-26 07:17:10 +00:00
test: Pass the test-state into ut_run_list()
Pass this into the function so that callers can inspect the state afterwards. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
7b576f0847
commit
94b5284398
4 changed files with 51 additions and 23 deletions
|
@ -147,10 +147,13 @@ void spl_board_init(void)
|
|||
if (state->run_unittests) {
|
||||
struct unit_test *tests = UNIT_TEST_ALL_START();
|
||||
const int count = UNIT_TEST_ALL_COUNT();
|
||||
struct unit_test_state uts;
|
||||
int ret;
|
||||
|
||||
ret = ut_run_list("spl", NULL, tests, count,
|
||||
ut_init_state(&uts);
|
||||
ret = ut_run_list(&uts, "spl", NULL, tests, count,
|
||||
state->select_unittests, 1, false, NULL);
|
||||
ut_uninit_state(&uts);
|
||||
/* continue execution into U-Boot */
|
||||
}
|
||||
}
|
||||
|
|
|
@ -479,12 +479,34 @@ struct unit_test_state *ut_get_state(void);
|
|||
*/
|
||||
void ut_set_state(struct unit_test_state *uts);
|
||||
|
||||
/**
|
||||
* ut_init_state() - Set up a new test state
|
||||
*
|
||||
* This must be called before using the test state with ut_run_tests()
|
||||
*
|
||||
* @uts: Test state to init
|
||||
*/
|
||||
void ut_init_state(struct unit_test_state *uts);
|
||||
|
||||
/**
|
||||
* ut_uninit_state() - Free memory used by test state
|
||||
*
|
||||
* This must be called before after the test state with ut_run_tests(). To later
|
||||
* reuse the test state to run more tests, call test_state_init() first
|
||||
*
|
||||
* @uts: Test state to uninit
|
||||
*/
|
||||
void ut_uninit_state(struct unit_test_state *uts);
|
||||
|
||||
/**
|
||||
* ut_run_tests() - Run a set of tests
|
||||
*
|
||||
* This runs the test, handling any preparation and clean-up needed. It prints
|
||||
* the name of each test before running it.
|
||||
*
|
||||
* @uts: Unit-test state, which must be ready for use, i.e. ut_init_state()
|
||||
* has been called. The caller is responsible for calling
|
||||
* ut_uninit_state() after this function returns
|
||||
* @category: Category of these tests. This is a string printed at the start to
|
||||
* announce the the number of tests
|
||||
* @prefix: String prefix for the tests. Any tests that have this prefix will be
|
||||
|
@ -503,8 +525,9 @@ void ut_set_state(struct unit_test_state *uts);
|
|||
* Pass NULL to disable this
|
||||
* Return: 0 if all tests passed, -1 if any failed
|
||||
*/
|
||||
int ut_run_list(const char *name, const char *prefix, struct unit_test *tests,
|
||||
int count, const char *select_name, int runs_per_test,
|
||||
bool force_run, const char *test_insert);
|
||||
int ut_run_list(struct unit_test_state *uts, const char *category,
|
||||
const char *prefix, struct unit_test *tests, int count,
|
||||
const char *select_name, int runs_per_test, bool force_run,
|
||||
const char *test_insert);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -21,6 +21,7 @@ int cmd_ut_category(const char *name, const char *prefix,
|
|||
struct unit_test *tests, int n_ents,
|
||||
int argc, char *const argv[])
|
||||
{
|
||||
struct unit_test_state uts;
|
||||
const char *test_insert = NULL;
|
||||
int runs_per_text = 1;
|
||||
bool force_run = false;
|
||||
|
@ -44,9 +45,11 @@ int cmd_ut_category(const char *name, const char *prefix,
|
|||
argc--;
|
||||
}
|
||||
|
||||
ret = ut_run_list(name, prefix, tests, n_ents,
|
||||
ut_init_state(&uts);
|
||||
ret = ut_run_list(&uts, name, prefix, tests, n_ents,
|
||||
cmd_arg1(argc, argv), runs_per_text, force_run,
|
||||
test_insert);
|
||||
ut_uninit_state(&uts);
|
||||
|
||||
return ret ? CMD_RET_FAILURE : 0;
|
||||
}
|
||||
|
|
|
@ -673,15 +673,15 @@ static int ut_run_tests(struct unit_test_state *uts, const char *prefix,
|
|||
return uts->fail_count ? -EBADF : 0;
|
||||
}
|
||||
|
||||
int ut_run_list(const char *category, const char *prefix,
|
||||
struct unit_test *tests, int count, const char *select_name,
|
||||
int runs_per_test, bool force_run, const char *test_insert)
|
||||
int ut_run_list(struct unit_test_state *uts, const char *category,
|
||||
const char *prefix, struct unit_test *tests, int count,
|
||||
const char *select_name, int runs_per_test, bool force_run,
|
||||
const char *test_insert)
|
||||
{
|
||||
struct unit_test_state uts;
|
||||
;
|
||||
bool has_dm_tests = false;
|
||||
int ret;
|
||||
|
||||
ut_init_state(&uts);
|
||||
if (!CONFIG_IS_ENABLED(OF_PLATDATA) &&
|
||||
ut_list_has_dm_tests(tests, count, prefix, select_name)) {
|
||||
has_dm_tests = true;
|
||||
|
@ -699,32 +699,31 @@ int ut_run_list(const char *category, const char *prefix,
|
|||
if (!select_name)
|
||||
printf("Running %d %s tests\n", count, category);
|
||||
|
||||
uts.of_root = gd_of_root();
|
||||
uts.runs_per_test = runs_per_test;
|
||||
uts->of_root = gd_of_root();
|
||||
uts->runs_per_test = runs_per_test;
|
||||
if (fdt_action() == FDTCHK_COPY && gd->fdt_blob) {
|
||||
uts.fdt_size = fdt_totalsize(gd->fdt_blob);
|
||||
uts.fdt_copy = os_malloc(uts.fdt_size);
|
||||
if (!uts.fdt_copy) {
|
||||
uts->fdt_size = fdt_totalsize(gd->fdt_blob);
|
||||
uts->fdt_copy = os_malloc(uts->fdt_size);
|
||||
if (!uts->fdt_copy) {
|
||||
printf("Out of memory for device tree copy\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
memcpy(uts.fdt_copy, gd->fdt_blob, uts.fdt_size);
|
||||
memcpy(uts->fdt_copy, gd->fdt_blob, uts->fdt_size);
|
||||
}
|
||||
uts.force_run = force_run;
|
||||
ret = ut_run_tests(&uts, prefix, tests, count, select_name,
|
||||
uts->force_run = force_run;
|
||||
ret = ut_run_tests(uts, prefix, tests, count, select_name,
|
||||
test_insert);
|
||||
|
||||
/* Best efforts only...ignore errors */
|
||||
if (has_dm_tests)
|
||||
dm_test_restore(uts.of_root);
|
||||
dm_test_restore(uts->of_root);
|
||||
|
||||
if (uts.skip_count)
|
||||
printf("Skipped: %d, ", uts.skip_count);
|
||||
if (uts->skip_count)
|
||||
printf("Skipped: %d, ", uts->skip_count);
|
||||
if (ret == -ENOENT)
|
||||
printf("Test '%s' not found\n", select_name);
|
||||
else
|
||||
printf("Failures: %d\n", uts.fail_count);
|
||||
ut_uninit_state(&uts);
|
||||
printf("Failures: %d\n", uts->fail_count);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue