Skip to content

Commit 32b72de

Browse files
committed
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. ...
2 parents 395b157 + a0474b8 commit 32b72de

34 files changed

+302
-111
lines changed

tools/testing/selftests/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# SPDX-License-Identifier: GPL-2.0
2+
TARGETS += acct
23
TARGETS += alsa
34
TARGETS += amd-pstate
45
TARGETS += arm64
@@ -109,7 +110,6 @@ TARGETS += tmpfs
109110
TARGETS += tpm2
110111
TARGETS += tty
111112
TARGETS += uevent
112-
TARGETS += user
113113
TARGETS += user_events
114114
TARGETS += vDSO
115115
TARGETS += mm
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
acct_syscall
2+
config
3+
process_log

tools/testing/selftests/acct/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
TEST_GEN_PROGS := acct_syscall
3+
CFLAGS += -Wall
4+
5+
include ../lib.mk
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
3+
/* kselftest for acct() system call
4+
* The acct() system call enables or disables process accounting.
5+
*/
6+
7+
#include <stdio.h>
8+
#include <errno.h>
9+
#include <string.h>
10+
#include <sys/wait.h>
11+
12+
#include "../kselftest.h"
13+
14+
int main(void)
15+
{
16+
char filename[] = "process_log";
17+
FILE *fp;
18+
pid_t child_pid;
19+
int sz;
20+
21+
// Setting up kselftest framework
22+
ksft_print_header();
23+
ksft_set_plan(1);
24+
25+
// Check if test is run a root
26+
if (geteuid()) {
27+
ksft_test_result_skip("This test needs root to run!\n");
28+
return 1;
29+
}
30+
31+
// Create file to log closed processes
32+
fp = fopen(filename, "w");
33+
34+
if (!fp) {
35+
ksft_test_result_error("%s.\n", strerror(errno));
36+
ksft_finished();
37+
return 1;
38+
}
39+
40+
acct(filename);
41+
42+
// Handle error conditions
43+
if (errno) {
44+
ksft_test_result_error("%s.\n", strerror(errno));
45+
fclose(fp);
46+
ksft_finished();
47+
return 1;
48+
}
49+
50+
// Create child process and wait for it to terminate.
51+
52+
child_pid = fork();
53+
54+
if (child_pid < 0) {
55+
ksft_test_result_error("Creating a child process to log failed\n");
56+
acct(NULL);
57+
return 1;
58+
} else if (child_pid > 0) {
59+
wait(NULL);
60+
fseek(fp, 0L, SEEK_END);
61+
sz = ftell(fp);
62+
63+
acct(NULL);
64+
65+
if (sz <= 0) {
66+
ksft_test_result_fail("Terminated child process not logged\n");
67+
ksft_exit_fail();
68+
return 1;
69+
}
70+
71+
ksft_test_result_pass("Successfully logged terminated process.\n");
72+
fclose(fp);
73+
ksft_exit_pass();
74+
return 0;
75+
}
76+
77+
return 1;
78+
}

tools/testing/selftests/core/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# SPDX-License-Identifier: GPL-2.0-only
22
CFLAGS += -g $(KHDR_INCLUDES)
33

4-
TEST_GEN_PROGS := close_range_test
4+
TEST_GEN_PROGS := close_range_test unshare_test
55

66
include ../lib.mk
77

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
3+
#define _GNU_SOURCE
4+
#include <errno.h>
5+
#include <fcntl.h>
6+
#include <linux/kernel.h>
7+
#include <limits.h>
8+
#include <stdbool.h>
9+
#include <stdio.h>
10+
#include <stdlib.h>
11+
#include <string.h>
12+
#include <syscall.h>
13+
#include <unistd.h>
14+
#include <sys/resource.h>
15+
#include <linux/close_range.h>
16+
17+
#include "../kselftest_harness.h"
18+
#include "../clone3/clone3_selftests.h"
19+
20+
TEST(unshare_EMFILE)
21+
{
22+
pid_t pid;
23+
int status;
24+
struct __clone_args args = {
25+
.flags = CLONE_FILES,
26+
.exit_signal = SIGCHLD,
27+
};
28+
int fd;
29+
ssize_t n, n2;
30+
static char buf[512], buf2[512];
31+
struct rlimit rlimit;
32+
int nr_open;
33+
34+
fd = open("/proc/sys/fs/nr_open", O_RDWR);
35+
ASSERT_GE(fd, 0);
36+
37+
n = read(fd, buf, sizeof(buf));
38+
ASSERT_GT(n, 0);
39+
ASSERT_EQ(buf[n - 1], '\n');
40+
41+
ASSERT_EQ(sscanf(buf, "%d", &nr_open), 1);
42+
43+
ASSERT_EQ(0, getrlimit(RLIMIT_NOFILE, &rlimit));
44+
45+
/* bump fs.nr_open */
46+
n2 = sprintf(buf2, "%d\n", nr_open + 1024);
47+
lseek(fd, 0, SEEK_SET);
48+
write(fd, buf2, n2);
49+
50+
/* bump ulimit -n */
51+
rlimit.rlim_cur = nr_open + 1024;
52+
rlimit.rlim_max = nr_open + 1024;
53+
EXPECT_EQ(0, setrlimit(RLIMIT_NOFILE, &rlimit)) {
54+
lseek(fd, 0, SEEK_SET);
55+
write(fd, buf, n);
56+
exit(EXIT_FAILURE);
57+
}
58+
59+
/* get a descriptor past the old fs.nr_open */
60+
EXPECT_GE(dup2(2, nr_open + 64), 0) {
61+
lseek(fd, 0, SEEK_SET);
62+
write(fd, buf, n);
63+
exit(EXIT_FAILURE);
64+
}
65+
66+
/* get descriptor table shared */
67+
pid = sys_clone3(&args, sizeof(args));
68+
EXPECT_GE(pid, 0) {
69+
lseek(fd, 0, SEEK_SET);
70+
write(fd, buf, n);
71+
exit(EXIT_FAILURE);
72+
}
73+
74+
if (pid == 0) {
75+
int err;
76+
77+
/* restore fs.nr_open */
78+
lseek(fd, 0, SEEK_SET);
79+
write(fd, buf, n);
80+
/* ... and now unshare(CLONE_FILES) must fail with EMFILE */
81+
err = unshare(CLONE_FILES);
82+
EXPECT_EQ(err, -1)
83+
exit(EXIT_FAILURE);
84+
EXPECT_EQ(errno, EMFILE)
85+
exit(EXIT_FAILURE);
86+
exit(EXIT_SUCCESS);
87+
}
88+
89+
EXPECT_EQ(waitpid(pid, &status, 0), pid);
90+
EXPECT_EQ(true, WIFEXITED(status));
91+
EXPECT_EQ(0, WEXITSTATUS(status));
92+
}
93+
94+
TEST_HARNESS_MAIN

tools/testing/selftests/cpufreq/cpufreq.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,21 @@ do_suspend()
231231

232232
for i in `seq 1 $2`; do
233233
printf "Starting $1\n"
234+
235+
if [ "$3" = "rtc" ]; then
236+
if ! command -v rtcwake &> /dev/null; then
237+
printf "rtcwake could not be found, please install it.\n"
238+
return 1
239+
fi
240+
241+
rtcwake -m $filename -s 15
242+
243+
if [ $? -ne 0 ]; then
244+
printf "Failed to suspend using RTC wake alarm\n"
245+
return 1
246+
fi
247+
fi
248+
234249
echo $filename > $SYSFS/power/state
235250
printf "Came out of $1\n"
236251

tools/testing/selftests/cpufreq/main.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ helpme()
2424
[-t <basic: Basic cpufreq testing
2525
suspend: suspend/resume,
2626
hibernate: hibernate/resume,
27+
suspend_rtc: suspend/resume back using the RTC wakeup alarm,
28+
hibernate_rtc: hibernate/resume back using the RTC wakeup alarm,
2729
modtest: test driver or governor modules. Only to be used with -d or -g options,
2830
sptest1: Simple governor switch to produce lockdep.
2931
sptest2: Concurrent governor switch to produce lockdep.
@@ -76,7 +78,8 @@ parse_arguments()
7678
helpme
7779
;;
7880

79-
t) # --func_type (Function to perform: basic, suspend, hibernate, modtest, sptest1/2/3/4 (default: basic))
81+
t) # --func_type (Function to perform: basic, suspend, hibernate,
82+
# suspend_rtc, hibernate_rtc, modtest, sptest1/2/3/4 (default: basic))
8083
FUNC=$OPTARG
8184
;;
8285

@@ -121,6 +124,14 @@ do_test()
121124
do_suspend "hibernate" 1
122125
;;
123126

127+
"suspend_rtc")
128+
do_suspend "suspend" 1 rtc
129+
;;
130+
131+
"hibernate_rtc")
132+
do_suspend "hibernate" 1 rtc
133+
;;
134+
124135
"modtest")
125136
# Do we have modules in place?
126137
if [ -z $DRIVER_MOD ] && [ -z $GOVERNOR_MOD ]; then

tools/testing/selftests/drivers/s390x/uvdevice/test_uvdevice.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,6 @@ TEST_F(attest_fixture, att_inval_addr)
257257
att_inval_addr_test(&self->uvio_attest.meas_addr, _metadata, self);
258258
}
259259

260-
static void __attribute__((constructor)) __constructor_order_last(void)
261-
{
262-
if (!__constructor_order)
263-
__constructor_order = _CONSTRUCTOR_ORDER_BACKWARD;
264-
}
265-
266260
int main(int argc, char **argv)
267261
{
268262
int fd = open(UV_PATH, O_ACCMODE);

tools/testing/selftests/exec/execveat.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ static int check_execveat_invoked_rc(int fd, const char *path, int flags,
117117
}
118118
if ((WEXITSTATUS(status) != expected_rc) &&
119119
(WEXITSTATUS(status) != expected_rc2)) {
120-
ksft_print_msg("child %d exited with %d not %d nor %d\n",
120+
ksft_print_msg("child %d exited with %d neither %d nor %d\n",
121121
child, WEXITSTATUS(status), expected_rc,
122122
expected_rc2);
123123
ksft_test_result_fail("%s\n", test_name);

0 commit comments

Comments
 (0)