2018-05-07 06:58:06 +09:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2014-02-27 07:59:21 +09:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2013 Google, Inc
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2015-05-21 04:27:29 +09:00
|
|
|
#include <command.h>
|
2015-11-09 15:47:45 +09:00
|
|
|
#include <console.h>
|
2014-02-27 07:59:21 +09:00
|
|
|
#include <dm.h>
|
|
|
|
#include <errno.h>
|
2020-05-11 02:40:05 +09:00
|
|
|
#include <log.h>
|
2014-10-05 02:29:50 +09:00
|
|
|
#include <malloc.h>
|
2020-10-31 12:38:53 +09:00
|
|
|
#include <asm/global_data.h>
|
2015-11-09 15:47:44 +09:00
|
|
|
#include <asm/state.h>
|
2014-02-27 07:59:21 +09:00
|
|
|
#include <dm/root.h>
|
|
|
|
#include <dm/uclass-internal.h>
|
2020-07-20 01:15:37 +09:00
|
|
|
#include <test/test.h>
|
|
|
|
#include <test/test.h>
|
2015-05-21 04:27:27 +09:00
|
|
|
#include <test/ut.h>
|
2014-02-27 07:59:21 +09:00
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2020-10-04 02:31:40 +09:00
|
|
|
static bool test_matches(const char *test_name, const char *find_name)
|
|
|
|
{
|
|
|
|
if (!find_name)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (!strcmp(test_name, find_name))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
/* All tests have this prefix */
|
|
|
|
if (!strncmp(test_name, "dm_test_", 8))
|
|
|
|
test_name += 8;
|
|
|
|
|
|
|
|
if (!strcmp(test_name, find_name))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-03-08 09:34:46 +09:00
|
|
|
int dm_test_run(const char *test_name)
|
2014-02-27 07:59:21 +09:00
|
|
|
{
|
2015-05-21 04:27:27 +09:00
|
|
|
struct unit_test *tests = ll_entry_start(struct unit_test, dm_test);
|
|
|
|
const int n_ents = ll_entry_count(struct unit_test, dm_test);
|
2021-03-08 09:35:04 +09:00
|
|
|
struct unit_test_state uts_s = { .fail_count = 0 }, *uts = &uts_s;
|
2015-05-21 04:27:27 +09:00
|
|
|
struct unit_test *test;
|
2019-09-25 23:55:52 +09:00
|
|
|
int found;
|
2014-02-27 07:59:21 +09:00
|
|
|
|
2016-01-28 15:57:46 +09:00
|
|
|
uts->fail_count = 0;
|
|
|
|
|
2020-10-26 11:38:27 +09:00
|
|
|
if (!CONFIG_IS_ENABLED(OF_PLATDATA)) {
|
|
|
|
/*
|
|
|
|
* If we have no device tree, or it only has a root node, then
|
|
|
|
* these * tests clearly aren't going to work...
|
|
|
|
*/
|
|
|
|
if (!gd->fdt_blob || fdt_next_node(gd->fdt_blob, 0, NULL) < 0) {
|
|
|
|
puts("Please run with test device tree:\n"
|
|
|
|
" ./u-boot -d arch/sandbox/dts/test.dtb\n");
|
|
|
|
ut_assert(gd->fdt_blob);
|
|
|
|
}
|
2014-02-27 07:59:21 +09:00
|
|
|
}
|
|
|
|
|
2015-03-26 03:23:04 +09:00
|
|
|
if (!test_name)
|
|
|
|
printf("Running %d driver model tests\n", n_ents);
|
2020-10-04 02:31:40 +09:00
|
|
|
else
|
2014-02-27 07:59:21 +09:00
|
|
|
|
2019-09-25 23:55:52 +09:00
|
|
|
found = 0;
|
2020-10-04 00:25:22 +09:00
|
|
|
uts->of_root = gd_of_root();
|
2014-02-27 07:59:21 +09:00
|
|
|
for (test = tests; test < tests + n_ents; test++) {
|
2015-07-07 03:54:23 +09:00
|
|
|
const char *name = test->name;
|
|
|
|
|
2020-10-04 02:31:40 +09:00
|
|
|
if (!test_matches(name, test_name))
|
2015-03-26 03:23:04 +09:00
|
|
|
continue;
|
2017-05-19 11:09:17 +09:00
|
|
|
|
2021-03-08 09:35:03 +09:00
|
|
|
ut_assertok(ut_run_test_live_flat(uts, test, test->name));
|
2019-09-25 23:55:52 +09:00
|
|
|
found++;
|
2014-02-27 07:59:21 +09:00
|
|
|
}
|
|
|
|
|
2019-09-25 23:55:52 +09:00
|
|
|
if (test_name && !found)
|
2015-07-07 03:54:23 +09:00
|
|
|
printf("Test '%s' not found\n", test_name);
|
|
|
|
else
|
|
|
|
printf("Failures: %d\n", uts->fail_count);
|
2014-02-27 07:59:21 +09:00
|
|
|
|
2019-09-25 23:55:51 +09:00
|
|
|
/* Put everything back to normal so that sandbox works as expected */
|
2020-10-04 00:25:22 +09:00
|
|
|
gd_set_of_root(uts->of_root);
|
2015-05-21 04:27:35 +09:00
|
|
|
gd->dm_root = NULL;
|
2020-10-04 00:25:22 +09:00
|
|
|
ut_assertok(dm_init(CONFIG_IS_ENABLED(OF_LIVE)));
|
2020-12-04 08:55:23 +09:00
|
|
|
dm_scan_plat(false);
|
2020-10-26 11:38:27 +09:00
|
|
|
if (!CONFIG_IS_ENABLED(OF_PLATDATA))
|
2020-11-29 09:50:09 +09:00
|
|
|
dm_scan_fdt(false);
|
2015-05-21 04:27:35 +09:00
|
|
|
|
2015-05-21 04:27:32 +09:00
|
|
|
return uts->fail_count ? CMD_RET_FAILURE : 0;
|
2014-02-27 07:59:21 +09:00
|
|
|
}
|
2015-05-21 04:27:29 +09:00
|
|
|
|
2020-05-11 02:40:03 +09:00
|
|
|
int do_ut_dm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
|
2015-05-21 04:27:29 +09:00
|
|
|
{
|
|
|
|
const char *test_name = NULL;
|
|
|
|
|
|
|
|
if (argc > 1)
|
|
|
|
test_name = argv[1];
|
|
|
|
|
2021-03-08 09:34:46 +09:00
|
|
|
return dm_test_run(test_name);
|
2015-05-21 04:27:29 +09:00
|
|
|
}
|