Jean-Jacques Hiblot | 07e3371 | 2019-07-05 09:33:57 +0200 | [diff] [blame] | 1 | // 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 Glass | 0e1fad4 | 2020-07-19 10:15:37 -0600 | [diff] [blame] | 16 | #include <test/test.h> |
Jean-Jacques Hiblot | 07e3371 | 2019-07-05 09:33:57 +0200 | [diff] [blame] | 17 | #include <test/ut.h> |
| 18 | |
| 19 | static 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)) |
| 28 | lists_bind_fdt(parent, ofnode, &dev, false); |
| 29 | ofnode = dev_read_next_subnode(ofnode); |
| 30 | } |
| 31 | |
| 32 | return 0; |
| 33 | } |
| 34 | |
| 35 | static const struct udevice_id noptest1_ids[] = { |
| 36 | { |
| 37 | .compatible = "sandbox,nop_sandbox1", |
| 38 | }, |
| 39 | { } |
| 40 | }; |
| 41 | |
| 42 | U_BOOT_DRIVER(noptest_drv1) = { |
| 43 | .name = "noptest1_drv", |
| 44 | .of_match = noptest1_ids, |
| 45 | .id = UCLASS_NOP, |
| 46 | .bind = noptest_bind, |
| 47 | }; |
| 48 | |
| 49 | static const struct udevice_id noptest2_ids[] = { |
| 50 | { |
| 51 | .compatible = "sandbox,nop_sandbox2", |
| 52 | }, |
| 53 | { } |
| 54 | }; |
| 55 | |
| 56 | U_BOOT_DRIVER(noptest_drv2) = { |
| 57 | .name = "noptest2_drv", |
| 58 | .of_match = noptest2_ids, |
| 59 | .id = UCLASS_NOP, |
| 60 | }; |
| 61 | |
| 62 | static 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 Glass | e180c2b | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 74 | DM_TEST(dm_test_nop, UT_TESTF_FLAT_TREE | UT_TESTF_SCAN_FDT); |