blob: 75b9e7b6cc0b489e986412e52cfec476a1cea5a5 [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>
Simon Glass0e1fad42020-07-19 10:15:37 -060016#include <test/test.h>
Jean-Jacques Hiblot07e33712019-07-05 09:33:57 +020017#include <test/ut.h>
18
19static int noptest_bind(struct udevice *parent)
20{
21 ofnode ofnode = dev_read_first_subnode(parent);
22
23 while (ofnode_valid(ofnode)) {
24 struct udevice *dev;
25 const char *bind_flag = ofnode_read_string(ofnode, "bind");
26
27 if (bind_flag && (strcmp(bind_flag, "True") == 0))
Patrice Chotard38f7d3b2021-09-10 16:16:20 +020028 lists_bind_fdt(parent, ofnode, &dev, NULL, false);
Jean-Jacques Hiblot07e33712019-07-05 09:33:57 +020029 ofnode = dev_read_next_subnode(ofnode);
30 }
31
32 return 0;
33}
34
35static const struct udevice_id noptest1_ids[] = {
36 {
37 .compatible = "sandbox,nop_sandbox1",
38 },
39 { }
40};
41
42U_BOOT_DRIVER(noptest_drv1) = {
43 .name = "noptest1_drv",
44 .of_match = noptest1_ids,
45 .id = UCLASS_NOP,
46 .bind = noptest_bind,
47};
48
49static const struct udevice_id noptest2_ids[] = {
50 {
51 .compatible = "sandbox,nop_sandbox2",
52 },
53 { }
54};
55
56U_BOOT_DRIVER(noptest_drv2) = {
57 .name = "noptest2_drv",
58 .of_match = noptest2_ids,
59 .id = UCLASS_NOP,
60};
61
62static int dm_test_nop(struct unit_test_state *uts)
63{
64 struct udevice *dev;
65
66 ut_assertok(uclass_get_device_by_name(UCLASS_NOP, "nop-test_0", &dev));
67 ut_assertok(uclass_get_device_by_name(UCLASS_NOP, "nop-test_1", &dev));
68 ut_asserteq(-ENODEV,
69 uclass_get_device_by_name(UCLASS_NOP, "nop-test_2", &dev));
70
71 return 0;
72}
73
Simon Glasse180c2b2020-07-28 19:41:12 -060074DM_TEST(dm_test_nop, UT_TESTF_FLAT_TREE | UT_TESTF_SCAN_FDT);