Commit e42bf3cf authored by Ivan Orlov's avatar Ivan Orlov Committed by Shuah Khan

selftests: media_tests: Add new subtest to video_device_test

Add new subtest to video_device_test to cover the VIDIOC_G_PRIORITY
and VIDIOC_S_PRIORITY ioctl calls. This test tries to set the priority
associated with the file descriptior via ioctl VIDIOC_S_PRIORITY
command from V4L2 API. After that, the test tries to get the new
priority via VIDIOC_G_PRIORITY ioctl command and compares the result
with the v4l2_priority it set before. At the end, the test restores the
old priority.

This test will increase the code coverage for video_device_test, so
I think it might be useful. Additionally, this patch will refactor the
video_device_test a little bit, according to the new functionality.
Signed-off-by: default avatarIvan Orlov <ivan.orlov0322@gmail.com>
Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
parent 858fd168
...@@ -37,15 +37,89 @@ ...@@ -37,15 +37,89 @@
#include <time.h> #include <time.h>
#include <linux/videodev2.h> #include <linux/videodev2.h>
int main(int argc, char **argv) #define PRIORITY_MAX 4
int priority_test(int fd)
{
/* This test will try to update the priority associated with a file descriptor */
enum v4l2_priority old_priority, new_priority, priority_to_compare;
int ret;
int result = 0;
ret = ioctl(fd, VIDIOC_G_PRIORITY, &old_priority);
if (ret < 0) {
printf("Failed to get priority: %s\n", strerror(errno));
return -1;
}
new_priority = (old_priority + 1) % PRIORITY_MAX;
ret = ioctl(fd, VIDIOC_S_PRIORITY, &new_priority);
if (ret < 0) {
printf("Failed to set priority: %s\n", strerror(errno));
return -1;
}
ret = ioctl(fd, VIDIOC_G_PRIORITY, &priority_to_compare);
if (ret < 0) {
printf("Failed to get new priority: %s\n", strerror(errno));
result = -1;
goto cleanup;
}
if (priority_to_compare != new_priority) {
printf("Priority wasn't set - test failed\n");
result = -1;
}
cleanup:
ret = ioctl(fd, VIDIOC_S_PRIORITY, &old_priority);
if (ret < 0) {
printf("Failed to restore priority: %s\n", strerror(errno));
return -1;
}
return result;
}
int loop_test(int fd)
{ {
int opt;
char video_dev[256];
int count; int count;
struct v4l2_tuner vtuner; struct v4l2_tuner vtuner;
struct v4l2_capability vcap; struct v4l2_capability vcap;
int ret; int ret;
/* Generate random number of interations */
srand((unsigned int) time(NULL));
count = rand();
printf("\nNote:\n"
"While test is running, remove the device or unbind\n"
"driver and ensure there are no use after free errors\n"
"and other Oops in the dmesg. When possible, enable KaSan\n"
"kernel config option for use-after-free error detection.\n\n");
while (count > 0) {
ret = ioctl(fd, VIDIOC_QUERYCAP, &vcap);
if (ret < 0)
printf("VIDIOC_QUERYCAP errno %s\n", strerror(errno));
else
printf("Video device driver %s\n", vcap.driver);
ret = ioctl(fd, VIDIOC_G_TUNER, &vtuner);
if (ret < 0)
printf("VIDIOC_G_TUNER, errno %s\n", strerror(errno));
else
printf("type %d rangelow %d rangehigh %d\n",
vtuner.type, vtuner.rangelow, vtuner.rangehigh);
sleep(10);
count--;
}
return 0;
}
int main(int argc, char **argv)
{
int opt;
char video_dev[256];
int fd; int fd;
int test_result;
if (argc < 2) { if (argc < 2) {
printf("Usage: %s [-d </dev/videoX>]\n", argv[0]); printf("Usage: %s [-d </dev/videoX>]\n", argv[0]);
...@@ -65,10 +139,6 @@ int main(int argc, char **argv) ...@@ -65,10 +139,6 @@ int main(int argc, char **argv)
} }
} }
/* Generate random number of interations */
srand((unsigned int) time(NULL));
count = rand();
/* Open Video device and keep it open */ /* Open Video device and keep it open */
fd = open(video_dev, O_RDWR); fd = open(video_dev, O_RDWR);
if (fd == -1) { if (fd == -1) {
...@@ -76,26 +146,11 @@ int main(int argc, char **argv) ...@@ -76,26 +146,11 @@ int main(int argc, char **argv)
exit(-1); exit(-1);
} }
printf("\nNote:\n" test_result = priority_test(fd);
"While test is running, remove the device or unbind\n" if (!test_result)
"driver and ensure there are no use after free errors\n" printf("Priority test - PASSED\n");
"and other Oops in the dmesg. When possible, enable KaSan\n"
"kernel config option for use-after-free error detection.\n\n");
while (count > 0) {
ret = ioctl(fd, VIDIOC_QUERYCAP, &vcap);
if (ret < 0)
printf("VIDIOC_QUERYCAP errno %s\n", strerror(errno));
else else
printf("Video device driver %s\n", vcap.driver); printf("Priority test - FAILED\n");
ret = ioctl(fd, VIDIOC_G_TUNER, &vtuner); loop_test(fd);
if (ret < 0)
printf("VIDIOC_G_TUNER, errno %s\n", strerror(errno));
else
printf("type %d rangelow %d rangehigh %d\n",
vtuner.type, vtuner.rangelow, vtuner.rangehigh);
sleep(10);
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