Commit 62e80f2b authored by Sidhartha Kumar's avatar Sidhartha Kumar Committed by akpm

tools/testing/selftests/vm/gup_test.c: clarify error statement

Print three possible reasons /sys/kernel/debug/gup_test cannot be opened
to help users of this test diagnose failures.

Link: https://lkml.kernel.org/r/20220405214809.3351223-1-sidhartha.kumar@oracle.comSigned-off-by: default avatarSidhartha Kumar <sidhartha.kumar@oracle.com>
Reviewed-by: default avatarShuah Khan <skhan@linuxfoundation.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent 0e5e64c0
#include <fcntl.h> #include <fcntl.h>
#include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <dirent.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <sys/stat.h> #include <sys/stat.h>
...@@ -9,6 +11,7 @@ ...@@ -9,6 +11,7 @@
#include <pthread.h> #include <pthread.h>
#include <assert.h> #include <assert.h>
#include "../../../../mm/gup_test.h" #include "../../../../mm/gup_test.h"
#include "../kselftest.h"
#include "util.h" #include "util.h"
...@@ -206,8 +209,23 @@ int main(int argc, char **argv) ...@@ -206,8 +209,23 @@ int main(int argc, char **argv)
gup_fd = open("/sys/kernel/debug/gup_test", O_RDWR); gup_fd = open("/sys/kernel/debug/gup_test", O_RDWR);
if (gup_fd == -1) { if (gup_fd == -1) {
perror("open"); switch (errno) {
exit(1); case EACCES:
if (getuid())
printf("Please run this test as root\n");
break;
case ENOENT:
if (opendir("/sys/kernel/debug") == NULL) {
printf("mount debugfs at /sys/kernel/debug\n");
break;
}
printf("check if CONFIG_GUP_TEST is enabled in kernel config\n");
break;
default:
perror("failed to open /sys/kernel/debug/gup_test");
break;
}
exit(KSFT_SKIP);
} }
p = mmap(NULL, size, PROT_READ | PROT_WRITE, flags, filed, 0); p = mmap(NULL, size, PROT_READ | PROT_WRITE, flags, filed, 0);
......
...@@ -162,22 +162,32 @@ echo "------------------------------------------------------" ...@@ -162,22 +162,32 @@ echo "------------------------------------------------------"
echo "running: gup_test -u # get_user_pages_fast() benchmark" echo "running: gup_test -u # get_user_pages_fast() benchmark"
echo "------------------------------------------------------" echo "------------------------------------------------------"
./gup_test -u ./gup_test -u
if [ $? -ne 0 ]; then ret_val=$?
if [ $ret_val -eq 0 ]; then
echo "[PASS]"
elif [ $ret_val -eq $ksft_skip ]; then
echo "[SKIP]"
exitcode=$ksft_skip
else
echo "[FAIL]" echo "[FAIL]"
exitcode=1 exitcode=1
else
echo "[PASS]"
fi fi
echo "------------------------------------------------------" echo "------------------------------------------------------"
echo "running: gup_test -a # pin_user_pages_fast() benchmark" echo "running: gup_test -a # pin_user_pages_fast() benchmark"
echo "------------------------------------------------------" echo "------------------------------------------------------"
./gup_test -a ./gup_test -a
if [ $? -ne 0 ]; then ret_val=$?
if [ $ret_val -eq 0 ]; then
echo "[PASS]"
elif [ $ret_val -eq $ksft_skip ]; then
echo "[SKIP]"
exitcode=$ksft_skip
else
echo "[FAIL]" echo "[FAIL]"
exitcode=1 exitcode=1
else
echo "[PASS]"
fi fi
echo "------------------------------------------------------------" echo "------------------------------------------------------------"
...@@ -185,11 +195,16 @@ echo "# Dump pages 0, 19, and 4096, using pin_user_pages:" ...@@ -185,11 +195,16 @@ echo "# Dump pages 0, 19, and 4096, using pin_user_pages:"
echo "running: gup_test -ct -F 0x1 0 19 0x1000 # dump_page() test" echo "running: gup_test -ct -F 0x1 0 19 0x1000 # dump_page() test"
echo "------------------------------------------------------------" echo "------------------------------------------------------------"
./gup_test -ct -F 0x1 0 19 0x1000 ./gup_test -ct -F 0x1 0 19 0x1000
if [ $? -ne 0 ]; then ret_val=$?
if [ $ret_val -eq 0 ]; then
echo "[PASS]"
elif [ $ret_val -eq $ksft_skip ]; then
echo "[SKIP]"
exitcode=$ksft_skip
else
echo "[FAIL]" echo "[FAIL]"
exitcode=1 exitcode=1
else
echo "[PASS]"
fi fi
echo "-------------------" echo "-------------------"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment