Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/mm: run_vmtests: remove sudo and conform to tap

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>

authored by

Muhammad Usama Anjum and committed by
Andrew Morton
20a2191c f2943f3f

+24 -21
+18 -20
tools/testing/selftests/mm/on-fault-limit.c
··· 5 5 #include <string.h> 6 6 #include <sys/time.h> 7 7 #include <sys/resource.h> 8 + #include "../kselftest.h" 8 9 9 - static int test_limit(void) 10 + static void test_limit(void) 10 11 { 11 - int ret = 1; 12 12 struct rlimit lims; 13 13 void *map; 14 14 15 - if (getrlimit(RLIMIT_MEMLOCK, &lims)) { 16 - perror("getrlimit"); 17 - return ret; 18 - } 15 + if (getrlimit(RLIMIT_MEMLOCK, &lims)) 16 + ksft_exit_fail_msg("getrlimit: %s\n", strerror(errno)); 19 17 20 - if (mlockall(MCL_ONFAULT | MCL_FUTURE)) { 21 - perror("mlockall"); 22 - return ret; 23 - } 18 + if (mlockall(MCL_ONFAULT | MCL_FUTURE)) 19 + ksft_exit_fail_msg("mlockall: %s\n", strerror(errno)); 24 20 25 21 map = mmap(NULL, 2 * lims.rlim_max, PROT_READ | PROT_WRITE, 26 22 MAP_PRIVATE | MAP_ANONYMOUS | MAP_POPULATE, -1, 0); 27 - if (map != MAP_FAILED) 28 - printf("mmap should have failed, but didn't\n"); 29 - else { 30 - ret = 0; 31 - munmap(map, 2 * lims.rlim_max); 32 - } 33 23 24 + ksft_test_result(map == MAP_FAILED, "The map failed respecting mlock limits\n"); 25 + 26 + if (map != MAP_FAILED) 27 + munmap(map, 2 * lims.rlim_max); 34 28 munlockall(); 35 - return ret; 36 29 } 37 30 38 31 int main(int argc, char **argv) 39 32 { 40 - int ret = 0; 33 + ksft_print_header(); 34 + ksft_set_plan(1); 41 35 42 - ret += test_limit(); 43 - return ret; 36 + if (!getuid()) 37 + ksft_test_result_skip("The test must be run from a normal user\n"); 38 + else 39 + test_limit(); 40 + 41 + ksft_finished(); 44 42 }
+6 -1
tools/testing/selftests/mm/run_vmtests.sh
··· 291 291 292 292 CATEGORY="compaction" run_test ./compaction_test 293 293 294 - CATEGORY="mlock" run_test sudo -u nobody ./on-fault-limit 294 + if command -v sudo &> /dev/null; 295 + then 296 + CATEGORY="mlock" run_test sudo -u nobody ./on-fault-limit 297 + else 298 + echo "# SKIP ./on-fault-limit" 299 + fi 295 300 296 301 CATEGORY="mmap" run_test ./map_populate 297 302