Commit e9c0d44f authored by Shuah Khan's avatar Shuah Khan

selftests: media_device_test change it to randomize loop count

Change it to randomize the loop count instead of hardcoded number of times
ioctl is called.
Signed-off-by: default avatarShuah Khan <shuahkh@osg.samsung.com>
parent bff12468
/* /*
* media_devkref_test.c - Media Controller Device Kref API Test * media_device_test.c - Media Controller Device ioctl loop Test
* *
* Copyright (c) 2016 Shuah Khan <shuahkh@osg.samsung.com> * Copyright (c) 2016 Shuah Khan <shuahkh@osg.samsung.com>
* Copyright (c) 2016 Samsung Electronics Co., Ltd. * Copyright (c) 2016 Samsung Electronics Co., Ltd.
...@@ -35,13 +35,14 @@ ...@@ -35,13 +35,14 @@
#include <fcntl.h> #include <fcntl.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <time.h>
#include <linux/media.h> #include <linux/media.h>
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
int opt; int opt;
char media_device[256]; char media_device[256];
int count = 0; int count;
struct media_device_info mdi; struct media_device_info mdi;
int ret; int ret;
int fd; int fd;
...@@ -69,6 +70,10 @@ int main(int argc, char **argv) ...@@ -69,6 +70,10 @@ int main(int argc, char **argv)
exit(-1); exit(-1);
} }
/* Generate random number of interations */
srand((unsigned int) time(NULL));
count = rand();
/* Open Media device and keep it open */ /* Open Media device and keep it open */
fd = open(media_device, O_RDWR); fd = open(media_device, O_RDWR);
if (fd == -1) { if (fd == -1) {
...@@ -82,14 +87,16 @@ int main(int argc, char **argv) ...@@ -82,14 +87,16 @@ int main(int argc, char **argv)
"other Oops in the dmesg. Enable KaSan kernel\n" "other Oops in the dmesg. Enable KaSan kernel\n"
"config option for use-after-free error detection.\n\n"); "config option for use-after-free error detection.\n\n");
while (count < 100) { printf("Running test for %d iternations\n", count);
while (count > 0) {
ret = ioctl(fd, MEDIA_IOC_DEVICE_INFO, &mdi); ret = ioctl(fd, MEDIA_IOC_DEVICE_INFO, &mdi);
if (ret < 0) if (ret < 0)
printf("Media Device Info errno %s\n", strerror(errno)); printf("Media Device Info errno %s\n", strerror(errno));
else else
printf("Media device model %s driver %s\n", printf("Media device model %s driver %s - count %d\n",
mdi.model, mdi.driver); mdi.model, mdi.driver, count);
sleep(10); sleep(10);
count++; count--;
} }
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment