Skip to content

Commit 4b95dc8

Browse files
committed
Merge tag 'linux_kselftest-next-6.10-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest
Pull kselftest updates from Shuah Khan: - make framework and tests reporting KTAP compliant - make ktap_helpers and power_supply test POSIX compliant - add ksft_exit_fail_perror() to include errono in string form - avoid clang reporting false positive static analysis errors about functions that exit and never return. ksft_exit* functions are marked __noreturn to address this problem - add mechanism for reporting a KSFT_ result code - fix build warnings related missing headers and unused variables - fix clang build failures - cleanups to resctrl test - add host arch for LLVM builds * tag 'linux_kselftest-next-6.10-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest: (44 commits) selftests/sgx: Include KHDR_INCLUDES in Makefile selftests: Compile kselftest headers with -D_GNU_SOURCE selftests/resctrl: fix clang build warnings related to abs(), labs() calls selftests/ftrace: Fix checkbashisms errors selftests/ftrace: Fix BTFARG testcase to check fprobe is enabled correctly selftests/capabilities: fix warn_unused_result build warnings selftests: filesystems: add missing stddef header selftests: kselftest_deps: fix l5_test() empty variable selftests: default to host arch for LLVM builds selftests/resctrl: fix clang build failure: use LOCAL_HDRS selftests/binderfs: use the Makefile's rules, not Make's implicit rules Documentation: kselftest: fix codeblock selftests: kselftest: Make ksft_exit functions return void instead of int selftests: x86: ksft_exit_pass() does not return selftests: timers: ksft_exit functions do not return selftests: sync: ksft_exit_pass() does not return selftests/resctrl: ksft_exit_skip() does not return selftests: pidfd: ksft_exit functions do not return selftests/mm: ksft_exit functions do not return selftests: membarrier: ksft_exit_pass() does not return ...
2 parents 896d3fc + 2c3b8f8 commit 4b95dc8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+703
-675
lines changed

Documentation/dev-tools/kselftest.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ expected time it takes to run a test. If you have control over the systems
183183
which will run the tests you can configure a test runner on those systems to
184184
use a greater or lower timeout on the command line as with the `-o` or
185185
the `--override-timeout` argument. For example to use 165 seconds instead
186-
one would use:
186+
one would use::
187187

188188
$ ./run_kselftest.sh --override-timeout 165
189189

tools/testing/selftests/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,11 @@ ifneq ($(KBUILD_OUTPUT),)
161161
# $(realpath ...) resolves symlinks
162162
abs_objtree := $(realpath $(abs_objtree))
163163
BUILD := $(abs_objtree)/kselftest
164-
KHDR_INCLUDES := -isystem ${abs_objtree}/usr/include
164+
KHDR_INCLUDES := -D_GNU_SOURCE -isystem ${abs_objtree}/usr/include
165165
else
166166
BUILD := $(CURDIR)
167167
abs_srctree := $(shell cd $(top_srcdir) && pwd)
168-
KHDR_INCLUDES := -isystem ${abs_srctree}/usr/include
168+
KHDR_INCLUDES := -D_GNU_SOURCE -isystem ${abs_srctree}/usr/include
169169
DEFAULT_INSTALL_HDR_PATH := 1
170170
endif
171171

tools/testing/selftests/capabilities/test_execve.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ static bool create_and_enter_ns(uid_t inner_uid)
8282
{
8383
uid_t outer_uid;
8484
gid_t outer_gid;
85-
int i;
85+
int i, ret;
8686
bool have_outer_privilege;
8787

8888
outer_uid = getuid();
@@ -97,7 +97,10 @@ static bool create_and_enter_ns(uid_t inner_uid)
9797
ksft_exit_fail_msg("setresuid - %s\n", strerror(errno));
9898

9999
// Re-enable effective caps
100-
capng_get_caps_process();
100+
ret = capng_get_caps_process();
101+
if (ret == -1)
102+
ksft_exit_fail_msg("capng_get_caps_process failed\n");
103+
101104
for (i = 0; i < CAP_LAST_CAP; i++)
102105
if (capng_have_capability(CAPNG_PERMITTED, i))
103106
capng_update(CAPNG_ADD, CAPNG_EFFECTIVE, i);
@@ -207,6 +210,7 @@ static void exec_validate_cap(bool eff, bool perm, bool inh, bool ambient)
207210

208211
static int do_tests(int uid, const char *our_path)
209212
{
213+
int ret;
210214
bool have_outer_privilege = create_and_enter_ns(uid);
211215

212216
int ourpath_fd = open(our_path, O_RDONLY | O_DIRECTORY);
@@ -250,7 +254,9 @@ static int do_tests(int uid, const char *our_path)
250254
ksft_exit_fail_msg("chmod - %s\n", strerror(errno));
251255
}
252256

253-
capng_get_caps_process();
257+
ret = capng_get_caps_process();
258+
if (ret == -1)
259+
ksft_exit_fail_msg("capng_get_caps_process failed\n");
254260

255261
/* Make sure that i starts out clear */
256262
capng_update(CAPNG_DROP, CAPNG_INHERITABLE, CAP_NET_BIND_SERVICE);

tools/testing/selftests/capabilities/validate_cap.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ static bool bool_arg(char **argv, int i)
2828
int main(int argc, char **argv)
2929
{
3030
const char *atsec = "";
31+
int ret;
3132

3233
/*
3334
* Be careful just in case a setgid or setcapped copy of this
@@ -44,7 +45,11 @@ int main(int argc, char **argv)
4445
atsec = " (AT_SECURE is not set)";
4546
#endif
4647

47-
capng_get_caps_process();
48+
ret = capng_get_caps_process();
49+
if (ret == -1) {
50+
ksft_print_msg("capng_get_caps_process failed\n");
51+
return 1;
52+
}
4853

4954
if (capng_have_capability(CAPNG_EFFECTIVE, CAP_NET_BIND_SERVICE) != bool_arg(argv, 1)) {
5055
ksft_print_msg("Wrong effective state%s\n", atsec);

tools/testing/selftests/clone3/clone3.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,14 @@ static int call_clone3(uint64_t flags, size_t size, enum test_mode test_mode)
9595
getpid(), pid);
9696

9797
if (waitpid(-1, &status, __WALL) < 0) {
98-
ksft_print_msg("Child returned %s\n", strerror(errno));
98+
ksft_print_msg("waitpid() returned %s\n", strerror(errno));
9999
return -errno;
100100
}
101+
if (!WIFEXITED(status)) {
102+
ksft_print_msg("Child did not exit normally, status 0x%x\n",
103+
status);
104+
return EXIT_FAILURE;
105+
}
101106
if (WEXITSTATUS(status))
102107
return WEXITSTATUS(status);
103108

tools/testing/selftests/clone3/clone3_clear_sighand.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,5 +120,5 @@ int main(int argc, char **argv)
120120

121121
test_clone3_clear_sighand();
122122

123-
return ksft_exit_pass();
123+
ksft_exit_pass();
124124
}

tools/testing/selftests/clone3/clone3_set_tid.c

Lines changed: 72 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ static int call_clone3_set_tid(pid_t *set_tid,
114114
return WEXITSTATUS(status);
115115
}
116116

117-
static void test_clone3_set_tid(pid_t *set_tid,
117+
static void test_clone3_set_tid(const char *desc,
118+
pid_t *set_tid,
118119
size_t set_tid_size,
119120
int flags,
120121
int expected,
@@ -129,17 +130,13 @@ static void test_clone3_set_tid(pid_t *set_tid,
129130
ret = call_clone3_set_tid(set_tid, set_tid_size, flags, expected_pid,
130131
wait_for_it);
131132
ksft_print_msg(
132-
"[%d] clone3() with CLONE_SET_TID %d says :%d - expected %d\n",
133+
"[%d] clone3() with CLONE_SET_TID %d says: %d - expected %d\n",
133134
getpid(), set_tid[0], ret, expected);
134-
if (ret != expected)
135-
ksft_test_result_fail(
136-
"[%d] Result (%d) is different than expected (%d)\n",
137-
getpid(), ret, expected);
138-
else
139-
ksft_test_result_pass(
140-
"[%d] Result (%d) matches expectation (%d)\n",
141-
getpid(), ret, expected);
135+
136+
ksft_test_result(ret == expected, "%s with %zu TIDs and flags 0x%x\n",
137+
desc, set_tid_size, flags);
142138
}
139+
143140
int main(int argc, char *argv[])
144141
{
145142
FILE *f;
@@ -172,73 +169,91 @@ int main(int argc, char *argv[])
172169

173170
/* Try invalid settings */
174171
memset(&set_tid, 0, sizeof(set_tid));
175-
test_clone3_set_tid(set_tid, MAX_PID_NS_LEVEL + 1, 0, -EINVAL, 0, 0);
172+
test_clone3_set_tid("invalid size, 0 TID",
173+
set_tid, MAX_PID_NS_LEVEL + 1, 0, -EINVAL, 0, 0);
176174

177-
test_clone3_set_tid(set_tid, MAX_PID_NS_LEVEL * 2, 0, -EINVAL, 0, 0);
175+
test_clone3_set_tid("invalid size, 0 TID",
176+
set_tid, MAX_PID_NS_LEVEL * 2, 0, -EINVAL, 0, 0);
178177

179-
test_clone3_set_tid(set_tid, MAX_PID_NS_LEVEL * 2 + 1, 0,
180-
-EINVAL, 0, 0);
178+
test_clone3_set_tid("invalid size, 0 TID",
179+
set_tid, MAX_PID_NS_LEVEL * 2 + 1, 0,
180+
-EINVAL, 0, 0);
181181

182-
test_clone3_set_tid(set_tid, MAX_PID_NS_LEVEL * 42, 0, -EINVAL, 0, 0);
182+
test_clone3_set_tid("invalid size, 0 TID",
183+
set_tid, MAX_PID_NS_LEVEL * 42, 0, -EINVAL, 0, 0);
183184

184185
/*
185186
* This can actually work if this test running in a MAX_PID_NS_LEVEL - 1
186187
* nested PID namespace.
187188
*/
188-
test_clone3_set_tid(set_tid, MAX_PID_NS_LEVEL - 1, 0, -EINVAL, 0, 0);
189+
test_clone3_set_tid("invalid size, 0 TID",
190+
set_tid, MAX_PID_NS_LEVEL - 1, 0, -EINVAL, 0, 0);
189191

190192
memset(&set_tid, 0xff, sizeof(set_tid));
191-
test_clone3_set_tid(set_tid, MAX_PID_NS_LEVEL + 1, 0, -EINVAL, 0, 0);
193+
test_clone3_set_tid("invalid size, TID all 1s",
194+
set_tid, MAX_PID_NS_LEVEL + 1, 0, -EINVAL, 0, 0);
192195

193-
test_clone3_set_tid(set_tid, MAX_PID_NS_LEVEL * 2, 0, -EINVAL, 0, 0);
196+
test_clone3_set_tid("invalid size, TID all 1s",
197+
set_tid, MAX_PID_NS_LEVEL * 2, 0, -EINVAL, 0, 0);
194198

195-
test_clone3_set_tid(set_tid, MAX_PID_NS_LEVEL * 2 + 1, 0,
196-
-EINVAL, 0, 0);
199+
test_clone3_set_tid("invalid size, TID all 1s",
200+
set_tid, MAX_PID_NS_LEVEL * 2 + 1, 0,
201+
-EINVAL, 0, 0);
197202

198-
test_clone3_set_tid(set_tid, MAX_PID_NS_LEVEL * 42, 0, -EINVAL, 0, 0);
203+
test_clone3_set_tid("invalid size, TID all 1s",
204+
set_tid, MAX_PID_NS_LEVEL * 42, 0, -EINVAL, 0, 0);
199205

200206
/*
201207
* This can actually work if this test running in a MAX_PID_NS_LEVEL - 1
202208
* nested PID namespace.
203209
*/
204-
test_clone3_set_tid(set_tid, MAX_PID_NS_LEVEL - 1, 0, -EINVAL, 0, 0);
210+
test_clone3_set_tid("invalid size, TID all 1s",
211+
set_tid, MAX_PID_NS_LEVEL - 1, 0, -EINVAL, 0, 0);
205212

206213
memset(&set_tid, 0, sizeof(set_tid));
207214
/* Try with an invalid PID */
208215
set_tid[0] = 0;
209-
test_clone3_set_tid(set_tid, 1, 0, -EINVAL, 0, 0);
216+
test_clone3_set_tid("valid size, 0 TID",
217+
set_tid, 1, 0, -EINVAL, 0, 0);
210218

211219
set_tid[0] = -1;
212-
test_clone3_set_tid(set_tid, 1, 0, -EINVAL, 0, 0);
220+
test_clone3_set_tid("valid size, -1 TID",
221+
set_tid, 1, 0, -EINVAL, 0, 0);
213222

214223
/* Claim that the set_tid array actually contains 2 elements. */
215-
test_clone3_set_tid(set_tid, 2, 0, -EINVAL, 0, 0);
224+
test_clone3_set_tid("2 TIDs, -1 and 0",
225+
set_tid, 2, 0, -EINVAL, 0, 0);
216226

217227
/* Try it in a new PID namespace */
218228
if (uid == 0)
219-
test_clone3_set_tid(set_tid, 1, CLONE_NEWPID, -EINVAL, 0, 0);
229+
test_clone3_set_tid("valid size, -1 TID",
230+
set_tid, 1, CLONE_NEWPID, -EINVAL, 0, 0);
220231
else
221232
ksft_test_result_skip("Clone3() with set_tid requires root\n");
222233

223234
/* Try with a valid PID (1) this should return -EEXIST. */
224235
set_tid[0] = 1;
225236
if (uid == 0)
226-
test_clone3_set_tid(set_tid, 1, 0, -EEXIST, 0, 0);
237+
test_clone3_set_tid("duplicate PID 1",
238+
set_tid, 1, 0, -EEXIST, 0, 0);
227239
else
228240
ksft_test_result_skip("Clone3() with set_tid requires root\n");
229241

230242
/* Try it in a new PID namespace */
231243
if (uid == 0)
232-
test_clone3_set_tid(set_tid, 1, CLONE_NEWPID, 0, 0, 0);
244+
test_clone3_set_tid("duplicate PID 1",
245+
set_tid, 1, CLONE_NEWPID, 0, 0, 0);
233246
else
234247
ksft_test_result_skip("Clone3() with set_tid requires root\n");
235248

236249
/* pid_max should fail everywhere */
237250
set_tid[0] = pid_max;
238-
test_clone3_set_tid(set_tid, 1, 0, -EINVAL, 0, 0);
251+
test_clone3_set_tid("set TID to maximum",
252+
set_tid, 1, 0, -EINVAL, 0, 0);
239253

240254
if (uid == 0)
241-
test_clone3_set_tid(set_tid, 1, CLONE_NEWPID, -EINVAL, 0, 0);
255+
test_clone3_set_tid("set TID to maximum",
256+
set_tid, 1, CLONE_NEWPID, -EINVAL, 0, 0);
242257
else
243258
ksft_test_result_skip("Clone3() with set_tid requires root\n");
244259

@@ -262,10 +277,12 @@ int main(int argc, char *argv[])
262277

263278
/* After the child has finished, its PID should be free. */
264279
set_tid[0] = pid;
265-
test_clone3_set_tid(set_tid, 1, 0, 0, 0, 0);
280+
test_clone3_set_tid("reallocate child TID",
281+
set_tid, 1, 0, 0, 0, 0);
266282

267283
/* This should fail as there is no PID 1 in that namespace */
268-
test_clone3_set_tid(set_tid, 1, CLONE_NEWPID, -EINVAL, 0, 0);
284+
test_clone3_set_tid("duplicate child TID",
285+
set_tid, 1, CLONE_NEWPID, -EINVAL, 0, 0);
269286

270287
/*
271288
* Creating a process with PID 1 in the newly created most nested
@@ -274,7 +291,8 @@ int main(int argc, char *argv[])
274291
*/
275292
set_tid[0] = 1;
276293
set_tid[1] = pid;
277-
test_clone3_set_tid(set_tid, 2, CLONE_NEWPID, 0, pid, 0);
294+
test_clone3_set_tid("create PID 1 in new NS",
295+
set_tid, 2, CLONE_NEWPID, 0, pid, 0);
278296

279297
ksft_print_msg("unshare PID namespace\n");
280298
if (unshare(CLONE_NEWPID) == -1)
@@ -284,7 +302,8 @@ int main(int argc, char *argv[])
284302
set_tid[0] = pid;
285303

286304
/* This should fail as there is no PID 1 in that namespace */
287-
test_clone3_set_tid(set_tid, 1, 0, -EINVAL, 0, 0);
305+
test_clone3_set_tid("duplicate PID 1",
306+
set_tid, 1, 0, -EINVAL, 0, 0);
288307

289308
/* Let's create a PID 1 */
290309
ns_pid = fork();
@@ -295,21 +314,25 @@ int main(int argc, char *argv[])
295314
*/
296315
set_tid[0] = 43;
297316
set_tid[1] = -1;
298-
test_clone3_set_tid(set_tid, 2, 0, -EINVAL, 0, 0);
317+
test_clone3_set_tid("check leak on invalid TID -1",
318+
set_tid, 2, 0, -EINVAL, 0, 0);
299319

300320
set_tid[0] = 43;
301321
set_tid[1] = pid;
302-
test_clone3_set_tid(set_tid, 2, 0, 0, 43, 0);
322+
test_clone3_set_tid("check leak on invalid specific TID",
323+
set_tid, 2, 0, 0, 43, 0);
303324

304325
ksft_print_msg("Child in PID namespace has PID %d\n", getpid());
305326
set_tid[0] = 2;
306-
test_clone3_set_tid(set_tid, 1, 0, 0, 2, 0);
327+
test_clone3_set_tid("create PID 2 in child NS",
328+
set_tid, 1, 0, 0, 2, 0);
307329

308330
set_tid[0] = 1;
309331
set_tid[1] = -1;
310332
set_tid[2] = pid;
311333
/* This should fail as there is invalid PID at level '1'. */
312-
test_clone3_set_tid(set_tid, 3, CLONE_NEWPID, -EINVAL, 0, 0);
334+
test_clone3_set_tid("fail due to invalid TID at level 1",
335+
set_tid, 3, CLONE_NEWPID, -EINVAL, 0, 0);
313336

314337
set_tid[0] = 1;
315338
set_tid[1] = 42;
@@ -319,13 +342,15 @@ int main(int argc, char *argv[])
319342
* namespaces. Again assuming this is running in the host's
320343
* PID namespace. Not yet nested.
321344
*/
322-
test_clone3_set_tid(set_tid, 4, CLONE_NEWPID, -EINVAL, 0, 0);
345+
test_clone3_set_tid("fail due to too few active PID NSs",
346+
set_tid, 4, CLONE_NEWPID, -EINVAL, 0, 0);
323347

324348
/*
325349
* This should work and from the parent we should see
326350
* something like 'NSpid: pid 42 1'.
327351
*/
328-
test_clone3_set_tid(set_tid, 3, CLONE_NEWPID, 0, 42, true);
352+
test_clone3_set_tid("verify that we have 3 PID NSs",
353+
set_tid, 3, CLONE_NEWPID, 0, 42, true);
329354

330355
child_exit(ksft_cnt.ksft_fail);
331356
}
@@ -380,16 +405,14 @@ int main(int argc, char *argv[])
380405
ksft_cnt.ksft_pass += 6 - (ksft_cnt.ksft_fail - WEXITSTATUS(status));
381406
ksft_cnt.ksft_fail = WEXITSTATUS(status);
382407

383-
if (ns3 == pid && ns2 == 42 && ns1 == 1)
384-
ksft_test_result_pass(
385-
"PIDs in all namespaces as expected (%d,%d,%d)\n",
386-
ns3, ns2, ns1);
387-
else
388-
ksft_test_result_fail(
389-
"PIDs in all namespaces not as expected (%d,%d,%d)\n",
390-
ns3, ns2, ns1);
408+
ksft_print_msg("Expecting PIDs %d, 42, 1\n", pid);
409+
ksft_print_msg("Have PIDs in namespaces: %d, %d, %d\n", ns3, ns2, ns1);
410+
ksft_test_result(ns3 == pid && ns2 == 42 && ns1 == 1,
411+
"PIDs in all namespaces as expected\n");
391412
out:
392413
ret = 0;
393414

394-
return !ret ? ksft_exit_pass() : ksft_exit_fail();
415+
if (ret)
416+
ksft_exit_fail();
417+
ksft_exit_pass();
395418
}

tools/testing/selftests/cpufreq/cpufreq.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,7 @@ cpufreq_basic_tests()
178178

179179
count=$(count_cpufreq_managed_cpus)
180180
if [ $count = 0 ]; then
181-
printf "No cpu is managed by cpufreq core, exiting\n"
182-
exit;
181+
ktap_exit_fail_msg "No cpu is managed by cpufreq core, exiting\n"
183182
else
184183
printf "CPUFreq manages: $count CPUs\n\n"
185184
fi

0 commit comments

Comments
 (0)