Claudiu Manoil | d9eaa92 | 2021-03-14 20:14:57 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
Vladimir Oltean | 5041e42 | 2021-09-17 14:27:13 +0300 | [diff] [blame] | 3 | * Copyright 2020-2021 NXP |
Claudiu Manoil | d9eaa92 | 2021-03-14 20:14:57 +0800 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <net/dsa.h> |
| 7 | #include <dm/test.h> |
| 8 | #include <test/ut.h> |
| 9 | #include <net.h> |
| 10 | #include <dm/uclass-internal.h> |
| 11 | #include <dm/device-internal.h> |
| 12 | |
| 13 | /* This test exercises the major dsa.h API functions, after making sure |
| 14 | * that the DSA ports and the master Eth are correctly probed. |
| 15 | */ |
| 16 | static int dm_test_dsa_probe(struct unit_test_state *uts) |
| 17 | { |
| 18 | struct udevice *dev_dsa, *dev_port, *dev_master; |
| 19 | struct dsa_pdata *dsa_pdata; |
| 20 | enum uclass_id id; |
| 21 | |
| 22 | id = uclass_get_by_name("dsa"); |
| 23 | ut_assert(id == UCLASS_DSA); |
| 24 | |
| 25 | ut_assertok(uclass_find_device_by_name(UCLASS_DSA, "dsa-test", |
| 26 | &dev_dsa)); |
| 27 | ut_assertok(uclass_find_device_by_name(UCLASS_ETH, "dsa-test-eth", |
| 28 | &dev_master)); |
| 29 | ut_assertok(device_probe(dev_master)); |
| 30 | |
| 31 | ut_assertok(uclass_find_device_by_name(UCLASS_ETH, "dsa-test@0", |
| 32 | &dev_port)); |
| 33 | ut_assertok(device_probe(dev_port)); |
| 34 | |
| 35 | ut_assertok(uclass_find_device_by_name(UCLASS_ETH, "dsa-test@1", |
| 36 | &dev_port)); |
| 37 | ut_assertok(device_probe(dev_port)); |
| 38 | |
| 39 | /* exercise DSA API */ |
| 40 | dsa_pdata = dev_get_uclass_plat(dev_dsa); |
| 41 | ut_assertnonnull(dsa_pdata); |
| 42 | /* includes CPU port */ |
| 43 | ut_assert(dsa_pdata->num_ports == 3); |
| 44 | |
| 45 | ut_assertok(uclass_find_device_by_name(UCLASS_ETH, "lan0", |
| 46 | &dev_port)); |
| 47 | ut_assertok(device_probe(dev_port)); |
| 48 | |
| 49 | ut_assertok(uclass_find_device_by_name(UCLASS_ETH, "lan1", |
| 50 | &dev_port)); |
| 51 | ut_assertok(device_probe(dev_port)); |
| 52 | |
| 53 | dev_master = dsa_get_master(dev_dsa); |
| 54 | ut_assertnonnull(dev_master); |
| 55 | ut_asserteq_str("dsa-test-eth", dev_master->name); |
| 56 | |
| 57 | return 0; |
| 58 | } |
Simon Glass | 1a92f83 | 2024-08-22 07:57:48 -0600 | [diff] [blame] | 59 | DM_TEST(dm_test_dsa_probe, UTF_SCAN_FDT); |
Claudiu Manoil | d9eaa92 | 2021-03-14 20:14:57 +0800 | [diff] [blame] | 60 | |
| 61 | /* This test sends ping requests with the local address through each DSA port |
| 62 | * via the sandbox DSA master Eth. |
| 63 | */ |
| 64 | static int dm_test_dsa(struct unit_test_state *uts) |
| 65 | { |
| 66 | net_ping_ip = string_to_ip("1.2.3.5"); |
| 67 | |
| 68 | env_set("ethact", "eth2"); |
| 69 | ut_assertok(net_loop(PING)); |
| 70 | |
| 71 | env_set("ethact", "lan0"); |
| 72 | ut_assertok(net_loop(PING)); |
| 73 | env_set("ethact", "lan1"); |
| 74 | ut_assertok(net_loop(PING)); |
| 75 | |
| 76 | env_set("ethact", ""); |
| 77 | |
| 78 | return 0; |
| 79 | } |
Simon Glass | 1a92f83 | 2024-08-22 07:57:48 -0600 | [diff] [blame] | 80 | DM_TEST(dm_test_dsa, UTF_SCAN_FDT); |