test-dm.c 1.7 KB
Newer Older
1
// SPDX-License-Identifier: GPL-2.0+
S
Simon Glass 已提交
2 3 4 5 6
/*
 * Copyright (c) 2013 Google, Inc
 */

#include <common.h>
7
#include <command.h>
8
#include <console.h>
S
Simon Glass 已提交
9 10
#include <dm.h>
#include <errno.h>
11
#include <log.h>
12
#include <malloc.h>
13
#include <asm/global_data.h>
14
#include <asm/state.h>
S
Simon Glass 已提交
15 16
#include <dm/root.h>
#include <dm/uclass-internal.h>
17 18
#include <test/test.h>
#include <test/test.h>
19
#include <test/ut.h>
S
Simon Glass 已提交
20 21 22

DECLARE_GLOBAL_DATA_PTR;

23
struct unit_test_state global_dm_test_state;
24

25
int dm_test_run(const char *test_name)
S
Simon Glass 已提交
26
{
27 28
	struct unit_test *tests = ll_entry_start(struct unit_test, dm_test);
	const int n_ents = ll_entry_count(struct unit_test, dm_test);
29
	struct unit_test_state uts_s = { .fail_count = 0 }, *uts = &uts_s;
30
	struct device_node *of_root;
S
Simon Glass 已提交
31

32 33
	uts->fail_count = 0;

34 35 36 37 38 39 40 41 42 43
	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);
		}
S
Simon Glass 已提交
44 45
	}

46 47
	of_root = gd_of_root();
	ut_run_list("driver model", "dm_test_", tests, n_ents, test_name);
S
Simon Glass 已提交
48

49
	/* Put everything back to normal so that sandbox works as expected */
50
	gd_set_of_root(of_root);
51
	gd->dm_root = NULL;
52
	ut_assertok(dm_init(CONFIG_IS_ENABLED(OF_LIVE)));
53
	dm_scan_plat(false);
54
	if (!CONFIG_IS_ENABLED(OF_PLATDATA))
55
		dm_scan_fdt(false);
56

57
	return uts->fail_count ? CMD_RET_FAILURE : 0;
S
Simon Glass 已提交
58
}
59

60
int do_ut_dm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
61 62 63 64 65 66
{
	const char *test_name = NULL;

	if (argc > 1)
		test_name = argv[1];

67
	return dm_test_run(test_name);
68
}