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