]>
Commit | Line | Data |
---|---|---|
07e33711 JJH |
1 | // SPDX-License-Identifier: GPL-2.0+ |
2 | /* | |
3 | * Test for the NOP uclass | |
4 | * | |
a94a4071 | 5 | * (C) Copyright 2019 - Texas Instruments Incorporated - https://www.ti.com/ |
07e33711 JJH |
6 | * Jean-Jacques Hiblot <jjhiblot@ti.com> |
7 | */ | |
8 | ||
07e33711 JJH |
9 | #include <dm.h> |
10 | #include <dm/ofnode.h> | |
11 | #include <dm/lists.h> | |
12 | #include <dm/device.h> | |
13 | #include <dm/test.h> | |
14 | #include <misc.h> | |
0e1fad43 | 15 | #include <test/test.h> |
07e33711 JJH |
16 | #include <test/ut.h> |
17 | ||
18 | static 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)) | |
38f7d3b6 | 27 | lists_bind_fdt(parent, ofnode, &dev, NULL, false); |
07e33711 JJH |
28 | ofnode = dev_read_next_subnode(ofnode); |
29 | } | |
30 | ||
31 | return 0; | |
32 | } | |
33 | ||
34 | static const struct udevice_id noptest1_ids[] = { | |
35 | { | |
36 | .compatible = "sandbox,nop_sandbox1", | |
37 | }, | |
38 | { } | |
39 | }; | |
40 | ||
41 | U_BOOT_DRIVER(noptest_drv1) = { | |
42 | .name = "noptest1_drv", | |
43 | .of_match = noptest1_ids, | |
44 | .id = UCLASS_NOP, | |
45 | .bind = noptest_bind, | |
46 | }; | |
47 | ||
48 | static const struct udevice_id noptest2_ids[] = { | |
49 | { | |
50 | .compatible = "sandbox,nop_sandbox2", | |
51 | }, | |
52 | { } | |
53 | }; | |
54 | ||
55 | U_BOOT_DRIVER(noptest_drv2) = { | |
56 | .name = "noptest2_drv", | |
57 | .of_match = noptest2_ids, | |
58 | .id = UCLASS_NOP, | |
59 | }; | |
60 | ||
61 | static 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 | ||
e180c2b1 | 73 | DM_TEST(dm_test_nop, UT_TESTF_FLAT_TREE | UT_TESTF_SCAN_FDT); |