* [PATCH v2] selftests/user_events: Fix failures when user_events is not installed
@ 2023-09-08 20:19 Beau Belgrave
2023-09-08 23:33 ` Mark Brown
0 siblings, 1 reply; 8+ messages in thread
From: Beau Belgrave @ 2023-09-08 20:19 UTC (permalink / raw)
To: rostedt, shuah, mhiramat
Cc: linux-kernel, linux-kselftest, broonie, naresh.kamboju,
anders.roxell, arnd
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.
Fixes: 68b4d2d58389 ("selftests/user_events: Reenable build")
Reported-by: Naresh Kamboju <naresh.kamboju@linaro.org>
Link: https://lore.kernel.org/all/CA+G9fYuugZ0OMeS6HvpSS4nuf_A3s455ecipGBvER0LJHojKZg@mail.gmail.com/
Signed-off-by: Beau Belgrave <beaub@linux.microsoft.com>
---
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
diff --git a/tools/testing/selftests/user_events/abi_test.c b/tools/testing/selftests/user_events/abi_test.c
index 5125c42efe65..22374d29ffdd 100644
--- a/tools/testing/selftests/user_events/abi_test.c
+++ b/tools/testing/selftests/user_events/abi_test.c
@@ -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;
}
diff --git a/tools/testing/selftests/user_events/dyn_test.c b/tools/testing/selftests/user_events/dyn_test.c
index 91a4444ad42b..32c827a52d7d 100644
--- a/tools/testing/selftests/user_events/dyn_test.c
+++ b/tools/testing/selftests/user_events/dyn_test.c
@@ -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) {
diff --git a/tools/testing/selftests/user_events/ftrace_test.c b/tools/testing/selftests/user_events/ftrace_test.c
index 5beb0aef1d81..6a260caeeddc 100644
--- a/tools/testing/selftests/user_events/ftrace_test.c
+++ b/tools/testing/selftests/user_events/ftrace_test.c
@@ -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);
diff --git a/tools/testing/selftests/user_events/perf_test.c b/tools/testing/selftests/user_events/perf_test.c
index 8b09be566fa2..f893398cda05 100644
--- a/tools/testing/selftests/user_events/perf_test.c
+++ b/tools/testing/selftests/user_events/perf_test.c
@@ -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);
}
diff --git a/tools/testing/selftests/user_events/user_events_selftests.h b/tools/testing/selftests/user_events/user_events_selftests.h
new file mode 100644
index 000000000000..690378942f82
--- /dev/null
+++ b/tools/testing/selftests/user_events/user_events_selftests.h
@@ -0,0 +1,100 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef _USER_EVENTS_SELFTESTS_H
+#define _USER_EVENTS_SELFTESTS_H
+
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/mount.h>
+#include <unistd.h>
+#include <errno.h>
+
+#include "../kselftest.h"
+
+static inline bool tracefs_enabled(char **message, bool *fail)
+{
+ struct stat buf;
+ int ret;
+
+ *message = "";
+ *fail = false;
+
+ /* Ensure tracefs is installed */
+ ret = stat("/sys/kernel/tracing", &buf);
+
+ if (ret == -1) {
+ *message = "Tracefs is not installed";
+ return false;
+ }
+
+ /* Ensure mounted tracefs */
+ ret = stat("/sys/kernel/tracing/README", &buf);
+
+ if (ret == -1 && errno == ENOENT) {
+ if (mount(NULL, "/sys/kernel/tracing", "tracefs", 0, NULL) != 0) {
+ *message = "Cannot mount tracefs";
+ *fail = true;
+ return false;
+ }
+
+ ret = stat("/sys/kernel/tracing/README", &buf);
+ }
+
+ if (ret == -1) {
+ *message = "Cannot access tracefs";
+ *fail = true;
+ return false;
+ }
+
+ return true;
+}
+
+static inline bool user_events_enabled(char **message, bool *fail)
+{
+ struct stat buf;
+ int ret;
+
+ *message = "";
+ *fail = false;
+
+ if (getuid() != 0) {
+ *message = "Must be run as root";
+ *fail = true;
+ return false;
+ }
+
+ if (!tracefs_enabled(message, fail))
+ return false;
+
+ /* Ensure user_events is installed */
+ ret = stat("/sys/kernel/tracing/user_events_data", &buf);
+
+ if (ret == -1) {
+ switch (errno) {
+ case ENOENT:
+ *message = "user_events is not installed";
+ return false;
+
+ default:
+ *message = "Cannot access user_events_data";
+ *fail = true;
+ return false;
+ }
+ }
+
+ return true;
+}
+
+#define USER_EVENT_FIXTURE_SETUP(statement) do { \
+ char *message; \
+ bool fail; \
+ if (!user_events_enabled(&message, &fail)) { \
+ if (fail) { \
+ TH_LOG("Setup failed due to: %s", message); \
+ ASSERT_FALSE(fail); \
+ } \
+ SKIP(statement, "Skipping due to: %s", message); \
+ } \
+} while (0)
+
+#endif /* _USER_EVENTS_SELFTESTS_H */
base-commit: 9b1db732866bee060b9bca9493e5ebf5e8874c48
--
2.34.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v2] selftests/user_events: Fix failures when user_events is not installed
2023-09-08 20:19 [PATCH v2] selftests/user_events: Fix failures when user_events is not installed Beau Belgrave
@ 2023-09-08 23:33 ` Mark Brown
2023-09-09 1:27 ` Steven Rostedt
2023-09-09 1:57 ` Masami Hiramatsu
0 siblings, 2 replies; 8+ messages in thread
From: Mark Brown @ 2023-09-08 23:33 UTC (permalink / raw)
To: Beau Belgrave
Cc: rostedt, shuah, mhiramat, linux-kernel, linux-kselftest,
naresh.kamboju, anders.roxell, arnd
[-- Attachment #1: Type: text/plain, Size: 594 bytes --]
On Fri, Sep 08, 2023 at 08:19:16PM +0000, Beau Belgrave wrote:
> 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.
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.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2] selftests/user_events: Fix failures when user_events is not installed
2023-09-08 23:33 ` Mark Brown
@ 2023-09-09 1:27 ` Steven Rostedt
2023-09-12 17:12 ` Beau Belgrave
2023-09-09 1:57 ` Masami Hiramatsu
1 sibling, 1 reply; 8+ messages in thread
From: Steven Rostedt @ 2023-09-09 1:27 UTC (permalink / raw)
To: Mark Brown
Cc: Beau Belgrave, shuah, mhiramat, linux-kernel, linux-kselftest,
naresh.kamboju, anders.roxell, arnd
On Sat, 9 Sep 2023 00:33:05 +0100
Mark Brown <broonie@kernel.org> wrote:
> On Fri, Sep 08, 2023 at 08:19:16PM +0000, Beau Belgrave wrote:
>
> > 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.
>
> 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
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2] selftests/user_events: Fix failures when user_events is not installed
2023-09-08 23:33 ` Mark Brown
2023-09-09 1:27 ` Steven Rostedt
@ 2023-09-09 1:57 ` Masami Hiramatsu
1 sibling, 0 replies; 8+ messages in thread
From: Masami Hiramatsu @ 2023-09-09 1:57 UTC (permalink / raw)
To: Mark Brown
Cc: Beau Belgrave, rostedt, shuah, mhiramat, linux-kernel,
linux-kselftest, naresh.kamboju, anders.roxell, arnd
On Sat, 9 Sep 2023 00:33:05 +0100
Mark Brown <broonie@kernel.org> wrote:
> On Fri, Sep 08, 2023 at 08:19:16PM +0000, Beau Belgrave wrote:
>
> > 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.
>
> 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!
--
Masami Hiramatsu (Google) <mhiramat@kernel.org>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2] selftests/user_events: Fix failures when user_events is not installed
2023-09-09 1:27 ` Steven Rostedt
@ 2023-09-12 17:12 ` Beau Belgrave
2023-09-12 17:46 ` Steven Rostedt
0 siblings, 1 reply; 8+ messages in thread
From: Beau Belgrave @ 2023-09-12 17:12 UTC (permalink / raw)
To: Steven Rostedt
Cc: Mark Brown, shuah, mhiramat, linux-kernel, linux-kselftest,
naresh.kamboju, anders.roxell, arnd
On Fri, Sep 08, 2023 at 09:27:12PM -0400, Steven Rostedt wrote:
> On Sat, 9 Sep 2023 00:33:05 +0100
> Mark Brown <broonie@kernel.org> wrote:
>
> > On Fri, Sep 08, 2023 at 08:19:16PM +0000, Beau Belgrave wrote:
> >
> > > 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.
> >
> > 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
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
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2] selftests/user_events: Fix failures when user_events is not installed
2023-09-12 17:12 ` Beau Belgrave
@ 2023-09-12 17:46 ` Steven Rostedt
2023-09-15 15:54 ` Shuah Khan
0 siblings, 1 reply; 8+ messages in thread
From: Steven Rostedt @ 2023-09-12 17:46 UTC (permalink / raw)
To: Beau Belgrave
Cc: Mark Brown, shuah, mhiramat, linux-kernel, linux-kselftest,
naresh.kamboju, anders.roxell, arnd, Shuah Khan
On Tue, 12 Sep 2023 10:12:34 -0700
Beau Belgrave <beaub@linux.microsoft.com> wrote:
> > 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
I'm guessing that this would go through Shuah's tree right? So it would be
up to her to decide that.
-- Steve
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2] selftests/user_events: Fix failures when user_events is not installed
2023-09-12 17:46 ` Steven Rostedt
@ 2023-09-15 15:54 ` Shuah Khan
2023-09-15 16:02 ` Shuah Khan
0 siblings, 1 reply; 8+ messages in thread
From: Shuah Khan @ 2023-09-15 15:54 UTC (permalink / raw)
To: Steven Rostedt, Beau Belgrave
Cc: Mark Brown, shuah, mhiramat, linux-kernel, linux-kselftest,
naresh.kamboju, anders.roxell, arnd, Shuah Khan
On 9/12/23 11:46, Steven Rostedt wrote:
> On Tue, 12 Sep 2023 10:12:34 -0700
> Beau Belgrave <beaub@linux.microsoft.com> wrote:
>
>
>>> 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?
Please send me patch on top of this one on linux-kselftest fixes.
thanks,
-- Shuah
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2] selftests/user_events: Fix failures when user_events is not installed
2023-09-15 15:54 ` Shuah Khan
@ 2023-09-15 16:02 ` Shuah Khan
0 siblings, 0 replies; 8+ messages in thread
From: Shuah Khan @ 2023-09-15 16:02 UTC (permalink / raw)
To: Steven Rostedt, Beau Belgrave
Cc: Mark Brown, shuah, mhiramat, linux-kernel, linux-kselftest,
naresh.kamboju, anders.roxell, arnd, Shuah Khan
On 9/15/23 09:54, Shuah Khan wrote:
> On 9/12/23 11:46, Steven Rostedt wrote:
>> On Tue, 12 Sep 2023 10:12:34 -0700
>> Beau Belgrave <beaub@linux.microsoft.com> wrote:
>>
>>
>>>> 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?
>
> 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
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2023-09-15 16:03 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-08 20:19 [PATCH v2] selftests/user_events: Fix failures when user_events is not installed Beau Belgrave
2023-09-08 23:33 ` Mark Brown
2023-09-09 1:27 ` Steven Rostedt
2023-09-12 17:12 ` Beau Belgrave
2023-09-12 17:46 ` Steven Rostedt
2023-09-15 15:54 ` Shuah Khan
2023-09-15 16:02 ` Shuah Khan
2023-09-09 1:57 ` Masami Hiramatsu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox