1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
39int 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
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
68 srand((unsigned int) time(NULL));
69 count = rand();
70
71
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