Commit 8ed99af4 authored by Beau Belgrave's avatar Beau Belgrave Committed by Shuah Khan

selftests/user_events: Fix to unmount tracefs when test created mount

Fix to unmount tracefs if the self-test mounted it to allow testing.
If tracefs was already mounted, this does nothing.
Suggested-by: default avatarMark Brown <broonie@kernel.org>
Link: https://lore.kernel.org/all/29fce076-746c-4650-8358-b4e0fa215cf7@sirena.org.uk/
Fixes: a06023a8 ("selftests/user_events: Fix failures when user_events is not installed")
Signed-off-by: default avatarBeau Belgrave <beaub@linux.microsoft.com>
Reviewed-by: default avatarMark Brown <broonie@kernel.org>
Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
parent ce9ecca0
...@@ -91,16 +91,18 @@ static int reg_disable(long *enable, int bit) ...@@ -91,16 +91,18 @@ static int reg_disable(long *enable, int bit)
FIXTURE(user) { FIXTURE(user) {
long check; long check;
bool umount;
}; };
FIXTURE_SETUP(user) { FIXTURE_SETUP(user) {
USER_EVENT_FIXTURE_SETUP(return); USER_EVENT_FIXTURE_SETUP(return, self->umount);
change_event(false); change_event(false);
self->check = 0; self->check = 0;
} }
FIXTURE_TEARDOWN(user) { FIXTURE_TEARDOWN(user) {
USER_EVENT_FIXTURE_TEARDOWN(self->umount);
} }
TEST_F(user, enablement) { TEST_F(user, enablement) {
......
...@@ -144,13 +144,16 @@ do { \ ...@@ -144,13 +144,16 @@ do { \
FIXTURE(user) { FIXTURE(user) {
int check; int check;
bool umount;
}; };
FIXTURE_SETUP(user) { FIXTURE_SETUP(user) {
USER_EVENT_FIXTURE_SETUP(return); USER_EVENT_FIXTURE_SETUP(return, self->umount);
} }
FIXTURE_TEARDOWN(user) { FIXTURE_TEARDOWN(user) {
USER_EVENT_FIXTURE_TEARDOWN(self->umount);
wait_for_delete(); wait_for_delete();
} }
......
...@@ -204,10 +204,11 @@ FIXTURE(user) { ...@@ -204,10 +204,11 @@ FIXTURE(user) {
int data_fd; int data_fd;
int enable_fd; int enable_fd;
int check; int check;
bool umount;
}; };
FIXTURE_SETUP(user) { FIXTURE_SETUP(user) {
USER_EVENT_FIXTURE_SETUP(return); USER_EVENT_FIXTURE_SETUP(return, self->umount);
self->status_fd = open(status_file, O_RDONLY); self->status_fd = open(status_file, O_RDONLY);
ASSERT_NE(-1, self->status_fd); ASSERT_NE(-1, self->status_fd);
...@@ -219,6 +220,8 @@ FIXTURE_SETUP(user) { ...@@ -219,6 +220,8 @@ FIXTURE_SETUP(user) {
} }
FIXTURE_TEARDOWN(user) { FIXTURE_TEARDOWN(user) {
USER_EVENT_FIXTURE_TEARDOWN(self->umount);
close(self->status_fd); close(self->status_fd);
close(self->data_fd); close(self->data_fd);
......
...@@ -111,16 +111,19 @@ static int clear(int *check) ...@@ -111,16 +111,19 @@ static int clear(int *check)
FIXTURE(user) { FIXTURE(user) {
int data_fd; int data_fd;
int check; int check;
bool umount;
}; };
FIXTURE_SETUP(user) { FIXTURE_SETUP(user) {
USER_EVENT_FIXTURE_SETUP(return); USER_EVENT_FIXTURE_SETUP(return, self->umount);
self->data_fd = open(data_file, O_RDWR); self->data_fd = open(data_file, O_RDWR);
ASSERT_NE(-1, self->data_fd); ASSERT_NE(-1, self->data_fd);
} }
FIXTURE_TEARDOWN(user) { FIXTURE_TEARDOWN(user) {
USER_EVENT_FIXTURE_TEARDOWN(self->umount);
close(self->data_fd); close(self->data_fd);
if (clear(&self->check) != 0) if (clear(&self->check) != 0)
......
...@@ -11,13 +11,19 @@ ...@@ -11,13 +11,19 @@
#include "../kselftest.h" #include "../kselftest.h"
static inline bool tracefs_enabled(char **message, bool *fail) static inline void tracefs_unmount(void)
{
umount("/sys/kernel/tracing");
}
static inline bool tracefs_enabled(char **message, bool *fail, bool *umount)
{ {
struct stat buf; struct stat buf;
int ret; int ret;
*message = ""; *message = "";
*fail = false; *fail = false;
*umount = false;
/* Ensure tracefs is installed */ /* Ensure tracefs is installed */
ret = stat("/sys/kernel/tracing", &buf); ret = stat("/sys/kernel/tracing", &buf);
...@@ -37,6 +43,8 @@ static inline bool tracefs_enabled(char **message, bool *fail) ...@@ -37,6 +43,8 @@ static inline bool tracefs_enabled(char **message, bool *fail)
return false; return false;
} }
*umount = true;
ret = stat("/sys/kernel/tracing/README", &buf); ret = stat("/sys/kernel/tracing/README", &buf);
} }
...@@ -49,13 +57,14 @@ static inline bool tracefs_enabled(char **message, bool *fail) ...@@ -49,13 +57,14 @@ static inline bool tracefs_enabled(char **message, bool *fail)
return true; return true;
} }
static inline bool user_events_enabled(char **message, bool *fail) static inline bool user_events_enabled(char **message, bool *fail, bool *umount)
{ {
struct stat buf; struct stat buf;
int ret; int ret;
*message = ""; *message = "";
*fail = false; *fail = false;
*umount = false;
if (getuid() != 0) { if (getuid() != 0) {
*message = "Must be run as root"; *message = "Must be run as root";
...@@ -63,7 +72,7 @@ static inline bool user_events_enabled(char **message, bool *fail) ...@@ -63,7 +72,7 @@ static inline bool user_events_enabled(char **message, bool *fail)
return false; return false;
} }
if (!tracefs_enabled(message, fail)) if (!tracefs_enabled(message, fail, umount))
return false; return false;
/* Ensure user_events is installed */ /* Ensure user_events is installed */
...@@ -85,10 +94,10 @@ static inline bool user_events_enabled(char **message, bool *fail) ...@@ -85,10 +94,10 @@ static inline bool user_events_enabled(char **message, bool *fail)
return true; return true;
} }
#define USER_EVENT_FIXTURE_SETUP(statement) do { \ #define USER_EVENT_FIXTURE_SETUP(statement, umount) do { \
char *message; \ char *message; \
bool fail; \ bool fail; \
if (!user_events_enabled(&message, &fail)) { \ if (!user_events_enabled(&message, &fail, &(umount))) { \
if (fail) { \ if (fail) { \
TH_LOG("Setup failed due to: %s", message); \ TH_LOG("Setup failed due to: %s", message); \
ASSERT_FALSE(fail); \ ASSERT_FALSE(fail); \
...@@ -97,4 +106,9 @@ static inline bool user_events_enabled(char **message, bool *fail) ...@@ -97,4 +106,9 @@ static inline bool user_events_enabled(char **message, bool *fail)
} \ } \
} while (0) } while (0)
#define USER_EVENT_FIXTURE_TEARDOWN(umount) do { \
if ((umount)) \
tracefs_unmount(); \
} while (0)
#endif /* _USER_EVENTS_SELFTESTS_H */ #endif /* _USER_EVENTS_SELFTESTS_H */
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