Skip to content

Commit

Permalink
tools/testing/selftests/vm/gup_test.c: clarify error statement
Browse files Browse the repository at this point in the history
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/[email protected]
Signed-off-by: Sidhartha Kumar <[email protected]>
Reviewed-by: Shuah Khan <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
  • Loading branch information
sidkumar99 authored and akpm00 committed Apr 29, 2022
1 parent 0e5e64c commit 62e80f2
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 11 deletions.
22 changes: 20 additions & 2 deletions tools/testing/selftests/vm/gup_test.c
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <dirent.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <pthread.h>
#include <assert.h>
#include "../../../../mm/gup_test.h"
#include "../kselftest.h"

#include "util.h"

Expand Down Expand Up @@ -206,8 +209,23 @@ int main(int argc, char **argv)

gup_fd = open("/sys/kernel/debug/gup_test", O_RDWR);
if (gup_fd == -1) {
perror("open");
exit(1);
switch (errno) {
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);
Expand Down
33 changes: 24 additions & 9 deletions tools/testing/selftests/vm/run_vmtests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -162,34 +162,49 @@ echo "------------------------------------------------------"
echo "running: gup_test -u # get_user_pages_fast() benchmark"
echo "------------------------------------------------------"
./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]"
exitcode=1
else
echo "[PASS]"
fi

echo "------------------------------------------------------"
echo "running: gup_test -a # pin_user_pages_fast() benchmark"
echo "------------------------------------------------------"
./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]"
exitcode=1
else
echo "[PASS]"
fi

echo "------------------------------------------------------------"
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 "------------------------------------------------------------"
./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]"
exitcode=1
else
echo "[PASS]"
fi

echo "-------------------"
Expand Down

0 comments on commit 62e80f2

Please sign in to comment.