selftests: ncdevmem: Run selftest when none of the -s or -c has been provided
authorStanislav Fomichev <sdf@fomichev.me>
Thu, 7 Nov 2024 18:12:09 +0000 (10:12 -0800)
committerJakub Kicinski <kuba@kernel.org>
Tue, 12 Nov 2024 01:01:04 +0000 (17:01 -0800)
This will be used as a 'probe' mode in the selftest to check whether
the device supports the devmem or not. Use hard-coded queue layout
(two last queues) and prevent user from passing custom -q and/or -t.

Reviewed-by: Mina Almasry <almasrymina@google.com>
Reviewed-by: Joe Damato <jdamato@fastly.com>
Signed-off-by: Stanislav Fomichev <sdf@fomichev.me>
Link: https://patch.msgid.link/20241107181211.3934153-11-sdf@fomichev.me
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
tools/testing/selftests/net/ncdevmem.c

index 1ea62c129ddc2557a664e7e3ca50e9b38a5b38aa..8e502a1f8f9bc1842db7e1dbfccbc7e1b003ea12 100644 (file)
@@ -76,7 +76,7 @@ static char *client_ip;
 static char *port;
 static size_t do_validation;
 static int start_queue = -1;
-static int num_queues = 1;
+static int num_queues = -1;
 static char *ifname;
 static unsigned int ifindex;
 static unsigned int dmabuf_id;
@@ -727,19 +727,38 @@ int main(int argc, char *argv[])
                }
        }
 
-       if (!server_ip)
-               error(1, 0, "Missing -s argument\n");
-
-       if (!port)
-               error(1, 0, "Missing -p argument\n");
-
        if (!ifname)
                error(1, 0, "Missing -f argument\n");
 
        ifindex = if_nametoindex(ifname);
 
-       if (start_queue < 0) {
-               start_queue = rxq_num(ifindex) - 1;
+       if (!server_ip && !client_ip) {
+               if (start_queue < 0 && num_queues < 0) {
+                       num_queues = rxq_num(ifindex);
+                       if (num_queues < 0)
+                               error(1, 0, "couldn't detect number of queues\n");
+                       if (num_queues < 2)
+                               error(1, 0,
+                                     "number of device queues is too low\n");
+                       /* make sure can bind to multiple queues */
+                       start_queue = num_queues / 2;
+                       num_queues /= 2;
+               }
+
+               if (start_queue < 0 || num_queues < 0)
+                       error(1, 0, "Both -t and -q are required\n");
+
+               run_devmem_tests();
+               return 0;
+       }
+
+       if (start_queue < 0 && num_queues < 0) {
+               num_queues = rxq_num(ifindex);
+               if (num_queues < 2)
+                       error(1, 0, "number of device queues is too low\n");
+
+               num_queues = 1;
+               start_queue = rxq_num(ifindex) - num_queues;
 
                if (start_queue < 0)
                        error(1, 0, "couldn't detect number of queues\n");
@@ -750,7 +769,17 @@ int main(int argc, char *argv[])
        for (; optind < argc; optind++)
                fprintf(stderr, "extra arguments: %s\n", argv[optind]);
 
-       run_devmem_tests();
+       if (start_queue < 0)
+               error(1, 0, "Missing -t argument\n");
+
+       if (num_queues < 0)
+               error(1, 0, "Missing -q argument\n");
+
+       if (!server_ip)
+               error(1, 0, "Missing -s argument\n");
+
+       if (!port)
+               error(1, 0, "Missing -p argument\n");
 
        mem = provider->alloc(getpagesize() * NUM_PAGES);
        ret = is_server ? do_server(mem) : 1;