diff options
author | Shuah Khan <shuahkh@osg.samsung.com> | 2016-06-18 02:06:36 +0200 |
---|---|---|
committer | Shuah Khan <shuahkh@osg.samsung.com> | 2016-06-27 21:21:33 +0200 |
commit | b96da0fc54ffeca53dbab231ae845ad093785cc7 (patch) | |
tree | 7bd2be04fc85ca53f6df1e2e02d18609e776a2d6 /tools | |
parent | selftests: media_device_test change it to randomize loop count (diff) | |
download | linux-b96da0fc54ffeca53dbab231ae845ad093785cc7.tar.xz linux-b96da0fc54ffeca53dbab231ae845ad093785cc7.zip |
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/Makefile | 4 | ||||
-rw-r--r-- | tools/testing/selftests/media_tests/media_device_open.c | 81 |
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 @@ -TEST_PROGS := media_device_test +TEST_PROGS := media_device_test media_device_open all: $(TEST_PROGS) include ../lib.mk clean: - rm -fr media_device_test + 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 @@ +/* + * media_device_open.c - Media Controller Device Open 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, closes the file, and exits. + * + * Usage: + * sudo ./media_device_open -d /dev/mediaX + * + * Run this test is a loop and run bind/unbind on the driver. +*/ + +#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); + } + + 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); +} |