0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 #include <stdio.h>
0030 #include <unistd.h>
0031 #include <stdlib.h>
0032 #include <errno.h>
0033 #include <string.h>
0034 #include <fcntl.h>
0035 #include <sys/ioctl.h>
0036 #include <sys/stat.h>
0037 #include <time.h>
0038 #include <linux/videodev2.h>
0039
0040 int main(int argc, char **argv)
0041 {
0042 int opt;
0043 char video_dev[256];
0044 int count;
0045 struct v4l2_tuner vtuner;
0046 struct v4l2_capability vcap;
0047 int ret;
0048 int fd;
0049
0050 if (argc < 2) {
0051 printf("Usage: %s [-d </dev/videoX>]\n", argv[0]);
0052 exit(-1);
0053 }
0054
0055
0056 while ((opt = getopt(argc, argv, "d:")) != -1) {
0057 switch (opt) {
0058 case 'd':
0059 strncpy(video_dev, optarg, sizeof(video_dev) - 1);
0060 video_dev[sizeof(video_dev)-1] = '\0';
0061 break;
0062 default:
0063 printf("Usage: %s [-d </dev/videoX>]\n", argv[0]);
0064 exit(-1);
0065 }
0066 }
0067
0068
0069 srand((unsigned int) time(NULL));
0070 count = rand();
0071
0072
0073 fd = open(video_dev, O_RDWR);
0074 if (fd == -1) {
0075 printf("Video Device open errno %s\n", strerror(errno));
0076 exit(-1);
0077 }
0078
0079 printf("\nNote:\n"
0080 "While test is running, remove the device or unbind\n"
0081 "driver and ensure there are no use after free errors\n"
0082 "and other Oops in the dmesg. When possible, enable KaSan\n"
0083 "kernel config option for use-after-free error detection.\n\n");
0084
0085 while (count > 0) {
0086 ret = ioctl(fd, VIDIOC_QUERYCAP, &vcap);
0087 if (ret < 0)
0088 printf("VIDIOC_QUERYCAP errno %s\n", strerror(errno));
0089 else
0090 printf("Video device driver %s\n", vcap.driver);
0091
0092 ret = ioctl(fd, VIDIOC_G_TUNER, &vtuner);
0093 if (ret < 0)
0094 printf("VIDIOC_G_TUNER, errno %s\n", strerror(errno));
0095 else
0096 printf("type %d rangelow %d rangehigh %d\n",
0097 vtuner.type, vtuner.rangelow, vtuner.rangehigh);
0098 sleep(10);
0099 count--;
0100 }
0101 }