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 <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, RTE_DIM(ARGV), __func__) 22 23 struct rte_ring *ring_server; 24 uint16_t portid; 25 uint16_t flag_for_send_pkts = 1; 26 27 int 28 test_pdump_init(void) 29 { 30 int ret = 0; 31 32 ret = rte_pdump_init(); 33 if (ret < 0) { 34 printf("rte_pdump_init failed\n"); 35 return -1; 36 } 37 ret = test_ring_setup(&ring_server, &portid); 38 if (ret < 0) { 39 printf("test_ring_setup failed\n"); 40 return -1; 41 } 42 printf("pdump_init success\n"); 43 return ret; 44 } 45 46 int 47 run_pdump_client_tests(void) 48 { 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"; 55 56 ret = test_get_mempool(&mp, poolname); 57 if (ret < 0) 58 return -1; 59 mp->flags = 0x0000; 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"); 63 return -1; 64 } 65 66 eth_dev = rte_eth_dev_attach_secondary(deviceid); 67 if (!eth_dev) { 68 printf("Failed to probe %s", deviceid); 69 return -1; 70 } 71 rte_eth_dev_probing_finish(eth_dev); 72 73 printf("\n***** flags = RTE_PDUMP_FLAG_TX *****\n"); 74 75 for (itr = 0; itr < NUM_ITR; itr++) { 76 ret = rte_pdump_enable(portid, QUEUE_ID, flags, ring_client, 77 mp, NULL); 78 if (ret < 0) { 79 printf("rte_pdump_enable failed\n"); 80 return -1; 81 } 82 printf("pdump_enable success\n"); 83 84 ret = rte_pdump_disable(portid, QUEUE_ID, flags); 85 if (ret < 0) { 86 printf("rte_pdump_disable failed\n"); 87 return -1; 88 } 89 printf("pdump_disable success\n"); 90 91 ret = rte_pdump_enable_by_deviceid(deviceid, QUEUE_ID, flags, 92 ring_client, mp, NULL); 93 if (ret < 0) { 94 printf("rte_pdump_enable_by_deviceid failed\n"); 95 return -1; 96 } 97 printf("pdump_enable_by_deviceid success\n"); 98 99 ret = rte_pdump_disable_by_deviceid(deviceid, QUEUE_ID, flags); 100 if (ret < 0) { 101 printf("rte_pdump_disable_by_deviceid failed\n"); 102 return -1; 103 } 104 printf("pdump_disable_by_deviceid success\n"); 105 106 if (itr == 0) { 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"); 112 } 113 } 114 if (ring_client != NULL) 115 test_ring_free(ring_client); 116 if (mp != NULL) 117 test_mp_free(mp); 118 119 return ret; 120 } 121 122 int 123 test_pdump_uninit(void) 124 { 125 int ret = 0; 126 127 ret = rte_pdump_uninit(); 128 if (ret < 0) { 129 printf("rte_pdump_uninit failed\n"); 130 return -1; 131 } 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"); 136 return ret; 137 } 138 139 void * 140 send_pkts(void *empty) 141 { 142 int ret = 0; 143 struct rte_mbuf *pbuf[NUM_PACKETS] = { }; 144 struct rte_mempool *mp; 145 char poolname[] = "mbuf_pool_server"; 146 147 ret = test_get_mbuf_from_pool(&mp, pbuf, poolname); 148 if (ret < 0) 149 printf("get_mbuf_from_pool failed\n"); 150 do { 151 ret = test_packet_forward(pbuf, portid, QUEUE_ID); 152 if (ret < 0) 153 printf("send pkts Failed\n"); 154 } while (flag_for_send_pkts); 155 test_put_mbuf_to_pool(mp, pbuf); 156 return empty; 157 } 158 159 /* 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 162 */ 163 164 int 165 run_pdump_server_tests(void) 166 { 167 int ret = 0; 168 char coremask[10]; 169 170 #ifdef RTE_EXEC_ENV_LINUX 171 char tmp[PATH_MAX] = { 0 }; 172 char prefix[PATH_MAX] = { 0 }; 173 174 get_current_prefix(tmp, sizeof(tmp)); 175 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp); 176 #else 177 const char *prefix = ""; 178 #endif 179 180 /* good case, using secondary */ 181 const char *const argv1[] = { 182 prgname, "-c", coremask, "--proc-type=secondary", 183 prefix 184 }; 185 186 snprintf(coremask, sizeof(coremask), "%x", 187 (1 << rte_get_main_lcore())); 188 189 ret = test_pdump_init(); 190 ret |= launch_p(argv1); 191 ret |= test_pdump_uninit(); 192 return ret; 193 } 194 195 int 196 test_pdump(void) 197 { 198 int ret = 0; 199 if (rte_eal_process_type() == RTE_PROC_PRIMARY) { 200 printf("IN PRIMARY PROCESS\n"); 201 ret = run_pdump_server_tests(); 202 if (ret < 0) 203 return TEST_FAILED; 204 } else if (rte_eal_process_type() == RTE_PROC_SECONDARY) { 205 printf("IN SECONDARY PROCESS\n"); 206 sleep(5); 207 ret = run_pdump_client_tests(); 208 if (ret < 0) 209 return TEST_FAILED; 210 } 211 return TEST_SUCCESS; 212 } 213 214 REGISTER_TEST_COMMAND(pdump_autotest, test_pdump); 215