1 /*
2 * v4l-test: Test environment for Video For Linux Two API
3 *
4 * 20 Apr 2009 0.5 Added string content validation
5 * 18 Apr 2009 0.4 More strict check for strings
6 * 29 Mar 2009 0.3 Clean up ret and errno variable names and dprintf() output
7 * 22 Dec 2008 0.2 Test case with NULL parameter added
8 * 18 Dec 2008 0.1 First release
9 *
10 * Written by M�rton N�meth <nm127@freemail.hu>
11 * Released under GPL
12 */
13
14 #include <stdio.h>
15 #include <sys/types.h>
16 #include <sys/stat.h>
17 #include <fcntl.h>
18 #include <unistd.h>
19 #include <sys/ioctl.h>
20 #include <errno.h>
21 #include <string.h>
22
23 #include <linux/videodev2.h>
24 #include <linux/errno.h>
25
26 #include <CUnit/CUnit.h>
27 #include <CUnit/Basic.h>
28
29 #include "v4l2_test.h"
30 #include "dev_video.h"
31 #include "video_limits.h"
32 #include "v4l2_validator.h"
33
34 #include "test_VIDIOC_QUERYCAP.h"
35
valid_capabilities(__u32 capabilities)36 int valid_capabilities(__u32 capabilities)
37 {
38 int valid = 1;
39
40 if ((capabilities & ~(V4L2_CAP_VIDEO_CAPTURE |
41 V4L2_CAP_VIDEO_OUTPUT |
42 V4L2_CAP_VIDEO_OVERLAY |
43 V4L2_CAP_VBI_CAPTURE |
44 V4L2_CAP_VBI_OUTPUT |
45 V4L2_CAP_SLICED_VBI_CAPTURE |
46 V4L2_CAP_SLICED_VBI_OUTPUT |
47 V4L2_CAP_RDS_CAPTURE |
48 V4L2_CAP_VIDEO_OUTPUT_OVERLAY |
49 V4L2_CAP_TUNER |
50 V4L2_CAP_AUDIO |
51 V4L2_CAP_RADIO |
52 V4L2_CAP_READWRITE |
53 V4L2_CAP_ASYNCIO | V4L2_CAP_STREAMING)) != 0) {
54 valid = 0;
55 }
56
57 return valid;
58 }
59
test_VIDIOC_QUERYCAP()60 void test_VIDIOC_QUERYCAP()
61 {
62 int ret;
63 struct v4l2_capability cap;
64 struct v4l2_capability cap2;
65
66 memset(&cap, 0xff, sizeof(cap));
67
68 ret = ioctl(get_video_fd(), VIDIOC_QUERYCAP, &cap);
69
70 dprintf("VIDIOC_QUERYCAP, ret=%i\n", ret);
71 dprintf("\tcap = { .driver = \"%s\", .card = \"%s\", "
72 ".bus_info = \"%s\", "
73 ".version = %u.%u.%u, "
74 ".capabilities = 0x%X, "
75 ".reserved[]={ 0x%X, 0x%X, 0x%X, 0x%X } }\n",
76 cap.driver,
77 cap.card,
78 cap.bus_info,
79 (cap.version >> 16) & 0xFF,
80 (cap.version >> 8) & 0xFF,
81 cap.version & 0xFF,
82 cap.capabilities,
83 cap.reserved[0],
84 cap.reserved[1], cap.reserved[2], cap.reserved[3]
85 );
86
87 /* This ioctl must be implemented by ALL drivers */
88 CU_ASSERT_EQUAL(ret, 0);
89 if (ret == 0) {
90 CU_ASSERT(0 < strlen((char *)cap.driver));
91 CU_ASSERT(valid_string((char *)cap.driver, sizeof(cap.driver)));
92
93 CU_ASSERT(0 < strlen((char *)cap.card));
94 CU_ASSERT(valid_string((char *)cap.card, sizeof(cap.card)));
95
96 /* cap.bus_info is allowed to be an empty string ("") if no
97 * is info available
98 */
99 CU_ASSERT(valid_string
100 ((char *)cap.bus_info, sizeof(cap.bus_info)));
101
102 //CU_ASSERT_EQUAL(cap.version, ?);
103 CU_ASSERT(valid_capabilities(cap.capabilities));
104
105 CU_ASSERT_EQUAL(cap.reserved[0], 0);
106 CU_ASSERT_EQUAL(cap.reserved[1], 0);
107 CU_ASSERT_EQUAL(cap.reserved[2], 0);
108 CU_ASSERT_EQUAL(cap.reserved[3], 0);
109
110 /* Check if the unused bytes of the driver, card and bus_info
111 * strings are also filled with zeros. Also check if there is
112 * any padding byte between any two fields then this padding
113 * byte is also filled with zeros.
114 */
115 memset(&cap2, 0, sizeof(cap2));
116 strncpy((char *)cap2.driver, (char *)cap.driver,
117 sizeof(cap2.driver));
118 strncpy((char *)cap2.card, (char *)cap.card, sizeof(cap2.card));
119 strncpy((char *)cap2.bus_info, (char *)cap.bus_info,
120 sizeof(cap2.bus_info));
121 cap2.version = cap.version;
122 cap2.capabilities = cap.capabilities;
123 CU_ASSERT_EQUAL(memcmp(&cap, &cap2, sizeof(cap)), 0);
124
125 }
126
127 }
128
test_VIDIOC_QUERYCAP_NULL()129 void test_VIDIOC_QUERYCAP_NULL()
130 {
131 int ret_null, errno_null;
132
133 ret_null = ioctl(get_video_fd(), VIDIOC_QUERYCAP, NULL);
134 errno_null = errno;
135
136 dprintf("\t%s:%u: VIDIOC_QUERYCAP, ret_null=%i, errno_null=%i\n",
137 __FILE__, __LINE__, ret_null, errno_null);
138
139 /* VIDIOC_QUERYCAP is a mandatory command, all drivers shall
140 * support it. The parameter shall be always tested.
141 */
142 CU_ASSERT_EQUAL(ret_null, -1);
143 CU_ASSERT_EQUAL(errno_null, EFAULT);
144
145 }
146