1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Intel Corporation
9 #include <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, RTE_DIM(ARGV), __func__)
23 struct rte_ring *ring_server;
25 uint16_t flag_for_send_pkts = 1;
32 ret = rte_pdump_init();
34 printf("rte_pdump_init failed\n");
37 ret = test_ring_setup(&ring_server, &portid);
39 printf("test_ring_setup failed\n");
42 printf("pdump_init success\n");
47 run_pdump_client_tests(void)
49 int flags = RTE_PDUMP_FLAG_TX, ret = 0, itr;
50 char deviceid[] = "net_ring_net_ringa";
51 struct rte_ring *ring_client;
52 struct rte_mempool *mp = NULL;
53 struct rte_eth_dev *eth_dev = NULL;
54 char poolname[] = "mbuf_pool_client";
56 ret = test_get_mempool(&mp, poolname);
60 ring_client = rte_ring_create("SR0", RING_SIZE, rte_socket_id(), 0);
61 if (ring_client == NULL) {
62 printf("rte_ring_create SR0 failed");
66 eth_dev = rte_eth_dev_attach_secondary(deviceid);
68 printf("Failed to probe %s", deviceid);
71 rte_eth_dev_probing_finish(eth_dev);
73 printf("\n***** flags = RTE_PDUMP_FLAG_TX *****\n");
75 for (itr = 0; itr < NUM_ITR; itr++) {
76 ret = rte_pdump_enable(portid, QUEUE_ID, flags, ring_client,
79 printf("rte_pdump_enable failed\n");
82 printf("pdump_enable success\n");
84 ret = rte_pdump_disable(portid, QUEUE_ID, flags);
86 printf("rte_pdump_disable failed\n");
89 printf("pdump_disable success\n");
91 ret = rte_pdump_enable_by_deviceid(deviceid, QUEUE_ID, flags,
92 ring_client, mp, NULL);
94 printf("rte_pdump_enable_by_deviceid failed\n");
97 printf("pdump_enable_by_deviceid success\n");
99 ret = rte_pdump_disable_by_deviceid(deviceid, QUEUE_ID, flags);
101 printf("rte_pdump_disable_by_deviceid failed\n");
104 printf("pdump_disable_by_deviceid success\n");
107 flags = RTE_PDUMP_FLAG_RX;
108 printf("\n***** flags = RTE_PDUMP_FLAG_RX *****\n");
109 } else if (itr == 1) {
110 flags = RTE_PDUMP_FLAG_RXTX;
111 printf("\n***** flags = RTE_PDUMP_FLAG_RXTX *****\n");
114 if (ring_client != NULL)
115 test_ring_free(ring_client);
123 test_pdump_uninit(void)
127 ret = rte_pdump_uninit();
129 printf("rte_pdump_uninit failed\n");
132 if (ring_server != NULL)
133 test_ring_free(ring_server);
134 printf("pdump_uninit success\n");
135 test_vdev_uninit("net_ring_net_ringa");
140 send_pkts(void *empty)
143 struct rte_mbuf *pbuf[NUM_PACKETS] = { };
144 struct rte_mempool *mp;
145 char poolname[] = "mbuf_pool_server";
147 ret = test_get_mbuf_from_pool(&mp, pbuf, poolname);
149 printf("get_mbuf_from_pool failed\n");
151 ret = test_packet_forward(pbuf, portid, QUEUE_ID);
153 printf("send pkts Failed\n");
154 } while (flag_for_send_pkts);
155 test_put_mbuf_to_pool(mp, pbuf);
160 * This function is called in the primary i.e. main test, to spawn off secondary
161 * processes to run actual mp tests. Uses fork() and exec pair
165 run_pdump_server_tests(void)
170 #ifdef RTE_EXEC_ENV_LINUX
171 char tmp[PATH_MAX] = { 0 };
172 char prefix[PATH_MAX] = { 0 };
174 get_current_prefix(tmp, sizeof(tmp));
175 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
177 const char *prefix = "";
180 /* good case, using secondary */
181 const char *const argv1[] = {
182 prgname, "-c", coremask, "--proc-type=secondary",
186 snprintf(coremask, sizeof(coremask), "%x",
187 (1 << rte_get_main_lcore()));
189 ret = test_pdump_init();
190 ret |= launch_p(argv1);
191 ret |= test_pdump_uninit();
199 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
200 printf("IN PRIMARY PROCESS\n");
201 ret = run_pdump_server_tests();
204 } else if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
205 printf("IN SECONDARY PROCESS\n");
207 ret = run_pdump_client_tests();
214 REGISTER_TEST_COMMAND(pdump_autotest, test_pdump);