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, 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(),
61 RING_F_SP_ENQ | RING_F_SC_DEQ);
62 if (ring_client == NULL) {
63 printf("rte_ring_create SR0 failed");
67 eth_dev = rte_eth_dev_attach_secondary(deviceid);
69 printf("Failed to probe %s", deviceid);
72 rte_eth_dev_probing_finish(eth_dev);
74 ring_client->prod.single = 0;
75 ring_client->cons.single = 0;
77 printf("\n***** flags = RTE_PDUMP_FLAG_TX *****\n");
79 for (itr = 0; itr < NUM_ITR; itr++) {
80 ret = rte_pdump_enable(portid, QUEUE_ID, flags, ring_client,
83 printf("rte_pdump_enable failed\n");
86 printf("pdump_enable success\n");
88 ret = rte_pdump_disable(portid, QUEUE_ID, flags);
90 printf("rte_pdump_disable failed\n");
93 printf("pdump_disable success\n");
95 ret = rte_pdump_enable_by_deviceid(deviceid, QUEUE_ID, flags,
96 ring_client, mp, NULL);
98 printf("rte_pdump_enable_by_deviceid failed\n");
101 printf("pdump_enable_by_deviceid success\n");
103 ret = rte_pdump_disable_by_deviceid(deviceid, QUEUE_ID, flags);
105 printf("rte_pdump_disable_by_deviceid failed\n");
108 printf("pdump_disable_by_deviceid success\n");
111 flags = RTE_PDUMP_FLAG_RX;
112 printf("\n***** flags = RTE_PDUMP_FLAG_RX *****\n");
113 } else if (itr == 1) {
114 flags = RTE_PDUMP_FLAG_RXTX;
115 printf("\n***** flags = RTE_PDUMP_FLAG_RXTX *****\n");
118 if (ring_client != NULL)
119 test_ring_free(ring_client);
127 test_pdump_uninit(void)
131 ret = rte_pdump_uninit();
133 printf("rte_pdump_uninit failed\n");
136 if (ring_server != NULL)
137 test_ring_free(ring_server);
138 printf("pdump_uninit success\n");
139 test_vdev_uninit("net_ring_net_ringa");
144 send_pkts(void *empty)
147 struct rte_mbuf *pbuf[NUM_PACKETS] = { };
148 struct rte_mempool *mp;
149 char poolname[] = "mbuf_pool_server";
151 ret = test_get_mbuf_from_pool(&mp, pbuf, poolname);
153 printf("get_mbuf_from_pool failed\n");
155 ret = test_packet_forward(pbuf, portid, QUEUE_ID);
157 printf("send pkts Failed\n");
158 } while (flag_for_send_pkts);
159 test_put_mbuf_to_pool(mp, pbuf);
164 * This function is called in the primary i.e. main test, to spawn off secondary
165 * processes to run actual mp tests. Uses fork() and exec pair
169 run_pdump_server_tests(void)
174 #ifdef RTE_EXEC_ENV_LINUX
175 char tmp[PATH_MAX] = { 0 };
176 char prefix[PATH_MAX] = { 0 };
178 get_current_prefix(tmp, sizeof(tmp));
179 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
181 const char *prefix = "";
184 /* good case, using secondary */
185 const char *const argv1[] = {
186 prgname, "-c", coremask, "--proc-type=secondary",
190 snprintf(coremask, sizeof(coremask), "%x",
191 (1 << rte_get_master_lcore()));
193 ret = test_pdump_init();
194 ret |= launch_p(argv1);
195 ret |= test_pdump_uninit();
203 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
204 printf("IN PRIMARY PROCESS\n");
205 ret = run_pdump_server_tests();
208 } else if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
209 printf("IN SECONDARY PROCESS\n");
211 ret = run_pdump_client_tests();
218 REGISTER_TEST_COMMAND(pdump_autotest, test_pdump);