1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Intel Corporation
9 #include <rte_ethdev_driver.h>
10 #include <rte_pdump.h>
12 #include "rte_lcore.h"
13 #include "rte_mempool.h"
16 #include "sample_packet_forward.h"
19 #include "test_pdump.h"
21 #define launch_p(ARGV) process_dup(ARGV, \
22 sizeof(ARGV)/(sizeof(ARGV[0])), __func__)
24 struct rte_ring *ring_server;
26 uint16_t flag_for_send_pkts = 1;
33 ret = rte_pdump_init();
35 printf("rte_pdump_init failed\n");
38 ret = test_ring_setup(&ring_server, &portid);
40 printf("test_ring_setup failed\n");
43 printf("pdump_init success\n");
48 run_pdump_client_tests(void)
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";
57 ret = test_get_mempool(&mp, poolname);
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");
68 eth_dev = rte_eth_dev_attach_secondary(deviceid);
70 printf("Failed to probe %s", deviceid);
73 rte_eth_dev_probing_finish(eth_dev);
75 ring_client->prod.single = 0;
76 ring_client->cons.single = 0;
78 printf("\n***** flags = RTE_PDUMP_FLAG_TX *****\n");
80 for (itr = 0; itr < NUM_ITR; itr++) {
81 ret = rte_pdump_enable(portid, QUEUE_ID, flags, ring_client,
84 printf("rte_pdump_enable failed\n");
87 printf("pdump_enable success\n");
89 ret = rte_pdump_disable(portid, QUEUE_ID, flags);
91 printf("rte_pdump_disable failed\n");
94 printf("pdump_disable success\n");
96 ret = rte_pdump_enable_by_deviceid(deviceid, QUEUE_ID, flags,
97 ring_client, mp, NULL);
99 printf("rte_pdump_enable_by_deviceid failed\n");
102 printf("pdump_enable_by_deviceid success\n");
104 ret = rte_pdump_disable_by_deviceid(deviceid, QUEUE_ID, flags);
106 printf("rte_pdump_disable_by_deviceid failed\n");
109 printf("pdump_disable_by_deviceid success\n");
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");
119 if (ring_client != NULL)
120 test_ring_free(ring_client);
128 test_pdump_uninit(void)
132 ret = rte_pdump_uninit();
134 printf("rte_pdump_uninit failed\n");
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");
145 send_pkts(void *empty)
148 struct rte_mbuf *pbuf[NUM_PACKETS] = { };
149 struct rte_mempool *mp;
150 char poolname[] = "mbuf_pool_server";
152 ret = test_get_mbuf_from_pool(&mp, pbuf, poolname);
154 printf("get_mbuf_from_pool failed\n");
156 ret = test_packet_forward(pbuf, portid, QUEUE_ID);
158 printf("send pkts Failed\n");
159 } while (flag_for_send_pkts);
160 test_put_mbuf_to_pool(mp, pbuf);
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
170 run_pdump_server_tests(void)
175 #ifdef RTE_EXEC_ENV_LINUXAPP
176 char tmp[PATH_MAX] = { 0 };
177 char prefix[PATH_MAX] = { 0 };
179 get_current_prefix(tmp, sizeof(tmp));
180 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
182 const char *prefix = "";
185 /* good case, using secondary */
186 const char *const argv1[] = {
187 prgname, "-c", coremask, "--proc-type=secondary",
191 snprintf(coremask, sizeof(coremask), "%x",
192 (1 << rte_get_master_lcore()));
194 ret = test_pdump_init();
195 ret |= launch_p(argv1);
196 ret |= test_pdump_uninit();
204 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
205 printf("IN PRIMARY PROCESS\n");
206 ret = run_pdump_server_tests();
209 } else if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
210 printf("IN SECONDARY PROCESS\n");
212 ret = run_pdump_client_tests();
219 REGISTER_TEST_COMMAND(pdump_autotest, test_pdump);