Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/xsk: move all tests to separate functions

Prepare for the capability to be able to run a single test by moving
all the tests to their own functions. This function can then be called
to execute that test in the next commit.

Also, the tests named RUN_TO_COMPLETION_* were not named well, so
change them to SEND_RECEIVE_* as it is just a basic send and receive
test of 4K packets.

Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com>
Link: https://lore.kernel.org/r/20230914084900.492-5-magnus.karlsson@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Magnus Karlsson and committed by
Alexei Starovoitov
13c341c4 3956bc34

+115 -55
+115 -55
tools/testing/selftests/bpf/xskxceiver.c
··· 1872 1872 { 1873 1873 struct pkt pkts[] = {{0, MIN_PKT_SIZE, 0, true}}; 1874 1874 1875 + test_spec_set_name(test, "SEND_RECEIVE_SINGLE_PKT"); 1875 1876 pkt_stream_generate_custom(test, pkts, ARRAY_SIZE(pkts)); 1876 1877 return testapp_validate_traffic(test); 1877 1878 } 1878 1879 1879 1880 static int testapp_multi_buffer(struct test_spec *test) 1880 1881 { 1881 - test_spec_set_name(test, "RUN_TO_COMPLETION_9K_PACKETS"); 1882 + test_spec_set_name(test, "SEND_RECEIVE_9K_PACKETS"); 1882 1883 test->mtu = MAX_ETH_JUMBO_SIZE; 1883 1884 pkt_stream_replace(test, DEFAULT_PKT_CNT, MAX_ETH_JUMBO_SIZE); 1884 1885 ··· 1984 1983 return testapp_validate_traffic(test); 1985 1984 } 1986 1985 1987 - static int testapp_xdp_metadata_count(struct test_spec *test) 1986 + static int testapp_xdp_metadata_copy(struct test_spec *test) 1988 1987 { 1989 1988 struct xsk_xdp_progs *skel_rx = test->ifobj_rx->xdp_progs; 1990 1989 struct xsk_xdp_progs *skel_tx = test->ifobj_tx->xdp_progs; ··· 2134 2133 } 2135 2134 } 2136 2135 2136 + static int testapp_send_receive(struct test_spec *test) 2137 + { 2138 + test_spec_set_name(test, "SEND_RECEIVE"); 2139 + return testapp_validate_traffic(test); 2140 + } 2141 + 2142 + static int testapp_send_receive_2k_frame(struct test_spec *test) 2143 + { 2144 + test_spec_set_name(test, "SEND_RECEIVE_2K_FRAME_SIZE"); 2145 + test->ifobj_tx->umem->frame_size = 2048; 2146 + test->ifobj_rx->umem->frame_size = 2048; 2147 + pkt_stream_replace(test, DEFAULT_PKT_CNT, MIN_PKT_SIZE); 2148 + return testapp_validate_traffic(test); 2149 + } 2150 + 2151 + static int testapp_poll_rx(struct test_spec *test) 2152 + { 2153 + test->ifobj_rx->use_poll = true; 2154 + test_spec_set_name(test, "POLL_RX"); 2155 + return testapp_validate_traffic(test); 2156 + } 2157 + 2158 + static int testapp_poll_tx(struct test_spec *test) 2159 + { 2160 + test->ifobj_tx->use_poll = true; 2161 + test_spec_set_name(test, "POLL_TX"); 2162 + return testapp_validate_traffic(test); 2163 + } 2164 + 2165 + static int testapp_aligned_inv_desc(struct test_spec *test) 2166 + { 2167 + test_spec_set_name(test, "ALIGNED_INV_DESC"); 2168 + return testapp_invalid_desc(test); 2169 + } 2170 + 2171 + static int testapp_aligned_inv_desc_2k_frame(struct test_spec *test) 2172 + { 2173 + test_spec_set_name(test, "ALIGNED_INV_DESC_2K_FRAME_SIZE"); 2174 + test->ifobj_tx->umem->frame_size = 2048; 2175 + test->ifobj_rx->umem->frame_size = 2048; 2176 + return testapp_invalid_desc(test); 2177 + } 2178 + 2179 + static int testapp_unaligned_inv_desc(struct test_spec *test) 2180 + { 2181 + test_spec_set_name(test, "UNALIGNED_INV_DESC"); 2182 + test->ifobj_tx->umem->unaligned_mode = true; 2183 + test->ifobj_rx->umem->unaligned_mode = true; 2184 + return testapp_invalid_desc(test); 2185 + } 2186 + 2187 + static int testapp_unaligned_inv_desc_4001_frame(struct test_spec *test) 2188 + { 2189 + u64 page_size, umem_size; 2190 + 2191 + test_spec_set_name(test, "UNALIGNED_INV_DESC_4K1_FRAME_SIZE"); 2192 + /* Odd frame size so the UMEM doesn't end near a page boundary. */ 2193 + test->ifobj_tx->umem->frame_size = 4001; 2194 + test->ifobj_rx->umem->frame_size = 4001; 2195 + test->ifobj_tx->umem->unaligned_mode = true; 2196 + test->ifobj_rx->umem->unaligned_mode = true; 2197 + /* This test exists to test descriptors that staddle the end of 2198 + * the UMEM but not a page. 2199 + */ 2200 + page_size = sysconf(_SC_PAGESIZE); 2201 + umem_size = test->ifobj_tx->umem->num_frames * test->ifobj_tx->umem->frame_size; 2202 + assert(umem_size % page_size > MIN_PKT_SIZE); 2203 + assert(umem_size % page_size < page_size - MIN_PKT_SIZE); 2204 + 2205 + return testapp_invalid_desc(test); 2206 + } 2207 + 2208 + static int testapp_aligned_inv_desc_mb(struct test_spec *test) 2209 + { 2210 + test_spec_set_name(test, "ALIGNED_INV_DESC_MULTI_BUFF"); 2211 + return testapp_invalid_desc_mb(test); 2212 + } 2213 + 2214 + static int testapp_unaligned_inv_desc_mb(struct test_spec *test) 2215 + { 2216 + test_spec_set_name(test, "UNALIGNED_INV_DESC_MULTI_BUFF"); 2217 + test->ifobj_tx->umem->unaligned_mode = true; 2218 + test->ifobj_rx->umem->unaligned_mode = true; 2219 + return testapp_invalid_desc_mb(test); 2220 + } 2221 + 2222 + static int testapp_xdp_metadata(struct test_spec *test) 2223 + { 2224 + test_spec_set_name(test, "XDP_METADATA_COPY"); 2225 + return testapp_xdp_metadata_copy(test); 2226 + } 2227 + 2228 + static int testapp_xdp_metadata_mb(struct test_spec *test) 2229 + { 2230 + test_spec_set_name(test, "XDP_METADATA_COPY_MULTI_BUFF"); 2231 + test->mtu = MAX_ETH_JUMBO_SIZE; 2232 + return testapp_xdp_metadata_copy(test); 2233 + } 2234 + 2137 2235 static void run_pkt_test(struct test_spec *test, enum test_mode mode, enum test_type type) 2138 2236 { 2139 2237 int ret = TEST_SKIP; ··· 2260 2160 ret = testapp_bpf_res(test); 2261 2161 break; 2262 2162 case TEST_TYPE_RUN_TO_COMPLETION: 2263 - test_spec_set_name(test, "RUN_TO_COMPLETION"); 2264 - ret = testapp_validate_traffic(test); 2163 + ret = testapp_send_receive(test); 2265 2164 break; 2266 2165 case TEST_TYPE_RUN_TO_COMPLETION_MB: 2267 2166 ret = testapp_multi_buffer(test); 2268 2167 break; 2269 2168 case TEST_TYPE_RUN_TO_COMPLETION_SINGLE_PKT: 2270 - test_spec_set_name(test, "RUN_TO_COMPLETION_SINGLE_PKT"); 2271 2169 ret = testapp_single_pkt(test); 2272 2170 break; 2273 2171 case TEST_TYPE_RUN_TO_COMPLETION_2K_FRAME: 2274 - test_spec_set_name(test, "RUN_TO_COMPLETION_2K_FRAME_SIZE"); 2275 - test->ifobj_tx->umem->frame_size = 2048; 2276 - test->ifobj_rx->umem->frame_size = 2048; 2277 - pkt_stream_replace(test, DEFAULT_PKT_CNT, MIN_PKT_SIZE); 2278 - ret = testapp_validate_traffic(test); 2172 + ret = testapp_send_receive_2k_frame(test); 2279 2173 break; 2280 2174 case TEST_TYPE_RX_POLL: 2281 - test->ifobj_rx->use_poll = true; 2282 - test_spec_set_name(test, "POLL_RX"); 2283 - ret = testapp_validate_traffic(test); 2175 + ret = testapp_poll_rx(test); 2284 2176 break; 2285 2177 case TEST_TYPE_TX_POLL: 2286 - test->ifobj_tx->use_poll = true; 2287 - test_spec_set_name(test, "POLL_TX"); 2288 - ret = testapp_validate_traffic(test); 2178 + ret = testapp_poll_tx(test); 2289 2179 break; 2290 2180 case TEST_TYPE_POLL_TXQ_TMOUT: 2291 2181 ret = testapp_poll_txq_tmout(test); ··· 2284 2194 ret = testapp_poll_rxq_tmout(test); 2285 2195 break; 2286 2196 case TEST_TYPE_ALIGNED_INV_DESC: 2287 - test_spec_set_name(test, "ALIGNED_INV_DESC"); 2288 - ret = testapp_invalid_desc(test); 2197 + ret = testapp_aligned_inv_desc(test); 2289 2198 break; 2290 2199 case TEST_TYPE_ALIGNED_INV_DESC_2K_FRAME: 2291 - test_spec_set_name(test, "ALIGNED_INV_DESC_2K_FRAME_SIZE"); 2292 - test->ifobj_tx->umem->frame_size = 2048; 2293 - test->ifobj_rx->umem->frame_size = 2048; 2294 - ret = testapp_invalid_desc(test); 2200 + ret = testapp_aligned_inv_desc_2k_frame(test); 2295 2201 break; 2296 2202 case TEST_TYPE_UNALIGNED_INV_DESC: 2297 - test_spec_set_name(test, "UNALIGNED_INV_DESC"); 2298 - test->ifobj_tx->umem->unaligned_mode = true; 2299 - test->ifobj_rx->umem->unaligned_mode = true; 2300 - ret = testapp_invalid_desc(test); 2203 + ret = testapp_unaligned_inv_desc(test); 2301 2204 break; 2302 - case TEST_TYPE_UNALIGNED_INV_DESC_4K1_FRAME: { 2303 - u64 page_size, umem_size; 2304 - 2305 - test_spec_set_name(test, "UNALIGNED_INV_DESC_4K1_FRAME_SIZE"); 2306 - /* Odd frame size so the UMEM doesn't end near a page boundary. */ 2307 - test->ifobj_tx->umem->frame_size = 4001; 2308 - test->ifobj_rx->umem->frame_size = 4001; 2309 - test->ifobj_tx->umem->unaligned_mode = true; 2310 - test->ifobj_rx->umem->unaligned_mode = true; 2311 - /* This test exists to test descriptors that staddle the end of 2312 - * the UMEM but not a page. 2313 - */ 2314 - page_size = sysconf(_SC_PAGESIZE); 2315 - umem_size = test->ifobj_tx->umem->num_frames * test->ifobj_tx->umem->frame_size; 2316 - assert(umem_size % page_size > MIN_PKT_SIZE); 2317 - assert(umem_size % page_size < page_size - MIN_PKT_SIZE); 2318 - ret = testapp_invalid_desc(test); 2205 + case TEST_TYPE_UNALIGNED_INV_DESC_4K1_FRAME: 2206 + ret = testapp_unaligned_inv_desc_4001_frame(test); 2319 2207 break; 2320 - } 2321 2208 case TEST_TYPE_ALIGNED_INV_DESC_MB: 2322 - test_spec_set_name(test, "ALIGNED_INV_DESC_MULTI_BUFF"); 2323 - ret = testapp_invalid_desc_mb(test); 2209 + ret = testapp_aligned_inv_desc_mb(test); 2324 2210 break; 2325 2211 case TEST_TYPE_UNALIGNED_INV_DESC_MB: 2326 - test_spec_set_name(test, "UNALIGNED_INV_DESC_MULTI_BUFF"); 2327 - test->ifobj_tx->umem->unaligned_mode = true; 2328 - test->ifobj_rx->umem->unaligned_mode = true; 2329 - ret = testapp_invalid_desc_mb(test); 2212 + ret = testapp_unaligned_inv_desc_mb(test); 2330 2213 break; 2331 2214 case TEST_TYPE_UNALIGNED: 2332 2215 ret = testapp_unaligned(test); ··· 2314 2251 ret = testapp_xdp_drop(test); 2315 2252 break; 2316 2253 case TEST_TYPE_XDP_METADATA_COUNT: 2317 - test_spec_set_name(test, "XDP_METADATA_COUNT"); 2318 - ret = testapp_xdp_metadata_count(test); 2254 + ret = testapp_xdp_metadata(test); 2319 2255 break; 2320 2256 case TEST_TYPE_XDP_METADATA_COUNT_MB: 2321 - test_spec_set_name(test, "XDP_METADATA_COUNT_MULTI_BUFF"); 2322 - test->mtu = MAX_ETH_JUMBO_SIZE; 2323 - ret = testapp_xdp_metadata_count(test); 2257 + ret = testapp_xdp_metadata_mb(test); 2324 2258 break; 2325 2259 case TEST_TYPE_TOO_MANY_FRAGS: 2326 2260 ret = testapp_too_many_frags(test);