Skip to content

Commit

Permalink
Merge tag 'linux-kselftest-fixes-6.6-rc2' of git://git.kernel.org/pub…
Browse files Browse the repository at this point in the history
…/scm/linux/kernel/git/shuah/linux-kselftest

Pull more kselftest fixes from Shuah Khan
 "Fixes to user_events test and ftrace test.

  The user_events test was enabled by default in Linux 6.6-rc1. The
  following fixes are for bugs found since then:

   - add checks for dependencies and skip the test if they aren't met.

     The user_events test requires root access, and tracefs and
     user_events enabled. It leaves tracefs mounted and a fix is in
     progress for that missing piece.

   - create user_events test-specific Kconfig fragments

  ftrace test fixes:

   - unmount tracefs for recovering environment. Fix identified during
     the above mentioned user_events dependencies fix.

   - adds softlink to latest log directory improving usage"

* tag 'linux-kselftest-fixes-6.6-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest:
  selftests: tracing: Fix to unmount tracefs for recovering environment
  selftests: user_events: create test-specific Kconfig fragments
  ftrace/selftests: Add softlink to latest log directory
  selftests/user_events: Fix failures when user_events is not installed
  • Loading branch information
torvalds committed Sep 16, 2023
2 parents d8d7cd6 + 7e021da commit 57d88e8
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 1 deletion.
18 changes: 17 additions & 1 deletion tools/testing/selftests/ftrace/ftracetest
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ err_ret=1
# kselftest skip code is 4
err_skip=4

# umount required
UMOUNT_DIR=""

# cgroup RT scheduling prevents chrt commands from succeeding, which
# induces failures in test wakeup tests. Disable for the duration of
# the tests.
Expand All @@ -45,6 +48,9 @@ setup() {

cleanup() {
echo $sched_rt_runtime_orig > $sched_rt_runtime
if [ -n "${UMOUNT_DIR}" ]; then
umount ${UMOUNT_DIR} ||:
fi
}

errexit() { # message
Expand Down Expand Up @@ -124,6 +130,7 @@ parse_opts() { # opts
;;
--logdir|-l)
LOG_DIR=$2
LINK_PTR=
shift 2
;;
*.tc)
Expand Down Expand Up @@ -160,11 +167,13 @@ if [ -z "$TRACING_DIR" ]; then
mount -t tracefs nodev /sys/kernel/tracing ||
errexit "Failed to mount /sys/kernel/tracing"
TRACING_DIR="/sys/kernel/tracing"
UMOUNT_DIR=${TRACING_DIR}
# If debugfs exists, then so does /sys/kernel/debug
elif [ -d "/sys/kernel/debug" ]; then
mount -t debugfs nodev /sys/kernel/debug ||
errexit "Failed to mount /sys/kernel/debug"
TRACING_DIR="/sys/kernel/debug/tracing"
UMOUNT_DIR=${TRACING_DIR}
else
err_ret=$err_skip
errexit "debugfs and tracefs are not configured in this kernel"
Expand All @@ -181,7 +190,10 @@ fi
TOP_DIR=`absdir $0`
TEST_DIR=$TOP_DIR/test.d
TEST_CASES=`find_testcases $TEST_DIR`
LOG_DIR=$TOP_DIR/logs/`date +%Y%m%d-%H%M%S`/
LOG_TOP_DIR=$TOP_DIR/logs
LOG_DATE=`date +%Y%m%d-%H%M%S`
LOG_DIR=$LOG_TOP_DIR/$LOG_DATE/
LINK_PTR=$LOG_TOP_DIR/latest
KEEP_LOG=0
KTAP=0
DEBUG=0
Expand All @@ -207,6 +219,10 @@ else
LOG_FILE=$LOG_DIR/ftracetest.log
mkdir -p $LOG_DIR || errexit "Failed to make a log directory: $LOG_DIR"
date > $LOG_FILE
if [ "x-$LINK_PTR" != "x-" ]; then
unlink $LINK_PTR
ln -fs $LOG_DATE $LINK_PTR
fi
fi

# Define text colors
Expand Down
3 changes: 3 additions & 0 deletions tools/testing/selftests/user_events/abi_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -93,6 +94,8 @@ FIXTURE(user) {
};

FIXTURE_SETUP(user) {
USER_EVENT_FIXTURE_SETUP(return);

change_event(false);
self->check = 0;
}
Expand Down
1 change: 1 addition & 0 deletions tools/testing/selftests/user_events/config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CONFIG_USER_EVENTS=y
2 changes: 2 additions & 0 deletions tools/testing/selftests/user_events/dyn_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -146,6 +147,7 @@ FIXTURE(user) {
};

FIXTURE_SETUP(user) {
USER_EVENT_FIXTURE_SETUP(return);
}

FIXTURE_TEARDOWN(user) {
Expand Down
3 changes: 3 additions & 0 deletions tools/testing/selftests/user_events/ftrace_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);

Expand Down
3 changes: 3 additions & 0 deletions tools/testing/selftests/user_events/perf_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
}
Expand Down
100 changes: 100 additions & 0 deletions tools/testing/selftests/user_events/user_events_selftests.h
Original file line number Diff line number Diff line change
@@ -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 */

0 comments on commit 57d88e8

Please sign in to comment.