Commit 43c5026b authored by Alexei Starovoitov's avatar Alexei Starovoitov

Merge branch 'selftests/bpf: xsk improvements and new stats'

Ciara Loftus says:

====================

This series attempts to improve the xsk selftest framework by:
1. making the default output less verbose
2. adding an optional verbose flag to both the test_xsk.sh script and xdpxceiver app.
3. renaming the debug option in the app to to 'dump-pkts' and add a flag to the test_xsk.sh
script which enables the flag in the app.
4. changing how tests are launched - now they are launched from the xdpxceiver app
instead of the script.

Once the improvements are made, a new set of tests are added which test the xsk
statistics.

The output of the test script now looks like:

./test_xsk.sh
PREREQUISITES: [ PASS ]
1..10
ok 1 PASS: SKB NOPOLL
ok 2 PASS: SKB POLL
ok 3 PASS: SKB NOPOLL Socket Teardown
ok 4 PASS: SKB NOPOLL Bi-directional Sockets
ok 5 PASS: SKB NOPOLL Stats
ok 6 PASS: DRV NOPOLL
ok 7 PASS: DRV POLL
ok 8 PASS: DRV NOPOLL Socket Teardown
ok 9 PASS: DRV NOPOLL Bi-directional Sockets
ok 10 PASS: DRV NOPOLL Stats
# Totals: pass:10 fail:0 xfail:0 xpass:0 skip:0 error:0
XSK KSELFTESTS: [ PASS ]

v2->v3:
* Rename dump-pkts to dump_pkts in test_xsk.sh
* Add examples of flag usage to test_xsk.sh

v1->v2:
* Changed '-d' flag in the shell script to '-D' to be consistent with the xdpxceiver app.
* Renamed debug mode to 'dump-pkts' which better reflects the behaviour.
* Use libpf APIs instead of calls to ss for configuring xdp on the links
* Remove mutex init & destroy for each stats test
* Added a description for each of the new statistics tests
* Distinguish between exiting due to initialisation failure vs test failure

This series applies on commit d310ec03

Ciara Loftus (3):
  selftests/bpf: expose and rename debug argument
  selftests/bpf: restructure xsk selftests
  selftests/bpf: introduce xsk statistics tests
====================
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parents e6ac5933 b267e5a4
...@@ -71,13 +71,21 @@ ...@@ -71,13 +71,21 @@
# #
# Run (full output without color-coding): # Run (full output without color-coding):
# sudo ./test_xsk.sh # sudo ./test_xsk.sh
#
# Run with verbose output:
# sudo ./test_xsk.sh -v
#
# Run and dump packet contents:
# sudo ./test_xsk.sh -D
. xsk_prereqs.sh . xsk_prereqs.sh
while getopts c flag while getopts "cvD" flag
do do
case "${flag}" in case "${flag}" in
c) colorconsole=1;; c) colorconsole=1;;
v) verbose=1;;
D) dump_pkts=1;;
esac esac
done done
...@@ -95,13 +103,17 @@ NS1=af_xdp${VETH1_POSTFIX} ...@@ -95,13 +103,17 @@ NS1=af_xdp${VETH1_POSTFIX}
MTU=1500 MTU=1500
setup_vethPairs() { setup_vethPairs() {
echo "setting up ${VETH0}: namespace: ${NS0}" if [[ $verbose -eq 1 ]]; then
echo "setting up ${VETH0}: namespace: ${NS0}"
fi
ip netns add ${NS1} ip netns add ${NS1}
ip link add ${VETH0} type veth peer name ${VETH1} ip link add ${VETH0} type veth peer name ${VETH1}
if [ -f /proc/net/if_inet6 ]; then if [ -f /proc/net/if_inet6 ]; then
echo 1 > /proc/sys/net/ipv6/conf/${VETH0}/disable_ipv6 echo 1 > /proc/sys/net/ipv6/conf/${VETH0}/disable_ipv6
fi fi
echo "setting up ${VETH1}: namespace: ${NS1}" if [[ $verbose -eq 1 ]]; then
echo "setting up ${VETH1}: namespace: ${NS1}"
fi
ip link set ${VETH1} netns ${NS1} ip link set ${VETH1} netns ${NS1}
ip netns exec ${NS1} ip link set ${VETH1} mtu ${MTU} ip netns exec ${NS1} ip link set ${VETH1} mtu ${MTU}
ip link set ${VETH0} mtu ${MTU} ip link set ${VETH0} mtu ${MTU}
...@@ -125,121 +137,24 @@ echo "${VETH0}:${VETH1},${NS1}" > ${SPECFILE} ...@@ -125,121 +137,24 @@ echo "${VETH0}:${VETH1},${NS1}" > ${SPECFILE}
validate_veth_spec_file validate_veth_spec_file
echo "Spec file created: ${SPECFILE}" if [[ $verbose -eq 1 ]]; then
echo "Spec file created: ${SPECFILE}"
test_status $retval "${TEST_NAME}" VERBOSE_ARG="-v"
## START TESTS
statusList=()
### TEST 1
TEST_NAME="XSK KSELFTEST FRAMEWORK"
echo "Switching interfaces [${VETH0}, ${VETH1}] to XDP Generic mode"
vethXDPgeneric ${VETH0} ${VETH1} ${NS1}
retval=$?
if [ $retval -eq 0 ]; then
echo "Switching interfaces [${VETH0}, ${VETH1}] to XDP Native mode"
vethXDPnative ${VETH0} ${VETH1} ${NS1}
fi fi
retval=$? if [[ $dump_pkts -eq 1 ]]; then
test_status $retval "${TEST_NAME}" DUMP_PKTS_ARG="-D"
statusList+=($retval) fi
### TEST 2
TEST_NAME="SKB NOPOLL"
vethXDPgeneric ${VETH0} ${VETH1} ${NS1}
params=("-S")
execxdpxceiver params
retval=$?
test_status $retval "${TEST_NAME}"
statusList+=($retval)
### TEST 3
TEST_NAME="SKB POLL"
vethXDPgeneric ${VETH0} ${VETH1} ${NS1}
params=("-S" "-p")
execxdpxceiver params
retval=$?
test_status $retval "${TEST_NAME}"
statusList+=($retval)
### TEST 4
TEST_NAME="DRV NOPOLL"
vethXDPnative ${VETH0} ${VETH1} ${NS1}
params=("-N")
execxdpxceiver params
retval=$?
test_status $retval "${TEST_NAME}"
statusList+=($retval)
### TEST 5
TEST_NAME="DRV POLL"
vethXDPnative ${VETH0} ${VETH1} ${NS1}
params=("-N" "-p")
execxdpxceiver params
retval=$?
test_status $retval "${TEST_NAME}"
statusList+=($retval)
### TEST 6
TEST_NAME="SKB SOCKET TEARDOWN"
vethXDPgeneric ${VETH0} ${VETH1} ${NS1}
params=("-S" "-T")
execxdpxceiver params
retval=$?
test_status $retval "${TEST_NAME}"
statusList+=($retval)
### TEST 7
TEST_NAME="DRV SOCKET TEARDOWN"
vethXDPnative ${VETH0} ${VETH1} ${NS1}
params=("-N" "-T")
execxdpxceiver params
retval=$?
test_status $retval "${TEST_NAME}" test_status $retval "${TEST_NAME}"
statusList+=($retval)
### TEST 8 ## START TESTS
TEST_NAME="SKB BIDIRECTIONAL SOCKETS"
vethXDPgeneric ${VETH0} ${VETH1} ${NS1}
params=("-S" "-B")
execxdpxceiver params
retval=$?
test_status $retval "${TEST_NAME}"
statusList+=($retval)
### TEST 9 statusList=()
TEST_NAME="DRV BIDIRECTIONAL SOCKETS"
vethXDPnative ${VETH0} ${VETH1} ${NS1} TEST_NAME="XSK KSELFTESTS"
params=("-N" "-B") execxdpxceiver
execxdpxceiver params
retval=$? retval=$?
test_status $retval "${TEST_NAME}" test_status $retval "${TEST_NAME}"
......
This diff is collapsed.
...@@ -41,33 +41,59 @@ ...@@ -41,33 +41,59 @@
#define BATCH_SIZE 64 #define BATCH_SIZE 64
#define POLL_TMOUT 1000 #define POLL_TMOUT 1000
#define NEED_WAKEUP true #define NEED_WAKEUP true
#define DEFAULT_PKT_CNT 10000
#define RX_FULL_RXQSIZE 32
#define print_verbose(x...) do { if (opt_verbose) ksft_print_msg(x); } while (0)
typedef __u32 u32; typedef __u32 u32;
typedef __u16 u16; typedef __u16 u16;
typedef __u8 u8; typedef __u8 u8;
enum TESTS { enum TEST_MODES {
ORDER_CONTENT_VALIDATE_XDP_SKB = 0, TEST_MODE_UNCONFIGURED = -1,
ORDER_CONTENT_VALIDATE_XDP_DRV = 1, TEST_MODE_SKB,
TEST_MODE_DRV,
TEST_MODE_MAX
};
enum TEST_TYPES {
TEST_TYPE_NOPOLL,
TEST_TYPE_POLL,
TEST_TYPE_TEARDOWN,
TEST_TYPE_BIDI,
TEST_TYPE_STATS,
TEST_TYPE_MAX
}; };
u8 uut; enum STAT_TEST_TYPES {
u8 debug_pkt_dump; STAT_TEST_RX_DROPPED,
u32 num_frames; STAT_TEST_TX_INVALID,
u8 switching_notify; STAT_TEST_RX_FULL,
u8 bidi_pass; STAT_TEST_RX_FILL_EMPTY,
STAT_TEST_TYPE_MAX
};
static int configured_mode = TEST_MODE_UNCONFIGURED;
static u8 debug_pkt_dump;
static u32 num_frames;
static u8 switching_notify;
static u8 bidi_pass;
static int test_type;
static u32 opt_xdp_flags = XDP_FLAGS_UPDATE_IF_NOEXIST;
static int opt_queue; static int opt_queue;
static int opt_pkt_count; static int opt_pkt_count;
static int opt_poll; static u8 opt_verbose;
static int opt_teardown;
static int opt_bidi; static u32 xdp_flags = XDP_FLAGS_UPDATE_IF_NOEXIST;
static u32 opt_xdp_bind_flags = XDP_USE_NEED_WAKEUP; static u32 xdp_bind_flags = XDP_USE_NEED_WAKEUP | XDP_COPY;
static u8 pkt_data[XSK_UMEM__DEFAULT_FRAME_SIZE]; static u8 pkt_data[XSK_UMEM__DEFAULT_FRAME_SIZE];
static u32 pkt_counter; static u32 pkt_counter;
static u32 prev_pkt = -1; static long prev_pkt = -1;
static int sigvar; static int sigvar;
static int stat_test_type;
static u32 rxqsize;
static u32 frame_headroom;
struct xsk_umem_info { struct xsk_umem_info {
struct xsk_ring_prod fq; struct xsk_ring_prod fq;
...@@ -137,8 +163,9 @@ pthread_t t0, t1, ns_thread; ...@@ -137,8 +163,9 @@ pthread_t t0, t1, ns_thread;
pthread_attr_t attr; pthread_attr_t attr;
struct targs { struct targs {
bool retptr; u8 retptr;
int idx; int idx;
u32 flags;
}; };
TAILQ_HEAD(head_s, pkt) head = TAILQ_HEAD_INITIALIZER(head); TAILQ_HEAD(head_s, pkt) head = TAILQ_HEAD_INITIALIZER(head);
......
...@@ -82,24 +82,21 @@ clear_configs() ...@@ -82,24 +82,21 @@ clear_configs()
{ {
if [ $(ip netns show | grep $3 &>/dev/null; echo $?;) == 0 ]; then if [ $(ip netns show | grep $3 &>/dev/null; echo $?;) == 0 ]; then
[ $(ip netns exec $3 ip link show $2 &>/dev/null; echo $?;) == 0 ] && [ $(ip netns exec $3 ip link show $2 &>/dev/null; echo $?;) == 0 ] &&
{ echo "removing link $1:$2"; ip netns exec $3 ip link del $2; } { ip netns exec $3 ip link del $2; }
echo "removing ns $3"
ip netns del $3 ip netns del $3
fi fi
#Once we delete a veth pair node, the entire veth pair is removed, #Once we delete a veth pair node, the entire veth pair is removed,
#this is just to be cautious just incase the NS does not exist then #this is just to be cautious just incase the NS does not exist then
#veth node inside NS won't get removed so we explicitly remove it #veth node inside NS won't get removed so we explicitly remove it
[ $(ip link show $1 &>/dev/null; echo $?;) == 0 ] && [ $(ip link show $1 &>/dev/null; echo $?;) == 0 ] &&
{ echo "removing link $1"; ip link del $1; } { ip link del $1; }
if [ -f ${SPECFILE} ]; then if [ -f ${SPECFILE} ]; then
echo "removing spec file:" ${SPECFILE}
rm -f ${SPECFILE} rm -f ${SPECFILE}
fi fi
} }
cleanup_exit() cleanup_exit()
{ {
echo "cleaning up..."
clear_configs $1 $2 $3 clear_configs $1 $2 $3
} }
...@@ -108,28 +105,7 @@ validate_ip_utility() ...@@ -108,28 +105,7 @@ validate_ip_utility()
[ ! $(type -P ip) ] && { echo "'ip' not found. Skipping tests."; test_exit $ksft_skip 1; } [ ! $(type -P ip) ] && { echo "'ip' not found. Skipping tests."; test_exit $ksft_skip 1; }
} }
vethXDPgeneric()
{
ip link set dev $1 xdpdrv off
ip netns exec $3 ip link set dev $2 xdpdrv off
}
vethXDPnative()
{
ip link set dev $1 xdpgeneric off
ip netns exec $3 ip link set dev $2 xdpgeneric off
}
execxdpxceiver() execxdpxceiver()
{ {
local -a 'paramkeys=("${!'"$1"'[@]}")' copy ./${XSKOBJ} -i ${VETH0} -i ${VETH1},${NS1} -C ${NUMPKTS} ${VERBOSE_ARG} ${DUMP_PKTS_ARG}
paramkeysstr=${paramkeys[*]}
for index in $paramkeysstr;
do
current=$1"[$index]"
copy[$index]=${!current}
done
./${XSKOBJ} -i ${VETH0} -i ${VETH1},${NS1} ${copy[*]} -C ${NUMPKTS}
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment