Jean-Jacques Hiblot | db97c7f | 2019-07-05 09:33:57 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Test for the NOP uclass |
| 4 | * |
Nishanth Menon | eaa39c6 | 2023-11-01 15:56:03 -0500 | [diff] [blame] | 5 | * (C) Copyright 2019 - Texas Instruments Incorporated - https://www.ti.com/ |
Jean-Jacques Hiblot | db97c7f | 2019-07-05 09:33:57 +0200 | [diff] [blame] | 6 | * Jean-Jacques Hiblot <jjhiblot@ti.com> |
| 7 | */ |
| 8 | |
Jean-Jacques Hiblot | db97c7f | 2019-07-05 09:33:57 +0200 | [diff] [blame] | 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> |
Simon Glass | 75c4d41 | 2020-07-19 10:15:37 -0600 | [diff] [blame] | 15 | #include <test/test.h> |
Jean-Jacques Hiblot | db97c7f | 2019-07-05 09:33:57 +0200 | [diff] [blame] | 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)) |
Patrice Chotard | cc523cf | 2021-09-10 16:16:20 +0200 | [diff] [blame] | 27 | lists_bind_fdt(parent, ofnode, &dev, NULL, false); |
Jean-Jacques Hiblot | db97c7f | 2019-07-05 09:33:57 +0200 | [diff] [blame] | 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 | |
Simon Glass | 974dccd | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 73 | DM_TEST(dm_test_nop, UT_TESTF_FLAT_TREE | UT_TESTF_SCAN_FDT); |