blob: 0c79431d9d80226aea8047b88622d5715d83ac95 [file] [log] [blame]
Jean-Jacques Hiblotdb97c7f2019-07-05 09:33:57 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Test for the NOP uclass
4 *
Nishanth Menoneaa39c62023-11-01 15:56:03 -05005 * (C) Copyright 2019 - Texas Instruments Incorporated - https://www.ti.com/
Jean-Jacques Hiblotdb97c7f2019-07-05 09:33:57 +02006 * Jean-Jacques Hiblot <jjhiblot@ti.com>
7 */
8
Jean-Jacques Hiblotdb97c7f2019-07-05 09:33:57 +02009#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>
Simon Glass75c4d412020-07-19 10:15:37 -060015#include <test/test.h>
Jean-Jacques Hiblotdb97c7f2019-07-05 09:33:57 +020016#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))
Patrice Chotardcc523cf2021-09-10 16:16:20 +020027 lists_bind_fdt(parent, ofnode, &dev, NULL, false);
Jean-Jacques Hiblotdb97c7f2019-07-05 09:33:57 +020028 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
Simon Glass974dccd2020-07-28 19:41:12 -060073DM_TEST(dm_test_nop, UT_TESTF_FLAT_TREE | UT_TESTF_SCAN_FDT);