~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/media_tests/media_device_test.c

Version: ~ [ linux-5.3 ] ~ [ linux-5.2.14 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.72 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.143 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.192 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.192 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.73 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * media_device_test.c - Media Controller Device ioctl loop Test
  3  *
  4  * Copyright (c) 2016 Shuah Khan <shuahkh@osg.samsung.com>
  5  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
  6  *
  7  * This file is released under the GPLv2.
  8  */
  9 
 10 /*
 11  * This file adds a test for Media Controller API.
 12  * This test should be run as root and should not be
 13  * included in the Kselftest run. This test should be
 14  * run when hardware and driver that makes use Media
 15  * Controller API are present in the system.
 16  *
 17  * This test opens user specified Media Device and calls
 18  * MEDIA_IOC_DEVICE_INFO ioctl in a loop once every 10
 19  * seconds.
 20  *
 21  * Usage:
 22  *      sudo ./media_device_test -d /dev/mediaX
 23  *
 24  *      While test is running, remove the device and
 25  *      ensure there are no use after free errors and
 26  *      other Oops in the dmesg. Enable KaSan kernel
 27  *      config option for use-after-free error detection.
 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 
 41 int 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         /* Process arguments */
 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         /* Generate random number of interations */
 74         srand((unsigned int) time(NULL));
 75         count = rand();
 76 
 77         /* Open Media device and keep it open */
 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 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp