selftests/xsk: dump packet at error
authorMagnus Karlsson <magnus.karlsson@intel.com>
Tue, 16 May 2023 10:31:03 +0000 (12:31 +0200)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 17 May 2023 05:31:51 +0000 (22:31 -0700)
Dump the content of the packet when a test finds that packets are
received out of order, the length is wrong, or some other packet
error. Use the already existing pkt_dump function for this and call it
when the above errors are detected. Get rid of the command line option
for dumping packets as it is not useful to print out thousands of
good packets followed by the faulty one you would like to see.

Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com>
Link: https://lore.kernel.org/r/20230516103109.3066-5-magnus.karlsson@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/test_xsk.sh
tools/testing/selftests/bpf/xskxceiver.c
tools/testing/selftests/bpf/xskxceiver.h

index 377fb157a57c566f768f000841c720419210813e..c2ad50f26b636a4f448aae34288e9ea37a34c9d2 100755 (executable)
@@ -68,9 +68,6 @@
 # Run with verbose output:
 #   sudo ./test_xsk.sh -v
 #
-# Run and dump packet contents:
-#   sudo ./test_xsk.sh -D
-#
 # Set up veth interfaces and leave them up so xskxceiver can be launched in a debugger:
 #   sudo ./test_xsk.sh -d
 #
 
 ETH=""
 
-while getopts "vDi:d" flag
+while getopts "vi:d" flag
 do
        case "${flag}" in
                v) verbose=1;;
-               D) dump_pkts=1;;
                d) debug=1;;
                i) ETH=${OPTARG};;
        esac
@@ -157,10 +153,6 @@ if [[ $verbose -eq 1 ]]; then
        ARGS+="-v "
 fi
 
-if [[ $dump_pkts -eq 1 ]]; then
-       ARGS="-D "
-fi
-
 retval=$?
 test_status $retval "${TEST_NAME}"
 
index 818b7130f932cc6b55ff460303fafab2fdda27bb..0a8231ed6626045ddaaf99880dfebadfc6e36b50 100644 (file)
@@ -275,7 +275,6 @@ out:
 static struct option long_options[] = {
        {"interface", required_argument, 0, 'i'},
        {"busy-poll", no_argument, 0, 'b'},
-       {"dump-pkts", no_argument, 0, 'D'},
        {"verbose", no_argument, 0, 'v'},
        {0, 0, 0, 0}
 };
@@ -286,7 +285,6 @@ static void usage(const char *prog)
                "  Usage: %s [OPTIONS]\n"
                "  Options:\n"
                "  -i, --interface      Use interface\n"
-               "  -D, --dump-pkts      Dump packets L2 - L5\n"
                "  -v, --verbose        Verbose output\n"
                "  -b, --busy-poll      Enable busy poll\n";
 
@@ -310,7 +308,7 @@ static void parse_command_line(struct ifobject *ifobj_tx, struct ifobject *ifobj
        opterr = 0;
 
        for (;;) {
-               c = getopt_long(argc, argv, "i:Dvb", long_options, &option_index);
+               c = getopt_long(argc, argv, "i:vb", long_options, &option_index);
                if (c == -1)
                        break;
 
@@ -332,9 +330,6 @@ static void parse_command_line(struct ifobject *ifobj_tx, struct ifobject *ifobj
 
                        interface_nb++;
                        break;
-               case 'D':
-                       opt_pkt_dump = true;
-                       break;
                case 'v':
                        opt_verbose = true;
                        break;
@@ -714,7 +709,7 @@ static bool is_pkt_valid(struct pkt *pkt, void *buffer, u64 addr, u32 len)
 
        if (!pkt) {
                ksft_print_msg("[%s] too many packets received\n", __func__);
-               return false;
+               goto error;
        }
 
        if (len < MIN_PKT_SIZE || pkt->len < MIN_PKT_SIZE) {
@@ -725,22 +720,23 @@ static bool is_pkt_valid(struct pkt *pkt, void *buffer, u64 addr, u32 len)
        if (pkt->len != len) {
                ksft_print_msg("[%s] expected length [%d], got length [%d]\n",
                               __func__, pkt->len, len);
-               return false;
+               goto error;
        }
 
        pkt_data = ntohl(*((u32 *)(data + PKT_HDR_SIZE)));
        seqnum = pkt_data >> 16;
 
-       if (opt_pkt_dump)
-               pkt_dump(data, len);
-
        if (pkt->pkt_nb != seqnum) {
                ksft_print_msg("[%s] expected seqnum [%d], got seqnum [%d]\n",
                               __func__, pkt->pkt_nb, seqnum);
-               return false;
+               goto error;
        }
 
        return true;
+
+error:
+       pkt_dump(data, len);
+       return false;
 }
 
 static void kick_tx(struct xsk_socket_info *xsk)
index 91022c4876eb94ab364e9ade0d271ccf1aabefce..5e0be96855578141e061d241596aea62a1c7176c 100644 (file)
@@ -85,7 +85,6 @@ enum test_type {
        TEST_TYPE_MAX
 };
 
-static bool opt_pkt_dump;
 static bool opt_verbose;
 
 struct xsk_umem_info {