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
30#include <stdio.h>
31#include <unistd.h>
32#include <stdlib.h>
33#include <errno.h>
34#include <string.h>
35#include <fcntl.h>
36#include <sys/ioctl.h>
37#include <sys/stat.h>
38#include <time.h>
39#include <linux/media.h>
40
41int main(int argc, char **argv)
42{
43 int opt;
44 char media_device[256];
45 int count;
46 struct media_device_info mdi;
47 int ret;
48 int fd;
49
50 if (argc < 2) {
51 printf("Usage: %s [-d </dev/mediaX>]\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(media_device, optarg, sizeof(media_device) - 1);
60 media_device[sizeof(media_device)-1] = '\0';
61 break;
62 default:
63 printf("Usage: %s [-d </dev/mediaX>]\n", argv[0]);
64 exit(-1);
65 }
66 }
67
68 if (getuid() != 0) {
69 printf("Please run the test as root - Exiting.\n");
70 exit(-1);
71 }
72
73
74 srand((unsigned int) time(NULL));
75 count = rand();
76
77
78 fd = open(media_device, O_RDWR);
79 if (fd == -1) {
80 printf("Media Device open errno %s\n", strerror(errno));
81 exit(-1);
82 }
83
84 printf("\nNote:\n"
85 "While test is running, remove the device and\n"
86 "ensure there are no use after free errors and\n"
87 "other Oops in the dmesg. Enable KaSan kernel\n"
88 "config option for use-after-free error detection.\n\n");
89
90 printf("Running test for %d iternations\n", count);
91
92 while (count > 0) {
93 ret = ioctl(fd, MEDIA_IOC_DEVICE_INFO, &mdi);
94 if (ret < 0)
95 printf("Media Device Info errno %s\n", strerror(errno));
96 else
97 printf("Media device model %s driver %s - count %d\n",
98 mdi.model, mdi.driver, count);
99 sleep(10);
100 count--;
101 }
102}
103