platform_device_mock.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Fake platform device API for unit testing platform drivers.
  4. *
  5. * Copyright (C) 2018, Google LLC.
  6. * Author: Brendan Higgins <[email protected]>
  7. */
  8. #include <linux/platform_device.h>
  9. #include <kunit/mock.h>
  10. static inline struct platform_driver *platform_driver_find(const char *name)
  11. {
  12. struct device_driver *driver;
  13. driver = driver_find(name, &platform_bus_type);
  14. if (!driver)
  15. return NULL;
  16. return to_platform_driver(driver);
  17. }
  18. /**
  19. * of_fake_node()
  20. * @test: the test to associate node with
  21. * @name: name of the node
  22. *
  23. * The &struct device_node returned is allocated as a root node with the given
  24. * name and otherwise behaves as a real &struct device_node.
  25. *
  26. * Returns: the faked &struct device_node
  27. */
  28. struct device_node *of_fake_node(struct kunit *test, const char *name);
  29. /**
  30. * of_fake_probe_platform()
  31. * @test: the test to associate the fake platform device with
  32. * @driver: driver to probe
  33. * @node_name: name of the device node created
  34. *
  35. * Creates a &struct platform_device and an associated &struct device_node,
  36. * probes the provided &struct platform_driver with the &struct platform_device.
  37. *
  38. * Returns: the &struct platform_device that was created
  39. */
  40. struct platform_device *
  41. of_fake_probe_platform(struct kunit *test,
  42. struct platform_driver *driver,
  43. const char *node_name);
  44. /**
  45. * of_fake_probe_platform_by_name()
  46. * @test: the test to associate the fake platform device with
  47. * @driver_name: name of the driver to probe
  48. * @node_name: name of the device node created
  49. *
  50. * Same as of_fake_probe_platform() but looks up the &struct platform_driver by
  51. * the provided name.
  52. *
  53. * Returns: the &struct platform_device that was created
  54. */
  55. struct platform_device *of_fake_probe_platform_by_name(struct kunit *test,
  56. const char *driver_name,
  57. const char *node_name);