Skip to content

Commit 0db240b

Browse files
committed
Merge tag 'linux_kselftest-next-6.17-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest
Pull kselftest updates from Shuah Khan: - Fixes: - false failure of subsystem event test - glob filter test to use mutex_unlock() instead of mutex_trylock() - several spelling errors in tests - test_kexec_jump build errors - pidfd test duplicate-symbol warnings for SCHED_ CPP symbols - Add a reliable check for suspend to breakpoints suspend test - Improvements to ipc test * tag 'linux_kselftest-next-6.17-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest: selftests/pidfd: Fix duplicate-symbol warnings for SCHED_ CPP symbols selftests/tracing: Fix false failure of subsystem event test selftests/kexec: fix test_kexec_jump build selftests: breakpoints: use suspend_stats to reliably check suspend success selftests: tracing: Use mutex_unlock for testing glob filter selftests: print installation complete message selftests/ptrace: Fix spelling mistake "multible" -> "multiple" selftests: ipc: Replace fail print statements with ksft_test_result_fail selftests: Add version file to kselftest installation dir selftests/cpu-hotplug: fix typo in hotplaggable_offline_cpus function name
2 parents 6f46e6f + 30fb5e1 commit 0db240b

9 files changed

Lines changed: 102 additions & 41 deletions

File tree

tools/testing/selftests/Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,14 @@ ifdef INSTALL_PATH
293293
$(MAKE) -s --no-print-directory OUTPUT=$$BUILD_TARGET COLLECTION=$$TARGET \
294294
-C $$TARGET emit_tests >> $(TEST_LIST); \
295295
done;
296+
@VERSION=$$(git describe HEAD 2>/dev/null); \
297+
if [ -n "$$VERSION" ]; then \
298+
echo "$$VERSION" > $(INSTALL_PATH)/VERSION; \
299+
printf "Version saved to $(INSTALL_PATH)/VERSION\n"; \
300+
else \
301+
printf "Unable to get version from git describe\n"; \
302+
fi
303+
@echo "**Kselftest Installation is complete: $(INSTALL_PATH)**"
296304
else
297305
$(error Error: set INSTALL_PATH to use install)
298306
endif

tools/testing/selftests/breakpoints/step_after_suspend_test.c

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -127,22 +127,42 @@ int run_test(int cpu)
127127
return KSFT_PASS;
128128
}
129129

130+
/*
131+
* Reads the suspend success count from sysfs.
132+
* Returns the count on success or exits on failure.
133+
*/
134+
static int get_suspend_success_count_or_fail(void)
135+
{
136+
FILE *fp;
137+
int val;
138+
139+
fp = fopen("/sys/power/suspend_stats/success", "r");
140+
if (!fp)
141+
ksft_exit_fail_msg(
142+
"Failed to open suspend_stats/success: %s\n",
143+
strerror(errno));
144+
145+
if (fscanf(fp, "%d", &val) != 1) {
146+
fclose(fp);
147+
ksft_exit_fail_msg(
148+
"Failed to read suspend success count\n");
149+
}
150+
151+
fclose(fp);
152+
return val;
153+
}
154+
130155
void suspend(void)
131156
{
132-
int power_state_fd;
133157
int timerfd;
134158
int err;
159+
int count_before;
160+
int count_after;
135161
struct itimerspec spec = {};
136162

137163
if (getuid() != 0)
138164
ksft_exit_skip("Please run the test as root - Exiting.\n");
139165

140-
power_state_fd = open("/sys/power/state", O_RDWR);
141-
if (power_state_fd < 0)
142-
ksft_exit_fail_msg(
143-
"open(\"/sys/power/state\") failed %s)\n",
144-
strerror(errno));
145-
146166
timerfd = timerfd_create(CLOCK_BOOTTIME_ALARM, 0);
147167
if (timerfd < 0)
148168
ksft_exit_fail_msg("timerfd_create() failed\n");
@@ -152,14 +172,15 @@ void suspend(void)
152172
if (err < 0)
153173
ksft_exit_fail_msg("timerfd_settime() failed\n");
154174

175+
count_before = get_suspend_success_count_or_fail();
176+
155177
system("(echo mem > /sys/power/state) 2> /dev/null");
156178

157-
timerfd_gettime(timerfd, &spec);
158-
if (spec.it_value.tv_sec != 0 || spec.it_value.tv_nsec != 0)
179+
count_after = get_suspend_success_count_or_fail();
180+
if (count_after <= count_before)
159181
ksft_exit_fail_msg("Failed to enter Suspend state\n");
160182

161183
close(timerfd);
162-
close(power_state_fd);
163184
}
164185

165186
int main(int argc, char **argv)

tools/testing/selftests/cpu-hotplug/cpu-on-off-test.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ hotpluggable_cpus()
6767
done
6868
}
6969

70-
hotplaggable_offline_cpus()
70+
hotpluggable_offline_cpus()
7171
{
7272
hotpluggable_cpus 0
7373
}
@@ -151,7 +151,7 @@ offline_cpu_expect_fail()
151151

152152
online_all_hot_pluggable_cpus()
153153
{
154-
for cpu in `hotplaggable_offline_cpus`; do
154+
for cpu in `hotpluggable_offline_cpus`; do
155155
online_cpu_expect_success $cpu
156156
done
157157
}

tools/testing/selftests/ftrace/test.d/event/subsystem-enable.tc

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,35 @@ fail() { #msg
1414
exit_fail
1515
}
1616

17+
# As reading trace can last forever, simply look for 3 different
18+
# events then exit out of reading the file. If there's not 3 different
19+
# events, then the test has failed.
20+
check_unique() {
21+
cat trace | grep -v '^#' | awk '
22+
BEGIN { cnt = 0; }
23+
{
24+
for (i = 0; i < cnt; i++) {
25+
if (event[i] == $5) {
26+
break;
27+
}
28+
}
29+
if (i == cnt) {
30+
event[cnt++] = $5;
31+
if (cnt > 2) {
32+
exit;
33+
}
34+
}
35+
}
36+
END {
37+
printf "%d", cnt;
38+
}'
39+
}
40+
1741
echo 'sched:*' > set_event
1842

1943
yield
2044

21-
count=`head -n 100 trace | grep -v ^# | awk '{ print $5 }' | sort -u | wc -l`
45+
count=`check_unique`
2246
if [ $count -lt 3 ]; then
2347
fail "at least fork, exec and exit events should be recorded"
2448
fi
@@ -29,7 +53,7 @@ echo 1 > events/sched/enable
2953

3054
yield
3155

32-
count=`head -n 100 trace | grep -v ^# | awk '{ print $5 }' | sort -u | wc -l`
56+
count=`check_unique`
3357
if [ $count -lt 3 ]; then
3458
fail "at least fork, exec and exit events should be recorded"
3559
fi

tools/testing/selftests/ftrace/test.d/ftrace/func-filter-glob.tc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ ftrace_filter_check 'schedule*' '^schedule.*$'
2929
ftrace_filter_check '*pin*lock' '.*pin.*lock$'
3030

3131
# filter by start*mid*
32-
ftrace_filter_check 'mutex*try*' '^mutex.*try.*'
32+
ftrace_filter_check 'mutex*unl*' '^mutex.*unl.*'
3333

3434
# Advanced full-glob matching feature is recently supported.
3535
# Skip the tests if we are sure the kernel does not support it.

tools/testing/selftests/ipc/msgque.c

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -39,34 +39,34 @@ int restore_queue(struct msgque_data *msgque)
3939

4040
fd = open("/proc/sys/kernel/msg_next_id", O_WRONLY);
4141
if (fd == -1) {
42-
printf("Failed to open /proc/sys/kernel/msg_next_id\n");
42+
ksft_test_result_fail("Failed to open /proc/sys/kernel/msg_next_id\n");
4343
return -errno;
4444
}
4545
sprintf(buf, "%d", msgque->msq_id);
4646

4747
ret = write(fd, buf, strlen(buf));
4848
if (ret != strlen(buf)) {
49-
printf("Failed to write to /proc/sys/kernel/msg_next_id\n");
49+
ksft_test_result_fail("Failed to write to /proc/sys/kernel/msg_next_id\n");
5050
return -errno;
5151
}
5252

5353
id = msgget(msgque->key, msgque->mode | IPC_CREAT | IPC_EXCL);
5454
if (id == -1) {
55-
printf("Failed to create queue\n");
55+
ksft_test_result_fail("Failed to create queue\n");
5656
return -errno;
5757
}
5858

5959
if (id != msgque->msq_id) {
60-
printf("Restored queue has wrong id (%d instead of %d)\n",
61-
id, msgque->msq_id);
60+
ksft_test_result_fail("Restored queue has wrong id (%d instead of %d)\n"
61+
, id, msgque->msq_id);
6262
ret = -EFAULT;
6363
goto destroy;
6464
}
6565

6666
for (i = 0; i < msgque->qnum; i++) {
6767
if (msgsnd(msgque->msq_id, &msgque->messages[i].mtype,
6868
msgque->messages[i].msize, IPC_NOWAIT) != 0) {
69-
printf("msgsnd failed (%m)\n");
69+
ksft_test_result_fail("msgsnd failed (%m)\n");
7070
ret = -errno;
7171
goto destroy;
7272
}
@@ -90,31 +90,30 @@ int check_and_destroy_queue(struct msgque_data *msgque)
9090
if (ret < 0) {
9191
if (errno == ENOMSG)
9292
break;
93-
printf("Failed to read IPC message: %m\n");
93+
ksft_test_result_fail("Failed to read IPC message: %m\n");
9494
ret = -errno;
9595
goto err;
9696
}
9797
if (ret != msgque->messages[cnt].msize) {
98-
printf("Wrong message size: %d (expected %d)\n", ret,
99-
msgque->messages[cnt].msize);
98+
ksft_test_result_fail("Wrong message size: %d (expected %d)\n", ret, msgque->messages[cnt].msize);
10099
ret = -EINVAL;
101100
goto err;
102101
}
103102
if (message.mtype != msgque->messages[cnt].mtype) {
104-
printf("Wrong message type\n");
103+
ksft_test_result_fail("Wrong message type\n");
105104
ret = -EINVAL;
106105
goto err;
107106
}
108107
if (memcmp(message.mtext, msgque->messages[cnt].mtext, ret)) {
109-
printf("Wrong message content\n");
108+
ksft_test_result_fail("Wrong message content\n");
110109
ret = -EINVAL;
111110
goto err;
112111
}
113112
cnt++;
114113
}
115114

116115
if (cnt != msgque->qnum) {
117-
printf("Wrong message number\n");
116+
ksft_test_result_fail("Wrong message number\n");
118117
ret = -EINVAL;
119118
goto err;
120119
}
@@ -139,7 +138,7 @@ int dump_queue(struct msgque_data *msgque)
139138
if (ret < 0) {
140139
if (errno == EINVAL)
141140
continue;
142-
printf("Failed to get stats for IPC queue with id %d\n",
141+
ksft_test_result_fail("Failed to get stats for IPC queue with id %d\n",
143142
kern_id);
144143
return -errno;
145144
}
@@ -150,7 +149,7 @@ int dump_queue(struct msgque_data *msgque)
150149

151150
msgque->messages = malloc(sizeof(struct msg1) * ds.msg_qnum);
152151
if (msgque->messages == NULL) {
153-
printf("Failed to get stats for IPC queue\n");
152+
ksft_test_result_fail("Failed to get stats for IPC queue\n");
154153
return -ENOMEM;
155154
}
156155

@@ -162,7 +161,7 @@ int dump_queue(struct msgque_data *msgque)
162161
ret = msgrcv(msgque->msq_id, &msgque->messages[i].mtype,
163162
MAX_MSG_SIZE, i, IPC_NOWAIT | MSG_COPY);
164163
if (ret < 0) {
165-
printf("Failed to copy IPC message: %m (%d)\n", errno);
164+
ksft_test_result_fail("Failed to copy IPC message: %m (%d)\n", errno);
166165
return -errno;
167166
}
168167
msgque->messages[i].msize = ret;
@@ -178,15 +177,15 @@ int fill_msgque(struct msgque_data *msgque)
178177
memcpy(msgbuf.mtext, TEST_STRING, sizeof(TEST_STRING));
179178
if (msgsnd(msgque->msq_id, &msgbuf.mtype, sizeof(TEST_STRING),
180179
IPC_NOWAIT) != 0) {
181-
printf("First message send failed (%m)\n");
180+
ksft_test_result_fail("First message send failed (%m)\n");
182181
return -errno;
183182
}
184183

185184
msgbuf.mtype = ANOTHER_MSG_TYPE;
186185
memcpy(msgbuf.mtext, ANOTHER_TEST_STRING, sizeof(ANOTHER_TEST_STRING));
187186
if (msgsnd(msgque->msq_id, &msgbuf.mtype, sizeof(ANOTHER_TEST_STRING),
188187
IPC_NOWAIT) != 0) {
189-
printf("Second message send failed (%m)\n");
188+
ksft_test_result_fail("Second message send failed (%m)\n");
190189
return -errno;
191190
}
192191
return 0;
@@ -202,44 +201,44 @@ int main(int argc, char **argv)
202201

203202
msgque.key = ftok(argv[0], 822155650);
204203
if (msgque.key == -1) {
205-
printf("Can't make key: %d\n", -errno);
204+
ksft_test_result_fail("Can't make key: %d\n", -errno);
206205
ksft_exit_fail();
207206
}
208207

209208
msgque.msq_id = msgget(msgque.key, IPC_CREAT | IPC_EXCL | 0666);
210209
if (msgque.msq_id == -1) {
211210
err = -errno;
212-
printf("Can't create queue: %d\n", err);
211+
ksft_test_result_fail("Can't create queue: %d\n", err);
213212
goto err_out;
214213
}
215214

216215
err = fill_msgque(&msgque);
217216
if (err) {
218-
printf("Failed to fill queue: %d\n", err);
217+
ksft_test_result_fail("Failed to fill queue: %d\n", err);
219218
goto err_destroy;
220219
}
221220

222221
err = dump_queue(&msgque);
223222
if (err) {
224-
printf("Failed to dump queue: %d\n", err);
223+
ksft_test_result_fail("Failed to dump queue: %d\n", err);
225224
goto err_destroy;
226225
}
227226

228227
err = check_and_destroy_queue(&msgque);
229228
if (err) {
230-
printf("Failed to check and destroy queue: %d\n", err);
229+
ksft_test_result_fail("Failed to check and destroy queue: %d\n", err);
231230
goto err_out;
232231
}
233232

234233
err = restore_queue(&msgque);
235234
if (err) {
236-
printf("Failed to restore queue: %d\n", err);
235+
ksft_test_result_fail("Failed to restore queue: %d\n", err);
237236
goto err_destroy;
238237
}
239238

240239
err = check_and_destroy_queue(&msgque);
241240
if (err) {
242-
printf("Failed to test queue: %d\n", err);
241+
ksft_test_result_fail("Failed to test queue: %d\n", err);
243242
goto err_out;
244243
}
245244
ksft_exit_pass();

tools/testing/selftests/kexec/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ include ../../../scripts/Makefile.arch
1212

1313
ifeq ($(IS_64_BIT)$(ARCH_PROCESSED),1x86)
1414
TEST_PROGS += test_kexec_jump.sh
15-
test_kexec_jump.sh: $(OUTPUT)/test_kexec_jump
15+
TEST_GEN_PROGS := test_kexec_jump
1616
endif
1717

1818
include ../lib.mk

tools/testing/selftests/pidfd/pidfd.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@
1616
#include <sys/types.h>
1717
#include <sys/wait.h>
1818

19+
/*
20+
* Remove the userspace definitions of the following preprocessor symbols
21+
* to avoid duplicate-definition warnings from the subsequent in-kernel
22+
* definitions.
23+
*/
24+
#undef SCHED_NORMAL
25+
#undef SCHED_FLAG_KEEP_ALL
26+
#undef SCHED_FLAG_UTIL_CLAMP
27+
1928
#include "../kselftest.h"
2029
#include "../clone3/clone3_selftests.h"
2130

tools/testing/selftests/ptrace/peeksiginfo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ int main(int argc, char *argv[])
199199

200200
/*
201201
* Dump signal from the process-wide queue.
202-
* The number of signals is not multible to the buffer size
202+
* The number of signals is not multiple to the buffer size
203203
*/
204204
if (check_direct_path(child, 1, 3))
205205
goto out;

0 commit comments

Comments
 (0)