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

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

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 
  3 /*
  4  * media_device_open.c - Media Controller Device Open Test
  5  *
  6  * Copyright (c) 2016 Shuah Khan <shuahkh@osg.samsung.com>
  7  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
  8  *
  9  */
 10 
 11 /*
 12  * This file adds a test for Media Controller API.
 13  * This test should be run as root and should not be
 14  * included in the Kselftest run. This test should be
 15  * run when hardware and driver that makes use Media
 16  * Controller API are present in the system.
 17  *
 18  * This test opens user specified Media Device and calls
 19  * MEDIA_IOC_DEVICE_INFO ioctl, closes the file, and exits.
 20  *
 21  * Usage:
 22  *      sudo ./media_device_open -d /dev/mediaX
 23  *
 24  *      Run this test is a loop and run bind/unbind on the driver.
 25 */
 26 
 27 #include <stdio.h>
 28 #include <unistd.h>
 29 #include <stdlib.h>
 30 #include <errno.h>
 31 #include <string.h>
 32 #include <fcntl.h>
 33 #include <sys/ioctl.h>
 34 #include <sys/stat.h>
 35 #include <linux/media.h>
 36 
 37 #include "../kselftest.h"
 38 
 39 int main(int argc, char **argv)
 40 {
 41         int opt;
 42         char media_device[256];
 43         int count = 0;
 44         struct media_device_info mdi;
 45         int ret;
 46         int fd;
 47 
 48         if (argc < 2) {
 49                 printf("Usage: %s [-d </dev/mediaX>]\n", argv[0]);
 50                 exit(-1);
 51         }
 52 
 53         /* Process arguments */
 54         while ((opt = getopt(argc, argv, "d:")) != -1) {
 55                 switch (opt) {
 56                 case 'd':
 57                         strncpy(media_device, optarg, sizeof(media_device) - 1);
 58                         media_device[sizeof(media_device)-1] = '\0';
 59                         break;
 60                 default:
 61                         printf("Usage: %s [-d </dev/mediaX>]\n", argv[0]);
 62                         exit(-1);
 63                 }
 64         }
 65 
 66         if (getuid() != 0)
 67                 ksft_exit_skip("Please run the test as root - Exiting.\n");
 68 
 69         /* Open Media device and keep it open */
 70         fd = open(media_device, O_RDWR);
 71         if (fd == -1) {
 72                 printf("Media Device open errno %s\n", strerror(errno));
 73                 exit(-1);
 74         }
 75 
 76         ret = ioctl(fd, MEDIA_IOC_DEVICE_INFO, &mdi);
 77         if (ret < 0)
 78                 printf("Media Device Info errno %s\n", strerror(errno));
 79         else
 80                 printf("Media device model %s driver %s\n",
 81                         mdi.model, mdi.driver);
 82 }
 83 

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

kernel.org | git.kernel.org | LWN.net | Project Home | 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.

sflogo.php