selftests/mm: run_vmtests: remove sudo and conform to tap
authorMuhammad Usama Anjum <usama.anjum@collabora.com>
Thu, 25 Jan 2024 15:46:05 +0000 (20:46 +0500)
committerAndrew Morton <akpm@linux-foundation.org>
Thu, 22 Feb 2024 23:38:55 +0000 (15:38 -0800)
Remove sudo as some test running environments may not have sudo available.
Instead skip the test if root privileges aren't available in the test.

[usama.anjum@collabora.com: on-fault-limit: run test without root privileges otherwise skip]
Link: https://lkml.kernel.org/r/20240201130538.1404897-1-usama.anjum@collabora.com
Link: https://lkml.kernel.org/r/20240125154608.720072-3-usama.anjum@collabora.com
Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Shuah Khan <shuah@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
tools/testing/selftests/mm/on-fault-limit.c
tools/testing/selftests/mm/run_vmtests.sh

index b5888d613f34ebe7f98017016f7a9d753452cf45..431c1277d83a1dcd6907c9a4ccaaa9b6227d4c76 100644 (file)
@@ -5,40 +5,38 @@
 #include <string.h>
 #include <sys/time.h>
 #include <sys/resource.h>
+#include "../kselftest.h"
 
-static int test_limit(void)
+static void test_limit(void)
 {
-       int ret = 1;
        struct rlimit lims;
        void *map;
 
-       if (getrlimit(RLIMIT_MEMLOCK, &lims)) {
-               perror("getrlimit");
-               return ret;
-       }
+       if (getrlimit(RLIMIT_MEMLOCK, &lims))
+               ksft_exit_fail_msg("getrlimit: %s\n", strerror(errno));
 
-       if (mlockall(MCL_ONFAULT | MCL_FUTURE)) {
-               perror("mlockall");
-               return ret;
-       }
+       if (mlockall(MCL_ONFAULT | MCL_FUTURE))
+               ksft_exit_fail_msg("mlockall: %s\n", strerror(errno));
 
        map = mmap(NULL, 2 * lims.rlim_max, PROT_READ | PROT_WRITE,
                   MAP_PRIVATE | MAP_ANONYMOUS | MAP_POPULATE, -1, 0);
+
+       ksft_test_result(map == MAP_FAILED, "The map failed respecting mlock limits\n");
+
        if (map != MAP_FAILED)
-               printf("mmap should have failed, but didn't\n");
-       else {
-               ret = 0;
                munmap(map, 2 * lims.rlim_max);
-       }
-
        munlockall();
-       return ret;
 }
 
 int main(int argc, char **argv)
 {
-       int ret = 0;
+       ksft_print_header();
+       ksft_set_plan(1);
+
+       if (!getuid())
+               ksft_test_result_skip("The test must be run from a normal user\n");
+       else
+               test_limit();
 
-       ret += test_limit();
-       return ret;
+       ksft_finished();
 }
index 246d53a5d7f287756795ca6fc73103018402ddfa..416bfc8198b30ee006e989a26b36f586362cc2df 100755 (executable)
@@ -291,7 +291,12 @@ echo "$nr_hugepgs" > /proc/sys/vm/nr_hugepages
 
 CATEGORY="compaction" run_test ./compaction_test
 
-CATEGORY="mlock" run_test sudo -u nobody ./on-fault-limit
+if command -v sudo &> /dev/null;
+then
+       CATEGORY="mlock" run_test sudo -u nobody ./on-fault-limit
+else
+       echo "# SKIP ./on-fault-limit"
+fi
 
 CATEGORY="mmap" run_test ./map_populate