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