dsa.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright 2020-2021 NXP Semiconductors
  4. */
  5. #include <net/dsa.h>
  6. #include <dm/test.h>
  7. #include <test/ut.h>
  8. #include <net.h>
  9. #include <dm/uclass-internal.h>
  10. #include <dm/device-internal.h>
  11. /* This test exercises the major dsa.h API functions, after making sure
  12. * that the DSA ports and the master Eth are correctly probed.
  13. */
  14. static int dm_test_dsa_probe(struct unit_test_state *uts)
  15. {
  16. struct udevice *dev_dsa, *dev_port, *dev_master;
  17. struct dsa_pdata *dsa_pdata;
  18. enum uclass_id id;
  19. id = uclass_get_by_name("dsa");
  20. ut_assert(id == UCLASS_DSA);
  21. ut_assertok(uclass_find_device_by_name(UCLASS_DSA, "dsa-test",
  22. &dev_dsa));
  23. ut_assertok(uclass_find_device_by_name(UCLASS_ETH, "dsa-test-eth",
  24. &dev_master));
  25. ut_assertok(device_probe(dev_master));
  26. ut_assertok(uclass_find_device_by_name(UCLASS_ETH, "dsa-test@0",
  27. &dev_port));
  28. ut_assertok(device_probe(dev_port));
  29. ut_assertok(uclass_find_device_by_name(UCLASS_ETH, "dsa-test@1",
  30. &dev_port));
  31. ut_assertok(device_probe(dev_port));
  32. /* exercise DSA API */
  33. dsa_pdata = dev_get_uclass_plat(dev_dsa);
  34. ut_assertnonnull(dsa_pdata);
  35. /* includes CPU port */
  36. ut_assert(dsa_pdata->num_ports == 3);
  37. ut_assertok(uclass_find_device_by_name(UCLASS_ETH, "lan0",
  38. &dev_port));
  39. ut_assertok(device_probe(dev_port));
  40. ut_assertok(uclass_find_device_by_name(UCLASS_ETH, "lan1",
  41. &dev_port));
  42. ut_assertok(device_probe(dev_port));
  43. dev_master = dsa_get_master(dev_dsa);
  44. ut_assertnonnull(dev_master);
  45. ut_asserteq_str("dsa-test-eth", dev_master->name);
  46. return 0;
  47. }
  48. DM_TEST(dm_test_dsa_probe, UT_TESTF_SCAN_FDT);
  49. /* This test sends ping requests with the local address through each DSA port
  50. * via the sandbox DSA master Eth.
  51. */
  52. static int dm_test_dsa(struct unit_test_state *uts)
  53. {
  54. net_ping_ip = string_to_ip("1.2.3.5");
  55. env_set("ethact", "eth2");
  56. ut_assertok(net_loop(PING));
  57. env_set("ethact", "lan0");
  58. ut_assertok(net_loop(PING));
  59. env_set("ethact", "lan1");
  60. ut_assertok(net_loop(PING));
  61. env_set("ethact", "");
  62. return 0;
  63. }
  64. DM_TEST(dm_test_dsa, UT_TESTF_SCAN_FDT);