Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: Ivan Orlov <ivan.orlov0322@gmail.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

authored by

Ivan Orlov and committed by
Shuah Khan
e42bf3cf 858fd168

+84 -29
+84 -29
tools/testing/selftests/media_tests/video_device_test.c
··· 37 37 #include <time.h> 38 38 #include <linux/videodev2.h> 39 39 40 - int main(int argc, char **argv) 40 + #define PRIORITY_MAX 4 41 + 42 + int priority_test(int fd) 41 43 { 42 - int opt; 43 - char video_dev[256]; 44 + /* This test will try to update the priority associated with a file descriptor */ 45 + 46 + enum v4l2_priority old_priority, new_priority, priority_to_compare; 47 + int ret; 48 + int result = 0; 49 + 50 + ret = ioctl(fd, VIDIOC_G_PRIORITY, &old_priority); 51 + if (ret < 0) { 52 + printf("Failed to get priority: %s\n", strerror(errno)); 53 + return -1; 54 + } 55 + new_priority = (old_priority + 1) % PRIORITY_MAX; 56 + ret = ioctl(fd, VIDIOC_S_PRIORITY, &new_priority); 57 + if (ret < 0) { 58 + printf("Failed to set priority: %s\n", strerror(errno)); 59 + return -1; 60 + } 61 + ret = ioctl(fd, VIDIOC_G_PRIORITY, &priority_to_compare); 62 + if (ret < 0) { 63 + printf("Failed to get new priority: %s\n", strerror(errno)); 64 + result = -1; 65 + goto cleanup; 66 + } 67 + if (priority_to_compare != new_priority) { 68 + printf("Priority wasn't set - test failed\n"); 69 + result = -1; 70 + } 71 + 72 + cleanup: 73 + ret = ioctl(fd, VIDIOC_S_PRIORITY, &old_priority); 74 + if (ret < 0) { 75 + printf("Failed to restore priority: %s\n", strerror(errno)); 76 + return -1; 77 + } 78 + return result; 79 + } 80 + 81 + int loop_test(int fd) 82 + { 44 83 int count; 45 84 struct v4l2_tuner vtuner; 46 85 struct v4l2_capability vcap; 47 86 int ret; 48 - int fd; 49 - 50 - if (argc < 2) { 51 - printf("Usage: %s [-d </dev/videoX>]\n", argv[0]); 52 - exit(-1); 53 - } 54 - 55 - /* Process arguments */ 56 - while ((opt = getopt(argc, argv, "d:")) != -1) { 57 - switch (opt) { 58 - case 'd': 59 - strncpy(video_dev, optarg, sizeof(video_dev) - 1); 60 - video_dev[sizeof(video_dev)-1] = '\0'; 61 - break; 62 - default: 63 - printf("Usage: %s [-d </dev/videoX>]\n", argv[0]); 64 - exit(-1); 65 - } 66 - } 67 87 68 88 /* Generate random number of interations */ 69 89 srand((unsigned int) time(NULL)); 70 90 count = rand(); 71 - 72 - /* Open Video device and keep it open */ 73 - fd = open(video_dev, O_RDWR); 74 - if (fd == -1) { 75 - printf("Video Device open errno %s\n", strerror(errno)); 76 - exit(-1); 77 - } 78 91 79 92 printf("\nNote:\n" 80 93 "While test is running, remove the device or unbind\n" ··· 111 98 sleep(10); 112 99 count--; 113 100 } 101 + return 0; 102 + } 103 + 104 + int main(int argc, char **argv) 105 + { 106 + int opt; 107 + char video_dev[256]; 108 + int fd; 109 + int test_result; 110 + 111 + if (argc < 2) { 112 + printf("Usage: %s [-d </dev/videoX>]\n", argv[0]); 113 + exit(-1); 114 + } 115 + 116 + /* Process arguments */ 117 + while ((opt = getopt(argc, argv, "d:")) != -1) { 118 + switch (opt) { 119 + case 'd': 120 + strncpy(video_dev, optarg, sizeof(video_dev) - 1); 121 + video_dev[sizeof(video_dev)-1] = '\0'; 122 + break; 123 + default: 124 + printf("Usage: %s [-d </dev/videoX>]\n", argv[0]); 125 + exit(-1); 126 + } 127 + } 128 + 129 + /* Open Video device and keep it open */ 130 + fd = open(video_dev, O_RDWR); 131 + if (fd == -1) { 132 + printf("Video Device open errno %s\n", strerror(errno)); 133 + exit(-1); 134 + } 135 + 136 + test_result = priority_test(fd); 137 + if (!test_result) 138 + printf("Priority test - PASSED\n"); 139 + else 140 + printf("Priority test - FAILED\n"); 141 + 142 + loop_test(fd); 114 143 }