bpf: allow self-xor operation
[dpdk.git] / app / test / test_ethdev_link.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
3  */
4
5 #include <rte_log.h>
6 #include <rte_ethdev.h>
7
8 #include <rte_test.h>
9 #include "test.h"
10
11
12 static int32_t
13 test_link_status_up_default(void)
14 {
15         int ret = 0;
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
21         };
22         char text[RTE_ETH_LINK_MAX_STR_LEN];
23
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");
29
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 "
38                 "string with HDX");
39
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 "
46                 "string with HDX");
47
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 "
54                 "string with HDX");
55
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");
64         return TEST_SUCCESS;
65 }
66
67 static int32_t
68 test_link_status_down_default(void)
69 {
70         int ret = 0;
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
76         };
77         char text[RTE_ETH_LINK_MAX_STR_LEN];
78
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");
83
84         return TEST_SUCCESS;
85 }
86
87 static int32_t
88 test_link_status_invalid(void)
89 {
90         int ret = 0;
91         struct rte_eth_link link_status = {
92                 .link_speed = 55555,
93                 .link_status = ETH_LINK_UP,
94                 .link_autoneg = ETH_LINK_AUTONEG,
95                 .link_duplex = ETH_LINK_FULL_DUPLEX
96         };
97         char text[RTE_ETH_LINK_MAX_STR_LEN];
98
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");
105
106         return TEST_SUCCESS;
107 }
108
109
110 static int32_t
111 test_link_speed_all_values(void)
112 {
113         const char *speed;
114         uint32_t i;
115         struct link_speed_t {
116                 const char *value;
117                 uint32_t link_speed;
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 },
134                 { "Invalid",   50505 }
135         };
136
137         for (i = 0; i < sizeof(speed_str_map) / sizeof(struct link_speed_t);
138                         i++) {
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");
143         }
144         return TEST_SUCCESS;
145 }
146
147 static struct unit_test_suite link_status_testsuite = {
148         .suite_name = "link status formatting",
149         .setup = NULL,
150         .teardown = NULL,
151         .unit_test_cases = {
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 */
157         }
158 };
159
160 static int
161 test_link_status(void)
162 {
163         rte_log_set_global_level(RTE_LOG_DEBUG);
164         rte_log_set_level(RTE_LOGTYPE_EAL, RTE_LOG_DEBUG);
165
166         return unit_test_suite_runner(&link_status_testsuite);
167 }
168
169 REGISTER_TEST_COMMAND(ethdev_link_status, test_link_status);