test: Allow SPL to run any available test

At present SPL only runs driver model tests. Update it to run all
available tests, i.e. in any test suite.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass 2021-03-07 17:35:12 -07:00 committed by Tom Rini
parent 2a2814d5f2
commit 8482356f48
4 changed files with 33 additions and 18 deletions

View File

@ -13,7 +13,7 @@
#include <asm/global_data.h>
#include <asm/spl.h>
#include <asm/state.h>
#include <test/test.h>
#include <test/ut.h>
DECLARE_GLOBAL_DATA_PTR;
@ -63,9 +63,12 @@ void spl_board_init(void)
preloader_console_init();
if (state->run_unittests) {
struct unit_test *tests = UNIT_TEST_ALL_START();
const int count = UNIT_TEST_ALL_COUNT();
int ret;
ret = dm_test_run(state->select_unittests);
ret = ut_run_list("spl", NULL, tests, count,
state->select_unittests);
/* continue execution into U-Boot */
}
}

View File

@ -99,6 +99,11 @@ struct unit_test {
#define UNIT_TEST_SUITE_COUNT(_suite) \
ll_entry_count(struct unit_test, ut_ ## _suite)
/* Use ! and ~ so that all tests will be sorted between these two values */
#define UNIT_TEST_ALL_START() ll_entry_start(struct unit_test, ut_!)
#define UNIT_TEST_ALL_END() ll_entry_start(struct unit_test, ut_~)
#define UNIT_TEST_ALL_COUNT() (UNIT_TEST_ALL_END() - UNIT_TEST_ALL_START())
/* Sizes for devres tests */
enum {
TEST_DEVRES_SIZE = 100,
@ -119,15 +124,4 @@ enum {
*/
struct udevice *testbus_get_clear_removed(void);
/**
* dm_test_run() - Run driver model tests
*
* Run all the available driver model tests, or a selection
*
* @test_name: Name of single test to run (e.g. "dm_test_fdt_pre_reloc" or just
* "fdt_pre_reloc"), or NULL to run all
* @return 0 if all tests passed, 1 if not
*/
int dm_test_run(const char *test_name);
#endif /* __TEST_TEST_H */

View File

@ -20,7 +20,16 @@
DECLARE_GLOBAL_DATA_PTR;
int dm_test_run(const char *test_name)
/**
* dm_test_run() - Run driver model tests
*
* Run all the available driver model tests, or a selection
*
* @test_name: Name of single test to run (e.g. "dm_test_fdt_pre_reloc" or just
* "fdt_pre_reloc"), or NULL to run all
* @return 0 if all tests passed, 1 if not
*/
static int dm_test_run(const char *test_name)
{
struct unit_test *tests = UNIT_TEST_SUITE_START(dm_test);
const int n_ents = UNIT_TEST_SUITE_COUNT(dm_test);

View File

@ -119,7 +119,8 @@ static bool ut_test_run_on_flattree(struct unit_test *test)
*
* @prefix: String prefix for the tests. Any tests that have this prefix will be
* printed without the prefix, so that it is easier to see the unique part
* of the test name. If NULL, no prefix processing is done
* of the test name. If NULL, any suite name (xxx_test) is considered to be
* a prefix.
* @test_name: Name of current test
* @select_name: Name of test to run (or NULL for all)
* @return true to run this test, false to skip it
@ -133,9 +134,17 @@ static bool test_matches(const char *prefix, const char *test_name,
if (!strcmp(test_name, select_name))
return true;
/* All tests have this prefix */
if (prefix && !strncmp(test_name, prefix, strlen(prefix)))
test_name += strlen(prefix);
if (!prefix) {
const char *p = strstr(test_name, "_test_");
/* convert xxx_test_yyy to yyy, i.e. remove the suite name */
if (p)
test_name = p + 6;
} else {
/* All tests have this prefix */
if (!strncmp(test_name, prefix, strlen(prefix)))
test_name += strlen(prefix);
}
if (!strcmp(test_name, select_name))
return true;