1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
6 #include <rte_ethdev.h>
13 test_link_status_up_default(void)
16 struct rte_eth_link link_status = {
17 .link_speed = ETH_SPEED_NUM_2_5G,
18 .link_status = ETH_LINK_UP,
19 .link_autoneg = ETH_LINK_AUTONEG,
20 .link_duplex = ETH_LINK_FULL_DUPLEX
22 char text[RTE_ETH_LINK_MAX_STR_LEN];
24 ret = rte_eth_link_to_str(text, sizeof(text), &link_status);
25 RTE_TEST_ASSERT(ret > 0, "Failed to format default string\n");
26 printf("Default link up #1: %s\n", text);
27 TEST_ASSERT_BUFFERS_ARE_EQUAL("Link up at 2.5 Gbps FDX Autoneg",
28 text, strlen(text), "Invalid default link status string");
30 link_status.link_duplex = ETH_LINK_HALF_DUPLEX;
31 link_status.link_autoneg = ETH_LINK_FIXED;
32 link_status.link_speed = ETH_SPEED_NUM_10M,
33 ret = rte_eth_link_to_str(text, sizeof(text), &link_status);
34 printf("Default link up #2: %s\n", text);
35 RTE_TEST_ASSERT(ret > 0, "Failed to format default string\n");
36 TEST_ASSERT_BUFFERS_ARE_EQUAL("Link up at 10 Mbps HDX Fixed",
37 text, strlen(text), "Invalid default link status "
40 link_status.link_speed = ETH_SPEED_NUM_UNKNOWN;
41 ret = rte_eth_link_to_str(text, sizeof(text), &link_status);
42 printf("Default link up #3: %s\n", text);
43 RTE_TEST_ASSERT(ret > 0, "Failed to format default string\n");
44 TEST_ASSERT_BUFFERS_ARE_EQUAL("Link up at Unknown HDX Fixed",
45 text, strlen(text), "Invalid default link status "
48 link_status.link_speed = ETH_SPEED_NUM_NONE;
49 ret = rte_eth_link_to_str(text, sizeof(text), &link_status);
50 printf("Default link up #3: %s\n", text);
51 RTE_TEST_ASSERT(ret > 0, "Failed to format default string\n");
52 TEST_ASSERT_BUFFERS_ARE_EQUAL("Link up at None HDX Fixed",
53 text, strlen(text), "Invalid default link status "
56 /* test max str len */
57 link_status.link_speed = ETH_SPEED_NUM_200G;
58 link_status.link_duplex = ETH_LINK_HALF_DUPLEX;
59 link_status.link_autoneg = ETH_LINK_AUTONEG;
60 ret = rte_eth_link_to_str(text, sizeof(text), &link_status);
61 printf("Default link up #4:len = %d, %s\n", ret, text);
62 RTE_TEST_ASSERT(ret < RTE_ETH_LINK_MAX_STR_LEN,
63 "String length exceeds max allowed value\n");
68 test_link_status_down_default(void)
71 struct rte_eth_link link_status = {
72 .link_speed = ETH_SPEED_NUM_2_5G,
73 .link_status = ETH_LINK_DOWN,
74 .link_autoneg = ETH_LINK_AUTONEG,
75 .link_duplex = ETH_LINK_FULL_DUPLEX
77 char text[RTE_ETH_LINK_MAX_STR_LEN];
79 ret = rte_eth_link_to_str(text, sizeof(text), &link_status);
80 RTE_TEST_ASSERT(ret > 0, "Failed to format default string\n");
81 TEST_ASSERT_BUFFERS_ARE_EQUAL("Link down",
82 text, strlen(text), "Invalid default link status string");
88 test_link_status_invalid(void)
91 struct rte_eth_link link_status = {
93 .link_status = ETH_LINK_UP,
94 .link_autoneg = ETH_LINK_AUTONEG,
95 .link_duplex = ETH_LINK_FULL_DUPLEX
97 char text[RTE_ETH_LINK_MAX_STR_LEN];
99 ret = rte_eth_link_to_str(text, sizeof(text), &link_status);
100 RTE_TEST_ASSERT(ret < RTE_ETH_LINK_MAX_STR_LEN,
101 "Failed to format invalid string\n");
102 printf("invalid link up #1: len=%d %s\n", ret, text);
103 TEST_ASSERT_BUFFERS_ARE_EQUAL("Link up at Invalid FDX Autoneg",
104 text, strlen(text), "Incorrect invalid link status string");
111 test_link_speed_all_values(void)
115 struct link_speed_t {
118 } speed_str_map[] = {
119 { "None", ETH_SPEED_NUM_NONE },
120 { "10 Mbps", ETH_SPEED_NUM_10M },
121 { "100 Mbps", ETH_SPEED_NUM_100M },
122 { "1 Gbps", ETH_SPEED_NUM_1G },
123 { "2.5 Gbps", ETH_SPEED_NUM_2_5G },
124 { "5 Gbps", ETH_SPEED_NUM_5G },
125 { "10 Gbps", ETH_SPEED_NUM_10G },
126 { "20 Gbps", ETH_SPEED_NUM_20G },
127 { "25 Gbps", ETH_SPEED_NUM_25G },
128 { "40 Gbps", ETH_SPEED_NUM_40G },
129 { "50 Gbps", ETH_SPEED_NUM_50G },
130 { "56 Gbps", ETH_SPEED_NUM_56G },
131 { "100 Gbps", ETH_SPEED_NUM_100G },
132 { "200 Gbps", ETH_SPEED_NUM_200G },
133 { "Unknown", ETH_SPEED_NUM_UNKNOWN },
137 for (i = 0; i < sizeof(speed_str_map) / sizeof(struct link_speed_t);
139 speed = rte_eth_link_speed_to_str(speed_str_map[i].link_speed);
140 TEST_ASSERT_BUFFERS_ARE_EQUAL(speed_str_map[i].value,
141 speed, strlen(speed_str_map[i].value),
142 "Invalid link speed string");
147 static struct unit_test_suite link_status_testsuite = {
148 .suite_name = "link status formatting",
152 TEST_CASE(test_link_status_up_default),
153 TEST_CASE(test_link_status_down_default),
154 TEST_CASE(test_link_speed_all_values),
155 TEST_CASE(test_link_status_invalid),
156 TEST_CASES_END() /**< NULL terminate unit test array */
161 test_link_status(void)
163 rte_log_set_global_level(RTE_LOG_DEBUG);
164 rte_log_set_level(RTE_LOGTYPE_EAL, RTE_LOG_DEBUG);
166 return unit_test_suite_runner(&link_status_testsuite);
169 REGISTER_TEST_COMMAND(ethdev_link_status, test_link_status);