1 // SPDX-License-Identifier: GPL-2.0
4 * video_device_test - Video Device Test
6 * Copyright (c) 2016 Shuah Khan <shuahkh@osg.samsung.com>
7 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
12 * This file adds a test for Video Device. This test should not be included
13 * in the Kselftest run. This test should be run when hardware and driver
14 * that makes use of V4L2 API is present.
16 * This test opens user specified Video Device and calls video ioctls in a
17 * loop once every 10 seconds.
20 * sudo ./video_device_test -d /dev/videoX
22 * While test is running, remove the device or unbind the driver and
23 * ensure there are no use after free errors and other Oops in the
25 * When possible, enable KaSan kernel config option for use-after-free
35 #include <sys/ioctl.h>
38 #include <linux/videodev2.h>
40 int main(int argc
, char **argv
)
45 struct v4l2_tuner vtuner
;
46 struct v4l2_capability vcap
;
51 printf("Usage: %s [-d </dev/videoX>]\n", argv
[0]);
55 /* Process arguments */
56 while ((opt
= getopt(argc
, argv
, "d:")) != -1) {
59 strncpy(video_dev
, optarg
, sizeof(video_dev
) - 1);
60 video_dev
[sizeof(video_dev
)-1] = '\0';
63 printf("Usage: %s [-d </dev/videoX>]\n", argv
[0]);
68 /* Generate random number of interations */
69 srand((unsigned int) time(NULL
));
72 /* Open Video device and keep it open */
73 fd
= open(video_dev
, O_RDWR
);
75 printf("Video Device open errno %s\n", strerror(errno
));
80 "While test is running, remove the device or unbind\n"
81 "driver and ensure there are no use after free errors\n"
82 "and other Oops in the dmesg. When possible, enable KaSan\n"
83 "kernel config option for use-after-free error detection.\n\n");
86 ret
= ioctl(fd
, VIDIOC_QUERYCAP
, &vcap
);
88 printf("VIDIOC_QUERYCAP errno %s\n", strerror(errno
));
90 printf("Video device driver %s\n", vcap
.driver
);
92 ret
= ioctl(fd
, VIDIOC_G_TUNER
, &vtuner
);
94 printf("VIDIOC_G_TUNER, errno %s\n", strerror(errno
));
96 printf("type %d rangelow %d rangehigh %d\n",
97 vtuner
.type
, vtuner
.rangelow
, vtuner
.rangehigh
);