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