Skip to content

Commit 3d15cfd

Browse files
committed
Merge tag 'linux-kselftest-4.6-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest
Pull Kselftest updates from Shuah Khan: "This update for Kselftest adds: - A new feature to create test-specific kconfig fragments. This feature helps configure Kselftests to test specific Kernel Configuration options as opposed to defconfig. - A new test for Media Controller API - A few fixes" * tag 'linux-kselftest-4.6-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest: selftests: media_dcevice_test fix usage information selftests: media_dcevice_test fix to handle ioctl failure case selftests: add missing .gitignore file or entry Makefile: add kselftest-merge selftests: create test-specific kconfig fragments selftests: breakpoint: add step_after_suspend_test selftests: add a new test for Media Controller API
2 parents 5cd0911 + 6accd8e commit 3d15cfd

File tree

21 files changed

+362
-1
lines changed

21 files changed

+362
-1
lines changed

Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,6 +1087,14 @@ kselftest:
10871087
kselftest-clean:
10881088
$(Q)$(MAKE) -C tools/testing/selftests clean
10891089

1090+
PHONY += kselftest-merge
1091+
kselftest-merge:
1092+
$(if $(wildcard $(objtree)/.config),, $(error No .config exists, config your kernel first!))
1093+
$(Q)$(CONFIG_SHELL) $(srctree)/scripts/kconfig/merge_config.sh \
1094+
-m $(objtree)/.config \
1095+
$(srctree)/tools/testing/selftests/*/config
1096+
+$(Q)$(MAKE) -f $(srctree)/Makefile olddefconfig
1097+
10901098
# ---------------------------------------------------------------------------
10911099
# Modules
10921100

@@ -1295,6 +1303,8 @@ help:
12951303
@echo ' Build, install, and boot kernel before'
12961304
@echo ' running kselftest on it'
12971305
@echo ' kselftest-clean - Remove all generated kselftest files'
1306+
@echo ' kselftest-merge - Merge all the config dependencies of kselftest to existed'
1307+
@echo ' .config.'
12981308
@echo ''
12991309
@echo 'Kernel packaging:'
13001310
@$(MAKE) $(build)=$(package-dir) help
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
breakpoint_test
2+
step_after_suspend_test

tools/testing/selftests/breakpoints/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ ifeq ($(ARCH),x86)
66
TEST_PROGS := breakpoint_test
77
endif
88

9+
TEST_PROGS += step_after_suspend_test
10+
911
all: $(TEST_PROGS)
1012

1113
include ../lib.mk
1214

1315
clean:
14-
rm -fr breakpoint_test
16+
rm -fr breakpoint_test step_after_suspend_test
Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
/*
2+
* Copyright (C) 2016 Google, Inc.
3+
*
4+
* This software is licensed under the terms of the GNU General Public
5+
* License version 2, as published by the Free Software Foundation, and
6+
* may be copied, distributed, and modified under those terms.
7+
*
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* GNU General Public License for more details.
12+
*
13+
*/
14+
15+
#define _GNU_SOURCE
16+
17+
#include <errno.h>
18+
#include <fcntl.h>
19+
#include <sched.h>
20+
#include <signal.h>
21+
#include <stdbool.h>
22+
#include <stdio.h>
23+
#include <string.h>
24+
#include <unistd.h>
25+
#include <sys/ptrace.h>
26+
#include <sys/stat.h>
27+
#include <sys/timerfd.h>
28+
#include <sys/types.h>
29+
#include <sys/wait.h>
30+
31+
#include "../kselftest.h"
32+
33+
void child(int cpu)
34+
{
35+
cpu_set_t set;
36+
37+
CPU_ZERO(&set);
38+
CPU_SET(cpu, &set);
39+
if (sched_setaffinity(0, sizeof(set), &set) != 0) {
40+
perror("sched_setaffinity() failed");
41+
_exit(1);
42+
}
43+
44+
if (ptrace(PTRACE_TRACEME, 0, NULL, NULL) != 0) {
45+
perror("ptrace(PTRACE_TRACEME) failed");
46+
_exit(1);
47+
}
48+
49+
if (raise(SIGSTOP) != 0) {
50+
perror("raise(SIGSTOP) failed");
51+
_exit(1);
52+
}
53+
54+
_exit(0);
55+
}
56+
57+
bool run_test(int cpu)
58+
{
59+
int status;
60+
pid_t pid = fork();
61+
pid_t wpid;
62+
63+
if (pid < 0) {
64+
perror("fork() failed");
65+
return false;
66+
}
67+
if (pid == 0)
68+
child(cpu);
69+
70+
wpid = waitpid(pid, &status, __WALL);
71+
if (wpid != pid) {
72+
perror("waitpid() failed");
73+
return false;
74+
}
75+
if (!WIFSTOPPED(status)) {
76+
printf("child did not stop\n");
77+
return false;
78+
}
79+
if (WSTOPSIG(status) != SIGSTOP) {
80+
printf("child did not stop with SIGSTOP\n");
81+
return false;
82+
}
83+
84+
if (ptrace(PTRACE_SINGLESTEP, pid, NULL, NULL) < 0) {
85+
if (errno == EIO) {
86+
printf("ptrace(PTRACE_SINGLESTEP) not supported on this architecture\n");
87+
ksft_exit_skip();
88+
}
89+
perror("ptrace(PTRACE_SINGLESTEP) failed");
90+
return false;
91+
}
92+
93+
wpid = waitpid(pid, &status, __WALL);
94+
if (wpid != pid) {
95+
perror("waitpid() failed");
96+
return false;
97+
}
98+
if (WIFEXITED(status)) {
99+
printf("child did not single-step\n");
100+
return false;
101+
}
102+
if (!WIFSTOPPED(status)) {
103+
printf("child did not stop\n");
104+
return false;
105+
}
106+
if (WSTOPSIG(status) != SIGTRAP) {
107+
printf("child did not stop with SIGTRAP\n");
108+
return false;
109+
}
110+
111+
if (ptrace(PTRACE_CONT, pid, NULL, NULL) < 0) {
112+
perror("ptrace(PTRACE_CONT) failed");
113+
return false;
114+
}
115+
116+
wpid = waitpid(pid, &status, __WALL);
117+
if (wpid != pid) {
118+
perror("waitpid() failed");
119+
return false;
120+
}
121+
if (!WIFEXITED(status)) {
122+
printf("child did not exit after PTRACE_CONT\n");
123+
return false;
124+
}
125+
126+
return true;
127+
}
128+
129+
void suspend(void)
130+
{
131+
int power_state_fd;
132+
struct sigevent event = {};
133+
int timerfd;
134+
int err;
135+
struct itimerspec spec = {};
136+
137+
power_state_fd = open("/sys/power/state", O_RDWR);
138+
if (power_state_fd < 0) {
139+
perror("open(\"/sys/power/state\") failed (is this test running as root?)");
140+
ksft_exit_fail();
141+
}
142+
143+
timerfd = timerfd_create(CLOCK_BOOTTIME_ALARM, 0);
144+
if (timerfd < 0) {
145+
perror("timerfd_create() failed");
146+
ksft_exit_fail();
147+
}
148+
149+
spec.it_value.tv_sec = 5;
150+
err = timerfd_settime(timerfd, 0, &spec, NULL);
151+
if (err < 0) {
152+
perror("timerfd_settime() failed");
153+
ksft_exit_fail();
154+
}
155+
156+
if (write(power_state_fd, "mem", strlen("mem")) != strlen("mem")) {
157+
perror("entering suspend failed");
158+
ksft_exit_fail();
159+
}
160+
161+
close(timerfd);
162+
close(power_state_fd);
163+
}
164+
165+
int main(int argc, char **argv)
166+
{
167+
int opt;
168+
bool do_suspend = true;
169+
bool succeeded = true;
170+
cpu_set_t available_cpus;
171+
int err;
172+
int cpu;
173+
174+
while ((opt = getopt(argc, argv, "n")) != -1) {
175+
switch (opt) {
176+
case 'n':
177+
do_suspend = false;
178+
break;
179+
default:
180+
printf("Usage: %s [-n]\n", argv[0]);
181+
printf(" -n: do not trigger a suspend/resume cycle before the test\n");
182+
return -1;
183+
}
184+
}
185+
186+
if (do_suspend)
187+
suspend();
188+
189+
err = sched_getaffinity(0, sizeof(available_cpus), &available_cpus);
190+
if (err < 0) {
191+
perror("sched_getaffinity() failed");
192+
ksft_exit_fail();
193+
}
194+
195+
for (cpu = 0; cpu < CPU_SETSIZE; cpu++) {
196+
bool test_success;
197+
198+
if (!CPU_ISSET(cpu, &available_cpus))
199+
continue;
200+
201+
test_success = run_test(cpu);
202+
printf("CPU %d: ", cpu);
203+
if (test_success) {
204+
printf("[OK]\n");
205+
ksft_inc_pass_cnt();
206+
} else {
207+
printf("[FAILED]\n");
208+
ksft_inc_fail_cnt();
209+
succeeded = false;
210+
}
211+
}
212+
213+
ksft_print_cnts();
214+
if (succeeded)
215+
ksft_exit_pass();
216+
else
217+
ksft_exit_fail();
218+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CONFIG_NOTIFIER_ERROR_INJECTION=y
2+
CONFIG_CPU_NOTIFIER_ERROR_INJECT=m
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CONFIG_TEST_FIRMWARE=y

tools/testing/selftests/ftrace/config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CONFIG_FTRACE=y
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
msgque_test

tools/testing/selftests/ipc/config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CONFIG_EXPERT=y
2+
CONFIG_CHECKPOINT_RESTORE=y
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
media_device_test
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
TEST_PROGS := media_device_test
2+
all: $(TEST_PROGS)
3+
4+
include ../lib.mk
5+
6+
clean:
7+
rm -fr media_device_test
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* media_devkref_test.c - Media Controller Device Kref API Test
3+
*
4+
* Copyright (c) 2016 Shuah Khan <[email protected]>
5+
* Copyright (c) 2016 Samsung Electronics Co., Ltd.
6+
*
7+
* This file is released under the GPLv2.
8+
*/
9+
10+
/*
11+
* This file adds a test for Media Controller API.
12+
* This test should be run as root and should not be
13+
* included in the Kselftest run. This test should be
14+
* run when hardware and driver that makes use Media
15+
* Controller API are present in the system.
16+
*
17+
* This test opens user specified Media Device and calls
18+
* MEDIA_IOC_DEVICE_INFO ioctl in a loop once every 10
19+
* seconds.
20+
*
21+
* Usage:
22+
* sudo ./media_device_test -d /dev/mediaX
23+
*
24+
* While test is running, remove the device and
25+
* ensure there are no use after free errors and
26+
* other Oops in the dmesg. Enable KaSan kernel
27+
* config option for use-after-free error detection.
28+
*/
29+
30+
#include <stdio.h>
31+
#include <unistd.h>
32+
#include <stdlib.h>
33+
#include <errno.h>
34+
#include <string.h>
35+
#include <fcntl.h>
36+
#include <sys/ioctl.h>
37+
#include <sys/stat.h>
38+
#include <linux/media.h>
39+
40+
int main(int argc, char **argv)
41+
{
42+
int opt;
43+
char media_device[256];
44+
int count = 0;
45+
struct media_device_info mdi;
46+
int ret;
47+
int fd;
48+
49+
if (argc < 2) {
50+
printf("Usage: %s [-d </dev/mediaX>]\n", argv[0]);
51+
exit(-1);
52+
}
53+
54+
/* Process arguments */
55+
while ((opt = getopt(argc, argv, "d:")) != -1) {
56+
switch (opt) {
57+
case 'd':
58+
strncpy(media_device, optarg, sizeof(media_device) - 1);
59+
media_device[sizeof(media_device)-1] = '\0';
60+
break;
61+
default:
62+
printf("Usage: %s [-d </dev/mediaX>]\n", argv[0]);
63+
exit(-1);
64+
}
65+
}
66+
67+
if (getuid() != 0) {
68+
printf("Please run the test as root - Exiting.\n");
69+
exit(-1);
70+
}
71+
72+
/* Open Media device and keep it open */
73+
fd = open(media_device, O_RDWR);
74+
if (fd == -1) {
75+
printf("Media Device open errno %s\n", strerror(errno));
76+
exit(-1);
77+
}
78+
79+
printf("\nNote:\n"
80+
"While test is running, remove the device and\n"
81+
"ensure there are no use after free errors and\n"
82+
"other Oops in the dmesg. Enable KaSan kernel\n"
83+
"config option for use-after-free error detection.\n\n");
84+
85+
while (count < 100) {
86+
ret = ioctl(fd, MEDIA_IOC_DEVICE_INFO, &mdi);
87+
if (ret < 0)
88+
printf("Media Device Info errno %s\n", strerror(errno));
89+
else
90+
printf("Media device model %s driver %s\n",
91+
mdi.model, mdi.driver);
92+
sleep(10);
93+
count++;
94+
}
95+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
CONFIG_MEMORY_HOTPLUG=y
2+
CONFIG_MEMORY_HOTPLUG_SPARSE=y
3+
CONFIG_NOTIFIER_ERROR_INJECTION=y
4+
CONFIG_MEMORY_NOTIFIER_ERROR_INJECT=m

tools/testing/selftests/mount/config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CONFIG_USER_NS=y
2+
CONFIG_DEVPTS_MULTIPLE_INSTANCES=y

tools/testing/selftests/net/config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CONFIG_USER_NS=y
2+
CONFIG_BPF_SYSCALL=y
3+
CONFIG_TEST_BPF=m

tools/testing/selftests/pstore/config

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
CONFIG_MISC_FILESYSTEMS=y
2+
CONFIG_PSTORE=y
3+
CONFIG_PSTORE_PMSG=y
4+
CONFIG_PSTORE_CONSOLE=y
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CONFIG_SECCOMP=y
2+
CONFIG_SECCOMP_FILTER=y
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CONFIG_TEST_STATIC_KEYS=m

0 commit comments

Comments
 (0)