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
29#include <stdio.h>
30#include <unistd.h>
31#include <stdlib.h>
32#include <errno.h>
33#include <string.h>
34#include <fcntl.h>
35#include <sys/ioctl.h>
36#include <sys/stat.h>
37#include <time.h>
38#include <linux/videodev2.h>
39
40int main(int argc, char **argv)
41{
42 int opt;
43 char video_dev[256];
44 int count;
45 struct v4l2_tuner vtuner;
46 struct v4l2_capability vcap;
47 int ret;
48 int fd;
49
50 if (argc < 2) {
51 printf("Usage: %s [-d </dev/videoX>]\n", argv[0]);
52 exit(-1);
53 }
54
55
56 while ((opt = getopt(argc, argv, "d:")) != -1) {
57 switch (opt) {
58 case 'd':
59 strncpy(video_dev, optarg, sizeof(video_dev) - 1);
60 video_dev[sizeof(video_dev)-1] = '\0';
61 break;
62 default:
63 printf("Usage: %s [-d </dev/videoX>]\n", argv[0]);
64 exit(-1);
65 }
66 }
67
68
69 srand((unsigned int) time(NULL));
70 count = rand();
71
72
73 fd = open(video_dev, O_RDWR);
74 if (fd == -1) {
75 printf("Video Device open errno %s\n", strerror(errno));
76 exit(-1);
77 }
78
79 printf("\nNote:\n"
80 "While test is running, remove the device or unbind\n"
81 "driver and ensure there are no use after free errors\n"
82 "and other Oops in the dmesg. When possible, enable KaSan\n"
83 "kernel config option for use-after-free error detection.\n\n");
84
85 while (count > 0) {
86 ret = ioctl(fd, VIDIOC_QUERYCAP, &vcap);
87 if (ret < 0)
88 printf("VIDIOC_QUERYCAP errno %s\n", strerror(errno));
89 else
90 printf("Video device driver %s\n", vcap.driver);
91
92 ret = ioctl(fd, VIDIOC_G_TUNER, &vtuner);
93 if (ret < 0)
94 printf("VIDIOC_G_TUNER, errno %s\n", strerror(errno));
95 else
96 printf("type %d rangelow %d rangehigh %d\n",
97 vtuner.type, vtuner.rangelow, vtuner.rangehigh);
98 sleep(10);
99 count--;
100 }
101}
102