Skip to content

Commit

Permalink
Merge tag 'linux_kselftest-next-6.14-rc1' 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 kselftest updates from Shuah Khan:

 - fixes, reporting improvements, and cleanup changes to several tests

 - add support for DT_GNU_HASH to selftests/vDSO

* tag 'linux_kselftest-next-6.14-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest:
  selftests/rseq: Fix handling of glibc without rseq support
  selftests/resctrl: Discover SNC kernel support and adjust messages
  selftests/resctrl: Adjust effective L3 cache size with SNC enabled
  selftests/ftrace: Make uprobe test more robust against binary name
  selftests/ftrace: Fix to use remount when testing mount GID option
  selftests: tmpfs: Add kselftest support to tmpfs
  selftests: tmpfs: Add Test-skip if not run as root
  selftests: harness: fix printing of mismatch values in __EXPECT()
  selftests/ring-buffer: Add test for out-of-bound pgoff mapping
  selftests/run_kselftest.sh: Fix help string for --per-test-log
  selftests: acct: Add ksft_exit_skip if not running as root
  selftests: kselftest: Fix the wrong format specifier
  selftests: timers: clocksource-switch: Adapt progress to kselftest framework
  selftests/zram: gitignore output file
  selftests/filesystems: Add missing gitignore file
  selftests: Warn about skipped tests in result summary
  selftests: kselftest: Add ksft_test_result_xpass
  selftests/vDSO: support DT_GNU_HASH
  selftests/ipc: Remove unused variables
  selftest: media_tests: fix trivial UAF typo
  • Loading branch information
Linus Torvalds committed Jan 22, 2025
2 parents 88e969f + 336d02b commit 8fb1e2e
Show file tree
Hide file tree
Showing 25 changed files with 371 additions and 86 deletions.
2 changes: 1 addition & 1 deletion tools/testing/selftests/acct/acct_syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ int main(void)

// Check if test is run a root
if (geteuid()) {
ksft_test_result_skip("This test needs root to run!\n");
ksft_exit_skip("This test needs root to run!\n");
return 1;
}

Expand Down
1 change: 1 addition & 0 deletions tools/testing/selftests/filesystems/statmount/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# SPDX-License-Identifier: GPL-2.0-only
statmount_test_ns
/*_test
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ find_alternate_gid() {
tac /etc/group | grep -v ":$original_gid:" | head -1 | cut -d: -f3
}

mount_tracefs_with_options() {
remount_tracefs_with_options() {
local mount_point="$1"
local options="$2"

mount -t tracefs -o "$options" nodev "$mount_point"
mount -t tracefs -o "remount,$options" nodev "$mount_point"

setup
}
Expand Down Expand Up @@ -81,7 +81,7 @@ test_gid_mount_option() {

# Unmount existing tracefs instance and mount with new GID
unmount_tracefs "$mount_point"
mount_tracefs_with_options "$mount_point" "$new_options"
remount_tracefs_with_options "$mount_point" "$new_options"

check_gid "$mount_point" "$other_group"

Expand All @@ -92,7 +92,7 @@ test_gid_mount_option() {

# Unmount and remount with the original GID
unmount_tracefs "$mount_point"
mount_tracefs_with_options "$mount_point" "$mount_options"
remount_tracefs_with_options "$mount_point" "$mount_options"
check_gid "$mount_point" "$original_group"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
echo 0 > events/enable
echo > dynamic_events

REALBIN=`readlink -f /bin/sh`

echo 'cat /proc/$$/maps' | /bin/sh | \
grep "r-xp .*/bin/.*sh$" | \
grep "r-xp .*${REALBIN}$" | \
awk '{printf "p:myevent %s:0x%s\n", $6,$3 }' >> uprobe_events

grep -q myevent uprobe_events
Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/ipc/msgque.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ int fill_msgque(struct msgque_data *msgque)

int main(int argc, char **argv)
{
int msg, pid, err;
int err;
struct msgque_data msgque;

if (getuid() != 0)
Expand Down
28 changes: 26 additions & 2 deletions tools/testing/selftests/kselftest.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@
* ksft_print_msg(fmt, ...);
* ksft_perror(msg);
*
* and finally report the pass/fail/skip/xfail state of the test with one of:
* and finally report the pass/fail/skip/xfail/xpass state of the test
* with one of:
*
* ksft_test_result(condition, fmt, ...);
* ksft_test_result_report(result, fmt, ...);
* ksft_test_result_pass(fmt, ...);
* ksft_test_result_fail(fmt, ...);
* ksft_test_result_skip(fmt, ...);
* ksft_test_result_xfail(fmt, ...);
* ksft_test_result_xpass(fmt, ...);
* ksft_test_result_error(fmt, ...);
* ksft_test_result_code(exit_code, test_name, fmt, ...);
*
Expand Down Expand Up @@ -147,6 +149,11 @@ static inline void ksft_set_plan(unsigned int plan)

static inline void ksft_print_cnts(void)
{
if (ksft_cnt.ksft_xskip > 0)
printf(
"# %u skipped test(s) detected. Consider enabling relevant config options to improve coverage.\n",
ksft_cnt.ksft_xskip
);
if (ksft_plan != ksft_test_num())
printf("# Planned tests != run tests (%u != %u)\n",
ksft_plan, ksft_test_num());
Expand Down Expand Up @@ -227,6 +234,20 @@ static inline __printf(1, 2) void ksft_test_result_xfail(const char *msg, ...)
va_end(args);
}

static inline __printf(1, 2) void ksft_test_result_xpass(const char *msg, ...)
{
int saved_errno = errno;
va_list args;

ksft_cnt.ksft_xpass++;

va_start(args, msg);
printf("ok %u # XPASS ", ksft_test_num());
errno = saved_errno;
vprintf(msg, args);
va_end(args);
}

static inline __printf(1, 2) void ksft_test_result_skip(const char *msg, ...)
{
int saved_errno = errno;
Expand Down Expand Up @@ -318,6 +339,9 @@ void ksft_test_result_code(int exit_code, const char *test_name,
case KSFT_XFAIL: \
ksft_test_result_xfail(fmt, ##__VA_ARGS__); \
break; \
case KSFT_XPASS: \
ksft_test_result_xpass(fmt, ##__VA_ARGS__); \
break; \
case KSFT_SKIP: \
ksft_test_result_skip(fmt, ##__VA_ARGS__); \
break; \
Expand Down Expand Up @@ -403,7 +427,7 @@ static inline __noreturn __printf(1, 2) void ksft_exit_skip(const char *msg, ...
*/
if (ksft_plan || ksft_test_num()) {
ksft_cnt.ksft_xskip++;
printf("ok %d # SKIP ", 1 + ksft_test_num());
printf("ok %u # SKIP ", 1 + ksft_test_num());
} else {
printf("1..0 # SKIP ");
}
Expand Down
3 changes: 3 additions & 0 deletions tools/testing/selftests/kselftest/ksft.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ def set_plan(num_tests):


def print_cnts():
if ksft_cnt['skip'] > 0:
print(f"# {ksft_cnt['skip']} skipped test(s) detected. Consider enabling relevant config options to improve coverage.")

print(
f"# Totals: pass:{ksft_cnt['pass']} fail:{ksft_cnt['fail']} xfail:0 xpass:0 skip:{ksft_cnt['skip']} error:0"
)
Expand Down
4 changes: 4 additions & 0 deletions tools/testing/selftests/kselftest/ktap_helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,9 @@ ktap_finished() {
}

ktap_print_totals() {
if [ "$KTAP_CNT_SKIP" -gt 0 ]; then
echo "# $KTAP_CNT_SKIP skipped test(s) detected. " \
"Consider enabling relevant config options to improve coverage."
fi
echo "# Totals: pass:$KTAP_CNT_PASS fail:$KTAP_CNT_FAIL xfail:$KTAP_CNT_XFAIL xpass:0 skip:$KTAP_CNT_SKIP error:0"
}
24 changes: 12 additions & 12 deletions tools/testing/selftests/kselftest_harness.h
Original file line number Diff line number Diff line change
Expand Up @@ -760,33 +760,33 @@
/* Report with actual signedness to avoid weird output. */ \
switch (is_signed_type(__exp) * 2 + is_signed_type(__seen)) { \
case 0: { \
unsigned long long __exp_print = (uintptr_t)__exp; \
unsigned long long __seen_print = (uintptr_t)__seen; \
__TH_LOG("Expected %s (%llu) %s %s (%llu)", \
uintmax_t __exp_print = (uintmax_t)__exp; \
uintmax_t __seen_print = (uintmax_t)__seen; \
__TH_LOG("Expected %s (%ju) %s %s (%ju)", \
_expected_str, __exp_print, #_t, \
_seen_str, __seen_print); \
break; \
} \
case 1: { \
unsigned long long __exp_print = (uintptr_t)__exp; \
long long __seen_print = (intptr_t)__seen; \
__TH_LOG("Expected %s (%llu) %s %s (%lld)", \
uintmax_t __exp_print = (uintmax_t)__exp; \
intmax_t __seen_print = (intmax_t)__seen; \
__TH_LOG("Expected %s (%ju) %s %s (%jd)", \
_expected_str, __exp_print, #_t, \
_seen_str, __seen_print); \
break; \
} \
case 2: { \
long long __exp_print = (intptr_t)__exp; \
unsigned long long __seen_print = (uintptr_t)__seen; \
__TH_LOG("Expected %s (%lld) %s %s (%llu)", \
intmax_t __exp_print = (intmax_t)__exp; \
uintmax_t __seen_print = (uintmax_t)__seen; \
__TH_LOG("Expected %s (%jd) %s %s (%ju)", \
_expected_str, __exp_print, #_t, \
_seen_str, __seen_print); \
break; \
} \
case 3: { \
long long __exp_print = (intptr_t)__exp; \
long long __seen_print = (intptr_t)__seen; \
__TH_LOG("Expected %s (%lld) %s %s (%lld)", \
intmax_t __exp_print = (intmax_t)__exp; \
intmax_t __seen_print = (intmax_t)__seen; \
__TH_LOG("Expected %s (%jd) %s %s (%jd)", \
_expected_str, __exp_print, #_t, \
_seen_str, __seen_print); \
break; \
Expand Down
8 changes: 4 additions & 4 deletions tools/testing/selftests/media_tests/regression_test.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Testing for regressions in Media Controller API register, ioctl, syscall,
and unregister paths. There have a few problems that result in user-after
and unregister paths. There have a few problems that result in use-after
free on media_device, media_devnode, and cdev pointers when the driver is
unbound while ioctl is in progress.

Expand All @@ -15,11 +15,11 @@ Build media_device_test
cd tools/testing/selftests/media_tests
make

Regressions test for cdev user-after free error on /dev/mediaX when driver
Regressions test for cdev use-after-free error on /dev/mediaX when driver
is unbound:

Start media_device_test to regression test media devnode dynamic alloc
and cdev user-after-free fixes. This opens media dev files and sits in
and cdev use-after-free fixes. This opens media dev files and sits in
a loop running media ioctl MEDIA_IOC_DEVICE_INFO command once every 10
seconds. The idea is when device file goes away, media devnode and cdev
should stick around until this test exits.
Expand All @@ -40,4 +40,4 @@ keep ioctls going while bind/unbind runs.
Copy bind_unbind_sample.txt and make changes to specify the driver name
and number to run bind and unbind. Start the bind_unbind.sh

Run dmesg looking for any user-after free errors or mutex lock errors.
Run dmesg looking for any use-after-free errors or mutex lock errors.
1 change: 1 addition & 0 deletions tools/testing/selftests/resctrl/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ TEST_GEN_PROGS := resctrl_tests
LOCAL_HDRS += $(wildcard *.h)

include ../lib.mk
CFLAGS += -I$(top_srcdir)/tools/include

$(OUTPUT)/resctrl_tests: $(wildcard *.c)
4 changes: 2 additions & 2 deletions tools/testing/selftests/resctrl/cmt_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ static int cmt_run_test(const struct resctrl_test *test, const struct user_param
return ret;

ret = check_results(&param, span, n);
if (ret && (get_vendor() == ARCH_INTEL))
ksft_print_msg("Intel CMT may be inaccurate when Sub-NUMA Clustering is enabled. Check BIOS configuration.\n");
if (ret && (get_vendor() == ARCH_INTEL) && !snc_kernel_support())
ksft_print_msg("Kernel doesn't support Sub-NUMA Clustering but it is enabled on the system.\n");

return ret;
}
Expand Down
2 changes: 2 additions & 0 deletions tools/testing/selftests/resctrl/mba_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ static int mba_run_test(const struct resctrl_test *test, const struct user_param
return ret;

ret = check_results();
if (ret && (get_vendor() == ARCH_INTEL) && !snc_kernel_support())
ksft_print_msg("Kernel doesn't support Sub-NUMA Clustering but it is enabled on the system.\n");

return ret;
}
Expand Down
4 changes: 2 additions & 2 deletions tools/testing/selftests/resctrl/mbm_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ static int mbm_run_test(const struct resctrl_test *test, const struct user_param
return ret;

ret = check_results(param.fill_buf ? param.fill_buf->buf_size : 0);
if (ret && (get_vendor() == ARCH_INTEL))
ksft_print_msg("Intel MBM may be inaccurate when Sub-NUMA Clustering is enabled. Check BIOS configuration.\n");
if (ret && (get_vendor() == ARCH_INTEL) && !snc_kernel_support())
ksft_print_msg("Kernel doesn't support Sub-NUMA Clustering but it is enabled on the system.\n");

return ret;
}
Expand Down
6 changes: 6 additions & 0 deletions tools/testing/selftests/resctrl/resctrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <signal.h>
#include <dirent.h>
#include <stdbool.h>
#include <ctype.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/mount.h>
Expand All @@ -21,6 +22,7 @@
#include <sys/eventfd.h>
#include <asm/unistd.h>
#include <linux/perf_event.h>
#include <linux/compiler.h>
#include "../kselftest.h"

#define MB (1024 * 1024)
Expand Down Expand Up @@ -156,8 +158,11 @@ struct perf_event_read {
*/
extern volatile int *value_sink;

extern int snc_unreliable;

extern char llc_occup_path[1024];

int snc_nodes_per_l3_cache(void);
int get_vendor(void);
bool check_resctrlfs_support(void);
int filter_dmesg(void);
Expand Down Expand Up @@ -198,6 +203,7 @@ void ctrlc_handler(int signum, siginfo_t *info, void *ptr);
int signal_handler_register(const struct resctrl_test *test);
void signal_handler_unregister(void);
unsigned int count_bits(unsigned long n);
int snc_kernel_support(void);

void perf_event_attr_initialize(struct perf_event_attr *pea, __u64 config);
void perf_event_initialize_read_format(struct perf_event_read *pe_read);
Expand Down
9 changes: 8 additions & 1 deletion tools/testing/selftests/resctrl/resctrl_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ static bool test_vendor_specific_check(const struct resctrl_test *test)

static void run_single_test(const struct resctrl_test *test, const struct user_params *uparams)
{
int ret;
int ret, snc_mode;

if (test->disabled)
return;
Expand All @@ -128,8 +128,15 @@ static void run_single_test(const struct resctrl_test *test, const struct user_p
return;
}

snc_mode = snc_nodes_per_l3_cache();

ksft_print_msg("Starting %s test ...\n", test->name);

if (snc_mode == 1 && snc_unreliable && get_vendor() == ARCH_INTEL) {
ksft_test_result_skip("SNC detection unreliable due to offline CPUs. Test results may not be accurate if SNC enabled.\n");
return;
}

if (test_prepare(test)) {
ksft_exit_fail_msg("Abnormal failure when preparing for the test\n");
return;
Expand Down
Loading

0 comments on commit 8fb1e2e

Please sign in to comment.