aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorShuah Khan <shuahkh@osg.samsung.com>2016-02-12 19:43:31 -0500
committerShuah Khan <shuahkh@osg.samsung.com>2016-02-25 11:47:02 -0500
commit9d22f6e14e249713108c8adcc8705c39303f0628 (patch)
tree7672a2a9738424f4e883a50d0792cebda3e7550b /tools
parent92e963f50fc74041b5e9e744c330dca48e04f08d (diff)
selftests: add a new test for Media Controller API
This test opens user specified Media Device and calls MEDIA_IOC_DEVICE_INFO ioctl in a loop once every 10 seconds. This test is for detecting errors in device removal path. 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. Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/testing/selftests/media_tests/.gitignore1
-rw-r--r--tools/testing/selftests/media_tests/Makefile7
-rw-r--r--tools/testing/selftests/media_tests/media_device_test.c94
3 files changed, 102 insertions, 0 deletions
diff --git a/tools/testing/selftests/media_tests/.gitignore b/tools/testing/selftests/media_tests/.gitignore
new file mode 100644
index 000000000000..1c0711708b98
--- /dev/null
+++ b/tools/testing/selftests/media_tests/.gitignore
@@ -0,0 +1 @@
media_device_test
diff --git a/tools/testing/selftests/media_tests/Makefile b/tools/testing/selftests/media_tests/Makefile
new file mode 100644
index 000000000000..7071bcc1d066
--- /dev/null
+++ b/tools/testing/selftests/media_tests/Makefile
@@ -0,0 +1,7 @@
1TEST_PROGS := media_device_test
2all: $(TEST_PROGS)
3
4include ../lib.mk
5
6clean:
7 rm -fr media_device_test
diff --git a/tools/testing/selftests/media_tests/media_device_test.c b/tools/testing/selftests/media_tests/media_device_test.c
new file mode 100644
index 000000000000..a47880b9e00a
--- /dev/null
+++ b/tools/testing/selftests/media_tests/media_device_test.c
@@ -0,0 +1,94 @@
1/*
2 * media_devkref_test.c - Media Controller Device Kref API Test
3 *
4 * Copyright (c) 2016 Shuah Khan <shuahkh@osg.samsung.com>
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_devkref_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
40int 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 printf("Media device model %s driver %s\n",
90 mdi.model, mdi.driver);
91 sleep(10);
92 count++;
93 }
94}