Commit 32b72deb authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'linux_kselftest-next-6.12-rc1' of...

Merge tag 'linux_kselftest-next-6.12-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest

Pull kselftest update from Shuah Khan:

 - test coverage for dup_fd() failure handling in unshare_fd()

 - new selftest for the acct() syscall

 - basic uprobe testcase

 - several small fixes and cleanups to existing tests

 - user and strscpy removal as they became kunit tests

 - fixes to build failures and warnings

* tag 'linux_kselftest-next-6.12-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest: (21 commits)
  selftests: kselftest: Use strerror() on nolibc
  selftests/timers: Remove unused NSEC_PER_SEC macro
  selftests:resctrl: Fix build failure on archs without __cpuid_count()
  selftests/ftrace: Fix eventfs ownership testcase to find mount point
  selftests: filesystems: fix warn_unused_result build warnings
  selftests:core: test coverage for dup_fd() failure handling in unshare_fd()
  selftests/ftrace: Fix test to handle both old and new kernels
  kselftest: timers: Fix const correctness
  selftests/ftrace: Add required dependency for kprobe tests
  selftests: rust: config: disable GCC_PLUGINS
  selftests: rust: config: add trailing newline
  tracing/selftests: Run the ownership test twice
  selftests/uprobes: Add a basic uprobe testcase
  selftests: harness: rename __constructor_order for clarification
  selftests: harness: remove unneeded __constructor_order_last()
  selftest: acct: Add selftest for the acct() syscall
  selftests: lib: remove strscpy test
  selftests: user: remove user suite
  kselftest: cpufreq: Add RTC wakeup alarm
  selftests/exec: Fix grammar in an error message.
  ...
parents 395b1577 a0474b8d
# SPDX-License-Identifier: GPL-2.0
TARGETS += acct
TARGETS += alsa
TARGETS += amd-pstate
TARGETS += arm64
......@@ -109,7 +110,6 @@ TARGETS += tmpfs
TARGETS += tpm2
TARGETS += tty
TARGETS += uevent
TARGETS += user
TARGETS += user_events
TARGETS += vDSO
TARGETS += mm
......
acct_syscall
config
process_log
\ No newline at end of file
# SPDX-License-Identifier: GPL-2.0
TEST_GEN_PROGS := acct_syscall
CFLAGS += -Wall
include ../lib.mk
\ No newline at end of file
// SPDX-License-Identifier: GPL-2.0
/* kselftest for acct() system call
* The acct() system call enables or disables process accounting.
*/
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <sys/wait.h>
#include "../kselftest.h"
int main(void)
{
char filename[] = "process_log";
FILE *fp;
pid_t child_pid;
int sz;
// Setting up kselftest framework
ksft_print_header();
ksft_set_plan(1);
// Check if test is run a root
if (geteuid()) {
ksft_test_result_skip("This test needs root to run!\n");
return 1;
}
// Create file to log closed processes
fp = fopen(filename, "w");
if (!fp) {
ksft_test_result_error("%s.\n", strerror(errno));
ksft_finished();
return 1;
}
acct(filename);
// Handle error conditions
if (errno) {
ksft_test_result_error("%s.\n", strerror(errno));
fclose(fp);
ksft_finished();
return 1;
}
// Create child process and wait for it to terminate.
child_pid = fork();
if (child_pid < 0) {
ksft_test_result_error("Creating a child process to log failed\n");
acct(NULL);
return 1;
} else if (child_pid > 0) {
wait(NULL);
fseek(fp, 0L, SEEK_END);
sz = ftell(fp);
acct(NULL);
if (sz <= 0) {
ksft_test_result_fail("Terminated child process not logged\n");
ksft_exit_fail();
return 1;
}
ksft_test_result_pass("Successfully logged terminated process.\n");
fclose(fp);
ksft_exit_pass();
return 0;
}
return 1;
}
# SPDX-License-Identifier: GPL-2.0-only
CFLAGS += -g $(KHDR_INCLUDES)
TEST_GEN_PROGS := close_range_test
TEST_GEN_PROGS := close_range_test unshare_test
include ../lib.mk
// SPDX-License-Identifier: GPL-2.0
#define _GNU_SOURCE
#include <errno.h>
#include <fcntl.h>
#include <linux/kernel.h>
#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syscall.h>
#include <unistd.h>
#include <sys/resource.h>
#include <linux/close_range.h>
#include "../kselftest_harness.h"
#include "../clone3/clone3_selftests.h"
TEST(unshare_EMFILE)
{
pid_t pid;
int status;
struct __clone_args args = {
.flags = CLONE_FILES,
.exit_signal = SIGCHLD,
};
int fd;
ssize_t n, n2;
static char buf[512], buf2[512];
struct rlimit rlimit;
int nr_open;
fd = open("/proc/sys/fs/nr_open", O_RDWR);
ASSERT_GE(fd, 0);
n = read(fd, buf, sizeof(buf));
ASSERT_GT(n, 0);
ASSERT_EQ(buf[n - 1], '\n');
ASSERT_EQ(sscanf(buf, "%d", &nr_open), 1);
ASSERT_EQ(0, getrlimit(RLIMIT_NOFILE, &rlimit));
/* bump fs.nr_open */
n2 = sprintf(buf2, "%d\n", nr_open + 1024);
lseek(fd, 0, SEEK_SET);
write(fd, buf2, n2);
/* bump ulimit -n */
rlimit.rlim_cur = nr_open + 1024;
rlimit.rlim_max = nr_open + 1024;
EXPECT_EQ(0, setrlimit(RLIMIT_NOFILE, &rlimit)) {
lseek(fd, 0, SEEK_SET);
write(fd, buf, n);
exit(EXIT_FAILURE);
}
/* get a descriptor past the old fs.nr_open */
EXPECT_GE(dup2(2, nr_open + 64), 0) {
lseek(fd, 0, SEEK_SET);
write(fd, buf, n);
exit(EXIT_FAILURE);
}
/* get descriptor table shared */
pid = sys_clone3(&args, sizeof(args));
EXPECT_GE(pid, 0) {
lseek(fd, 0, SEEK_SET);
write(fd, buf, n);
exit(EXIT_FAILURE);
}
if (pid == 0) {
int err;
/* restore fs.nr_open */
lseek(fd, 0, SEEK_SET);
write(fd, buf, n);
/* ... and now unshare(CLONE_FILES) must fail with EMFILE */
err = unshare(CLONE_FILES);
EXPECT_EQ(err, -1)
exit(EXIT_FAILURE);
EXPECT_EQ(errno, EMFILE)
exit(EXIT_FAILURE);
exit(EXIT_SUCCESS);
}
EXPECT_EQ(waitpid(pid, &status, 0), pid);
EXPECT_EQ(true, WIFEXITED(status));
EXPECT_EQ(0, WEXITSTATUS(status));
}
TEST_HARNESS_MAIN
......@@ -231,6 +231,21 @@ do_suspend()
for i in `seq 1 $2`; do
printf "Starting $1\n"
if [ "$3" = "rtc" ]; then
if ! command -v rtcwake &> /dev/null; then
printf "rtcwake could not be found, please install it.\n"
return 1
fi
rtcwake -m $filename -s 15
if [ $? -ne 0 ]; then
printf "Failed to suspend using RTC wake alarm\n"
return 1
fi
fi
echo $filename > $SYSFS/power/state
printf "Came out of $1\n"
......
......@@ -24,6 +24,8 @@ helpme()
[-t <basic: Basic cpufreq testing
suspend: suspend/resume,
hibernate: hibernate/resume,
suspend_rtc: suspend/resume back using the RTC wakeup alarm,
hibernate_rtc: hibernate/resume back using the RTC wakeup alarm,
modtest: test driver or governor modules. Only to be used with -d or -g options,
sptest1: Simple governor switch to produce lockdep.
sptest2: Concurrent governor switch to produce lockdep.
......@@ -76,7 +78,8 @@ parse_arguments()
helpme
;;
t) # --func_type (Function to perform: basic, suspend, hibernate, modtest, sptest1/2/3/4 (default: basic))
t) # --func_type (Function to perform: basic, suspend, hibernate,
# suspend_rtc, hibernate_rtc, modtest, sptest1/2/3/4 (default: basic))
FUNC=$OPTARG
;;
......@@ -121,6 +124,14 @@ do_test()
do_suspend "hibernate" 1
;;
"suspend_rtc")
do_suspend "suspend" 1 rtc
;;
"hibernate_rtc")
do_suspend "hibernate" 1 rtc
;;
"modtest")
# Do we have modules in place?
if [ -z $DRIVER_MOD ] && [ -z $GOVERNOR_MOD ]; then
......
......@@ -257,12 +257,6 @@ TEST_F(attest_fixture, att_inval_addr)
att_inval_addr_test(&self->uvio_attest.meas_addr, _metadata, self);
}
static void __attribute__((constructor)) __constructor_order_last(void)
{
if (!__constructor_order)
__constructor_order = _CONSTRUCTOR_ORDER_BACKWARD;
}
int main(int argc, char **argv)
{
int fd = open(UV_PATH, O_ACCMODE);
......
......@@ -117,7 +117,7 @@ static int check_execveat_invoked_rc(int fd, const char *path, int flags,
}
if ((WEXITSTATUS(status) != expected_rc) &&
(WEXITSTATUS(status) != expected_rc2)) {
ksft_print_msg("child %d exited with %d not %d nor %d\n",
ksft_print_msg("child %d exited with %d neither %d nor %d\n",
child, WEXITSTATUS(status), expected_rc,
expected_rc2);
ksft_test_result_fail("%s\n", test_name);
......
......@@ -319,8 +319,11 @@ static void test_listmount_ns(void)
* Tell our parent how many mounts we have, and then wait for it
* to tell us we're done.
*/
write(child_ready_pipe[1], &nr_mounts, sizeof(nr_mounts));
read(parent_ready_pipe[0], &cval, sizeof(cval));
if (write(child_ready_pipe[1], &nr_mounts, sizeof(nr_mounts)) !=
sizeof(nr_mounts))
ret = NSID_ERROR;
if (read(parent_ready_pipe[0], &cval, sizeof(cval)) != sizeof(cval))
ret = NSID_ERROR;
exit(NSID_PASS);
}
......
......@@ -6,6 +6,18 @@ original_group=`stat -c "%g" .`
original_owner=`stat -c "%u" .`
mount_point=`stat -c '%m' .`
# If stat -c '%m' does not work (e.g. busybox) or failed, try to use the
# current working directory (which should be a tracefs) as the mount point.
if [ ! -d "$mount_point" ]; then
if mount | grep -qw $PWD ; then
mount_point=$PWD
else
# If PWD doesn't work, that is an environmental problem.
exit_unresolved
fi
fi
mount_options=`mount | grep "$mount_point" | sed -e 's/.*(\(.*\)).*/\1/'`
# find another owner and group that is not the original
......@@ -83,32 +95,38 @@ run_tests() {
done
}
mount -o remount,"$new_options" .
# Run the tests twice as leftovers can cause issues
for loop in 1 2 ; do
run_tests
echo "Running iteration $loop"
mount -o remount,"$mount_options" .
mount -o remount,"$new_options" .
for d in "." "events" "events/sched" "events/sched/sched_switch" "events/sched/sched_switch/enable" $canary; do
test "$d" $original_group
done
run_tests
mount -o remount,"$mount_options" .
for d in "." "events" "events/sched" "events/sched/sched_switch" "events/sched/sched_switch/enable" $canary; do
test "$d" $original_group
done
# check instances as well
chgrp $other_group instances
chgrp $other_group instances
instance="$(mktemp -u test-XXXXXX)"
instance="$(mktemp -u test-XXXXXX)"
mkdir instances/$instance
mkdir instances/$instance
cd instances/$instance
cd instances/$instance
run_tests
run_tests
cd ../..
cd ../..
rmdir instances/$instance
rmdir instances/$instance
chgrp $original_group instances
chgrp $original_group instances
done
exit 0
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# description: Generic dynamic event - add/remove/test uprobe events
# requires: uprobe_events
echo 0 > events/enable
echo > dynamic_events
echo 'cat /proc/$$/maps' | /bin/sh | \
grep "r-xp .*/bin/.*sh$" | \
awk '{printf "p:myevent %s:0x%s\n", $6,$3 }' >> uprobe_events
grep -q myevent uprobe_events
test -d events/uprobes/myevent
echo 1 > events/uprobes/myevent/enable
echo 'ls' | /bin/sh > /dev/null
echo 0 > events/uprobes/myevent/enable
grep -q myevent trace
echo "-:myevent" >> uprobe_events
! grep -q myevent uprobe_events
echo > uprobe_events
clear_trace
......@@ -19,7 +19,14 @@ fail() { # mesg
FILTER=set_ftrace_filter
FUNC1="schedule"
FUNC2="sched_tick"
if grep '^sched_tick\b' available_filter_functions; then
FUNC2="sched_tick"
elif grep '^scheduler_tick\b' available_filter_functions; then
FUNC2="scheduler_tick"
else
exit_unresolved
fi
ALL_FUNCS="#### all functions enabled ####"
......
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# description: Kprobe event char type argument
# requires: kprobe_events
# requires: kprobe_events available_filter_functions
case `uname -m` in
x86_64)
......
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# description: Kprobe event string type argument
# requires: kprobe_events
# requires: kprobe_events available_filter_functions
case `uname -m` in
x86_64)
......
......@@ -1357,12 +1357,6 @@ static int libbpf_print_fn(enum libbpf_print_level level,
return 0;
}
static void __attribute__((constructor)) __constructor_order_last(void)
{
if (!__constructor_order)
__constructor_order = _CONSTRUCTOR_ORDER_BACKWARD;
}
int main(int argc, char **argv)
{
/* Use libbpf 1.0 API mode */
......
......@@ -61,6 +61,7 @@
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
#endif
#if defined(__i386__) || defined(__x86_64__) /* arch */
/*
* gcc cpuid.h provides __cpuid_count() since v4.4.
* Clang/LLVM cpuid.h provides __cpuid_count() since v3.4.0.
......@@ -75,6 +76,7 @@
: "=a" (a), "=b" (b), "=c" (c), "=d" (d) \
: "0" (level), "2" (count))
#endif
#endif /* end arch */
/* define kselftest exit codes */
#define KSFT_PASS 0
......@@ -371,15 +373,7 @@ static inline __noreturn __printf(1, 2) void ksft_exit_fail_msg(const char *msg,
static inline __noreturn void ksft_exit_fail_perror(const char *msg)
{
#ifndef NOLIBC
ksft_exit_fail_msg("%s: %s (%d)\n", msg, strerror(errno), errno);
#else
/*
* nolibc doesn't provide strerror() and it seems
* inappropriate to add one, just print the errno.
*/
ksft_exit_fail_msg("%s: %d)\n", msg, errno);
#endif
}
static inline __noreturn void ksft_exit_xfail(void)
......
......@@ -488,12 +488,6 @@
* Use once to append a main() to the test file.
*/
#define TEST_HARNESS_MAIN \
static void __attribute__((constructor)) \
__constructor_order_last(void) \
{ \
if (!__constructor_order) \
__constructor_order = _CONSTRUCTOR_ORDER_BACKWARD; \
} \
int main(int argc, char **argv) { \
return test_harness_run(argc, argv); \
}
......@@ -824,7 +818,7 @@
item->prev = item; \
return; \
} \
if (__constructor_order == _CONSTRUCTOR_ORDER_FORWARD) { \
if (__constructor_order_forward) { \
item->next = NULL; \
item->prev = head->prev; \
item->prev->next = item; \
......@@ -888,10 +882,7 @@ struct __test_xfail {
}
static struct __fixture_metadata *__fixture_list = &_fixture_global;
static int __constructor_order;
#define _CONSTRUCTOR_ORDER_FORWARD 1
#define _CONSTRUCTOR_ORDER_BACKWARD -1
static bool __constructor_order_forward;
static inline void __register_fixture(struct __fixture_metadata *f)
{
......@@ -942,7 +933,7 @@ static inline bool __test_passed(struct __test_metadata *metadata)
* list so tests are run in source declaration order.
* https://gcc.gnu.org/onlinedocs/gccint/Initialization.html
* However, it seems not all toolchains do this correctly, so use
* __constructor_order to detect which direction is called first
* __constructor_order_foward to detect which direction is called first
* and adjust list building logic to get things running in the right
* direction.
*/
......@@ -1337,8 +1328,7 @@ static int test_harness_run(int argc, char **argv)
static void __attribute__((constructor)) __constructor_order_first(void)
{
if (!__constructor_order)
__constructor_order = _CONSTRUCTOR_ORDER_FORWARD;
__constructor_order_forward = true;
}
#endif /* __KSELFTEST_HARNESS_H */
......@@ -4,6 +4,5 @@
# No binaries, but make sure arg-less "make" doesn't trigger "run_tests"
all:
TEST_PROGS := printf.sh bitmap.sh prime_numbers.sh scanf.sh strscpy.sh
TEST_PROGS := printf.sh bitmap.sh prime_numbers.sh scanf.sh
include ../lib.mk
......@@ -2,5 +2,4 @@ CONFIG_TEST_PRINTF=m
CONFIG_TEST_SCANF=m
CONFIG_TEST_BITMAP=m
CONFIG_PRIME_NUMBERS=m
CONFIG_TEST_STRSCPY=m
CONFIG_TEST_BITOPS=m
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0+
$(dirname $0)/../kselftest/module.sh "strscpy*" test_strscpy
......@@ -290,12 +290,12 @@ static int cat_run_test(const struct resctrl_test *test, const struct user_param
static bool arch_supports_noncont_cat(const struct resctrl_test *test)
{
unsigned int eax, ebx, ecx, edx;
/* AMD always supports non-contiguous CBM. */
if (get_vendor() == ARCH_AMD)
return true;
#if defined(__i386__) || defined(__x86_64__) /* arch */
unsigned int eax, ebx, ecx, edx;
/* Intel support for non-contiguous CBM needs to be discovered. */
if (!strcmp(test->resource, "L3"))
__cpuid_count(0x10, 1, eax, ebx, ecx, edx);
......@@ -305,6 +305,9 @@ static bool arch_supports_noncont_cat(const struct resctrl_test *test)
return false;
return ((ecx >> 3) & 1);
#endif /* end arch */
return false;
}
static int noncont_cat_run_test(const struct resctrl_test *test,
......
......@@ -410,13 +410,6 @@ TEST_F_TIMEOUT(rtc, alarm_wkalm_set_minute, 65) {
ASSERT_EQ(new, secs);
}
static void __attribute__((constructor))
__constructor_order_last(void)
{
if (!__constructor_order)
__constructor_order = _CONSTRUCTOR_ORDER_BACKWARD;
}
int main(int argc, char **argv)
{
switch (argc) {
......
# CONFIG_GCC_PLUGINS is not set
CONFIG_RUST=y
CONFIG_SAMPLES=y
CONFIG_SAMPLES_RUST=y
CONFIG_SAMPLE_RUST_MINIMAL=m
CONFIG_SAMPLE_RUST_PRINT=m
\ No newline at end of file
CONFIG_SAMPLE_RUST_PRINT=m
......@@ -30,9 +30,6 @@
#include <time.h>
#include "../kselftest.h"
#define NSEC_PER_SEC 1000000000LL
int change_skew_test(int ppm)
{
struct timex tx;
......
......@@ -36,8 +36,6 @@
#include <sys/wait.h>
#include "../kselftest.h"
#define NSEC_PER_SEC 1000000000LL
int main(int argc, char **argv)
{
struct timex tx;
......
......@@ -38,10 +38,10 @@ struct timespec global_list[LISTSIZE];
int listcount = 0;
void checklist(struct timespec *list, int size)
void checklist(const struct timespec *list, int size)
{
int i, j;
struct timespec *a, *b;
const struct timespec *a, *b;
/* scan the list */
for (i = 0; i < size-1; i++) {
......
......@@ -7,4 +7,4 @@ ksft_skip=4
[ -e /dev/tpm0 ] || exit $ksft_skip
[ -e /dev/tpmrm0 ] || exit $ksft_skip
python3 -m unittest -v tpm2_tests.AsyncTest
python3 -m unittest -v tpm2_tests.AsyncTest 2>&1
......@@ -6,4 +6,4 @@ ksft_skip=4
[ -e /dev/tpm0 ] || exit $ksft_skip
python3 -m unittest -v tpm2_tests.SmokeTest
python3 -m unittest -v tpm2_tests.SmokeTest 2>&1
......@@ -6,4 +6,4 @@ ksft_skip=4
[ -e /dev/tpmrm0 ] || exit $ksft_skip
python3 -m unittest -v tpm2_tests.SpaceTest
python3 -m unittest -v tpm2_tests.SpaceTest 2>&1
# SPDX-License-Identifier: GPL-2.0-only
# Makefile for user memory selftests
# No binaries, but make sure arg-less "make" doesn't trigger "run_tests"
all:
TEST_PROGS := test_user_copy.sh
include ../lib.mk
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# Runs copy_to/from_user infrastructure using test_user_copy kernel module
# Kselftest framework requirement - SKIP code is 4.
ksft_skip=4
if ! /sbin/modprobe -q -n test_user_copy; then
echo "user: module test_user_copy is not found [SKIP]"
exit $ksft_skip
fi
if /sbin/modprobe -q test_user_copy; then
/sbin/modprobe -q -r test_user_copy
echo "user_copy: ok"
else
echo "user_copy: [FAIL]"
exit 1
fi
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