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
0030
0031 #include <stdio.h>
0032 #include <unistd.h>
0033 #include <stdlib.h>
0034 #include <errno.h>
0035 #include <string.h>
0036 #include <fcntl.h>
0037 #include <sys/ioctl.h>
0038 #include <sys/stat.h>
0039 #include <time.h>
0040 #include <linux/media.h>
0041
0042 #include "../kselftest.h"
0043
0044 int main(int argc, char **argv)
0045 {
0046 int opt;
0047 char media_device[256];
0048 int count;
0049 struct media_device_info mdi;
0050 int ret;
0051 int fd;
0052
0053 if (argc < 2) {
0054 printf("Usage: %s [-d </dev/mediaX>]\n", argv[0]);
0055 exit(-1);
0056 }
0057
0058
0059 while ((opt = getopt(argc, argv, "d:")) != -1) {
0060 switch (opt) {
0061 case 'd':
0062 strncpy(media_device, optarg, sizeof(media_device) - 1);
0063 media_device[sizeof(media_device)-1] = '\0';
0064 break;
0065 default:
0066 printf("Usage: %s [-d </dev/mediaX>]\n", argv[0]);
0067 exit(-1);
0068 }
0069 }
0070
0071 if (getuid() != 0)
0072 ksft_exit_skip("Please run the test as root - Exiting.\n");
0073
0074
0075 srand((unsigned int) time(NULL));
0076 count = rand();
0077
0078
0079 fd = open(media_device, O_RDWR);
0080 if (fd == -1) {
0081 printf("Media Device open errno %s\n", strerror(errno));
0082 exit(-1);
0083 }
0084
0085 printf("\nNote:\n"
0086 "While test is running, remove the device and\n"
0087 "ensure there are no use after free errors and\n"
0088 "other Oops in the dmesg. Enable KaSan kernel\n"
0089 "config option for use-after-free error detection.\n\n");
0090
0091 printf("Running test for %d iterations\n", count);
0092
0093 while (count > 0) {
0094 ret = ioctl(fd, MEDIA_IOC_DEVICE_INFO, &mdi);
0095 if (ret < 0)
0096 printf("Media Device Info errno %s\n", strerror(errno));
0097 else
0098 printf("Media device model %s driver %s - count %d\n",
0099 mdi.model, mdi.driver, count);
0100 sleep(10);
0101 count--;
0102 }
0103 }