aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorShuah Khan <shuahkh@osg.samsung.com>2016-06-17 20:06:36 -0400
committerShuah Khan <shuahkh@osg.samsung.com>2016-06-27 15:21:33 -0400
commitb96da0fc54ffeca53dbab231ae845ad093785cc7 (patch)
tree7bd2be04fc85ca53f6df1e2e02d18609e776a2d6 /tools
parente9c0d44f5328ba844f7e037791b9cc72ee3ef964 (diff)
selftests: add media_device_open test
Add a new media test to open, run ioctl, and close the media device file. Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/testing/selftests/media_tests/Makefile4
-rw-r--r--tools/testing/selftests/media_tests/media_device_open.c81
2 files changed, 83 insertions, 2 deletions
diff --git a/tools/testing/selftests/media_tests/Makefile b/tools/testing/selftests/media_tests/Makefile
index 7071bcc1d066..177256aa4e0a 100644
--- a/tools/testing/selftests/media_tests/Makefile
+++ b/tools/testing/selftests/media_tests/Makefile
@@ -1,7 +1,7 @@
1TEST_PROGS := media_device_test 1TEST_PROGS := media_device_test media_device_open
2all: $(TEST_PROGS) 2all: $(TEST_PROGS)
3 3
4include ../lib.mk 4include ../lib.mk
5 5
6clean: 6clean:
7 rm -fr media_device_test 7 rm -fr media_device_test media_device_open
diff --git a/tools/testing/selftests/media_tests/media_device_open.c b/tools/testing/selftests/media_tests/media_device_open.c
new file mode 100644
index 000000000000..44343c091a20
--- /dev/null
+++ b/tools/testing/selftests/media_tests/media_device_open.c
@@ -0,0 +1,81 @@
1/*
2 * media_device_open.c - Media Controller Device Open 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, closes the file, and exits.
19 *
20 * Usage:
21 * sudo ./media_device_open -d /dev/mediaX
22 *
23 * Run this test is a loop and run bind/unbind on the driver.
24*/
25
26#include <stdio.h>
27#include <unistd.h>
28#include <stdlib.h>
29#include <errno.h>
30#include <string.h>
31#include <fcntl.h>
32#include <sys/ioctl.h>
33#include <sys/stat.h>
34#include <linux/media.h>
35
36int main(int argc, char **argv)
37{
38 int opt;
39 char media_device[256];
40 int count = 0;
41 struct media_device_info mdi;
42 int ret;
43 int fd;
44
45 if (argc < 2) {
46 printf("Usage: %s [-d </dev/mediaX>]\n", argv[0]);
47 exit(-1);
48 }
49
50 /* Process arguments */
51 while ((opt = getopt(argc, argv, "d:")) != -1) {
52 switch (opt) {
53 case 'd':
54 strncpy(media_device, optarg, sizeof(media_device) - 1);
55 media_device[sizeof(media_device)-1] = '\0';
56 break;
57 default:
58 printf("Usage: %s [-d </dev/mediaX>]\n", argv[0]);
59 exit(-1);
60 }
61 }
62
63 if (getuid() != 0) {
64 printf("Please run the test as root - Exiting.\n");
65 exit(-1);
66 }
67
68 /* Open Media device and keep it open */
69 fd = open(media_device, O_RDWR);
70 if (fd == -1) {
71 printf("Media Device open errno %s\n", strerror(errno));
72 exit(-1);
73 }
74
75 ret = ioctl(fd, MEDIA_IOC_DEVICE_INFO, &mdi);
76 if (ret < 0)
77 printf("Media Device Info errno %s\n", strerror(errno));
78 else
79 printf("Media device model %s driver %s\n",
80 mdi.model, mdi.driver);
81}