Skip to content

Commit ab27740

Browse files
committed
Merge tag 'linux_kselftest-next-6.8-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest
Pull kselftest update from Shuah Khan: "Enhancements to reporting test results, fixes to root and user run behavior and fixing ksft_print_msg() calls" * tag 'linux_kselftest-next-6.8-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest: tracing/selftests: Add ownership modification tests for eventfs selftests: sched: Remove initialization to 0 for a static variable selftests: capabilities: namespace create varies for root and normal user selftests: prctl: Add prctl test for PR_GET_NAME kselftest/vDSO: Use ksft_print_msg() rather than printf in vdso_test_abi kselftest/vDSO: Fix message formatting for clock_id logging kselftest/vDSO: Make test name reporting for vdso_abi_test tooling friendly selftests:x86: Fix Format String Warnings in lam.c selftests/breakpoints: Fix format specifier in ksft_print_msg in step_after_suspend_test.c selftests:breakpoints: Fix Format String Warning in breakpoint_test
2 parents 41daf06 + ee9793b commit ab27740

8 files changed

Lines changed: 192 additions & 44 deletions

File tree

tools/testing/selftests/breakpoints/breakpoint_test.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,9 @@ static void check_success(const char *msg)
284284
nr_tests++;
285285

286286
if (ret)
287-
ksft_test_result_pass(msg);
287+
ksft_test_result_pass("%s", msg);
288288
else
289-
ksft_test_result_fail(msg);
289+
ksft_test_result_fail("%s", msg);
290290
}
291291

292292
static void launch_instruction_breakpoints(char *buf, int local, int global)

tools/testing/selftests/breakpoints/step_after_suspend_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ int run_test(int cpu)
8989

9090
wpid = waitpid(pid, &status, __WALL);
9191
if (wpid != pid) {
92-
ksft_print_msg("waitpid() failed: $s\n", strerror(errno));
92+
ksft_print_msg("waitpid() failed: %s\n", strerror(errno));
9393
return KSFT_FAIL;
9494
}
9595
if (WIFEXITED(status)) {

tools/testing/selftests/capabilities/test_execve.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,7 @@ static bool create_and_enter_ns(uid_t inner_uid)
8888
outer_uid = getuid();
8989
outer_gid = getgid();
9090

91-
/*
92-
* TODO: If we're already root, we could skip creating the userns.
93-
*/
94-
95-
if (unshare(CLONE_NEWNS) == 0) {
91+
if (outer_uid == 0 && unshare(CLONE_NEWNS) == 0) {
9692
ksft_print_msg("[NOTE]\tUsing global UIDs for tests\n");
9793
if (prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0) != 0)
9894
ksft_exit_fail_msg("PR_SET_KEEPCAPS - %s\n",
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
#!/bin/sh
2+
# SPDX-License-Identifier: GPL-2.0
3+
# description: Test file and directory owership changes for eventfs
4+
5+
original_group=`stat -c "%g" .`
6+
original_owner=`stat -c "%u" .`
7+
8+
mount_point=`stat -c '%m' .`
9+
mount_options=`mount | grep "$mount_point" | sed -e 's/.*(\(.*\)).*/\1/'`
10+
11+
# find another owner and group that is not the original
12+
other_group=`tac /etc/group | grep -v ":$original_group:" | head -1 | cut -d: -f3`
13+
other_owner=`tac /etc/passwd | grep -v ":$original_owner:" | head -1 | cut -d: -f3`
14+
15+
# Remove any group ownership already
16+
new_options=`echo "$mount_options" | sed -e "s/gid=[0-9]*/gid=$other_group/"`
17+
18+
if [ "$new_options" = "$mount_options" ]; then
19+
new_options="$mount_options,gid=$other_group"
20+
mount_options="$mount_options,gid=$original_group"
21+
fi
22+
23+
canary="events/timer events/timer/timer_cancel events/timer/timer_cancel/format"
24+
25+
test() {
26+
file=$1
27+
test_group=$2
28+
29+
owner=`stat -c "%u" $file`
30+
group=`stat -c "%g" $file`
31+
32+
echo "testing $file $owner=$original_owner and $group=$test_group"
33+
if [ $owner -ne $original_owner ]; then
34+
exit_fail
35+
fi
36+
if [ $group -ne $test_group ]; then
37+
exit_fail
38+
fi
39+
40+
# Note, the remount does not update ownership so test going to and from owner
41+
echo "test owner $file to $other_owner"
42+
chown $other_owner $file
43+
owner=`stat -c "%u" $file`
44+
if [ $owner -ne $other_owner ]; then
45+
exit_fail
46+
fi
47+
48+
chown $original_owner $file
49+
owner=`stat -c "%u" $file`
50+
if [ $owner -ne $original_owner ]; then
51+
exit_fail
52+
fi
53+
54+
}
55+
56+
run_tests() {
57+
for d in "." "events" "events/sched" "events/sched/sched_switch" "events/sched/sched_switch/enable" $canary; do
58+
test "$d" $other_group
59+
done
60+
61+
chgrp $original_group events
62+
test "events" $original_group
63+
for d in "." "events/sched" "events/sched/sched_switch" "events/sched/sched_switch/enable" $canary; do
64+
test "$d" $other_group
65+
done
66+
67+
chgrp $original_group events/sched
68+
test "events/sched" $original_group
69+
for d in "." "events/sched/sched_switch" "events/sched/sched_switch/enable" $canary; do
70+
test "$d" $other_group
71+
done
72+
73+
chgrp $original_group events/sched/sched_switch
74+
test "events/sched/sched_switch" $original_group
75+
for d in "." "events/sched/sched_switch/enable" $canary; do
76+
test "$d" $other_group
77+
done
78+
79+
chgrp $original_group events/sched/sched_switch/enable
80+
test "events/sched/sched_switch/enable" $original_group
81+
for d in "." $canary; do
82+
test "$d" $other_group
83+
done
84+
}
85+
86+
mount -o remount,"$new_options" .
87+
88+
run_tests
89+
90+
mount -o remount,"$mount_options" .
91+
92+
for d in "." "events" "events/sched" "events/sched/sched_switch" "events/sched/sched_switch/enable" $canary; do
93+
test "$d" $original_group
94+
done
95+
96+
# check instances as well
97+
98+
chgrp $other_group instances
99+
100+
instance="$(mktemp -u test-XXXXXX)"
101+
102+
mkdir instances/$instance
103+
104+
cd instances/$instance
105+
106+
run_tests
107+
108+
cd ../..
109+
110+
rmdir instances/$instance
111+
112+
chgrp $original_group instances
113+
114+
exit 0

tools/testing/selftests/prctl/set-process-name.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#define CHANGE_NAME "changename"
1313
#define EMPTY_NAME ""
1414
#define TASK_COMM_LEN 16
15+
#define MAX_PATH_LEN 50
1516

1617
int set_name(char *name)
1718
{
@@ -47,6 +48,35 @@ int check_null_pointer(char *check_name)
4748
return res;
4849
}
4950

51+
int check_name(void)
52+
{
53+
54+
int pid;
55+
56+
pid = getpid();
57+
FILE *fptr = NULL;
58+
char path[MAX_PATH_LEN] = {};
59+
char name[TASK_COMM_LEN] = {};
60+
char output[TASK_COMM_LEN] = {};
61+
int j;
62+
63+
j = snprintf(path, MAX_PATH_LEN, "/proc/self/task/%d/comm", pid);
64+
fptr = fopen(path, "r");
65+
if (!fptr)
66+
return -EIO;
67+
68+
fscanf(fptr, "%s", output);
69+
if (ferror(fptr))
70+
return -EIO;
71+
72+
int res = prctl(PR_GET_NAME, name, NULL, NULL, NULL);
73+
74+
if (res < 0)
75+
return -errno;
76+
77+
return !strcmp(output, name);
78+
}
79+
5080
TEST(rename_process) {
5181

5282
EXPECT_GE(set_name(CHANGE_NAME), 0);
@@ -57,6 +87,8 @@ TEST(rename_process) {
5787

5888
EXPECT_GE(set_name(CHANGE_NAME), 0);
5989
EXPECT_LT(check_null_pointer(CHANGE_NAME), 0);
90+
91+
EXPECT_TRUE(check_name());
6092
}
6193

6294
TEST_HARNESS_MAIN

tools/testing/selftests/sched/cs_prctl_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ struct child_args {
7272

7373
static struct child_args procs[MAX_PROCESSES];
7474
static int num_processes = 2;
75-
static int need_cleanup = 0;
75+
static int need_cleanup;
7676

7777
static int _prctl(int option, unsigned long arg2, unsigned long arg3, unsigned long arg4,
7878
unsigned long arg5)

tools/testing/selftests/vDSO/vdso_test_abi.c

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,20 @@ typedef long (*vdso_clock_gettime_t)(clockid_t clk_id, struct timespec *ts);
3333
typedef long (*vdso_clock_getres_t)(clockid_t clk_id, struct timespec *ts);
3434
typedef time_t (*vdso_time_t)(time_t *t);
3535

36-
#define VDSO_TEST_PASS_MSG() "\n%s(): PASS\n", __func__
37-
#define VDSO_TEST_FAIL_MSG(x) "\n%s(): %s FAIL\n", __func__, x
38-
#define VDSO_TEST_SKIP_MSG(x) "\n%s(): SKIP: Could not find %s\n", __func__, x
36+
const char *vdso_clock_name[12] = {
37+
"CLOCK_REALTIME",
38+
"CLOCK_MONOTONIC",
39+
"CLOCK_PROCESS_CPUTIME_ID",
40+
"CLOCK_THREAD_CPUTIME_ID",
41+
"CLOCK_MONOTONIC_RAW",
42+
"CLOCK_REALTIME_COARSE",
43+
"CLOCK_MONOTONIC_COARSE",
44+
"CLOCK_BOOTTIME",
45+
"CLOCK_REALTIME_ALARM",
46+
"CLOCK_BOOTTIME_ALARM",
47+
"CLOCK_SGI_CYCLE",
48+
"CLOCK_TAI",
49+
};
3950

4051
static void vdso_test_gettimeofday(void)
4152
{
@@ -44,7 +55,8 @@ static void vdso_test_gettimeofday(void)
4455
(vdso_gettimeofday_t)vdso_sym(version, name[0]);
4556

4657
if (!vdso_gettimeofday) {
47-
ksft_test_result_skip(VDSO_TEST_SKIP_MSG(name[0]));
58+
ksft_print_msg("Couldn't find %s\n", name[0]);
59+
ksft_test_result_skip("%s\n", name[0]);
4860
return;
4961
}
5062

@@ -54,9 +66,9 @@ static void vdso_test_gettimeofday(void)
5466
if (ret == 0) {
5567
ksft_print_msg("The time is %lld.%06lld\n",
5668
(long long)tv.tv_sec, (long long)tv.tv_usec);
57-
ksft_test_result_pass(VDSO_TEST_PASS_MSG());
69+
ksft_test_result_pass("%s\n", name[0]);
5870
} else {
59-
ksft_test_result_fail(VDSO_TEST_FAIL_MSG(name[0]));
71+
ksft_test_result_fail("%s\n", name[0]);
6072
}
6173
}
6274

@@ -67,7 +79,9 @@ static void vdso_test_clock_gettime(clockid_t clk_id)
6779
(vdso_clock_gettime_t)vdso_sym(version, name[1]);
6880

6981
if (!vdso_clock_gettime) {
70-
ksft_test_result_skip(VDSO_TEST_SKIP_MSG(name[1]));
82+
ksft_print_msg("Couldn't find %s\n", name[1]);
83+
ksft_test_result_skip("%s %s\n", name[1],
84+
vdso_clock_name[clk_id]);
7185
return;
7286
}
7387

@@ -77,9 +91,11 @@ static void vdso_test_clock_gettime(clockid_t clk_id)
7791
if (ret == 0) {
7892
ksft_print_msg("The time is %lld.%06lld\n",
7993
(long long)ts.tv_sec, (long long)ts.tv_nsec);
80-
ksft_test_result_pass(VDSO_TEST_PASS_MSG());
94+
ksft_test_result_pass("%s %s\n", name[1],
95+
vdso_clock_name[clk_id]);
8196
} else {
82-
ksft_test_result_fail(VDSO_TEST_FAIL_MSG(name[1]));
97+
ksft_test_result_fail("%s %s\n", name[1],
98+
vdso_clock_name[clk_id]);
8399
}
84100
}
85101

@@ -90,7 +106,8 @@ static void vdso_test_time(void)
90106
(vdso_time_t)vdso_sym(version, name[2]);
91107

92108
if (!vdso_time) {
93-
ksft_test_result_skip(VDSO_TEST_SKIP_MSG(name[2]));
109+
ksft_print_msg("Couldn't find %s\n", name[2]);
110+
ksft_test_result_skip("%s\n", name[2]);
94111
return;
95112
}
96113

@@ -99,9 +116,9 @@ static void vdso_test_time(void)
99116
if (ret > 0) {
100117
ksft_print_msg("The time in hours since January 1, 1970 is %lld\n",
101118
(long long)(ret / 3600));
102-
ksft_test_result_pass(VDSO_TEST_PASS_MSG());
119+
ksft_test_result_pass("%s\n", name[2]);
103120
} else {
104-
ksft_test_result_fail(VDSO_TEST_FAIL_MSG(name[2]));
121+
ksft_test_result_fail("%s\n", name[2]);
105122
}
106123
}
107124

@@ -114,7 +131,9 @@ static void vdso_test_clock_getres(clockid_t clk_id)
114131
(vdso_clock_getres_t)vdso_sym(version, name[3]);
115132

116133
if (!vdso_clock_getres) {
117-
ksft_test_result_skip(VDSO_TEST_SKIP_MSG(name[3]));
134+
ksft_print_msg("Couldn't find %s\n", name[3]);
135+
ksft_test_result_skip("%s %s\n", name[3],
136+
vdso_clock_name[clk_id]);
118137
return;
119138
}
120139

@@ -137,34 +156,21 @@ static void vdso_test_clock_getres(clockid_t clk_id)
137156
clock_getres_fail++;
138157

139158
if (clock_getres_fail > 0) {
140-
ksft_test_result_fail(VDSO_TEST_FAIL_MSG(name[3]));
159+
ksft_test_result_fail("%s %s\n", name[3],
160+
vdso_clock_name[clk_id]);
141161
} else {
142-
ksft_test_result_pass(VDSO_TEST_PASS_MSG());
162+
ksft_test_result_pass("%s %s\n", name[3],
163+
vdso_clock_name[clk_id]);
143164
}
144165
}
145166

146-
const char *vdso_clock_name[12] = {
147-
"CLOCK_REALTIME",
148-
"CLOCK_MONOTONIC",
149-
"CLOCK_PROCESS_CPUTIME_ID",
150-
"CLOCK_THREAD_CPUTIME_ID",
151-
"CLOCK_MONOTONIC_RAW",
152-
"CLOCK_REALTIME_COARSE",
153-
"CLOCK_MONOTONIC_COARSE",
154-
"CLOCK_BOOTTIME",
155-
"CLOCK_REALTIME_ALARM",
156-
"CLOCK_BOOTTIME_ALARM",
157-
"CLOCK_SGI_CYCLE",
158-
"CLOCK_TAI",
159-
};
160-
161167
/*
162168
* This function calls vdso_test_clock_gettime and vdso_test_clock_getres
163169
* with different values for clock_id.
164170
*/
165171
static inline void vdso_test_clock(clockid_t clock_id)
166172
{
167-
ksft_print_msg("\nclock_id: %s\n", vdso_clock_name[clock_id]);
173+
ksft_print_msg("clock_id: %s\n", vdso_clock_name[clock_id]);
168174

169175
vdso_test_clock_gettime(clock_id);
170176

@@ -181,14 +187,14 @@ int main(int argc, char **argv)
181187
ksft_set_plan(VDSO_TEST_PLAN);
182188

183189
if (!sysinfo_ehdr) {
184-
printf("AT_SYSINFO_EHDR is not present!\n");
190+
ksft_print_msg("AT_SYSINFO_EHDR is not present!\n");
185191
return KSFT_SKIP;
186192
}
187193

188194
version = versions[VDSO_VERSION];
189195
name = (const char **)&names[VDSO_NAMES];
190196

191-
printf("[vDSO kselftest] VDSO_VERSION: %s\n", version);
197+
ksft_print_msg("[vDSO kselftest] VDSO_VERSION: %s\n", version);
192198

193199
vdso_init_from_sysinfo_ehdr(getauxval(AT_SYSINFO_EHDR));
194200

tools/testing/selftests/x86/lam.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@ static void run_test(struct testcases *test, int count)
817817

818818
/* return 3 is not support LA57, the case should be skipped */
819819
if (ret == 3) {
820-
ksft_test_result_skip(t->msg);
820+
ksft_test_result_skip("%s", t->msg);
821821
continue;
822822
}
823823

@@ -826,7 +826,7 @@ static void run_test(struct testcases *test, int count)
826826
else
827827
ret = !(t->expected);
828828

829-
ksft_test_result(ret, t->msg);
829+
ksft_test_result(ret, "%s", t->msg);
830830
}
831831
}
832832

0 commit comments

Comments
 (0)