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

selftests/xsk: add timeout for Tx thread

Add a timeout for the transmission thread. If packets are not
completed properly, for some reason, the test harness would previously
get stuck forever in a while loop. But with this patch, this timeout
will trigger, flag the test as a failure, and continue with the next
test.

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

authored by

Magnus Karlsson and committed by
Alexei Starovoitov
64370d7c 2d2712ca

+22 -4
+22 -4
tools/testing/selftests/bpf/xskxceiver.c
··· 1216 1216 return TEST_CONTINUE; 1217 1217 } 1218 1218 1219 - static void wait_for_tx_completion(struct xsk_socket_info *xsk) 1219 + static int wait_for_tx_completion(struct xsk_socket_info *xsk) 1220 1220 { 1221 - while (xsk->outstanding_tx) 1221 + struct timeval tv_end, tv_now, tv_timeout = {THREAD_TMOUT, 0}; 1222 + int ret; 1223 + 1224 + ret = gettimeofday(&tv_now, NULL); 1225 + if (ret) 1226 + exit_with_error(errno); 1227 + timeradd(&tv_now, &tv_timeout, &tv_end); 1228 + 1229 + while (xsk->outstanding_tx) { 1230 + ret = gettimeofday(&tv_now, NULL); 1231 + if (ret) 1232 + exit_with_error(errno); 1233 + if (timercmp(&tv_now, &tv_end, >)) { 1234 + ksft_print_msg("ERROR: [%s] Transmission loop timed out\n", __func__); 1235 + return TEST_FAILURE; 1236 + } 1237 + 1222 1238 complete_pkts(xsk, BATCH_SIZE); 1239 + } 1240 + 1241 + return TEST_PASS; 1223 1242 } 1224 1243 1225 1244 static int send_pkts(struct test_spec *test, struct ifobject *ifobject) ··· 1261 1242 return ret; 1262 1243 } 1263 1244 1264 - wait_for_tx_completion(ifobject->xsk); 1265 - return TEST_PASS; 1245 + return wait_for_tx_completion(ifobject->xsk); 1266 1246 } 1267 1247 1268 1248 static int get_xsk_stats(struct xsk_socket *xsk, struct xdp_statistics *stats)