-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge tag 'linux-kselftest-4.6-rc1' of git://git.kernel.org/pub/scm/l…
…inux/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
- Loading branch information
Showing
21 changed files
with
362 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
breakpoint_test | ||
step_after_suspend_test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
218 changes: 218 additions & 0 deletions
218
tools/testing/selftests/breakpoints/step_after_suspend_test.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,218 @@ | ||
/* | ||
* Copyright (C) 2016 Google, Inc. | ||
* | ||
* This software is licensed under the terms of the GNU General Public | ||
* License version 2, as published by the Free Software Foundation, and | ||
* may be copied, distributed, and modified under those terms. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
*/ | ||
|
||
#define _GNU_SOURCE | ||
|
||
#include <errno.h> | ||
#include <fcntl.h> | ||
#include <sched.h> | ||
#include <signal.h> | ||
#include <stdbool.h> | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include <unistd.h> | ||
#include <sys/ptrace.h> | ||
#include <sys/stat.h> | ||
#include <sys/timerfd.h> | ||
#include <sys/types.h> | ||
#include <sys/wait.h> | ||
|
||
#include "../kselftest.h" | ||
|
||
void child(int cpu) | ||
{ | ||
cpu_set_t set; | ||
|
||
CPU_ZERO(&set); | ||
CPU_SET(cpu, &set); | ||
if (sched_setaffinity(0, sizeof(set), &set) != 0) { | ||
perror("sched_setaffinity() failed"); | ||
_exit(1); | ||
} | ||
|
||
if (ptrace(PTRACE_TRACEME, 0, NULL, NULL) != 0) { | ||
perror("ptrace(PTRACE_TRACEME) failed"); | ||
_exit(1); | ||
} | ||
|
||
if (raise(SIGSTOP) != 0) { | ||
perror("raise(SIGSTOP) failed"); | ||
_exit(1); | ||
} | ||
|
||
_exit(0); | ||
} | ||
|
||
bool run_test(int cpu) | ||
{ | ||
int status; | ||
pid_t pid = fork(); | ||
pid_t wpid; | ||
|
||
if (pid < 0) { | ||
perror("fork() failed"); | ||
return false; | ||
} | ||
if (pid == 0) | ||
child(cpu); | ||
|
||
wpid = waitpid(pid, &status, __WALL); | ||
if (wpid != pid) { | ||
perror("waitpid() failed"); | ||
return false; | ||
} | ||
if (!WIFSTOPPED(status)) { | ||
printf("child did not stop\n"); | ||
return false; | ||
} | ||
if (WSTOPSIG(status) != SIGSTOP) { | ||
printf("child did not stop with SIGSTOP\n"); | ||
return false; | ||
} | ||
|
||
if (ptrace(PTRACE_SINGLESTEP, pid, NULL, NULL) < 0) { | ||
if (errno == EIO) { | ||
printf("ptrace(PTRACE_SINGLESTEP) not supported on this architecture\n"); | ||
ksft_exit_skip(); | ||
} | ||
perror("ptrace(PTRACE_SINGLESTEP) failed"); | ||
return false; | ||
} | ||
|
||
wpid = waitpid(pid, &status, __WALL); | ||
if (wpid != pid) { | ||
perror("waitpid() failed"); | ||
return false; | ||
} | ||
if (WIFEXITED(status)) { | ||
printf("child did not single-step\n"); | ||
return false; | ||
} | ||
if (!WIFSTOPPED(status)) { | ||
printf("child did not stop\n"); | ||
return false; | ||
} | ||
if (WSTOPSIG(status) != SIGTRAP) { | ||
printf("child did not stop with SIGTRAP\n"); | ||
return false; | ||
} | ||
|
||
if (ptrace(PTRACE_CONT, pid, NULL, NULL) < 0) { | ||
perror("ptrace(PTRACE_CONT) failed"); | ||
return false; | ||
} | ||
|
||
wpid = waitpid(pid, &status, __WALL); | ||
if (wpid != pid) { | ||
perror("waitpid() failed"); | ||
return false; | ||
} | ||
if (!WIFEXITED(status)) { | ||
printf("child did not exit after PTRACE_CONT\n"); | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
void suspend(void) | ||
{ | ||
int power_state_fd; | ||
struct sigevent event = {}; | ||
int timerfd; | ||
int err; | ||
struct itimerspec spec = {}; | ||
|
||
power_state_fd = open("/sys/power/state", O_RDWR); | ||
if (power_state_fd < 0) { | ||
perror("open(\"/sys/power/state\") failed (is this test running as root?)"); | ||
ksft_exit_fail(); | ||
} | ||
|
||
timerfd = timerfd_create(CLOCK_BOOTTIME_ALARM, 0); | ||
if (timerfd < 0) { | ||
perror("timerfd_create() failed"); | ||
ksft_exit_fail(); | ||
} | ||
|
||
spec.it_value.tv_sec = 5; | ||
err = timerfd_settime(timerfd, 0, &spec, NULL); | ||
if (err < 0) { | ||
perror("timerfd_settime() failed"); | ||
ksft_exit_fail(); | ||
} | ||
|
||
if (write(power_state_fd, "mem", strlen("mem")) != strlen("mem")) { | ||
perror("entering suspend failed"); | ||
ksft_exit_fail(); | ||
} | ||
|
||
close(timerfd); | ||
close(power_state_fd); | ||
} | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
int opt; | ||
bool do_suspend = true; | ||
bool succeeded = true; | ||
cpu_set_t available_cpus; | ||
int err; | ||
int cpu; | ||
|
||
while ((opt = getopt(argc, argv, "n")) != -1) { | ||
switch (opt) { | ||
case 'n': | ||
do_suspend = false; | ||
break; | ||
default: | ||
printf("Usage: %s [-n]\n", argv[0]); | ||
printf(" -n: do not trigger a suspend/resume cycle before the test\n"); | ||
return -1; | ||
} | ||
} | ||
|
||
if (do_suspend) | ||
suspend(); | ||
|
||
err = sched_getaffinity(0, sizeof(available_cpus), &available_cpus); | ||
if (err < 0) { | ||
perror("sched_getaffinity() failed"); | ||
ksft_exit_fail(); | ||
} | ||
|
||
for (cpu = 0; cpu < CPU_SETSIZE; cpu++) { | ||
bool test_success; | ||
|
||
if (!CPU_ISSET(cpu, &available_cpus)) | ||
continue; | ||
|
||
test_success = run_test(cpu); | ||
printf("CPU %d: ", cpu); | ||
if (test_success) { | ||
printf("[OK]\n"); | ||
ksft_inc_pass_cnt(); | ||
} else { | ||
printf("[FAILED]\n"); | ||
ksft_inc_fail_cnt(); | ||
succeeded = false; | ||
} | ||
} | ||
|
||
ksft_print_cnts(); | ||
if (succeeded) | ||
ksft_exit_pass(); | ||
else | ||
ksft_exit_fail(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
CONFIG_NOTIFIER_ERROR_INJECTION=y | ||
CONFIG_CPU_NOTIFIER_ERROR_INJECT=m |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CONFIG_TEST_FIRMWARE=y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CONFIG_FTRACE=y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
msgque_test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
CONFIG_EXPERT=y | ||
CONFIG_CHECKPOINT_RESTORE=y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
media_device_test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
TEST_PROGS := media_device_test | ||
all: $(TEST_PROGS) | ||
|
||
include ../lib.mk | ||
|
||
clean: | ||
rm -fr media_device_test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* media_devkref_test.c - Media Controller Device Kref API Test | ||
* | ||
* Copyright (c) 2016 Shuah Khan <shuahkh@osg.samsung.com> | ||
* Copyright (c) 2016 Samsung Electronics Co., Ltd. | ||
* | ||
* This file is released under the GPLv2. | ||
*/ | ||
|
||
/* | ||
* This file adds a test for Media Controller API. | ||
* This test should be run as root and should not be | ||
* included in the Kselftest run. This test should be | ||
* run when hardware and driver that makes use Media | ||
* Controller API are present in the system. | ||
* | ||
* This test opens user specified Media Device and calls | ||
* MEDIA_IOC_DEVICE_INFO ioctl in a loop once every 10 | ||
* seconds. | ||
* | ||
* Usage: | ||
* sudo ./media_device_test -d /dev/mediaX | ||
* | ||
* While test is running, remove the device and | ||
* ensure there are no use after free errors and | ||
* other Oops in the dmesg. Enable KaSan kernel | ||
* config option for use-after-free error detection. | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <unistd.h> | ||
#include <stdlib.h> | ||
#include <errno.h> | ||
#include <string.h> | ||
#include <fcntl.h> | ||
#include <sys/ioctl.h> | ||
#include <sys/stat.h> | ||
#include <linux/media.h> | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
int opt; | ||
char media_device[256]; | ||
int count = 0; | ||
struct media_device_info mdi; | ||
int ret; | ||
int fd; | ||
|
||
if (argc < 2) { | ||
printf("Usage: %s [-d </dev/mediaX>]\n", argv[0]); | ||
exit(-1); | ||
} | ||
|
||
/* Process arguments */ | ||
while ((opt = getopt(argc, argv, "d:")) != -1) { | ||
switch (opt) { | ||
case 'd': | ||
strncpy(media_device, optarg, sizeof(media_device) - 1); | ||
media_device[sizeof(media_device)-1] = '\0'; | ||
break; | ||
default: | ||
printf("Usage: %s [-d </dev/mediaX>]\n", argv[0]); | ||
exit(-1); | ||
} | ||
} | ||
|
||
if (getuid() != 0) { | ||
printf("Please run the test as root - Exiting.\n"); | ||
exit(-1); | ||
} | ||
|
||
/* Open Media device and keep it open */ | ||
fd = open(media_device, O_RDWR); | ||
if (fd == -1) { | ||
printf("Media Device open errno %s\n", strerror(errno)); | ||
exit(-1); | ||
} | ||
|
||
printf("\nNote:\n" | ||
"While test is running, remove the device and\n" | ||
"ensure there are no use after free errors and\n" | ||
"other Oops in the dmesg. Enable KaSan kernel\n" | ||
"config option for use-after-free error detection.\n\n"); | ||
|
||
while (count < 100) { | ||
ret = ioctl(fd, MEDIA_IOC_DEVICE_INFO, &mdi); | ||
if (ret < 0) | ||
printf("Media Device Info errno %s\n", strerror(errno)); | ||
else | ||
printf("Media device model %s driver %s\n", | ||
mdi.model, mdi.driver); | ||
sleep(10); | ||
count++; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
CONFIG_MEMORY_HOTPLUG=y | ||
CONFIG_MEMORY_HOTPLUG_SPARSE=y | ||
CONFIG_NOTIFIER_ERROR_INJECTION=y | ||
CONFIG_MEMORY_NOTIFIER_ERROR_INJECT=m |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
CONFIG_USER_NS=y | ||
CONFIG_DEVPTS_MULTIPLE_INSTANCES=y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
CONFIG_USER_NS=y | ||
CONFIG_BPF_SYSCALL=y | ||
CONFIG_TEST_BPF=m |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
CONFIG_MISC_FILESYSTEMS=y | ||
CONFIG_PSTORE=y | ||
CONFIG_PSTORE_PMSG=y | ||
CONFIG_PSTORE_CONSOLE=y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
CONFIG_SECCOMP=y | ||
CONFIG_SECCOMP_FILTER=y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CONFIG_TEST_STATIC_KEYS=m |
Oops, something went wrong.