blob: 2df29f3d15b25aae624e85b1707db5655930cc85 [file] [log] [blame]
Jean-Jacques Hiblot07e33712019-07-05 09:33:57 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Test for the NOP uclass
4 *
5 * (C) Copyright 2019 - Texas Instruments Incorporated - http://www.ti.com/
6 * Jean-Jacques Hiblot <jjhiblot@ti.com>
7 */
8
9#include <common.h>
10#include <dm.h>
11#include <dm/ofnode.h>
12#include <dm/lists.h>
13#include <dm/device.h>
14#include <dm/test.h>
15#include <misc.h>
16#include <test/ut.h>
17
18static int noptest_bind(struct udevice *parent)
19{
20 ofnode ofnode = dev_read_first_subnode(parent);
21
22 while (ofnode_valid(ofnode)) {
23 struct udevice *dev;
24 const char *bind_flag = ofnode_read_string(ofnode, "bind");
25
26 if (bind_flag && (strcmp(bind_flag, "True") == 0))
27 lists_bind_fdt(parent, ofnode, &dev, false);
28 ofnode = dev_read_next_subnode(ofnode);
29 }
30
31 return 0;
32}
33
34static const struct udevice_id noptest1_ids[] = {
35 {
36 .compatible = "sandbox,nop_sandbox1",
37 },
38 { }
39};
40
41U_BOOT_DRIVER(noptest_drv1) = {
42 .name = "noptest1_drv",
43 .of_match = noptest1_ids,
44 .id = UCLASS_NOP,
45 .bind = noptest_bind,
46};
47
48static const struct udevice_id noptest2_ids[] = {
49 {
50 .compatible = "sandbox,nop_sandbox2",
51 },
52 { }
53};
54
55U_BOOT_DRIVER(noptest_drv2) = {
56 .name = "noptest2_drv",
57 .of_match = noptest2_ids,
58 .id = UCLASS_NOP,
59};
60
61static int dm_test_nop(struct unit_test_state *uts)
62{
63 struct udevice *dev;
64
65 ut_assertok(uclass_get_device_by_name(UCLASS_NOP, "nop-test_0", &dev));
66 ut_assertok(uclass_get_device_by_name(UCLASS_NOP, "nop-test_1", &dev));
67 ut_asserteq(-ENODEV,
68 uclass_get_device_by_name(UCLASS_NOP, "nop-test_2", &dev));
69
70 return 0;
71}
72
73DM_TEST(dm_test_nop, DM_TESTF_FLAT_TREE | DM_TESTF_SCAN_FDT);