selftests/user_events: Fix failures when user_events is not installed
PATCH v2 1/1 selftests/user_events: Fix failures when user_events is not installed
When user_events is not installed the self tests currently fail. Now that these self tests run by default we need to ensure they don't fail when user_events was not enabled for the kernel being tested.
Add common methods to detect if tracefs and user_events is enabled. If either is not enabled skip the test. If tracefs is enabled, but is not mounted, mount tracefs and fail if there were any errors. Fail if not run as root.
---
V2 Changes:
Moved to stat() for existence checks vs open()/close().
.../testing/selftests/user_events/abi_test.c | 3 + .../testing/selftests/user_events/dyn_test.c | 2 + .../selftests/user_events/ftrace_test.c | 3 + .../testing/selftests/user_events/perf_test.c | 3 + .../user_events/user_events_selftests.h | 100 ++++++++++++++++++ 5 files changed, 111 insertions(+) create mode 100644 tools/testing/selftests/user_events/user_events_selftests.h
tools/testing/selftests/user_events/abi_test.c +3 -0
@@ -19,6 +19,7 @@#include <asm/unistd.h> #include "../kselftest_harness.h" +#include "user_events_selftests.h" const char *data_file ="/sys/kernel/tracing/user_events_data" ;const char *enable_file ="/sys/kernel/tracing/events/user_events/__abi_event/enable" ;
@@ -93,6 +94,8 @@ FIXTURE(user) { };FIXTURE_SETUP (user) { +USER_EVENT_FIXTURE_SETUP (return); +change_event (false); self->check =0 ; }
tools/testing/selftests/user_events/dyn_test.c +2 -0
@@ -15,6 +15,7 @@#include <unistd.h> #include "../kselftest_harness.h" +#include "user_events_selftests.h" const char *abi_file ="/sys/kernel/tracing/user_events_data" ;const char *enable_file ="/sys/kernel/tracing/events/user_events/__test_event/enable" ;
@@ -146,6 +147,7 @@ FIXTURE(user) { };FIXTURE_SETUP (user) { +USER_EVENT_FIXTURE_SETUP (return); }FIXTURE_TEARDOWN (user) {
tools/testing/selftests/user_events/ftrace_test.c +3 -0
@@ -16,6 +16,7 @@#include <unistd.h> #include "../kselftest_harness.h" +#include "user_events_selftests.h" const char *data_file ="/sys/kernel/tracing/user_events_data" ;const char *status_file ="/sys/kernel/tracing/user_events_status" ;
@@ -206,6 +207,8 @@ FIXTURE(user) { };FIXTURE_SETUP (user) { +USER_EVENT_FIXTURE_SETUP (return); + self->status_fd =open (status_file,O_RDONLY );ASSERT_NE (-1 , self->status_fd);
tools/testing/selftests/user_events/perf_test.c +3 -0
@@ -17,6 +17,7 @@#include <asm/unistd.h> #include "../kselftest_harness.h" +#include "user_events_selftests.h" const char *data_file ="/sys/kernel/tracing/user_events_data" ;const char *id_file ="/sys/kernel/tracing/events/user_events/__test_event/id" ;
@@ -113,6 +114,8 @@ FIXTURE(user) { };FIXTURE_SETUP (user) { +USER_EVENT_FIXTURE_SETUP (return); + self->data_fd =open (data_file,O_RDWR );ASSERT_NE (-1 , self->data_fd); }
tools/testing/selftests/user_events/user_events_selftests.h new file +100 -0
100 lines not on this page · raw message
base-commit: 9b1db732866bee060b9bca9493e5ebf5e8874c48
Signature · 1 line
2.34.1
Quoted 4 lines · Beau Belgrave
Add common methods to detect if tracefs and
user_eventsis enabled. If either is not enabled skip the test. If tracefs is enabled, but is not mounted, mount tracefs and fail if there were any errors. Fail if not run as root.
This will leave tracefs mounted if it was not already mounted which is a change to the system configuration. While that may happen if things go wrong during a test we should probably avoid actively doing this and either only skip or try to umount at the end of the test if we mounted ourselves.
Quoted 7 lines · On Sat, 9 Sep 2023 00:33:05 +0100 Mark Brown <[email protected]> wrote:
Quoted 4 lines · Beau Belgrave
Add common methods to detect if tracefs and
user_eventsis enabled. If either is not enabled skip the test. If tracefs is enabled, but is not mounted, mount tracefs and fail if there were any errors. Fail if not run as root.
Quoted 5 lines
This will leave tracefs mounted if it was not already mounted which is a change to the system configuration. While that may happen if things go wrong during a test we should probably avoid actively doing this and either only skip or try to umount at the end of the test if we mounted ourselves.
LOL! Beau just asked me yesterday if anyone would care if the test mounted tracefs and left it mounted. I told him "no" as ftracetest in the selftests already do that.
I guess I was wrong and some people do care ;-)
-- Steve
Quoted 16 lines · Steven Rostedt
Quoted 7 lines · On Sat, 9 Sep 2023 00:33:05 +0100 Mark Brown <[email protected]> wrote:
Quoted 4 lines · Beau Belgrave
Add common methods to detect if tracefs and
user_eventsis enabled. If either is not enabled skip the test. If tracefs is enabled, but is not mounted, mount tracefs and fail if there were any errors. Fail if not run as root.Quoted 5 lines
This will leave tracefs mounted if it was not already mounted which is a change to the system configuration. While that may happen if things go wrong during a test we should probably avoid actively doing this and either only skip or try to umount at the end of the test if we mounted ourselves.
Quoted 7 lines
LOL! Beau just asked me yesterday if anyone would care if the test mounted tracefs and left it mounted. I told him "no" as ftracetest in the selftests already do that.
I guess I was wrong and some people do care ;-)
-- Steve
It looks like this change got applied [1] to the fixes branch of linux-kselftest. I can either send a V3 with this addressed or build a patch based upon the fixes branch on top of this one to address it.
Which way do you all prefer?
Thanks,
-Beau
1. https://git.kernel.org/shuah/linux-kselftest/c/a06023a8f78d
Quoted 8 lines · On Tue, 12 Sep 2023 10:12:34 -0700 Beau Belgrave <[email protected]>…
Quoted 3 lines
I guess I was wrong and some people do care ;-)
-- Steve
It looks like this change got applied [1] to the fixes branch of linux-kselftest. I can either send a V3 with this addressed or build a patch based upon the fixes branch on top of this one to address it.
Quoted 6 lines
Which way do you all prefer?
Thanks,
-Beau1. https://git.kernel.org/shuah/linux-kselftest/c/a06023a8f78d
I'm guessing that this would go through Shuah's tree right? So it would be up to her to decide that.
-- Steve
Shuah Khan
maintainerQuoted 6 lines · Steven Rostedt
Quoted 2 lines · On Tue, 12 Sep 2023 10:12:34 -0700 Beau Belgrave <[email protected]>…
Quoted 2 lines
I guess I was wrong and some people do care ;-)
Quoted 7 lines
Quoted 7 lines
Quoted 1 line
-- Steve
It looks like this change got applied [1] to the fixes branch of linux-kselftest. I can either send a V3 with this addressed or build a patch based upon the fixes branch on top of this one to address it.
Which way do you all prefer?
Please send me patch on top of this one on linux-kselftest fixes.
thanks,
-- Shuah
Shuah Khan
maintainerQuoted 9 lines · Shuah Khan
Quoted 8 lines · Steven Rostedt
Quoted 4 lines · On Tue, 12 Sep 2023 10:12:34 -0700 Beau Belgrave <[email protected]>…
Quoted 3 lines
I guess I was wrong and some people do care ;-)
-- Steve
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
It looks like this change got applied [1] to the fixes branch of linux-kselftest. I can either send a V3 with this addressed or build a patch based upon the fixes branch on top of this one to address it.
Which way do you all prefer?
Please send me patch on top of this one on linux-kselftest fixes.
One more thing. I am sending pull request now with this patch to address the test failures.
Please send the unmount fix as soon as possible to include it in the next rc.
thanks,
-- Shuah
Quoted 7 lines · On Sat, 9 Sep 2023 00:33:05 +0100 Mark Brown <[email protected]> wrote:
Quoted 4 lines · Beau Belgrave
Add common methods to detect if tracefs and
user_eventsis enabled. If either is not enabled skip the test. If tracefs is enabled, but is not mounted, mount tracefs and fail if there were any errors. Fail if not run as root.
Quoted 5 lines
This will leave tracefs mounted if it was not already mounted which is a change to the system configuration. While that may happen if things go wrong during a test we should probably avoid actively doing this and either only skip or try to umount at the end of the test if we mounted ourselves.
Oh, I didn't know that. I need to update ftracetest to unmount tracefs if it is not mounted.
Thanks!
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>