2018-01-09 18:38:55 -07:00
// SPDX-License-Identifier: GPL-2.0
2016-02-12 17:43:31 -07:00
/*
2016-06-17 18:05:05 -06:00
* media_device_test . c - Media Controller Device ioctl loop Test
2016-02-12 17:43:31 -07:00
*
* Copyright ( c ) 2016 Shuah Khan < shuahkh @ osg . samsung . com >
* Copyright ( c ) 2016 Samsung Electronics Co . , Ltd .
*
*/
/*
* This file adds a test for Media Controller API .
* This test should be run as root and should not be
* included in the Kselftest run . This test should be
* run when hardware and driver that makes use Media
* Controller API are present in the system .
*
* This test opens user specified Media Device and calls
* MEDIA_IOC_DEVICE_INFO ioctl in a loop once every 10
* seconds .
*
* Usage :
2016-02-25 10:35:01 -07:00
* sudo . / media_device_test - d / dev / mediaX
2016-02-12 17:43:31 -07:00
*
* While test is running , remove the device and
* ensure there are no use after free errors and
* other Oops in the dmesg . Enable KaSan kernel
* config option for use - after - free error detection .
*/
# include <stdio.h>
# include <unistd.h>
# include <stdlib.h>
# include <errno.h>
# include <string.h>
# include <fcntl.h>
# include <sys/ioctl.h>
# include <sys/stat.h>
2016-06-17 18:05:05 -06:00
# include <time.h>
2016-02-12 17:43:31 -07:00
# include <linux/media.h>
2018-05-04 12:06:46 -06:00
# include "../kselftest.h"
2016-02-12 17:43:31 -07:00
int main ( int argc , char * * argv )
{
int opt ;
char media_device [ 256 ] ;
2016-06-17 18:05:05 -06:00
int count ;
2016-02-12 17:43:31 -07:00
struct media_device_info mdi ;
int ret ;
int fd ;
if ( argc < 2 ) {
printf ( " Usage: %s [-d </dev/mediaX>] \n " , argv [ 0 ] ) ;
exit ( - 1 ) ;
}
/* Process arguments */
while ( ( opt = getopt ( argc , argv , " d: " ) ) ! = - 1 ) {
switch ( opt ) {
case ' d ' :
strncpy ( media_device , optarg , sizeof ( media_device ) - 1 ) ;
media_device [ sizeof ( media_device ) - 1 ] = ' \0 ' ;
break ;
default :
printf ( " Usage: %s [-d </dev/mediaX>] \n " , argv [ 0 ] ) ;
exit ( - 1 ) ;
}
}
2018-05-04 12:06:46 -06:00
if ( getuid ( ) ! = 0 )
ksft_exit_skip ( " Please run the test as root - Exiting. \n " ) ;
2016-02-12 17:43:31 -07:00
2016-06-17 18:05:05 -06:00
/* Generate random number of interations */
srand ( ( unsigned int ) time ( NULL ) ) ;
count = rand ( ) ;
2016-02-12 17:43:31 -07:00
/* Open Media device and keep it open */
fd = open ( media_device , O_RDWR ) ;
if ( fd = = - 1 ) {
printf ( " Media Device open errno %s \n " , strerror ( errno ) ) ;
exit ( - 1 ) ;
}
printf ( " \n Note: \n "
" While test is running, remove the device and \n "
" ensure there are no use after free errors and \n "
" other Oops in the dmesg. Enable KaSan kernel \n "
" config option for use-after-free error detection. \n \n " ) ;
2018-05-02 16:00:10 +01:00
printf ( " Running test for %d iterations \n " , count ) ;
2016-06-17 18:05:05 -06:00
while ( count > 0 ) {
2016-02-12 17:43:31 -07:00
ret = ioctl ( fd , MEDIA_IOC_DEVICE_INFO , & mdi ) ;
if ( ret < 0 )
printf ( " Media Device Info errno %s \n " , strerror ( errno ) ) ;
2016-02-25 10:17:42 -07:00
else
2016-06-17 18:05:05 -06:00
printf ( " Media device model %s driver %s - count %d \n " ,
mdi . model , mdi . driver , count ) ;
2016-02-12 17:43:31 -07:00
sleep ( 10 ) ;
2016-06-17 18:05:05 -06:00
count - - ;
2016-02-12 17:43:31 -07:00
}
}