selftests/xsk: add option to only run tests in a single mode
authorMagnus Karlsson <magnus.karlsson@intel.com>
Thu, 14 Sep 2023 08:48:50 +0000 (10:48 +0200)
committerAlexei Starovoitov <ast@kernel.org>
Thu, 14 Sep 2023 16:47:55 +0000 (09:47 -0700)
Add an option -m on the command line that allows the user to run the
tests in a single mode instead of all of them. Valid modes are skb,
drv, and zc (zero-copy). An example:

To run test suite in drv mode only:

./test_xsk.sh -m drv

Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com>
Link: https://lore.kernel.org/r/20230914084900.492-4-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 2aa5a3445056ac917a44fcb73a17482c137efeb7..85e7a7e843f7750b725e4ea313272c0dcf978a10 100755 (executable)
 #
 # Run test suite for physical device in loopback mode
 #   sudo ./test_xsk.sh -i IFACE
+#
+# Run test suite in a specific mode only [skb,drv,zc]
+#   sudo ./test_xsk.sh -m MODE
 
 . xsk_prereqs.sh
 
 ETH=""
 
-while getopts "vi:d" flag
+while getopts "vi:dm:" flag
 do
        case "${flag}" in
                v) verbose=1;;
                d) debug=1;;
                i) ETH=${OPTARG};;
+               m) MODE=${OPTARG};;
        esac
 done
 
@@ -153,6 +157,10 @@ if [[ $verbose -eq 1 ]]; then
        ARGS+="-v "
 fi
 
+if [ -n "$MODE" ]; then
+       ARGS+="-m ${MODE} "
+fi
+
 retval=$?
 test_status $retval "${TEST_NAME}"
 
index 514fe994e02be7befbfc36ee7614f1ef76e1ba16..64a671fca54aa6cc8d224a99c69975bd396d8a68 100644 (file)
 static const char *MAC1 = "\x00\x0A\x56\x9E\xEE\x62";
 static const char *MAC2 = "\x00\x0A\x56\x9E\xEE\x61";
 
+static bool opt_verbose;
+static enum test_mode opt_mode = TEST_MODE_ALL;
+
 static void __exit_with_error(int error, const char *file, const char *func, int line)
 {
        ksft_test_result_fail("[%s:%s:%i]: ERROR: %d/\"%s\"\n", file, func, line, error,
@@ -310,17 +313,19 @@ static struct option long_options[] = {
        {"interface", required_argument, 0, 'i'},
        {"busy-poll", no_argument, 0, 'b'},
        {"verbose", no_argument, 0, 'v'},
+       {"mode", required_argument, 0, 'm'},
        {0, 0, 0, 0}
 };
 
 static void usage(const char *prog)
 {
        const char *str =
-               "  Usage: %s [OPTIONS]\n"
+               "  Usage: xskxceiver [OPTIONS]\n"
                "  Options:\n"
                "  -i, --interface      Use interface\n"
                "  -v, --verbose        Verbose output\n"
-               "  -b, --busy-poll      Enable busy poll\n";
+               "  -b, --busy-poll      Enable busy poll\n"
+               "  -m, --mode           Run only mode skb, drv, or zc\n";
 
        ksft_print_msg(str, prog);
 }
@@ -342,7 +347,7 @@ static void parse_command_line(struct ifobject *ifobj_tx, struct ifobject *ifobj
        opterr = 0;
 
        for (;;) {
-               c = getopt_long(argc, argv, "i:vb", long_options, &option_index);
+               c = getopt_long(argc, argv, "i:vbm:", long_options, &option_index);
                if (c == -1)
                        break;
 
@@ -371,6 +376,18 @@ static void parse_command_line(struct ifobject *ifobj_tx, struct ifobject *ifobj
                        ifobj_tx->busy_poll = true;
                        ifobj_rx->busy_poll = true;
                        break;
+               case 'm':
+                       if (!strncmp("skb", optarg, strlen(optarg))) {
+                               opt_mode = TEST_MODE_SKB;
+                       } else if (!strncmp("drv", optarg, strlen(optarg))) {
+                               opt_mode = TEST_MODE_DRV;
+                       } else if (!strncmp("zc", optarg, strlen(optarg))) {
+                               opt_mode = TEST_MODE_ZC;
+                       } else {
+                               usage(basename(argv[0]));
+                               ksft_exit_xfail();
+                       }
+                       break;
                default:
                        usage(basename(argv[0]));
                        ksft_exit_xfail();
@@ -2365,9 +2382,25 @@ int main(int argc, char **argv)
        test.tx_pkt_stream_default = tx_pkt_stream_default;
        test.rx_pkt_stream_default = rx_pkt_stream_default;
 
-       ksft_set_plan(modes * TEST_TYPE_MAX);
+       if (opt_mode == TEST_MODE_ALL) {
+               ksft_set_plan(modes * TEST_TYPE_MAX);
+       } else {
+               if (opt_mode == TEST_MODE_DRV && modes <= TEST_MODE_DRV) {
+                       ksft_print_msg("Error: XDP_DRV mode not supported.\n");
+                       ksft_exit_xfail();
+               }
+               if (opt_mode == TEST_MODE_ZC && modes <= TEST_MODE_ZC) {
+                       ksft_print_msg("Error: zero-copy mode not supported.\n");
+                       ksft_exit_xfail();
+               }
+
+               ksft_set_plan(TEST_TYPE_MAX);
+       }
 
        for (i = 0; i < modes; i++) {
+               if (opt_mode != TEST_MODE_ALL && i != opt_mode)
+                       continue;
+
                for (j = 0; j < TEST_TYPE_MAX; j++) {
                        test_spec_init(&test, ifobj_tx, ifobj_rx, i);
                        run_pkt_test(&test, i, j);
index 233b66cef64a59369dae5f35fdfdc72d2b9a9170..1412492e9618910cf15b08783f32f0f622d86086 100644 (file)
@@ -63,7 +63,7 @@ enum test_mode {
        TEST_MODE_SKB,
        TEST_MODE_DRV,
        TEST_MODE_ZC,
-       TEST_MODE_MAX
+       TEST_MODE_ALL
 };
 
 enum test_type {
@@ -98,8 +98,6 @@ enum test_type {
        TEST_TYPE_MAX
 };
 
-static bool opt_verbose;
-
 struct xsk_umem_info {
        struct xsk_ring_prod fq;
        struct xsk_ring_cons cq;