Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2018 Intel Corporation
3 : : */
4 : :
5 : : #define ALLOW_INTERNAL_API
6 : :
7 : : #include <stdio.h>
8 : : #include <unistd.h>
9 : : #include <stdint.h>
10 : : #include <limits.h>
11 : :
12 : : #include <ethdev_driver.h>
13 : : #include <rte_pdump.h>
14 : : #include "rte_eal.h"
15 : : #include "rte_lcore.h"
16 : : #include "rte_mempool.h"
17 : : #include "rte_ring.h"
18 : :
19 : : #include "sample_packet_forward.h"
20 : : #include "test.h"
21 : : #include "process.h"
22 : : #include "test_pdump.h"
23 : :
24 : : #define launch_p(ARGV) process_dup(ARGV, RTE_DIM(ARGV), __func__)
25 : :
26 : : struct rte_ring *ring_server;
27 : : uint16_t portid;
28 : : uint16_t flag_for_send_pkts = 1;
29 : :
30 : : int
31 : 1 : test_pdump_init(void)
32 : : {
33 : : int ret = 0;
34 : :
35 : 1 : ret = rte_pdump_init();
36 [ - + ]: 1 : if (ret < 0) {
37 : : printf("rte_pdump_init failed\n");
38 : 0 : return -1;
39 : : }
40 : 1 : ret = test_ring_setup(&ring_server, &portid);
41 [ - + ]: 1 : if (ret < 0) {
42 : : printf("test_ring_setup failed\n");
43 : 0 : return -1;
44 : : }
45 : : printf("pdump_init success\n");
46 : 1 : return ret;
47 : : }
48 : :
49 : : int
50 : 0 : run_pdump_client_tests(void)
51 : : {
52 : : int flags = RTE_PDUMP_FLAG_TX, ret = 0, itr;
53 : 0 : char deviceid[] = "net_ring_net_ringa";
54 : : struct rte_ring *ring_client;
55 : 0 : struct rte_mempool *mp = NULL;
56 : : struct rte_eth_dev *eth_dev = NULL;
57 : 0 : char poolname[] = "mbuf_pool_client";
58 : :
59 : 0 : ret = test_get_mempool(&mp, poolname);
60 [ # # ]: 0 : if (ret < 0)
61 : : return -1;
62 : 0 : mp->flags = 0x0000;
63 : 0 : ring_client = rte_ring_create("SR0", RING_SIZE, rte_socket_id(), 0);
64 [ # # ]: 0 : if (ring_client == NULL) {
65 : : printf("rte_ring_create SR0 failed");
66 : 0 : return -1;
67 : : }
68 : :
69 : 0 : eth_dev = rte_eth_dev_attach_secondary(deviceid);
70 [ # # ]: 0 : if (!eth_dev) {
71 : : printf("Failed to probe %s", deviceid);
72 : 0 : return -1;
73 : : }
74 : 0 : rte_eth_dev_probing_finish(eth_dev);
75 : :
76 : : printf("\n***** flags = RTE_PDUMP_FLAG_TX *****\n");
77 : :
78 [ # # ]: 0 : for (itr = 0; itr < NUM_ITR; itr++) {
79 : 0 : ret = rte_pdump_enable(portid, QUEUE_ID, flags, ring_client,
80 : : mp, NULL);
81 [ # # ]: 0 : if (ret < 0) {
82 : : printf("rte_pdump_enable failed\n");
83 : 0 : return -1;
84 : : }
85 : : printf("pdump_enable success\n");
86 : :
87 : 0 : ret = rte_pdump_disable(portid, QUEUE_ID, flags);
88 [ # # ]: 0 : if (ret < 0) {
89 : : printf("rte_pdump_disable failed\n");
90 : 0 : return -1;
91 : : }
92 : : printf("pdump_disable success\n");
93 : :
94 : 0 : ret = rte_pdump_enable_by_deviceid(deviceid, QUEUE_ID, flags,
95 : : ring_client, mp, NULL);
96 [ # # ]: 0 : if (ret < 0) {
97 : : printf("rte_pdump_enable_by_deviceid failed\n");
98 : 0 : return -1;
99 : : }
100 : : printf("pdump_enable_by_deviceid success\n");
101 : :
102 : 0 : ret = rte_pdump_disable_by_deviceid(deviceid, QUEUE_ID, flags);
103 [ # # ]: 0 : if (ret < 0) {
104 : : printf("rte_pdump_disable_by_deviceid failed\n");
105 : 0 : return -1;
106 : : }
107 : : printf("pdump_disable_by_deviceid success\n");
108 : :
109 [ # # ]: 0 : if (itr == 0) {
110 : : flags = RTE_PDUMP_FLAG_RX;
111 : : printf("\n***** flags = RTE_PDUMP_FLAG_RX *****\n");
112 [ # # ]: 0 : } else if (itr == 1) {
113 : : flags = RTE_PDUMP_FLAG_RXTX;
114 : : printf("\n***** flags = RTE_PDUMP_FLAG_RXTX *****\n");
115 : : }
116 : : }
117 : : if (ring_client != NULL)
118 : 0 : test_ring_free(ring_client);
119 [ # # ]: 0 : if (mp != NULL)
120 : 0 : test_mp_free(mp);
121 : :
122 : : return ret;
123 : : }
124 : :
125 : : int
126 : 1 : test_pdump_uninit(void)
127 : : {
128 : : int ret = 0;
129 : :
130 : 1 : ret = rte_pdump_uninit();
131 [ - + ]: 1 : if (ret < 0) {
132 : : printf("rte_pdump_uninit failed\n");
133 : 0 : return -1;
134 : : }
135 [ + - ]: 1 : if (ring_server != NULL)
136 : 1 : test_ring_free(ring_server);
137 : : printf("pdump_uninit success\n");
138 : 1 : test_vdev_uninit("net_ring_net_ringa");
139 : 1 : return ret;
140 : : }
141 : :
142 : : uint32_t
143 : 1 : send_pkts(void *empty __rte_unused)
144 : : {
145 : : int ret = 0;
146 : 1 : struct rte_mbuf *pbuf[NUM_PACKETS] = { };
147 : : struct rte_mempool *mp;
148 : 1 : char poolname[] = "mbuf_pool_server";
149 : :
150 : 1 : ret = test_get_mbuf_from_pool(&mp, pbuf, poolname);
151 [ - + ]: 1 : if (ret < 0)
152 : : printf("get_mbuf_from_pool failed\n");
153 : :
154 : 1 : ret = test_dev_start(portid, mp);
155 [ - + ]: 1 : if (ret < 0)
156 : 0 : printf("test_dev_start(%hu, %p) failed, error code: %d\n",
157 : : portid, mp, ret);
158 : :
159 [ + - + + ]: 3175062 : while (ret >= 0 && flag_for_send_pkts) {
160 : 3175061 : ret = test_packet_forward(pbuf, portid, QUEUE_ID);
161 [ - + ]: 3175061 : if (ret < 0)
162 : : printf("send pkts Failed\n");
163 : : };
164 : :
165 : 1 : rte_eth_dev_stop(portid);
166 : 1 : test_put_mbuf_to_pool(mp, pbuf);
167 : 1 : return 0;
168 : : }
169 : :
170 : : /*
171 : : * This function is called in the primary i.e. main test, to spawn off secondary
172 : : * processes to run actual mp tests. Uses fork() and exec pair
173 : : */
174 : :
175 : : int
176 : 1 : run_pdump_server_tests(void)
177 : : {
178 : : int ret = 0;
179 : : char core_str[10];
180 : : const char *prefix;
181 : :
182 : 1 : prefix = file_prefix_arg();
183 [ + - ]: 1 : if (prefix == NULL)
184 : : return -1;
185 : :
186 : : /* good case, using secondary */
187 : 1 : const char *const argv1[] = {
188 : : prgname, "-l", core_str, "--proc-type=secondary",
189 : : prefix
190 : : };
191 : :
192 : 1 : snprintf(core_str, sizeof(core_str), "%u", rte_get_main_lcore());
193 : :
194 : 1 : ret = test_pdump_init();
195 : 1 : ret |= launch_p(argv1);
196 : 1 : ret |= test_pdump_uninit();
197 : 1 : return ret;
198 : : }
199 : :
200 : : int
201 : 1 : test_pdump(void)
202 : : {
203 : : int ret = 0;
204 : :
205 : : if (RTE_EXEC_ENV_IS_FREEBSD)
206 : : return TEST_SKIPPED;
207 : :
208 [ + - ]: 1 : if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
209 : : printf("IN PRIMARY PROCESS\n");
210 : 1 : ret = run_pdump_server_tests();
211 [ - + ]: 1 : if (ret < 0)
212 : 0 : return TEST_FAILED;
213 [ # # ]: 0 : } else if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
214 : : printf("IN SECONDARY PROCESS\n");
215 : 0 : sleep(5);
216 : 0 : ret = run_pdump_client_tests();
217 [ # # ]: 0 : if (ret < 0)
218 : 0 : return TEST_FAILED;
219 : : }
220 : : return TEST_SUCCESS;
221 : : }
222 : :
223 : 302 : REGISTER_FAST_TEST(pdump_autotest, NOHUGE_OK, ASAN_SKIP, test_pdump);
|