Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 
0003 /*
0004  * media_device_open.c - Media Controller Device Open Test
0005  *
0006  * Copyright (c) 2016 Shuah Khan <shuahkh@osg.samsung.com>
0007  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
0008  *
0009  */
0010 
0011 /*
0012  * This file adds a test for Media Controller API.
0013  * This test should be run as root and should not be
0014  * included in the Kselftest run. This test should be
0015  * run when hardware and driver that makes use Media
0016  * Controller API are present in the system.
0017  *
0018  * This test opens user specified Media Device and calls
0019  * MEDIA_IOC_DEVICE_INFO ioctl, closes the file, and exits.
0020  *
0021  * Usage:
0022  *  sudo ./media_device_open -d /dev/mediaX
0023  *
0024  *  Run this test is a loop and run bind/unbind on the driver.
0025 */
0026 
0027 #include <stdio.h>
0028 #include <unistd.h>
0029 #include <stdlib.h>
0030 #include <errno.h>
0031 #include <string.h>
0032 #include <fcntl.h>
0033 #include <sys/ioctl.h>
0034 #include <sys/stat.h>
0035 #include <linux/media.h>
0036 
0037 #include "../kselftest.h"
0038 
0039 int main(int argc, char **argv)
0040 {
0041     int opt;
0042     char media_device[256];
0043     int count = 0;
0044     struct media_device_info mdi;
0045     int ret;
0046     int fd;
0047 
0048     if (argc < 2) {
0049         printf("Usage: %s [-d </dev/mediaX>]\n", argv[0]);
0050         exit(-1);
0051     }
0052 
0053     /* Process arguments */
0054     while ((opt = getopt(argc, argv, "d:")) != -1) {
0055         switch (opt) {
0056         case 'd':
0057             strncpy(media_device, optarg, sizeof(media_device) - 1);
0058             media_device[sizeof(media_device)-1] = '\0';
0059             break;
0060         default:
0061             printf("Usage: %s [-d </dev/mediaX>]\n", argv[0]);
0062             exit(-1);
0063         }
0064     }
0065 
0066     if (getuid() != 0)
0067         ksft_exit_skip("Please run the test as root - Exiting.\n");
0068 
0069     /* Open Media device and keep it open */
0070     fd = open(media_device, O_RDWR);
0071     if (fd == -1) {
0072         printf("Media Device open errno %s\n", strerror(errno));
0073         exit(-1);
0074     }
0075 
0076     ret = ioctl(fd, MEDIA_IOC_DEVICE_INFO, &mdi);
0077     if (ret < 0)
0078         printf("Media Device Info errno %s\n", strerror(errno));
0079     else
0080         printf("Media device model %s driver %s\n",
0081             mdi.model, mdi.driver);
0082 }