nop.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. #include <common.h>
  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>
  15. #include <test/test.h>
  16. #include <test/ut.h>
  17. static int noptest_bind(struct udevice *parent)
  18. {
  19. ofnode ofnode = dev_read_first_subnode(parent);
  20. while (ofnode_valid(ofnode)) {
  21. struct udevice *dev;
  22. const char *bind_flag = ofnode_read_string(ofnode, "bind");
  23. if (bind_flag && (strcmp(bind_flag, "True") == 0))
  24. lists_bind_fdt(parent, ofnode, &dev, false);
  25. ofnode = dev_read_next_subnode(ofnode);
  26. }
  27. return 0;
  28. }
  29. static const struct udevice_id noptest1_ids[] = {
  30. {
  31. .compatible = "sandbox,nop_sandbox1",
  32. },
  33. { }
  34. };
  35. U_BOOT_DRIVER(noptest_drv1) = {
  36. .name = "noptest1_drv",
  37. .of_match = noptest1_ids,
  38. .id = UCLASS_NOP,
  39. .bind = noptest_bind,
  40. };
  41. static const struct udevice_id noptest2_ids[] = {
  42. {
  43. .compatible = "sandbox,nop_sandbox2",
  44. },
  45. { }
  46. };
  47. U_BOOT_DRIVER(noptest_drv2) = {
  48. .name = "noptest2_drv",
  49. .of_match = noptest2_ids,
  50. .id = UCLASS_NOP,
  51. };
  52. static int dm_test_nop(struct unit_test_state *uts)
  53. {
  54. struct udevice *dev;
  55. ut_assertok(uclass_get_device_by_name(UCLASS_NOP, "nop-test_0", &dev));
  56. ut_assertok(uclass_get_device_by_name(UCLASS_NOP, "nop-test_1", &dev));
  57. ut_asserteq(-ENODEV,
  58. uclass_get_device_by_name(UCLASS_NOP, "nop-test_2", &dev));
  59. return 0;
  60. }
  61. DM_TEST(dm_test_nop, UT_TESTF_FLAT_TREE | UT_TESTF_SCAN_FDT);