* [PATCH v2] selftest/vm clarify error statement in gup_test
@ 2022-04-05 21:48 Sidhartha Kumar
2022-04-05 22:33 ` Matthew Wilcox
2022-04-06 19:35 ` Shuah Khan
0 siblings, 2 replies; 4+ messages in thread
From: Sidhartha Kumar @ 2022-04-05 21:48 UTC (permalink / raw)
To: shuah, akpm; +Cc: Sidhartha Kumar, linux-mm, linux-kselftest, linux-kernel
Print three possible reasons /sys/kernel/debug/gup_test
cannot be opened to help users of this test diagnose
failures.
Signed-off-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
---
v2:
- Add support for skipping the test due to unmet dependencies.
- Use errno to print a more specific message.
- Add check for root privileges.
- dropped CC to stable.
tools/testing/selftests/vm/gup_test.c | 22 +++++++++++++--
tools/testing/selftests/vm/run_vmtests.sh | 33 ++++++++++++++++-------
2 files changed, 44 insertions(+), 11 deletions(-)
diff --git a/tools/testing/selftests/vm/gup_test.c b/tools/testing/selftests/vm/gup_test.c
index fe043f67798b0..bdedaa6c58e18 100644
--- a/tools/testing/selftests/vm/gup_test.c
+++ b/tools/testing/selftests/vm/gup_test.c
@@ -1,7 +1,9 @@
#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>
@@ -9,6 +11,7 @@
#include <pthread.h>
#include <assert.h>
#include "../../../../mm/gup_test.h"
+#include "../kselftest.h"
#define MB (1UL << 20)
#define PAGE_SIZE sysconf(_SC_PAGESIZE)
@@ -205,8 +208,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);
diff --git a/tools/testing/selftests/vm/run_vmtests.sh b/tools/testing/selftests/vm/run_vmtests.sh
index 45e803af7c775..88e15fbb50278 100755
--- a/tools/testing/selftests/vm/run_vmtests.sh
+++ b/tools/testing/selftests/vm/run_vmtests.sh
@@ -127,22 +127,32 @@ 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 "------------------------------------------------------------"
@@ -150,11 +160,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 "------------------------------------------------------------"
./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 "-------------------"
--
2.27.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] selftest/vm clarify error statement in gup_test
2022-04-05 21:48 [PATCH v2] selftest/vm clarify error statement in gup_test Sidhartha Kumar
@ 2022-04-05 22:33 ` Matthew Wilcox
2022-04-06 19:38 ` Shuah Khan
2022-04-06 19:35 ` Shuah Khan
1 sibling, 1 reply; 4+ messages in thread
From: Matthew Wilcox @ 2022-04-05 22:33 UTC (permalink / raw)
To: Sidhartha Kumar; +Cc: shuah, akpm, linux-mm, linux-kselftest, linux-kernel
On Tue, Apr 05, 2022 at 09:48:09PM +0000, Sidhartha Kumar wrote:
> - perror("open");
> - exit(1);
> + switch (errno) {
> + case EACCES:
> + if (getuid())
> + printf("Please run this test as root\n");
Shouldn't all these be fprintf(stderr, ...); ?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] selftest/vm clarify error statement in gup_test
2022-04-05 21:48 [PATCH v2] selftest/vm clarify error statement in gup_test Sidhartha Kumar
2022-04-05 22:33 ` Matthew Wilcox
@ 2022-04-06 19:35 ` Shuah Khan
1 sibling, 0 replies; 4+ messages in thread
From: Shuah Khan @ 2022-04-06 19:35 UTC (permalink / raw)
To: Sidhartha Kumar, shuah, akpm
Cc: linux-mm, linux-kselftest, linux-kernel, Shuah Khan
On 4/5/22 3:48 PM, Sidhartha Kumar wrote:
> Print three possible reasons /sys/kernel/debug/gup_test
> cannot be opened to help users of this test diagnose
> failures.
>
> Signed-off-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
> ---
> v2:
> - Add support for skipping the test due to unmet dependencies.
> - Use errno to print a more specific message.
> - Add check for root privileges.
> - dropped CC to stable.
> tools/testing/selftests/vm/gup_test.c | 22 +++++++++++++--
> tools/testing/selftests/vm/run_vmtests.sh | 33 ++++++++++++++++-------
> 2 files changed, 44 insertions(+), 11 deletions(-)
>
Thank you for fixing the reporting and adding tests for dependencies
and skip conditions.
Reviewed-by: Shuah Khan <skhan@linuxfoundation.org>
thanks,
-- Shuah
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] selftest/vm clarify error statement in gup_test
2022-04-05 22:33 ` Matthew Wilcox
@ 2022-04-06 19:38 ` Shuah Khan
0 siblings, 0 replies; 4+ messages in thread
From: Shuah Khan @ 2022-04-06 19:38 UTC (permalink / raw)
To: Matthew Wilcox, Sidhartha Kumar
Cc: shuah, akpm, linux-mm, linux-kselftest, linux-kernel, Shuah Khan
On 4/5/22 4:33 PM, Matthew Wilcox wrote:
> On Tue, Apr 05, 2022 at 09:48:09PM +0000, Sidhartha Kumar wrote:
>> - perror("open");
>> - exit(1);
>> + switch (errno) {
>> + case EACCES:
>> + if (getuid())
>> + printf("Please run this test as root\n");
>
> Shouldn't all these be fprintf(stderr, ...); ?
>
>
printf() is consistent with the other messages in this file. Either
works.
thanks,
-- Shuah
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-04-06 21:03 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-05 21:48 [PATCH v2] selftest/vm clarify error statement in gup_test Sidhartha Kumar
2022-04-05 22:33 ` Matthew Wilcox
2022-04-06 19:38 ` Shuah Khan
2022-04-06 19:35 ` Shuah Khan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).