1 /*
2 * v4l-test: Test environment for Video For Linux Two API
3 *
4 * 20 Apr 2009 0.9 Added string content validation
5 * 19 Apr 2009 0.8 Also check std field
6 * 18 Apr 2009 0.7 More strict check for strings
7 * 3 Apr 2009 0.6 Test case for NULL parameter reworked
8 * 28 Mar 2009 0.5 Clean up ret and errno variable names and dprintf() output
9 * 18 Jan 2009 0.4 Test case for MAX_EM28XX_TVNORMS removed, test cases for
10 * S32_MAX & U32_MAX are enough
11 * 1 Jan 2009 0.3 Added index=S32_MAX and S32_MAX+1
12 * 22 Dec 2008 0.2 Test case with NULL parameter added
13 * 18 Dec 2008 0.1 First release
14 *
15 * Written by M�rton N�meth <nm127@freemail.hu>
16 * Released under GPL
17 */
18
19 /* TODO: from V4L2 Spec:
20 * "Drivers may enumerate a different set of standards after switching the video input or output."
21 *
22 */
23
24 #include <stdio.h>
25 #include <sys/types.h>
26 #include <sys/stat.h>
27 #include <fcntl.h>
28 #include <unistd.h>
29 #include <sys/ioctl.h>
30 #include <errno.h>
31 #include <string.h>
32
33 #include <linux/videodev2.h>
34 #include <linux/errno.h>
35
36 #include <CUnit/CUnit.h>
37 #include <CUnit/Basic.h>
38
39 #include "v4l2_test.h"
40 #include "dev_video.h"
41 #include "video_limits.h"
42 #include "v4l2_validator.h"
43
44 #include "test_VIDIOC_ENUMSTD.h"
45
test_VIDIOC_ENUMSTD()46 void test_VIDIOC_ENUMSTD()
47 {
48 int ret_enum, errno_enum;
49 struct v4l2_standard std;
50 struct v4l2_standard std2;
51 __u32 i;
52
53 i = 0;
54 do {
55 memset(&std, 0xff, sizeof(std));
56 std.index = i;
57 ret_enum = ioctl(get_video_fd(), VIDIOC_ENUMSTD, &std);
58 errno_enum = errno;
59
60 dprintf("\t%s:%u: VIDIOC_ENUMSTD, ret_enum=%i, errno_enum=%i\n",
61 __FILE__, __LINE__, ret_enum, errno_enum);
62
63 if (ret_enum == 0) {
64 CU_ASSERT_EQUAL(ret_enum, 0);
65 CU_ASSERT_EQUAL(std.index, i);
66 CU_ASSERT(valid_v4l2_std_id(std.id));
67
68 CU_ASSERT(0 < strlen((char *)std.name));
69 CU_ASSERT(valid_string
70 ((char *)std.name, sizeof(std.name)));
71
72 //CU_ASSERT_EQUAL(std.frameperiod.numerator, ?);
73 //CU_ASSERT_EQUAL(std.frameperiod.denominator, ?);
74 //CU_ASSERT_EQUAL(std.framelines, ?);
75 CU_ASSERT_EQUAL(std.reserved[0], 0);
76 CU_ASSERT_EQUAL(std.reserved[1], 0);
77 CU_ASSERT_EQUAL(std.reserved[2], 0);
78 CU_ASSERT_EQUAL(std.reserved[3], 0);
79
80 /* Check if the unused bytes of the name string is also filled
81 * with zeros. Also check if there is any padding byte between
82 * any two fields then this padding byte is also filled with zeros.
83 */
84 memset(&std2, 0, sizeof(std2));
85 std2.index = std.index;
86 std2.id = std.id;
87 strncpy((char *)std2.name, (char *)std.name,
88 sizeof(std2.name));
89 std2.frameperiod.numerator = std.frameperiod.numerator;
90 std2.frameperiod.denominator =
91 std.frameperiod.denominator;
92 std2.framelines = std.framelines;
93 CU_ASSERT_EQUAL(memcmp(&std, &std2, sizeof(std)), 0);
94
95 dprintf("\tstd = {.index=%u, .id=%llX, .name=\"%s\", "
96 ".frameperiod={ .numerator=%u, .denominator=%u }, "
97 ".framelines=%u, "
98 ".reserved[]={ 0x%X, 0x%X, 0x%X, 0x%X } }\n",
99 std.index,
100 std.id,
101 std.name,
102 std.frameperiod.numerator,
103 std.frameperiod.denominator,
104 std.framelines,
105 std.reserved[0],
106 std.reserved[1],
107 std.reserved[2], std.reserved[3]
108 );
109
110 } else {
111 CU_ASSERT_EQUAL(ret_enum, -1);
112 CU_ASSERT_EQUAL(errno_enum, EINVAL);
113
114 memset(&std2, 0xff, sizeof(std2));
115 std2.index = i;
116 CU_ASSERT_EQUAL(memcmp(&std, &std2, sizeof(std)), 0);
117
118 }
119 i++;
120 } while (ret_enum == 0);
121 }
122
test_VIDIOC_ENUMSTD_S32_MAX()123 void test_VIDIOC_ENUMSTD_S32_MAX()
124 {
125 int ret_enum, errno_enum;
126 struct v4l2_standard std;
127 struct v4l2_standard std2;
128
129 memset(&std, 0xff, sizeof(std));
130 std.index = (__u32) S32_MAX;
131 ret_enum = ioctl(get_video_fd(), VIDIOC_ENUMSTD, &std);
132 errno_enum = errno;
133
134 CU_ASSERT_EQUAL(ret_enum, -1);
135 CU_ASSERT_EQUAL(errno_enum, EINVAL);
136
137 memset(&std2, 0xff, sizeof(std2));
138 std2.index = (__u32) S32_MAX;
139 CU_ASSERT_EQUAL(memcmp(&std, &std2, sizeof(std)), 0);
140 }
141
test_VIDIOC_ENUMSTD_S32_MAX_1()142 void test_VIDIOC_ENUMSTD_S32_MAX_1()
143 {
144 int ret_enum, errno_enum;
145 struct v4l2_standard std;
146 struct v4l2_standard std2;
147
148 memset(&std, 0xff, sizeof(std));
149 std.index = ((__u32) S32_MAX) + 1;
150 ret_enum = ioctl(get_video_fd(), VIDIOC_ENUMSTD, &std);
151 errno_enum = errno;
152
153 CU_ASSERT_EQUAL(ret_enum, -1);
154 CU_ASSERT_EQUAL(errno_enum, EINVAL);
155
156 memset(&std2, 0xff, sizeof(std2));
157 std2.index = ((__u32) S32_MAX) + 1;
158 CU_ASSERT_EQUAL(memcmp(&std, &std2, sizeof(std)), 0);
159 }
160
test_VIDIOC_ENUMSTD_U32_MAX()161 void test_VIDIOC_ENUMSTD_U32_MAX()
162 {
163 int ret_enum, errno_enum;
164 struct v4l2_standard std;
165 struct v4l2_standard std2;
166
167 memset(&std, 0xff, sizeof(std));
168 std.index = U32_MAX;
169 ret_enum = ioctl(get_video_fd(), VIDIOC_ENUMSTD, &std);
170 errno_enum = errno;
171
172 dprintf("\t%s:%u: VIDIOC_ENUMSTD, ret_enum=%i, errno_enum=%i\n",
173 __FILE__, __LINE__, ret_enum, errno_enum);
174
175 CU_ASSERT_EQUAL(ret_enum, -1);
176 CU_ASSERT_EQUAL(errno_enum, EINVAL);
177
178 memset(&std2, 0xff, sizeof(std2));
179 std2.index = U32_MAX;
180 CU_ASSERT_EQUAL(memcmp(&std, &std2, sizeof(std)), 0);
181 }
182
test_VIDIOC_ENUMSTD_NULL()183 void test_VIDIOC_ENUMSTD_NULL()
184 {
185 int ret_enum, errno_enum;
186 int ret_null, errno_null;
187 struct v4l2_standard std;
188
189 memset(&std, 0xff, sizeof(std));
190 std.index = 0;
191 ret_enum = ioctl(get_video_fd(), VIDIOC_ENUMSTD, &std);
192 errno_enum = errno;
193
194 dprintf("\t%s:%u: VIDIOC_ENUMSTD, ret_enum=%i, errno_enum=%i\n",
195 __FILE__, __LINE__, ret_enum, errno_enum);
196
197 ret_null = ioctl(get_video_fd(), VIDIOC_ENUMSTD, NULL);
198 errno_null = errno;
199
200 dprintf("\t%s:%u: VIDIOC_ENUMSTD, ret_null=%i, errno_null=%i\n",
201 __FILE__, __LINE__, ret_null, errno_null);
202
203 if (ret_enum == 0) {
204 CU_ASSERT_EQUAL(ret_enum, 0);
205 CU_ASSERT_EQUAL(ret_null, -1);
206 CU_ASSERT_EQUAL(errno_null, EFAULT);
207 } else {
208 CU_ASSERT_EQUAL(ret_enum, -1);
209 CU_ASSERT_EQUAL(errno_enum, EINVAL);
210 CU_ASSERT_EQUAL(ret_null, -1);
211 CU_ASSERT_EQUAL(errno_null, EINVAL);
212 }
213
214 }
215