~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/media_tests/video_device_test.c

Version: ~ [ linux-5.3-rc5 ] ~ [ linux-5.2.9 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.67 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.139 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.189 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.189 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.72 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * video_device_test - Video Device 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 Video Device. This test should not be included
 12  * in the Kselftest run. This test should be run when hardware and driver
 13  * that makes use of V4L2 API is present.
 14  *
 15  * This test opens user specified Video Device and calls video ioctls in a
 16  * loop once every 10 seconds.
 17  *
 18  * Usage:
 19  *      sudo ./video_device_test -d /dev/videoX
 20  *
 21  *      While test is running, remove the device or unbind the driver and
 22  *      ensure there are no use after free errors and other Oops in the
 23  *      dmesg.
 24  *      When possible, enable KaSan kernel config option for use-after-free
 25  *      error detection.
 26 */
 27 
 28 #include <stdio.h>
 29 #include <unistd.h>
 30 #include <stdlib.h>
 31 #include <errno.h>
 32 #include <string.h>
 33 #include <fcntl.h>
 34 #include <sys/ioctl.h>
 35 #include <sys/stat.h>
 36 #include <time.h>
 37 #include <linux/videodev2.h>
 38 
 39 int main(int argc, char **argv)
 40 {
 41         int opt;
 42         char video_dev[256];
 43         int count;
 44         struct v4l2_tuner vtuner;
 45         struct v4l2_capability vcap;
 46         int ret;
 47         int fd;
 48 
 49         if (argc < 2) {
 50                 printf("Usage: %s [-d </dev/videoX>]\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(video_dev, optarg, sizeof(video_dev) - 1);
 59                         video_dev[sizeof(video_dev)-1] = '\0';
 60                         break;
 61                 default:
 62                         printf("Usage: %s [-d </dev/videoX>]\n", argv[0]);
 63                         exit(-1);
 64                 }
 65         }
 66 
 67         /* Generate random number of interations */
 68         srand((unsigned int) time(NULL));
 69         count = rand();
 70 
 71         /* Open Video device and keep it open */
 72         fd = open(video_dev, O_RDWR);
 73         if (fd == -1) {
 74                 printf("Video Device open errno %s\n", strerror(errno));
 75                 exit(-1);
 76         }
 77 
 78         printf("\nNote:\n"
 79                "While test is running, remove the device or unbind\n"
 80                "driver and ensure there are no use after free errors\n"
 81                "and other Oops in the dmesg. When possible, enable KaSan\n"
 82                "kernel config option for use-after-free error detection.\n\n");
 83 
 84         while (count > 0) {
 85                 ret = ioctl(fd, VIDIOC_QUERYCAP, &vcap);
 86                 if (ret < 0)
 87                         printf("VIDIOC_QUERYCAP errno %s\n", strerror(errno));
 88                 else
 89                         printf("Video device driver %s\n", vcap.driver);
 90 
 91                 ret = ioctl(fd, VIDIOC_G_TUNER, &vtuner);
 92                 if (ret < 0)
 93                         printf("VIDIOC_G_TUNER, errno %s\n", strerror(errno));
 94                 else
 95                         printf("type %d rangelow %d rangehigh %d\n",
 96                                 vtuner.type, vtuner.rangelow, vtuner.rangehigh);
 97                 sleep(10);
 98                 count--;
 99         }
100 }
101 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp