1 /*
2 * v4l-test: Test environment for Video For Linux Two API
3 *
4 * 16 Jun 2009 0.1 First release
5 *
6 * Written by M�rton N�meth <nm127@freemail.hu>
7 * Released under GPL
8 */
9
10 #include <stdio.h>
11 #include <sys/types.h>
12 #include <sys/stat.h>
13 #include <fcntl.h>
14 #include <unistd.h>
15 #include <sys/ioctl.h>
16 #include <errno.h>
17 #include <string.h>
18
19 #include <linux/videodev2.h>
20 #include <linux/errno.h>
21
22 #include <CUnit/CUnit.h>
23
24 #include "v4l2_test.h"
25 #include "dev_video.h"
26 #include "video_limits.h"
27 #include "v4l2_validator.h"
28 #include "v4l2_foreach.h"
29 #include "v4l2_show.h"
30
31 #include "test_VIDIOC_ENUM_FRAMESIZES.h"
32
valid_framesize_type(__u32 type)33 static int valid_framesize_type(__u32 type)
34 {
35 int valid = 0;
36
37 if ((type == V4L2_FRMSIZE_TYPE_DISCRETE) ||
38 (type == V4L2_FRMSIZE_TYPE_CONTINUOUS) ||
39 (type == V4L2_FRMSIZE_TYPE_STEPWISE)) {
40 valid = 1;
41 } else {
42 valid = 0;
43 }
44 return valid;
45 }
46
do_test_VIDIOC_ENUM_FRAMESIZES(__u32 fmt)47 static void do_test_VIDIOC_ENUM_FRAMESIZES(__u32 fmt)
48 {
49 struct v4l2_frmsizeenum framesize;
50 int ret_frame, errno_frame;
51 __u32 i;
52 __u32 first_type;
53
54 i = 0;
55 first_type = 0;
56 do {
57 memset(&framesize, 0xff, sizeof(framesize));
58 framesize.index = i;
59 framesize.pixel_format = fmt;
60 ret_frame =
61 ioctl(get_video_fd(), VIDIOC_ENUM_FRAMESIZES, &framesize);
62 errno_frame = errno;
63
64 dprintf
65 ("\t%s:%u: VIDIOC_ENUM_FRAMESIZES, index=%u, pixel_format=0x%x, ret_frame=%i, errno_frame=%i\n",
66 __FILE__, __LINE__, i, fmt, ret_frame, errno_frame);
67
68 if (i != 0 && first_type != V4L2_FRMSIZE_TYPE_DISCRETE) {
69 CU_ASSERT_EQUAL(ret_frame, -1);
70 CU_ASSERT_EQUAL(errno_frame, EINVAL);
71 }
72
73 if (ret_frame == 0) {
74 CU_ASSERT_EQUAL(ret_frame, 0);
75 CU_ASSERT_EQUAL(framesize.index, i);
76 CU_ASSERT_EQUAL(framesize.pixel_format, fmt);
77 CU_ASSERT(valid_framesize_type(framesize.type));
78
79 if (i == 0) {
80 first_type = framesize.type;
81 } else {
82 CU_ASSERT_EQUAL(framesize.type, first_type);
83 }
84
85 switch (framesize.type) {
86 case V4L2_FRMSIZE_TYPE_DISCRETE:
87 CU_ASSERT(0 < framesize.discrete.width);
88 CU_ASSERT(0 < framesize.discrete.height);
89 break;
90
91 case V4L2_FRMSIZE_TYPE_CONTINUOUS:
92 CU_ASSERT(0 < framesize.stepwise.min_width);
93 CU_ASSERT(0 < framesize.stepwise.max_width);
94 CU_ASSERT_EQUAL(framesize.stepwise.step_width,
95 1);
96
97 CU_ASSERT(framesize.stepwise.min_width <
98 framesize.stepwise.max_width);
99
100 CU_ASSERT(0 < framesize.stepwise.min_height);
101 CU_ASSERT(0 < framesize.stepwise.max_height);
102 CU_ASSERT_EQUAL(framesize.stepwise.step_height,
103 1);
104
105 CU_ASSERT(framesize.stepwise.min_height <
106 framesize.stepwise.max_height);
107 break;
108
109 case V4L2_FRMSIZE_TYPE_STEPWISE:
110 CU_ASSERT(0 < framesize.stepwise.min_width);
111 CU_ASSERT(0 < framesize.stepwise.max_width);
112 CU_ASSERT(0 < framesize.stepwise.step_width);
113
114 CU_ASSERT(framesize.stepwise.min_width <
115 framesize.stepwise.max_width);
116
117 /* check if the given step is unambigous: min + n * step = max */
118 if (framesize.stepwise.step_width != 0) {
119 CU_ASSERT_EQUAL((framesize.stepwise.
120 max_width -
121 framesize.stepwise.
122 min_width) %
123 framesize.stepwise.
124 step_width, 0);
125 }
126
127 CU_ASSERT(0 < framesize.stepwise.min_height);
128 CU_ASSERT(0 < framesize.stepwise.max_height);
129 CU_ASSERT(0 < framesize.stepwise.step_height);
130
131 CU_ASSERT(framesize.stepwise.min_height <
132 framesize.stepwise.max_height);
133
134 /* check if the given step is unambigous: min + n * step = max */
135 if (framesize.stepwise.step_height != 0) {
136 CU_ASSERT_EQUAL((framesize.stepwise.
137 max_height -
138 framesize.stepwise.
139 min_height) %
140 framesize.stepwise.
141 step_height, 0);
142 }
143
144 break;
145 }
146
147 CU_ASSERT_EQUAL(framesize.reserved[0], 0);
148 CU_ASSERT_EQUAL(framesize.reserved[1], 0);
149
150 show_v4l2_frmsizeenum(&framesize);
151
152 } else {
153 CU_ASSERT_EQUAL(ret_frame, -1);
154 CU_ASSERT_EQUAL(errno_frame, EINVAL);
155 }
156 i++;
157 } while (ret_frame == 0 && i != 0);
158
159 }
160
do_test_VIDIOC_ENUM_FRAMESIZES_type(enum v4l2_buf_type type)161 static void do_test_VIDIOC_ENUM_FRAMESIZES_type(enum v4l2_buf_type type)
162 {
163 int ret_enum, errno_enum;
164 struct v4l2_fmtdesc format;
165 __u32 i;
166
167 i = 0;
168 do {
169 memset(&format, 0xff, sizeof(format));
170 format.index = i;
171 format.type = type;
172
173 ret_enum = ioctl(get_video_fd(), VIDIOC_ENUM_FMT, &format);
174 errno_enum = errno;
175
176 dprintf
177 ("\t%s:%u: VIDIOC_ENUM_FMT, index=%u, type=%i, ret_enum=%i, errno_enum=%i\n",
178 __FILE__, __LINE__, i, format.type, ret_enum, errno_enum);
179
180 /* Ensure that VIDIOC_ENUM_FRAMESIZES is called at least once
181 * even if VIDIOC_ENUM_FMT returns error
182 */
183 do_test_VIDIOC_ENUM_FRAMESIZES(format.pixelformat);
184
185 i++;
186 } while (ret_enum == 0 && i != 0);
187
188 }
189
test_VIDIOC_ENUM_FRAMESIZES()190 void test_VIDIOC_ENUM_FRAMESIZES()
191 {
192 do_test_VIDIOC_ENUM_FRAMESIZES_type(V4L2_BUF_TYPE_VIDEO_CAPTURE);
193 do_test_VIDIOC_ENUM_FRAMESIZES_type(V4L2_BUF_TYPE_VIDEO_OUTPUT);
194 do_test_VIDIOC_ENUM_FRAMESIZES_type(V4L2_BUF_TYPE_VIDEO_OVERLAY);
195 do_test_VIDIOC_ENUM_FRAMESIZES_type(V4L2_BUF_TYPE_PRIVATE);
196 }
197
do_test_VIDIOC_ENUM_FRAMESIZES_invalid_index(__u32 fmt)198 static void do_test_VIDIOC_ENUM_FRAMESIZES_invalid_index(__u32 fmt)
199 {
200 struct v4l2_frmsizeenum framesize;
201 int ret_frame, errno_frame;
202 __u32 i;
203 __u32 max_index;
204
205 i = 0;
206 do {
207 memset(&framesize, 0xff, sizeof(framesize));
208 framesize.index = i;
209 framesize.pixel_format = fmt;
210 ret_frame =
211 ioctl(get_video_fd(), VIDIOC_ENUM_FRAMESIZES, &framesize);
212 errno_frame = errno;
213
214 dprintf
215 ("\t%s:%u: VIDIOC_ENUM_FRAMESIZES, index=%u, pixel_format=0x%x, ret_frame=%i, errno_frame=%i\n",
216 __FILE__, __LINE__, i, fmt, ret_frame, errno_frame);
217
218 i++;
219 } while (ret_frame == 0 && i != 0);
220
221 max_index = i - 1;
222
223 i = max_index + 1;
224 memset(&framesize, 0xff, sizeof(framesize));
225 framesize.index = i;
226 framesize.pixel_format = fmt;
227 ret_frame = ioctl(get_video_fd(), VIDIOC_ENUM_FRAMESIZES, &framesize);
228 errno_frame = errno;
229
230 dprintf
231 ("\t%s:%u: VIDIOC_ENUM_FRAMESIZES, index=%u, pixel_format=0x%x, ret_frame=%i, errno_frame=%i\n",
232 __FILE__, __LINE__, i, fmt, ret_frame, errno_frame);
233
234 CU_ASSERT_EQUAL(ret_frame, -1);
235 CU_ASSERT_EQUAL(errno_frame, EINVAL);
236
237 i = (__u32) S32_MIN;
238 if (max_index < i) {
239 memset(&framesize, 0xff, sizeof(framesize));
240 framesize.index = i;
241 framesize.pixel_format = fmt;
242 ret_frame =
243 ioctl(get_video_fd(), VIDIOC_ENUM_FRAMESIZES, &framesize);
244 errno_frame = errno;
245
246 dprintf
247 ("\t%s:%u: VIDIOC_ENUM_FRAMESIZES, index=0x%x, pixel_format=0x%x, ret_frame=%i, errno_frame=%i\n",
248 __FILE__, __LINE__, i, fmt, ret_frame, errno_frame);
249
250 CU_ASSERT_EQUAL(ret_frame, -1);
251 CU_ASSERT_EQUAL(errno_frame, EINVAL);
252 }
253
254 i = (__u32) S32_MAX;
255 if (max_index < i) {
256 memset(&framesize, 0xff, sizeof(framesize));
257 framesize.index = i;
258 framesize.pixel_format = fmt;
259 ret_frame =
260 ioctl(get_video_fd(), VIDIOC_ENUM_FRAMESIZES, &framesize);
261 errno_frame = errno;
262
263 dprintf
264 ("\t%s:%u: VIDIOC_ENUM_FRAMESIZES, index=0x%x, pixel_format=0x%x, ret_frame=%i, errno_frame=%i\n",
265 __FILE__, __LINE__, i, fmt, ret_frame, errno_frame);
266
267 CU_ASSERT_EQUAL(ret_frame, -1);
268 CU_ASSERT_EQUAL(errno_frame, EINVAL);
269 }
270
271 i = (__u32) U32_MAX;
272 if (max_index < i) {
273 memset(&framesize, 0xff, sizeof(framesize));
274 framesize.index = i;
275 framesize.pixel_format = fmt;
276 ret_frame =
277 ioctl(get_video_fd(), VIDIOC_ENUM_FRAMESIZES, &framesize);
278 errno_frame = errno;
279
280 dprintf
281 ("\t%s:%u: VIDIOC_ENUM_FRAMESIZES, index=0x%x, pixel_format=0x%x, ret_frame=%i, errno_frame=%i\n",
282 __FILE__, __LINE__, i, fmt, ret_frame, errno_frame);
283
284 CU_ASSERT_EQUAL(ret_frame, -1);
285 CU_ASSERT_EQUAL(errno_frame, EINVAL);
286 }
287
288 }
289
do_test_VIDIOC_ENUM_FRAMESIZES_type_invalid_index(enum v4l2_buf_type type)290 static void do_test_VIDIOC_ENUM_FRAMESIZES_type_invalid_index(enum v4l2_buf_type
291 type)
292 {
293 int ret_enum, errno_enum;
294 struct v4l2_fmtdesc format;
295 __u32 i;
296
297 i = 0;
298 do {
299 memset(&format, 0xff, sizeof(format));
300 format.index = i;
301 format.type = type;
302
303 ret_enum = ioctl(get_video_fd(), VIDIOC_ENUM_FMT, &format);
304 errno_enum = errno;
305
306 dprintf
307 ("\t%s:%u: VIDIOC_ENUM_FMT, index=%u, type=%i, ret_enum=%i, errno_enum=%i\n",
308 __FILE__, __LINE__, i, format.type, ret_enum, errno_enum);
309
310 /* Ensure that VIDIOC_ENUM_FRAMESIZES is called at least once
311 * even if VIDIOC_ENUM_FMT returns error
312 */
313 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_index(format.
314 pixelformat);
315
316 i++;
317 } while (ret_enum == 0 && i != 0);
318
319 }
320
test_VIDIOC_ENUM_FRAMESIZES_invalid_index()321 void test_VIDIOC_ENUM_FRAMESIZES_invalid_index()
322 {
323 do_test_VIDIOC_ENUM_FRAMESIZES_type_invalid_index
324 (V4L2_BUF_TYPE_VIDEO_CAPTURE);
325 do_test_VIDIOC_ENUM_FRAMESIZES_type_invalid_index
326 (V4L2_BUF_TYPE_VIDEO_OUTPUT);
327 do_test_VIDIOC_ENUM_FRAMESIZES_type_invalid_index
328 (V4L2_BUF_TYPE_VIDEO_OVERLAY);
329 do_test_VIDIOC_ENUM_FRAMESIZES_type_invalid_index
330 (V4L2_BUF_TYPE_PRIVATE);
331 }
332
supported_pixel_format_type(enum v4l2_buf_type type,__u32 pixel_format)333 static int supported_pixel_format_type(enum v4l2_buf_type type,
334 __u32 pixel_format)
335 {
336 int ret_enum, errno_enum;
337 struct v4l2_fmtdesc format;
338 __u32 i;
339 int supported = 0;
340
341 i = 0;
342 do {
343 memset(&format, 0xff, sizeof(format));
344 format.index = i;
345 format.type = type;
346
347 ret_enum = ioctl(get_video_fd(), VIDIOC_ENUM_FMT, &format);
348 errno_enum = errno;
349
350 dprintf
351 ("\t%s:%u: VIDIOC_ENUM_FMT, index=%u, type=%i, ret_enum=%i, errno_enum=%i\n",
352 __FILE__, __LINE__, i, format.type, ret_enum, errno_enum);
353
354 i++;
355 } while (ret_enum == 0 && i != 0 && format.pixelformat != pixel_format);
356
357 if (ret_enum == 0 && i != 0 && format.pixelformat == pixel_format) {
358 supported = 1;
359 }
360
361 return supported;
362 }
363
supported_pixel_format(__u32 pixel_format)364 static int supported_pixel_format(__u32 pixel_format)
365 {
366 int supported = 0;
367
368 supported =
369 supported_pixel_format_type(V4L2_BUF_TYPE_VIDEO_CAPTURE,
370 pixel_format);
371 if (!supported) {
372 supported =
373 supported_pixel_format_type(V4L2_BUF_TYPE_VIDEO_OUTPUT,
374 pixel_format);
375 if (!supported) {
376 supported =
377 supported_pixel_format_type
378 (V4L2_BUF_TYPE_VIDEO_OVERLAY, pixel_format);
379 if (!supported) {
380 supported =
381 supported_pixel_format_type
382 (V4L2_BUF_TYPE_PRIVATE, pixel_format);
383 }
384 }
385 }
386
387 return supported;
388 }
389
do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format(__u32 fmt)390 static void do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format(__u32 fmt)
391 {
392 struct v4l2_frmsizeenum framesize;
393 int ret_frame, errno_frame;
394 __u32 i;
395
396 if (!supported_pixel_format(fmt)) {
397 i = 0;
398 memset(&framesize, 0xff, sizeof(framesize));
399 framesize.index = i;
400 framesize.pixel_format = fmt;
401 ret_frame =
402 ioctl(get_video_fd(), VIDIOC_ENUM_FRAMESIZES, &framesize);
403 errno_frame = errno;
404
405 dprintf
406 ("\t%s:%u: VIDIOC_ENUM_FRAMESIZES, index=%u, pixel_format=0x%x, ret_frame=%i, errno_frame=%i\n",
407 __FILE__, __LINE__, i, fmt, ret_frame, errno_frame);
408
409 CU_ASSERT_EQUAL(ret_frame, -1);
410 CU_ASSERT_EQUAL(errno_frame, EINVAL);
411 }
412
413 }
414
test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format()415 void test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format()
416 {
417
418 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format(U32_MIN);
419 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format((__u32) S32_MIN);
420 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format((__u32) S32_MAX);
421 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format(U32_MAX);
422
423 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format
424 (V4L2_PIX_FMT_RGB332);
425 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format
426 (V4L2_PIX_FMT_RGB444);
427 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format
428 (V4L2_PIX_FMT_RGB555);
429 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format
430 (V4L2_PIX_FMT_RGB565);
431 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format
432 (V4L2_PIX_FMT_RGB555X);
433 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format
434 (V4L2_PIX_FMT_RGB565X);
435 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format(V4L2_PIX_FMT_BGR24);
436 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format(V4L2_PIX_FMT_RGB24);
437 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format(V4L2_PIX_FMT_BGR32);
438 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format(V4L2_PIX_FMT_RGB32);
439 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format(V4L2_PIX_FMT_GREY);
440 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format(V4L2_PIX_FMT_Y16);
441 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format(V4L2_PIX_FMT_PAL8);
442 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format
443 (V4L2_PIX_FMT_YVU410);
444 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format
445 (V4L2_PIX_FMT_YVU420);
446 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format(V4L2_PIX_FMT_YUYV);
447 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format(V4L2_PIX_FMT_UYVY);
448 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format
449 (V4L2_PIX_FMT_YUV422P);
450 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format
451 (V4L2_PIX_FMT_YUV411P);
452 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format(V4L2_PIX_FMT_Y41P);
453 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format
454 (V4L2_PIX_FMT_YUV444);
455 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format
456 (V4L2_PIX_FMT_YUV555);
457 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format
458 (V4L2_PIX_FMT_YUV565);
459 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format(V4L2_PIX_FMT_YUV32);
460 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format(V4L2_PIX_FMT_NV12);
461 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format(V4L2_PIX_FMT_NV21);
462 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format
463 (V4L2_PIX_FMT_YUV410);
464 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format
465 (V4L2_PIX_FMT_YUV420);
466 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format(V4L2_PIX_FMT_YYUV);
467 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format(V4L2_PIX_FMT_HI240);
468 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format(V4L2_PIX_FMT_HM12);
469 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format
470 (V4L2_PIX_FMT_SBGGR8);
471 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format
472 (V4L2_PIX_FMT_SBGGR16);
473 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format(V4L2_PIX_FMT_MJPEG);
474 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format(V4L2_PIX_FMT_JPEG);
475 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format(V4L2_PIX_FMT_DV);
476 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format(V4L2_PIX_FMT_MPEG);
477 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format(V4L2_PIX_FMT_WNVA);
478 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format
479 (V4L2_PIX_FMT_SN9C10X);
480 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format(V4L2_PIX_FMT_PWC1);
481 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format(V4L2_PIX_FMT_PWC2);
482 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format
483 (V4L2_PIX_FMT_ET61X251);
484
485 #ifdef V4L2_PIX_FMT_VYUY
486 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format(V4L2_PIX_FMT_VYUY);
487 #endif
488
489 #ifdef V4L2_PIX_FMT_NV16
490 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format(V4L2_PIX_FMT_NV16);
491 #endif
492
493 #ifdef V4L2_PIX_FMT_NV61
494 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format(V4L2_PIX_FMT_NV61);
495 #endif
496
497 #ifdef V4L2_PIX_FMT_SGBRG8
498 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format
499 (V4L2_PIX_FMT_SGBRG8);
500 #endif
501
502 #ifdef V4L2_PIX_FMT_SGRBG8
503 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format
504 (V4L2_PIX_FMT_SGRBG8);
505 #endif
506
507 #ifdef V4L2_PIX_FMT_SGRBG10
508 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format
509 (V4L2_PIX_FMT_SGRBG10);
510 #endif
511
512 #ifdef V4L2_PIX_FMT_SGRBG10DPCM8
513 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format
514 (V4L2_PIX_FMT_SGRBG10DPCM8);
515 #endif
516
517 #ifdef V4L2_PIX_FMT_SPCA501
518 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format
519 (V4L2_PIX_FMT_SPCA501);
520 #endif
521
522 #ifdef V4L2_PIX_FMT_SPCA505
523 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format
524 (V4L2_PIX_FMT_SPCA505);
525 #endif
526
527 #ifdef V4L2_PIX_FMT_SPCA508
528 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format
529 (V4L2_PIX_FMT_SPCA508);
530 #endif
531
532 #ifdef V4L2_PIX_FMT_SPCA561
533 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format
534 (V4L2_PIX_FMT_SPCA561);
535 #endif
536
537 #ifdef V4L2_PIX_FMT_PAC207
538 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format
539 (V4L2_PIX_FMT_PAC207);
540 #endif
541
542 #ifdef V4L2_PIX_FMT_MR97310A
543 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format
544 (V4L2_PIX_FMT_MR97310A);
545 #endif
546
547 #ifdef V4L2_PIX_FMT_SQ905C
548 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format
549 (V4L2_PIX_FMT_SQ905C);
550 #endif
551
552 #ifdef V4L2_PIX_FMT_PJPG
553 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format(V4L2_PIX_FMT_PJPG);
554 #endif
555
556 #ifdef V4L2_PIX_FMT_YVYU
557 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format(V4L2_PIX_FMT_YVYU);
558 #endif
559
560 #ifdef V4L2_PIX_FMT_OV511
561 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format(V4L2_PIX_FMT_OV511);
562 #endif
563
564 #ifdef V4L2_PIX_FMT_OV518
565 do_test_VIDIOC_ENUM_FRAMESIZES_invalid_pixel_format(V4L2_PIX_FMT_OV518);
566 #endif
567
568 }
569
test_VIDIOC_ENUM_FRAMESIZES_NULL()570 void test_VIDIOC_ENUM_FRAMESIZES_NULL()
571 {
572 struct v4l2_fmtdesc format_capture;
573 struct v4l2_fmtdesc format_output;
574 struct v4l2_fmtdesc format_overlay;
575 struct v4l2_fmtdesc format_private;
576 struct v4l2_frmsizeenum framesize;
577 int ret_fmt_capture, errno_fmt_capture;
578 int ret_fmt_output, errno_fmt_output;
579 int ret_fmt_overlay, errno_fmt_overlay;
580 int ret_fmt_private, errno_fmt_private;
581 int ret_size, errno_size;
582 int ret_null, errno_null;
583 __u32 fmt;
584
585 memset(&format_capture, 0xff, sizeof(format_capture));
586 format_capture.index = 0;
587 format_capture.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
588
589 ret_fmt_capture =
590 ioctl(get_video_fd(), VIDIOC_ENUM_FMT, &format_capture);
591 errno_fmt_capture = errno;
592
593 dprintf
594 ("\t%s:%u: VIDIOC_ENUM_FMT, index=%u, type=%i, ret_fmt_capture=%i, errno_fmt_capture=%i\n",
595 __FILE__, __LINE__, format_capture.index, format_capture.type,
596 ret_fmt_capture, errno_fmt_capture);
597
598 memset(&format_output, 0xff, sizeof(format_output));
599 format_output.index = 0;
600 format_output.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
601
602 ret_fmt_output = ioctl(get_video_fd(), VIDIOC_ENUM_FMT, &format_output);
603 errno_fmt_output = errno;
604
605 dprintf
606 ("\t%s:%u: VIDIOC_ENUM_FMT, index=%u, type=%i, ret_fmt_output=%i, errno_fmt_output=%i\n",
607 __FILE__, __LINE__, format_output.index, format_output.type,
608 ret_fmt_output, errno_fmt_output);
609
610 memset(&format_overlay, 0xff, sizeof(format_overlay));
611 format_overlay.index = 0;
612 format_overlay.type = V4L2_BUF_TYPE_VIDEO_OVERLAY;
613
614 ret_fmt_overlay =
615 ioctl(get_video_fd(), VIDIOC_ENUM_FMT, &format_overlay);
616 errno_fmt_overlay = errno;
617
618 dprintf
619 ("\t%s:%u: VIDIOC_ENUM_FMT, index=%u, type=%i, ret_fmt_overlay=%i, errno_fmt_overlay=%i\n",
620 __FILE__, __LINE__, format_overlay.index, format_overlay.type,
621 ret_fmt_overlay, errno_fmt_overlay);
622
623 memset(&format_private, 0xff, sizeof(format_private));
624 format_private.index = 0;
625 format_private.type = V4L2_BUF_TYPE_PRIVATE;
626
627 ret_fmt_private =
628 ioctl(get_video_fd(), VIDIOC_ENUM_FMT, &format_private);
629 errno_fmt_private = errno;
630
631 dprintf
632 ("\t%s:%u: VIDIOC_ENUM_FMT, index=%u, type=%i, ret_fmt_private=%i, errno_fmt_private=%i\n",
633 __FILE__, __LINE__, format_private.index, format_private.type,
634 ret_fmt_private, errno_fmt_private);
635
636 if (ret_fmt_capture == 0) {
637 fmt = format_capture.pixelformat;
638 } else if (ret_fmt_output == 0) {
639 fmt = format_output.pixelformat;
640 } else if (ret_fmt_overlay == 0) {
641 fmt = format_overlay.pixelformat;
642 } else if (ret_fmt_private == 0) {
643 fmt = format_private.pixelformat;
644 } else {
645 fmt = 0;
646 }
647
648 memset(&framesize, 0xff, sizeof(framesize));
649 framesize.index = 0;
650 framesize.pixel_format = fmt;
651 ret_size = ioctl(get_video_fd(), VIDIOC_ENUM_FRAMESIZES, &framesize);
652 errno_size = errno;
653
654 dprintf
655 ("\tVIDIOC_ENUM_FRAMESIZES, index=%u, pixel_format=0x%x, ret_size=%i, errno_size=%i\n",
656 framesize.index, framesize.pixel_format, ret_size, errno_size);
657
658 ret_null = ioctl(get_video_fd(), VIDIOC_ENUM_FRAMESIZES, NULL);
659 errno_null = errno;
660
661 dprintf("\tVIDIOC_ENUM_FRAMESIZES, ret_null=%i, errno_null=%i\n",
662 ret_null, errno_null);
663
664 if (ret_size == 0) {
665 CU_ASSERT_EQUAL(ret_size, 0);
666 CU_ASSERT_EQUAL(ret_null, -1);
667 CU_ASSERT_EQUAL(errno_null, EFAULT);
668 } else {
669 CU_ASSERT_EQUAL(ret_size, -1);
670 CU_ASSERT_EQUAL(errno_size, EINVAL);
671 CU_ASSERT_EQUAL(ret_null, -1);
672 CU_ASSERT_EQUAL(errno_null, EINVAL);
673 }
674
675 }
676