1 /*
2 * v4l-test: Test environment for Video For Linux Two API
3 *
4 * 19 Jul 2009 0.4 More V4L2_PIX_FMT_* formats added to valid_poxelformat()
5 * 18 Apr 2009 0.3 Type added to debug printouts
6 * 15 Apr 2009 0.2 Added test case for VIDIOC_S_FMT
7 * 4 Apr 2009 0.1 First release
8 *
9 * Written by M�rton N�meth <nm127@freemail.hu>
10 * Released under GPL
11 */
12
13 #include <stdio.h>
14 #include <sys/types.h>
15 #include <sys/stat.h>
16 #include <fcntl.h>
17 #include <unistd.h>
18 #include <sys/ioctl.h>
19 #include <errno.h>
20 #include <string.h>
21
22 #include <linux/videodev2.h>
23 #include <linux/errno.h>
24
25 #include <CUnit/CUnit.h>
26 #include <CUnit/Basic.h>
27
28 #include "v4l2_test.h"
29 #include "dev_video.h"
30 #include "video_limits.h"
31
32 #include "test_VIDIOC_FMT.h"
33
valid_pixelformat(__u32 pixelformat)34 int valid_pixelformat(__u32 pixelformat)
35 {
36 int valid = 0;
37
38 switch (pixelformat) {
39 case V4L2_PIX_FMT_RGB332:
40 case V4L2_PIX_FMT_RGB444:
41 case V4L2_PIX_FMT_RGB555:
42 case V4L2_PIX_FMT_RGB565:
43 case V4L2_PIX_FMT_RGB555X:
44 case V4L2_PIX_FMT_RGB565X:
45 case V4L2_PIX_FMT_BGR24:
46 case V4L2_PIX_FMT_RGB24:
47 case V4L2_PIX_FMT_BGR32:
48 case V4L2_PIX_FMT_RGB32:
49 case V4L2_PIX_FMT_GREY:
50 case V4L2_PIX_FMT_Y16:
51 case V4L2_PIX_FMT_PAL8:
52 case V4L2_PIX_FMT_YVU410:
53 case V4L2_PIX_FMT_YVU420:
54 case V4L2_PIX_FMT_YUYV:
55 case V4L2_PIX_FMT_UYVY:
56 case V4L2_PIX_FMT_YUV422P:
57 case V4L2_PIX_FMT_YUV411P:
58 case V4L2_PIX_FMT_Y41P:
59 case V4L2_PIX_FMT_YUV444:
60 case V4L2_PIX_FMT_YUV555:
61 case V4L2_PIX_FMT_YUV565:
62 case V4L2_PIX_FMT_YUV32:
63 case V4L2_PIX_FMT_NV12:
64 case V4L2_PIX_FMT_NV21:
65 case V4L2_PIX_FMT_YUV410:
66 case V4L2_PIX_FMT_YUV420:
67 case V4L2_PIX_FMT_YYUV:
68 case V4L2_PIX_FMT_HI240:
69 case V4L2_PIX_FMT_HM12:
70 case V4L2_PIX_FMT_SBGGR8:
71 case V4L2_PIX_FMT_SBGGR16:
72 case V4L2_PIX_FMT_MJPEG:
73 case V4L2_PIX_FMT_JPEG:
74 case V4L2_PIX_FMT_DV:
75 case V4L2_PIX_FMT_MPEG:
76 case V4L2_PIX_FMT_WNVA:
77 case V4L2_PIX_FMT_SN9C10X:
78 case V4L2_PIX_FMT_PWC1:
79 case V4L2_PIX_FMT_PWC2:
80 case V4L2_PIX_FMT_ET61X251:
81
82 /* formats from Linux kernel 2.6.31-rc2 */
83
84 #ifdef V4L2_PIX_FMT_VYUY
85 case V4L2_PIX_FMT_VYUY:
86 #endif
87
88 #ifdef V4L2_PIX_FMT_NV16
89 case V4L2_PIX_FMT_NV16:
90 #endif
91
92 #ifdef V4L2_PIX_FMT_NV61
93 case V4L2_PIX_FMT_NV61:
94 #endif
95
96 #ifdef V4L2_PIX_FMT_SGBRG8
97 case V4L2_PIX_FMT_SGBRG8:
98 #endif
99
100 #ifdef V4L2_PIX_FMT_SGRBG8
101 case V4L2_PIX_FMT_SGRBG8:
102 #endif
103
104 #ifdef V4L2_PIX_FMT_SGRBG10
105 case V4L2_PIX_FMT_SGRBG10:
106 #endif
107
108 #ifdef V4L2_PIX_FMT_SGRBG10DPCM8
109 case V4L2_PIX_FMT_SGRBG10DPCM8:
110 #endif
111
112 #ifdef V4L2_PIX_FMT_SPCA501
113 case V4L2_PIX_FMT_SPCA501:
114 #endif
115
116 #ifdef V4L2_PIX_FMT_SPCA505
117 case V4L2_PIX_FMT_SPCA505:
118 #endif
119
120 #ifdef V4L2_PIX_FMT_SPCA508
121 case V4L2_PIX_FMT_SPCA508:
122 #endif
123
124 #ifdef V4L2_PIX_FMT_SPCA561
125 case V4L2_PIX_FMT_SPCA561:
126 #endif
127
128 #ifdef V4L2_PIX_FMT_PAC207
129 case V4L2_PIX_FMT_PAC207:
130 #endif
131
132 #ifdef V4L2_PIX_FMT_MR97310A
133 case V4L2_PIX_FMT_MR97310A:
134 #endif
135
136 #ifdef V4L2_PIX_FMT_SQ905C
137 case V4L2_PIX_FMT_SQ905C:
138 #endif
139
140 #ifdef V4L2_PIX_FMT_PJPG
141 case V4L2_PIX_FMT_PJPG:
142 #endif
143
144 #ifdef V4L2_PIX_FMT_YVYU
145 case V4L2_PIX_FMT_YVYU:
146 #endif
147
148 #ifdef V4L2_PIX_FMT_OV511
149 case V4L2_PIX_FMT_OV511:
150 #endif
151
152 #ifdef V4L2_PIX_FMT_OV518
153 case V4L2_PIX_FMT_OV518:
154 #endif
155
156 valid = 1;
157 break;
158 default:
159 valid = 0;
160 }
161
162 return valid;
163 }
164
valid_colorspace(enum v4l2_colorspace colorspace)165 int valid_colorspace(enum v4l2_colorspace colorspace)
166 {
167 int valid = 0;
168
169 switch (colorspace) {
170 case V4L2_COLORSPACE_SMPTE170M:
171 case V4L2_COLORSPACE_SMPTE240M:
172 case V4L2_COLORSPACE_REC709:
173 case V4L2_COLORSPACE_BT878:
174 case V4L2_COLORSPACE_470_SYSTEM_M:
175 case V4L2_COLORSPACE_470_SYSTEM_BG:
176 case V4L2_COLORSPACE_JPEG:
177 case V4L2_COLORSPACE_SRGB:
178 valid = 1;
179 break;
180 default:
181 valid = 0;
182 }
183
184 return valid;
185 }
186
do_get_formats(enum v4l2_buf_type type)187 static void do_get_formats(enum v4l2_buf_type type)
188 {
189 int ret_get, errno_get;
190 struct v4l2_format format;
191 struct v4l2_format format2;
192 unsigned int j;
193
194 memset(&format, 0xff, sizeof(format));
195 format.type = type;
196
197 ret_get = ioctl(get_video_fd(), VIDIOC_G_FMT, &format);
198 errno_get = errno;
199
200 dprintf("\t%s:%u: VIDIOC_G_FMT, type=%i, ret_get=%i, errno_get=%i\n",
201 __FILE__, __LINE__, type, ret_get, errno_get);
202 if (ret_get == 0) {
203 CU_ASSERT_EQUAL(ret_get, 0);
204 CU_ASSERT_EQUAL(format.type, type);
205
206 switch (format.type) {
207 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
208 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
209 dprintf("\tformat = {.type=0x%X, .fmt.pix = { "
210 ".width=%u, "
211 ".height=%u, "
212 ".pixelformat=0x%X, "
213 ".field=%i, "
214 ".bytesperline=%i, "
215 ".sizeimage=%u, "
216 ".colorspace=%i, "
217 ".priv=0x%X "
218 " } }\n",
219 format.type,
220 format.fmt.pix.width,
221 format.fmt.pix.height,
222 format.fmt.pix.pixelformat,
223 format.fmt.pix.field,
224 format.fmt.pix.bytesperline,
225 format.fmt.pix.sizeimage,
226 format.fmt.pix.colorspace, format.fmt.pix.priv);
227 if (sizeof(format.fmt.pix) <
228 sizeof(format.fmt.raw_data)) {
229 dprintf1
230 ("\tformat = { ..., .fmt.raw_data[] = { ...");
231 for (j = sizeof(format.fmt.pix);
232 j < sizeof(format.fmt.raw_data); j++) {
233 dprintf(", 0x%x",
234 format.fmt.raw_data[j]);
235 }
236 dprintf1(" }}\n");
237 }
238
239 /* TODO: check different fields */
240 //CU_ASSERT_EQUAL(format.fmt.pix.width, ???);
241 //CU_ASSERT_EQUAL(format.fmt.pix.height, ???);
242 //CU_ASSERT_EQUAL(format.fmt.pix.pixelformat, ???);
243 CU_ASSERT(valid_pixelformat
244 (format.fmt.pix.pixelformat));
245
246 //CU_ASSERT_EQUAL(format.fmt.pix.field, ???);
247 //CU_ASSERT_EQUAL(format.fmt.pix.bytesperline, ???);
248 //CU_ASSERT_EQUAL(format.fmt.pix.sizeimage, ???);
249 //CU_ASSERT_EQUAL(format.fmt.pix.colorspace, ???);
250 CU_ASSERT(valid_colorspace(format.fmt.pix.colorspace));
251 //CU_ASSERT_EQUAL(format.fmt.pix.priv, ???);
252
253 /* Check whether the remaining bytes of rawdata is set to zero */
254 memset(&format2, 0, sizeof(format2));
255 CU_ASSERT_EQUAL(memcmp
256 (format.fmt.raw_data +
257 sizeof(format.fmt.pix),
258 format2.fmt.raw_data +
259 sizeof(format2.fmt.pix),
260 sizeof(format.fmt.raw_data) -
261 sizeof(format.fmt.pix)), 0);
262 break;
263
264 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
265 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
266 dprintf("\tformat = {.type=0x%X, .fmt.win={ "
267 ".w = { .left=%i, .top=%i, .width=%i, .height=%i, }, "
268 ".field = %i, "
269 ".chromakey = 0x%X, "
270 ".clips = %p, "
271 ".clipcount = %u, "
272 ".bitmap = %p, "
273 ".global_alpha = %u "
274 "} }\n",
275 format.type,
276 format.fmt.win.w.left,
277 format.fmt.win.w.top,
278 format.fmt.win.w.width,
279 format.fmt.win.w.height,
280 format.fmt.win.field,
281 format.fmt.win.chromakey,
282 format.fmt.win.clips,
283 format.fmt.win.clipcount,
284 format.fmt.win.bitmap,
285 format.fmt.win.global_alpha);
286 if (sizeof(format.fmt.win) <
287 sizeof(format.fmt.raw_data)) {
288 dprintf1
289 ("\tformat = { ..., .fmt.raw_data[] = { ...");
290 for (j = sizeof(format.fmt.win);
291 j < sizeof(format.fmt.raw_data); j++) {
292 dprintf(", 0x%x",
293 format.fmt.raw_data[j]);
294 }
295 dprintf1(" }}\n");
296 }
297
298 /* TODO: check different fields */
299 //CU_ASSERT_EQUAL(format.fmt.win.w.left, ???);
300 //CU_ASSERT_EQUAL(format.fmt.win.w.top, ???);
301 //CU_ASSERT_EQUAL(format.fmt.win.w.width, ???);
302 //CU_ASSERT_EQUAL(format.fmt.win.w.height, ???);
303 //CU_ASSERT_EQUAL(format.fmt.win.field, ???);
304 //CU_ASSERT_EQUAL(format.fmt.win.chromakey, ???);
305 //CU_ASSERT_EQUAL(format.fmt.win.clips, ???);
306 //CU_ASSERT_EQUAL(format.fmt.win.clipcount, ???);
307 //CU_ASSERT_EQUAL(format.fmt.win.bitmap, ???);
308 //CU_ASSERT_EQUAL(format.fmt.win.global_alpha ???);
309
310 /* Check whether the remaining bytes of raw_data is set to zero */
311 memset(&format2, 0, sizeof(format2));
312 CU_ASSERT_EQUAL(memcmp
313 (format.fmt.raw_data +
314 sizeof(format.fmt.win),
315 format2.fmt.raw_data +
316 sizeof(format2.fmt.win),
317 sizeof(format.fmt.raw_data) -
318 sizeof(format.fmt.win)), 0);
319 break;
320
321 case V4L2_BUF_TYPE_VBI_CAPTURE:
322 case V4L2_BUF_TYPE_VBI_OUTPUT:
323 dprintf("\tformat = {.type=0x%X, .fmt.vbi={ "
324 ".sampling_rate=%u, "
325 ".offset=%u, "
326 ".samples_per_line=%u "
327 ".sample_format=0x%X "
328 ".start = { %u, %u }, "
329 ".count = { %u, %u }, "
330 ".flags = 0x%X, "
331 ".reserved = { 0x%X, 0x%X } "
332 "} }\n",
333 format.type,
334 format.fmt.vbi.sampling_rate,
335 format.fmt.vbi.offset,
336 format.fmt.vbi.samples_per_line,
337 format.fmt.vbi.sample_format,
338 format.fmt.vbi.start[0],
339 format.fmt.vbi.start[1],
340 format.fmt.vbi.count[0],
341 format.fmt.vbi.count[1],
342 format.fmt.vbi.flags,
343 format.fmt.vbi.reserved[0],
344 format.fmt.vbi.reserved[1]
345 );
346 if (sizeof(format.fmt.vbi) <
347 sizeof(format.fmt.raw_data)) {
348 dprintf1
349 ("\tformat = { ..., .fmt.raw_data[] = { ...");
350 for (j = sizeof(format.fmt.vbi);
351 j < sizeof(format.fmt.raw_data); j++) {
352 dprintf(", 0x%x",
353 format.fmt.raw_data[j]);
354 }
355 dprintf1(" }}\n");
356 }
357
358 /* TODO: check different fields */
359 //CU_ASSERT_EQUAL(format.fmt.vbi.sampling_rate, ???);
360 //CU_ASSERT_EQUAL(format.fmt.vbi.offset, ???);
361 //CU_ASSERT_EQUAL(format.fmt.vbi.samples_per_line, ???);
362 //CU_ASSERT_EQUAL(format.fmt.vbi.sample_format, ???);
363 //CU_ASSERT_EQUAL(format.fmt.vbi.start[0], ???);
364 //CU_ASSERT_EQUAL(format.fmt.vbi.start[1], ???);
365 //CU_ASSERT_EQUAL(format.fmt.vbi.count[0], ???);
366 //CU_ASSERT_EQUAL(format.fmt.vbi.count[1], ???);
367 //CU_ASSERT_EQUAL(format.fmt.vbi.flags, ???);
368 CU_ASSERT_EQUAL(format.fmt.vbi.reserved[0], 0);
369 CU_ASSERT_EQUAL(format.fmt.vbi.reserved[1], 0);
370
371 /* Check whether the remaining bytes of raw_data is set to zero */
372 memset(&format2, 0, sizeof(format2));
373 CU_ASSERT_EQUAL(memcmp
374 (format.fmt.raw_data +
375 sizeof(format.fmt.vbi),
376 format2.fmt.raw_data +
377 sizeof(format2.fmt.vbi),
378 sizeof(format.fmt.raw_data) -
379 sizeof(format.fmt.vbi)), 0);
380 break;
381
382 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
383 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
384 dprintf("\tformat = {.type=0x%X, "
385 ".fmt.sliced = { .service_set = 0x%X, "
386 ".service_lines = { ... }, "
387 ".io_size = %u, "
388 ".reserved[0] = 0x%X, "
389 ".reserved[1] = 0x%X "
390 "} }\n",
391 format.type, format.fmt.sliced.service_set,
392 //format.fmt.sliced.service_lines[][],
393 format.fmt.sliced.io_size,
394 format.fmt.sliced.reserved[0],
395 format.fmt.sliced.reserved[1]
396 );
397 if (sizeof(format.fmt.sliced) <
398 sizeof(format.fmt.raw_data)) {
399 dprintf1
400 ("\tformat = { ..., .fmt.raw_data[] = { ...");
401 for (j = sizeof(format.fmt.sliced);
402 j < sizeof(format.fmt.raw_data); j++) {
403 dprintf(", 0x%x",
404 format.fmt.raw_data[j]);
405 }
406 dprintf1(" }}\n");
407 }
408
409 /* TODO: check different fields */
410 //CU_ASSERT_EQUAL(format.fmt.sliced.service_set, ???);
411 CU_ASSERT_EQUAL(format.fmt.sliced.service_lines[0][0],
412 0);
413 //CU_ASSERT_EQUAL(format.fmt.sliced.service_lines[0][1], ???);
414 //CU_ASSERT_EQUAL(format.fmt.sliced.service_lines[0][2], ???);
415 //CU_ASSERT_EQUAL(format.fmt.sliced.service_lines[0][3], ???);
416 //CU_ASSERT_EQUAL(format.fmt.sliced.service_lines[0][4], ???);
417 //CU_ASSERT_EQUAL(format.fmt.sliced.service_lines[0][5], ???);
418 //CU_ASSERT_EQUAL(format.fmt.sliced.service_lines[0][6], ???);
419 //CU_ASSERT_EQUAL(format.fmt.sliced.service_lines[0][7], ???);
420 //CU_ASSERT_EQUAL(format.fmt.sliced.service_lines[0][8], ???);
421 //CU_ASSERT_EQUAL(format.fmt.sliced.service_lines[0][9], ???);
422 //CU_ASSERT_EQUAL(format.fmt.sliced.service_lines[0][10], ???);
423 //CU_ASSERT_EQUAL(format.fmt.sliced.service_lines[0][11], ???);
424 //CU_ASSERT_EQUAL(format.fmt.sliced.service_lines[0][12], ???);
425 //CU_ASSERT_EQUAL(format.fmt.sliced.service_lines[0][13], ???);
426 //CU_ASSERT_EQUAL(format.fmt.sliced.service_lines[0][14], ???);
427 //CU_ASSERT_EQUAL(format.fmt.sliced.service_lines[0][15], ???);
428 //CU_ASSERT_EQUAL(format.fmt.sliced.service_lines[0][16], ???);
429 //CU_ASSERT_EQUAL(format.fmt.sliced.service_lines[0][17], ???);
430 //CU_ASSERT_EQUAL(format.fmt.sliced.service_lines[0][18], ???);
431 //CU_ASSERT_EQUAL(format.fmt.sliced.service_lines[0][19], ???);
432 //CU_ASSERT_EQUAL(format.fmt.sliced.service_lines[0][20], ???);
433 //CU_ASSERT_EQUAL(format.fmt.sliced.service_lines[0][21], ???);
434 //CU_ASSERT_EQUAL(format.fmt.sliced.service_lines[0][22], ???);
435 //CU_ASSERT_EQUAL(format.fmt.sliced.service_lines[0][23], ???);
436 CU_ASSERT_EQUAL(format.fmt.sliced.service_lines[1][0],
437 0);
438 //CU_ASSERT_EQUAL(format.fmt.sliced.service_lines[1][1], ???);
439 //CU_ASSERT_EQUAL(format.fmt.sliced.service_lines[1][2], ???);
440 //CU_ASSERT_EQUAL(format.fmt.sliced.service_lines[1][3], ???);
441 //CU_ASSERT_EQUAL(format.fmt.sliced.service_lines[1][4], ???);
442 //CU_ASSERT_EQUAL(format.fmt.sliced.service_lines[1][5], ???);
443 //CU_ASSERT_EQUAL(format.fmt.sliced.service_lines[1][6], ???);
444 //CU_ASSERT_EQUAL(format.fmt.sliced.service_lines[1][7], ???);
445 //CU_ASSERT_EQUAL(format.fmt.sliced.service_lines[1][8], ???);
446 //CU_ASSERT_EQUAL(format.fmt.sliced.service_lines[1][9], ???);
447 //CU_ASSERT_EQUAL(format.fmt.sliced.service_lines[1][10], ???);
448 //CU_ASSERT_EQUAL(format.fmt.sliced.service_lines[1][11], ???);
449 //CU_ASSERT_EQUAL(format.fmt.sliced.service_lines[1][12], ???);
450 //CU_ASSERT_EQUAL(format.fmt.sliced.service_lines[1][13], ???);
451 //CU_ASSERT_EQUAL(format.fmt.sliced.service_lines[1][14], ???);
452 //CU_ASSERT_EQUAL(format.fmt.sliced.service_lines[1][15], ???);
453 //CU_ASSERT_EQUAL(format.fmt.sliced.service_lines[1][16], ???);
454 //CU_ASSERT_EQUAL(format.fmt.sliced.service_lines[1][17], ???);
455 //CU_ASSERT_EQUAL(format.fmt.sliced.service_lines[1][18], ???);
456 //CU_ASSERT_EQUAL(format.fmt.sliced.service_lines[1][19], ???);
457 //CU_ASSERT_EQUAL(format.fmt.sliced.service_lines[1][20], ???);
458 //CU_ASSERT_EQUAL(format.fmt.sliced.service_lines[1][21], ???);
459 //CU_ASSERT_EQUAL(format.fmt.sliced.service_lines[1][22], ???);
460 //CU_ASSERT_EQUAL(format.fmt.sliced.service_lines[1][23], ???);
461 //CU_ASSERT_EQUAL(format.fmt.sliced.io_size, ???);
462 CU_ASSERT_EQUAL(format.fmt.sliced.reserved[0], 0);
463 CU_ASSERT_EQUAL(format.fmt.sliced.reserved[1], 0);
464
465 /* Check whether the remaining bytes of raw_data is set to zero */
466 memset(&format2, 0, sizeof(format2));
467 CU_ASSERT_EQUAL(memcmp
468 (format.fmt.raw_data +
469 sizeof(format.fmt.sliced),
470 format2.fmt.raw_data +
471 sizeof(format2.fmt.sliced),
472 sizeof(format.fmt.raw_data) -
473 sizeof(format.fmt.sliced)), 0);
474 break;
475
476 case V4L2_BUF_TYPE_PRIVATE:
477 dprintf("\tformat = {.type=0x%X, ... }\n", format.type);
478 /* TODO: check different fields */
479 }
480
481 } else {
482 CU_ASSERT_EQUAL(ret_get, -1);
483 CU_ASSERT_EQUAL(errno_get, EINVAL);
484
485 memset(&format2, 0xff, sizeof(format2));
486 format2.type = type;
487 CU_ASSERT_EQUAL(memcmp(&format, &format2, sizeof(format)), 0);
488
489 }
490
491 }
492
test_VIDIOC_G_FMT()493 void test_VIDIOC_G_FMT()
494 {
495 do_get_formats(V4L2_BUF_TYPE_VIDEO_CAPTURE);
496 do_get_formats(V4L2_BUF_TYPE_VIDEO_OUTPUT);
497 do_get_formats(V4L2_BUF_TYPE_VIDEO_OVERLAY);
498 do_get_formats(V4L2_BUF_TYPE_VBI_CAPTURE);
499 do_get_formats(V4L2_BUF_TYPE_VBI_OUTPUT);
500 do_get_formats(V4L2_BUF_TYPE_SLICED_VBI_CAPTURE);
501 do_get_formats(V4L2_BUF_TYPE_SLICED_VBI_OUTPUT);
502 do_get_formats(V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY);
503 do_get_formats(V4L2_BUF_TYPE_PRIVATE);
504 }
505
do_get_format_invalid(enum v4l2_buf_type type)506 static void do_get_format_invalid(enum v4l2_buf_type type)
507 {
508 int ret_get, errno_get;
509 struct v4l2_format format;
510 struct v4l2_format format2;
511
512 memset(&format, 0xff, sizeof(format));
513 format.type = type;
514 ret_get = ioctl(get_video_fd(), VIDIOC_G_FMT, &format);
515 errno_get = errno;
516
517 dprintf("\t%s:%u: VIDIOC_G_FMT, type=%i, ret_get=%i, errno_get=%i\n",
518 __FILE__, __LINE__, type, ret_get, errno_get);
519
520 CU_ASSERT_EQUAL(ret_get, -1);
521 CU_ASSERT_EQUAL(errno_get, EINVAL);
522
523 /* Check whether the original format struct is untouched */
524 memset(&format2, 0xff, sizeof(format2));
525 format2.type = type;
526 CU_ASSERT_EQUAL(memcmp(&format, &format2, sizeof(format)), 0);
527 }
528
test_VIDIOC_G_FMT_invalid_type()529 void test_VIDIOC_G_FMT_invalid_type()
530 {
531 int i;
532
533 /* In this test case the .index is valid (0) and only the .type
534 * is invalid. The .type filed is an enum which is stored in an 'int'.
535 */
536
537 /* test invalid .type=0 */
538 do_get_format_invalid(0);
539
540 /* test invalid .type=SINT_MIN */
541 do_get_format_invalid(SINT_MIN);
542
543 /* test invalid .type=-1 */
544 do_get_format_invalid(-1);
545
546 /* test invalid .type= 8..0x7F */
547 for (i = V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY + 1;
548 i < V4L2_BUF_TYPE_PRIVATE; i++) {
549 do_get_format_invalid(i);
550 }
551
552 /* .type = 0x80..0x7FFF FFFF is the private range */
553
554 /* Assume that 0x7FFF FFFF is invalid in the private range.
555 * This might be a wrong assumption, but let's have a test case like
556 * this for now.
557 */
558 do_get_format_invalid(SINT_MAX);
559
560 }
561
test_VIDIOC_G_FMT_NULL()562 void test_VIDIOC_G_FMT_NULL()
563 {
564 int ret_capture, errno_capture;
565 int ret_output, errno_output;
566 int ret_video_overlay, errno_video_overlay;
567 int ret_vbi_capture, errno_vbi_capture;
568 int ret_vbi_output, errno_vbi_output;
569 int ret_sliced_vbi_capture, errno_sliced_vbi_capture;
570 int ret_sliced_vbi_output, errno_sliced_vbi_output;
571 int ret_video_output_overlay, errno_video_output_overlay;
572 int ret_private, errno_private;
573 int ret_null, errno_null;
574 struct v4l2_format format;
575 enum v4l2_buf_type type;
576
577 type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
578 memset(&format, 0xff, sizeof(format));
579 format.type = type;
580 ret_capture = ioctl(get_video_fd(), VIDIOC_G_FMT, &format);
581 errno_capture = errno;
582
583 dprintf
584 ("\t%s:%u: VIDIOC_G_FMT, type=%i, ret_capture=%i, errno_capture=%i\n",
585 __FILE__, __LINE__, type, ret_capture, errno_capture);
586
587 type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
588 memset(&format, 0xff, sizeof(format));
589 format.type = type;
590 ret_output = ioctl(get_video_fd(), VIDIOC_G_FMT, &format);
591 errno_output = errno;
592
593 dprintf
594 ("\t%s:%u: VIDIOC_G_FMT, type=%i, ret_output=%i, errno_output=%i\n",
595 __FILE__, __LINE__, type, ret_output, errno_output);
596
597 type = V4L2_BUF_TYPE_VIDEO_OVERLAY;
598 memset(&format, 0xff, sizeof(format));
599 format.type = type;
600 ret_video_overlay = ioctl(get_video_fd(), VIDIOC_G_FMT, &format);
601 errno_video_overlay = errno;
602
603 dprintf
604 ("\t%s:%u: VIDIOC_G_FMT, type=%i, ret_video_overlay=%i, errno_video_overlay=%i\n",
605 __FILE__, __LINE__, type, ret_video_overlay, errno_video_overlay);
606
607 type = V4L2_BUF_TYPE_VBI_CAPTURE;
608 memset(&format, 0xff, sizeof(format));
609 format.type = type;
610 ret_vbi_capture = ioctl(get_video_fd(), VIDIOC_G_FMT, &format);
611 errno_vbi_capture = errno;
612
613 dprintf
614 ("\t%s:%u: VIDIOC_G_FMT, type=%i, ret_vbi_capture=%i, errno_vbi_capture=%i\n",
615 __FILE__, __LINE__, type, ret_vbi_capture, errno_vbi_capture);
616
617 type = V4L2_BUF_TYPE_VBI_OUTPUT;
618 memset(&format, 0xff, sizeof(format));
619 format.type = type;
620 ret_vbi_output = ioctl(get_video_fd(), VIDIOC_G_FMT, &format);
621 errno_vbi_output = errno;
622
623 dprintf
624 ("\t%s:%u: VIDIOC_G_FMT, type=%i, ret_vbi_output=%i, errno_vbi_output=%i\n",
625 __FILE__, __LINE__, type, ret_vbi_output, errno_vbi_output);
626
627 type = V4L2_BUF_TYPE_SLICED_VBI_CAPTURE;
628 memset(&format, 0xff, sizeof(format));
629 format.type = type;
630 ret_sliced_vbi_capture = ioctl(get_video_fd(), VIDIOC_G_FMT, &format);
631 errno_sliced_vbi_capture = errno;
632
633 dprintf
634 ("\t%s:%u: VIDIOC_G_FMT, type=%i, ret_sliced_vbi_capture=%i, errno_sliced_vbi_capture=%i\n",
635 __FILE__, __LINE__, type, ret_sliced_vbi_capture,
636 errno_sliced_vbi_capture);
637
638 type = V4L2_BUF_TYPE_SLICED_VBI_OUTPUT;
639 memset(&format, 0xff, sizeof(format));
640 format.type = type;
641 ret_sliced_vbi_output = ioctl(get_video_fd(), VIDIOC_G_FMT, &format);
642 errno_sliced_vbi_output = errno;
643
644 dprintf
645 ("\t%s:%u: VIDIOC_G_FMT, type=%i, ret_sliced_vbi_output=%i, errno_sliced_vbi_output=%i\n",
646 __FILE__, __LINE__, type, ret_sliced_vbi_output,
647 errno_sliced_vbi_output);
648
649 type = V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY;
650 memset(&format, 0xff, sizeof(format));
651 format.type = type;
652 ret_video_output_overlay = ioctl(get_video_fd(), VIDIOC_G_FMT, &format);
653 errno_video_output_overlay = errno;
654
655 dprintf
656 ("\t%s:%u: VIDIOC_G_FMT, type=%i, ret_video_output_overlay=%i, errno_video_output_overlay=%i\n",
657 __FILE__, __LINE__, type, ret_video_output_overlay,
658 errno_video_output_overlay);
659
660 type = V4L2_BUF_TYPE_PRIVATE;
661 memset(&format, 0xff, sizeof(format));
662 format.type = type;
663 ret_private = ioctl(get_video_fd(), VIDIOC_G_FMT, &format);
664 errno_private = errno;
665
666 dprintf
667 ("\t%s:%u: VIDIOC_G_FMT, type=%i, ret_private=%i, errno_private=%i\n",
668 __FILE__, __LINE__, type, ret_private, errno_private);
669
670 ret_null = ioctl(get_video_fd(), VIDIOC_G_FMT, NULL);
671 errno_null = errno;
672
673 dprintf("\t%s:%u: VIDIOC_G_FMT, ret_null=%i, errno_null=%i\n",
674 __FILE__, __LINE__, ret_null, errno_null);
675
676 if (ret_capture == 0 || ret_output == 0 ||
677 ret_video_overlay == 0 || ret_vbi_capture == 0 ||
678 ret_vbi_output == 0 || ret_sliced_vbi_capture == 0 ||
679 ret_sliced_vbi_output == 0 || ret_video_output_overlay == 0 ||
680 ret_private == 0) {
681 CU_ASSERT_EQUAL(ret_null, -1);
682 CU_ASSERT_EQUAL(errno_null, EFAULT);
683 } else {
684 CU_ASSERT_EQUAL(ret_capture, -1);
685 CU_ASSERT_EQUAL(errno_null, EINVAL);
686 CU_ASSERT_EQUAL(ret_output, -1);
687 CU_ASSERT_EQUAL(errno_output, EINVAL);
688 CU_ASSERT_EQUAL(ret_video_overlay, -1);
689 CU_ASSERT_EQUAL(errno_video_overlay, EINVAL);
690 CU_ASSERT_EQUAL(ret_vbi_capture, -1);
691 CU_ASSERT_EQUAL(errno_vbi_capture, EINVAL);
692 CU_ASSERT_EQUAL(ret_vbi_output, -1);
693 CU_ASSERT_EQUAL(errno_vbi_output, EINVAL);
694 CU_ASSERT_EQUAL(ret_sliced_vbi_capture, -1);
695 CU_ASSERT_EQUAL(errno_sliced_vbi_capture, EINVAL);
696 CU_ASSERT_EQUAL(ret_sliced_vbi_output, -1);
697 CU_ASSERT_EQUAL(errno_sliced_vbi_output, EINVAL);
698 CU_ASSERT_EQUAL(ret_video_output_overlay, -1);
699 CU_ASSERT_EQUAL(errno_video_output_overlay, EINVAL);
700 CU_ASSERT_EQUAL(ret_private, -1);
701 CU_ASSERT_EQUAL(errno_private, EINVAL);
702 CU_ASSERT_EQUAL(ret_null, -1);
703 CU_ASSERT_EQUAL(errno_null, EINVAL);
704 }
705
706 }
707
do_set_formats_enum(enum v4l2_buf_type type)708 static void do_set_formats_enum(enum v4l2_buf_type type)
709 {
710 int ret_get, errno_get;
711 int ret_enum, errno_enum;
712 int ret_max, errno_max;
713 int ret_min, errno_min;
714 int ret_set, errno_set;
715 struct v4l2_format format_orig;
716 struct v4l2_format format_min;
717 struct v4l2_format format_max;
718 struct v4l2_format format_set;
719 struct v4l2_format format2;
720 struct v4l2_fmtdesc fmtdesc;
721 __u32 i;
722 unsigned int j;
723
724 memset(&format_orig, 0xff, sizeof(format_orig));
725 format_orig.type = type;
726
727 ret_get = ioctl(get_video_fd(), VIDIOC_G_FMT, &format_orig);
728 errno_get = errno;
729
730 dprintf("\t%s:%u: VIDIOC_G_FMT, type=%i, ret_get=%i, errno_get=%i\n",
731 __FILE__, __LINE__, type, ret_get, errno_get);
732
733 i = 0;
734 do {
735 memset(&fmtdesc, 0, sizeof(fmtdesc));
736 fmtdesc.index = i;
737 fmtdesc.type = type;
738
739 ret_enum = ioctl(get_video_fd(), VIDIOC_ENUM_FMT, &fmtdesc);
740 errno_enum = errno;
741
742 dprintf
743 ("\t%s:%u: VIDIOC_ENUM_FMT, index=%u, type=%i, ret_enum=%i, errno_enum=%i\n",
744 __FILE__, __LINE__, i, type, ret_enum, errno_enum);
745
746 switch (type) {
747 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
748 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
749 memset(&format_max, 0xff, sizeof(format_max));
750 format_max.type = type;
751 format_max.fmt.pix.pixelformat = fmtdesc.pixelformat;
752 format_max.fmt.pix.field = V4L2_FIELD_ANY;
753
754 ret_max =
755 ioctl(get_video_fd(), VIDIOC_S_FMT, &format_max);
756 errno_max = errno;
757
758 dprintf
759 ("\t%s:%u: VIDIOC_S_FMT, type=%i, ret_max=%i, errno_max=%i\n",
760 __FILE__, __LINE__, type, ret_max, errno_max);
761
762 if (ret_max == 0) {
763 CU_ASSERT_EQUAL(ret_enum, 0);
764
765 dprintf
766 ("\tformat_max = {.type=0x%X, .fmt.pix = { "
767 ".width=%u, " ".height=%u, "
768 ".pixelformat=0x%X, " ".field=%i, "
769 ".bytesperline=%i, " ".sizeimage=%u, "
770 ".colorspace=%i, " ".priv=0x%X " "} }\n",
771 format_max.type, format_max.fmt.pix.width,
772 format_max.fmt.pix.height,
773 format_max.fmt.pix.pixelformat,
774 format_max.fmt.pix.field,
775 format_max.fmt.pix.bytesperline,
776 format_max.fmt.pix.sizeimage,
777 format_max.fmt.pix.colorspace,
778 format_max.fmt.pix.priv);
779 if (sizeof(format_max.fmt.pix) <
780 sizeof(format_max.fmt.raw_data)) {
781 dprintf1
782 ("\tformat_max = { ..., .fmt.raw_data[] = { ...");
783 for (j = sizeof(format_max.fmt.pix);
784 j <
785 sizeof(format_max.fmt.raw_data);
786 j++) {
787 dprintf(", 0x%x",
788 format_max.fmt.
789 raw_data[j]);
790 }
791 dprintf1(" }}\n");
792 }
793
794 CU_ASSERT_EQUAL(ret_max, 0);
795 CU_ASSERT(valid_pixelformat
796 (format_max.fmt.pix.pixelformat));
797 CU_ASSERT_EQUAL(format_max.fmt.pix.pixelformat,
798 fmtdesc.pixelformat);
799 CU_ASSERT(0 < format_max.fmt.pix.width);
800 CU_ASSERT(0 < format_max.fmt.pix.height);
801 CU_ASSERT_NOT_EQUAL(format_max.fmt.pix.field,
802 V4L2_FIELD_ANY);
803 CU_ASSERT(0 < format_max.fmt.pix.bytesperline);
804 CU_ASSERT(0 < format_max.fmt.pix.sizeimage);
805 CU_ASSERT(valid_colorspace
806 (format_max.fmt.pix.colorspace));
807 //CU_ASSERT_EQUAL(format_max.fmt.pix.priv, ???);
808
809 /* Check whether the remaining bytes of rawdata is set to zero */
810 memset(&format2, 0, sizeof(format2));
811 CU_ASSERT_EQUAL(memcmp
812 (format_max.fmt.raw_data +
813 sizeof(format_max.fmt.pix),
814 format2.fmt.raw_data +
815 sizeof(format2.fmt.pix),
816 sizeof(format_max.fmt.
817 raw_data) -
818 sizeof(format_max.fmt.pix)),
819 0);
820
821 } else {
822 CU_ASSERT_EQUAL(ret_max, -1);
823 CU_ASSERT_EQUAL(errno_max, EINVAL);
824 }
825
826 memset(&format_min, 0, sizeof(format_min));
827 format_min.type = type;
828 format_min.fmt.pix.pixelformat = fmtdesc.pixelformat;
829 format_min.fmt.pix.field = V4L2_FIELD_ANY;
830
831 ret_min =
832 ioctl(get_video_fd(), VIDIOC_S_FMT, &format_min);
833 errno_min = errno;
834
835 dprintf
836 ("\t%s:%u: VIDIOC_S_FMT, type=%i, ret_min=%i, errno_min=%i\n",
837 __FILE__, __LINE__, type, ret_min, errno_min);
838
839 if (ret_min == 0) {
840 CU_ASSERT_EQUAL(ret_enum, 0);
841
842 dprintf
843 ("\tformat_min = {.type=0x%X, .fmt.pix = { "
844 ".width=%u, " ".height=%u, "
845 ".pixelformat=0x%X, " ".field=%i, "
846 ".bytesperline=%i, " ".sizeimage=%u, "
847 ".colorspace=%i, " ".priv=0x%X " "} }\n",
848 format_min.type, format_min.fmt.pix.width,
849 format_min.fmt.pix.height,
850 format_min.fmt.pix.pixelformat,
851 format_min.fmt.pix.field,
852 format_min.fmt.pix.bytesperline,
853 format_min.fmt.pix.sizeimage,
854 format_min.fmt.pix.colorspace,
855 format_min.fmt.pix.priv);
856 if (sizeof(format_min.fmt.pix) <
857 sizeof(format_min.fmt.raw_data)) {
858 dprintf1
859 ("\tformat_min = { ..., .fmt.raw_data[] = { ...");
860 for (j = sizeof(format_min.fmt.pix);
861 j <
862 sizeof(format_min.fmt.raw_data);
863 j++) {
864 dprintf(", 0x%x",
865 format_min.fmt.
866 raw_data[j]);
867 }
868 dprintf1(" }}\n");
869 }
870
871 CU_ASSERT_EQUAL(ret_min, 0);
872 CU_ASSERT(valid_pixelformat
873 (format_min.fmt.pix.pixelformat));
874 CU_ASSERT_EQUAL(format_min.fmt.pix.pixelformat,
875 fmtdesc.pixelformat);
876 CU_ASSERT(0 < format_min.fmt.pix.width);
877 CU_ASSERT(0 < format_min.fmt.pix.height);
878 CU_ASSERT_NOT_EQUAL(format_min.fmt.pix.field,
879 V4L2_FIELD_ANY);
880 CU_ASSERT(0 < format_min.fmt.pix.bytesperline);
881 CU_ASSERT(0 < format_min.fmt.pix.sizeimage);
882 CU_ASSERT(valid_colorspace
883 (format_min.fmt.pix.colorspace));
884 //CU_ASSERT_EQUAL(format_min.fmt.pix.priv, ???);
885
886 /* Check whether the remaining bytes of rawdata is set to zero */
887 memset(&format2, 0, sizeof(format2));
888 CU_ASSERT_EQUAL(memcmp
889 (format_min.fmt.raw_data +
890 sizeof(format_min.fmt.pix),
891 format2.fmt.raw_data +
892 sizeof(format2.fmt.pix),
893 sizeof(format_min.fmt.
894 raw_data) -
895 sizeof(format_min.fmt.pix)),
896 0);
897 } else {
898 CU_ASSERT_EQUAL(ret_min, -1);
899 CU_ASSERT_EQUAL(errno_min, EINVAL);
900 }
901
902 if (ret_max == 0 && ret_min == 0) {
903 CU_ASSERT(format_min.fmt.pix.width <=
904 format_max.fmt.pix.width);
905 CU_ASSERT(format_min.fmt.pix.height <=
906 format_max.fmt.pix.height);
907 CU_ASSERT_EQUAL(format_min.fmt.pix.colorspace,
908 format_max.fmt.pix.colorspace);
909
910 /* If priv equals zero then this field is not used and shall
911 * be set to zero each case. Otherwise it can have any driver
912 * specific value which cannot be checked here.
913 */
914 if (format_min.fmt.pix.priv == 0) {
915 CU_ASSERT_EQUAL(format_min.fmt.pix.priv,
916 0);
917 CU_ASSERT_EQUAL(format_max.fmt.pix.priv,
918 0);
919 }
920 }
921
922 if (ret_max == -1 && ret_min == -1) {
923 CU_ASSERT_EQUAL(ret_enum, -1);
924 CU_ASSERT_EQUAL(errno_enum, EINVAL);
925 }
926
927 break;
928
929 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
930 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
931 memset(&format_max, 0xff, sizeof(format_max));
932 format_max.type = type;
933
934 ret_max =
935 ioctl(get_video_fd(), VIDIOC_S_FMT, &format_max);
936 errno_max = errno;
937
938 dprintf
939 ("\t%s:%u: VIDIOC_S_FMT, type=%i, ret_max=%i, errno_max=%i\n",
940 __FILE__, __LINE__, type, ret_max, errno_max);
941
942 if (ret_max == 0) {
943 CU_ASSERT_EQUAL(ret_enum, 0);
944
945 dprintf
946 ("\tformat_max = {.type=0x%X, .fmt.win={ "
947 ".w = { .left=%i, .top=%i, .width=%i, .height=%i, }, "
948 ".field = %i, " ".chromakey = 0x%X, "
949 ".clips = %p, " ".clipcount = %u, "
950 ".bitmap = %p, " ".global_alpha = %u "
951 "} }\n", format_max.type,
952 format_max.fmt.win.w.left,
953 format_max.fmt.win.w.top,
954 format_max.fmt.win.w.width,
955 format_max.fmt.win.w.height,
956 format_max.fmt.win.field,
957 format_max.fmt.win.chromakey,
958 format_max.fmt.win.clips,
959 format_max.fmt.win.clipcount,
960 format_max.fmt.win.bitmap,
961 format_max.fmt.win.global_alpha);
962 if (sizeof(format_max.fmt.win) <
963 sizeof(format_max.fmt.raw_data)) {
964 dprintf1
965 ("\tformat_max = { ..., .fmt.raw_data[] = { ...");
966 for (j = sizeof(format_max.fmt.win);
967 j <
968 sizeof(format_max.fmt.raw_data);
969 j++) {
970 dprintf(", 0x%x",
971 format_max.fmt.
972 raw_data[j]);
973 }
974 dprintf1(" }}\n");
975 }
976
977 /* TODO: check the different fields */
978 //CU_ASSERT_EQUAL(format.fmt.win.w.left, ???);
979 //CU_ASSERT_EQUAL(format.fmt.win.w.top, ???);
980 //CU_ASSERT_EQUAL(format.fmt.win.w.width, ???);
981 //CU_ASSERT_EQUAL(format.fmt.win.w.height, ???);
982 //CU_ASSERT_EQUAL(format.fmt.win.field, ???);
983 //CU_ASSERT_EQUAL(format.fmt.win.chromakey, ???);
984 //CU_ASSERT_EQUAL(format.fmt.win.clips, ???);
985 //CU_ASSERT_EQUAL(format.fmt.win.clipcount, ???);
986 //CU_ASSERT_EQUAL(format.fmt.win.bitmap, ???);
987 //CU_ASSERT_EQUAL(format.fmt.win.global_alpha ???);
988 } else {
989 CU_ASSERT_EQUAL(ret_max, -1);
990 CU_ASSERT_EQUAL(errno_max, EINVAL);
991 }
992
993 memset(&format_min, 0, sizeof(format_min));
994 format_min.type = type;
995 format_min.fmt.pix.pixelformat = fmtdesc.pixelformat;
996
997 ret_min =
998 ioctl(get_video_fd(), VIDIOC_S_FMT, &format_min);
999 errno_min = errno;
1000
1001 dprintf
1002 ("\t%s:%u: VIDIOC_S_FMT, type=%i, ret_min=%i, errno_min=%i\n",
1003 __FILE__, __LINE__, type, ret_min, errno_min);
1004
1005 if (ret_min == 0) {
1006 CU_ASSERT_EQUAL(ret_enum, 0);
1007 dprintf
1008 ("\tformat_min = {.type=0x%X, .fmt.win={ "
1009 ".w = { .left=%i, .top=%i, .width=%i, .height=%i, }, "
1010 ".field = %i, " ".chromakey = 0x%X, "
1011 ".clips = %p, " ".clipcount = %u, "
1012 ".bitmap = %p, " ".global_alpha = %u "
1013 "} }\n", format_min.type,
1014 format_min.fmt.win.w.left,
1015 format_min.fmt.win.w.top,
1016 format_min.fmt.win.w.width,
1017 format_min.fmt.win.w.height,
1018 format_min.fmt.win.field,
1019 format_min.fmt.win.chromakey,
1020 format_min.fmt.win.clips,
1021 format_min.fmt.win.clipcount,
1022 format_min.fmt.win.bitmap,
1023 format_min.fmt.win.global_alpha);
1024 if (sizeof(format_min.fmt.win) <
1025 sizeof(format_min.fmt.raw_data)) {
1026 dprintf1
1027 ("\tformat_min = { ..., .fmt.raw_data[] = { ...");
1028 for (j = sizeof(format_min.fmt.win);
1029 j <
1030 sizeof(format_min.fmt.raw_data);
1031 j++) {
1032 dprintf(", 0x%x",
1033 format_min.fmt.
1034 raw_data[j]);
1035 }
1036 dprintf1(" }}\n");
1037 }
1038
1039 /* TODO: check the different fields */
1040 //CU_ASSERT_EQUAL(format.fmt.win.w.left, ???);
1041 //CU_ASSERT_EQUAL(format.fmt.win.w.top, ???);
1042 //CU_ASSERT_EQUAL(format.fmt.win.w.width, ???);
1043 //CU_ASSERT_EQUAL(format.fmt.win.w.height, ???);
1044 //CU_ASSERT_EQUAL(format.fmt.win.field, ???);
1045 //CU_ASSERT_EQUAL(format.fmt.win.chromakey, ???);
1046 //CU_ASSERT_EQUAL(format.fmt.win.clips, ???);
1047 //CU_ASSERT_EQUAL(format.fmt.win.clipcount, ???);
1048 //CU_ASSERT_EQUAL(format.fmt.win.bitmap, ???);
1049 //CU_ASSERT_EQUAL(format.fmt.win.global_alpha ???);
1050
1051 } else {
1052 CU_ASSERT_EQUAL(ret_min, -1);
1053 CU_ASSERT_EQUAL(errno_min, EINVAL);
1054 }
1055
1056 if (ret_max == -1 && ret_min == -1) {
1057 CU_ASSERT_EQUAL(ret_enum, -1);
1058 CU_ASSERT_EQUAL(errno_enum, EINVAL);
1059 }
1060 break;
1061
1062 case V4L2_BUF_TYPE_VBI_CAPTURE:
1063 case V4L2_BUF_TYPE_VBI_OUTPUT:
1064 memset(&format_max, 0xff, sizeof(format_max));
1065 format_max.type = type;
1066
1067 ret_max =
1068 ioctl(get_video_fd(), VIDIOC_S_FMT, &format_max);
1069 errno_max = errno;
1070
1071 dprintf
1072 ("\t%s:%u: VIDIOC_S_FMT, type=%i, ret_max=%i, errno_max=%i\n",
1073 __FILE__, __LINE__, type, ret_max, errno_max);
1074
1075 if (ret_max == 0) {
1076 CU_ASSERT_EQUAL(ret_enum, 0);
1077 dprintf
1078 ("\tformat_max = {.type=0x%X, .fmt.vbi={ "
1079 ".sampling_rate=%u, " ".offset=%u, "
1080 ".samples_per_line=%u "
1081 ".sample_format=0x%X "
1082 ".start = { %u, %u }, "
1083 ".count = { %u, %u }, " ".flags = 0x%X, "
1084 ".reserved = { 0x%X, 0x%X } " "} }\n",
1085 format_max.type,
1086 format_max.fmt.vbi.sampling_rate,
1087 format_max.fmt.vbi.offset,
1088 format_max.fmt.vbi.samples_per_line,
1089 format_max.fmt.vbi.sample_format,
1090 format_max.fmt.vbi.start[0],
1091 format_max.fmt.vbi.start[1],
1092 format_max.fmt.vbi.count[0],
1093 format_max.fmt.vbi.count[1],
1094 format_max.fmt.vbi.flags,
1095 format_max.fmt.vbi.reserved[0],
1096 format_max.fmt.vbi.reserved[1]
1097 );
1098 if (sizeof(format_max.fmt.vbi) <
1099 sizeof(format_max.fmt.raw_data)) {
1100 dprintf1
1101 ("\tformat_max = { ..., .fmt.raw_data[] = { ...");
1102 for (j = sizeof(format_max.fmt.vbi);
1103 j <
1104 sizeof(format_max.fmt.raw_data);
1105 j++) {
1106 dprintf(", 0x%x",
1107 format_max.fmt.
1108 raw_data[j]);
1109 }
1110 dprintf1(" }}\n");
1111 }
1112
1113 /* TODO: check the different fields */
1114 //CU_ASSERT_EQUAL(format_max.fmt.vbi.sampling_rate, ???);
1115 //CU_ASSERT_EQUAL(format_max.fmt.vbi.offset, ???);
1116 //CU_ASSERT_EQUAL(format_max.fmt.vbi.samples_per_line, ???);
1117 //CU_ASSERT_EQUAL(format_max.fmt.vbi.sample_format, ???);
1118 //CU_ASSERT_EQUAL(format_max.fmt.vbi.start[0], ???);
1119 //CU_ASSERT_EQUAL(format_max.fmt.vbi.start[1], ???);
1120 //CU_ASSERT_EQUAL(format_max.fmt.vbi.count[0], ???);
1121 //CU_ASSERT_EQUAL(format_max.fmt.vbi.count[1], ???);
1122 //CU_ASSERT_EQUAL(format_max.fmt.vbi.flags, ???);
1123 CU_ASSERT_EQUAL(format_max.fmt.vbi.reserved[0],
1124 0);
1125 CU_ASSERT_EQUAL(format_max.fmt.vbi.reserved[1],
1126 0);
1127
1128 } else {
1129 CU_ASSERT_EQUAL(ret_max, -1);
1130 CU_ASSERT_EQUAL(errno_max, EINVAL);
1131 }
1132
1133 memset(&format_min, 0, sizeof(format_min));
1134 format_min.type = type;
1135 format_min.fmt.pix.pixelformat = fmtdesc.pixelformat;
1136
1137 ret_min =
1138 ioctl(get_video_fd(), VIDIOC_S_FMT, &format_min);
1139 errno_min = errno;
1140
1141 dprintf
1142 ("\t%s:%u: VIDIOC_S_FMT, type=%i, ret_min=%i, errno_min=%i\n",
1143 __FILE__, __LINE__, type, ret_min, errno_min);
1144
1145 if (ret_min == 0) {
1146 CU_ASSERT_EQUAL(ret_enum, 0);
1147 dprintf
1148 ("\tformat_min = {.type=0x%X, .fmt.vbi={ "
1149 ".sampling_rate=%u, " ".offset=%u, "
1150 ".samples_per_line=%u "
1151 ".sample_format=0x%X "
1152 ".start = { %u, %u }, "
1153 ".count = { %u, %u }, " ".flags = 0x%X, "
1154 ".reserved = { 0x%X, 0x%X } " "} }\n",
1155 format_min.type,
1156 format_min.fmt.vbi.sampling_rate,
1157 format_min.fmt.vbi.offset,
1158 format_min.fmt.vbi.samples_per_line,
1159 format_min.fmt.vbi.sample_format,
1160 format_min.fmt.vbi.start[0],
1161 format_min.fmt.vbi.start[1],
1162 format_min.fmt.vbi.count[0],
1163 format_min.fmt.vbi.count[1],
1164 format_min.fmt.vbi.flags,
1165 format_min.fmt.vbi.reserved[0],
1166 format_min.fmt.vbi.reserved[1]
1167 );
1168 if (sizeof(format_min.fmt.vbi) <
1169 sizeof(format_min.fmt.raw_data)) {
1170 dprintf1
1171 ("\tformat_min = { ..., .fmt.raw_data[] = { ...");
1172 for (j = sizeof(format_min.fmt.vbi);
1173 j <
1174 sizeof(format_min.fmt.raw_data);
1175 j++) {
1176 dprintf(", 0x%x",
1177 format_min.fmt.
1178 raw_data[j]);
1179 }
1180 dprintf1(" }}\n");
1181 }
1182
1183 /* TODO: check the different fields */
1184 //CU_ASSERT_EQUAL(format_min.fmt.vbi.sampling_rate, ???);
1185 //CU_ASSERT_EQUAL(format_min.fmt.vbi.offset, ???);
1186 //CU_ASSERT_EQUAL(format_min.fmt.vbi.samples_per_line, ???);
1187 //CU_ASSERT_EQUAL(format_min.fmt.vbi.sample_format, ???);
1188 //CU_ASSERT_EQUAL(format_min.fmt.vbi.start[0], ???);
1189 //CU_ASSERT_EQUAL(format_min.fmt.vbi.start[1], ???);
1190 //CU_ASSERT_EQUAL(format_min.fmt.vbi.count[0], ???);
1191 //CU_ASSERT_EQUAL(format_min.fmt.vbi.count[1], ???);
1192 //CU_ASSERT_EQUAL(format_min.fmt.vbi.flags, ???);
1193 CU_ASSERT_EQUAL(format_min.fmt.vbi.reserved[0],
1194 0);
1195 CU_ASSERT_EQUAL(format_min.fmt.vbi.reserved[1],
1196 0);
1197 } else {
1198 CU_ASSERT_EQUAL(ret_min, -1);
1199 CU_ASSERT_EQUAL(errno_min, EINVAL);
1200 }
1201
1202 if (ret_max == -1 && ret_min == -1) {
1203 CU_ASSERT_EQUAL(ret_enum, -1);
1204 CU_ASSERT_EQUAL(errno_enum, EINVAL);
1205 }
1206 break;
1207
1208 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
1209 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
1210 memset(&format_max, 0xff, sizeof(format_max));
1211 format_max.type = type;
1212
1213 ret_max =
1214 ioctl(get_video_fd(), VIDIOC_S_FMT, &format_max);
1215 errno_max = errno;
1216
1217 dprintf
1218 ("\t%s:%u: VIDIOC_S_FMT, type=%i, ret_max=%i, errno_max=%i\n",
1219 __FILE__, __LINE__, type, ret_max, errno_max);
1220
1221 if (ret_max == 0) {
1222 CU_ASSERT_EQUAL(ret_enum, 0);
1223 dprintf("\tformat_max = {.type=0x%X, "
1224 ".fmt.sliced = { .service_set = 0x%X, "
1225 ".service_lines = { ... }, "
1226 ".io_size = %u, "
1227 ".reserved[0] = 0x%X, "
1228 ".reserved[1] = 0x%X "
1229 "} }\n",
1230 format_max.type,
1231 format_max.fmt.sliced.service_set,
1232 //format_max.fmt.sliced.service_lines[][],
1233 format_max.fmt.sliced.io_size,
1234 format_max.fmt.sliced.reserved[0],
1235 format_max.fmt.sliced.reserved[1]
1236 );
1237 if (sizeof(format_max.fmt.sliced) <
1238 sizeof(format_max.fmt.raw_data)) {
1239 dprintf1
1240 ("\tformat_max = { ..., .fmt.raw_data[] = { ...");
1241 for (j = sizeof(format_max.fmt.sliced);
1242 j <
1243 sizeof(format_max.fmt.raw_data);
1244 j++) {
1245 dprintf(", 0x%x",
1246 format_max.fmt.
1247 raw_data[j]);
1248 }
1249 dprintf1(" }}\n");
1250 }
1251
1252 /* TODO: check the different fields */
1253 //CU_ASSERT_EQUAL(format_max.fmt.sliced.service_set, ???);
1254 CU_ASSERT_EQUAL(format_max.fmt.sliced.
1255 service_lines[0][0], 0);
1256 //CU_ASSERT_EQUAL(format_max.fmt.sliced.service_lines[0][1], ???);
1257 //CU_ASSERT_EQUAL(format_max.fmt.sliced.service_lines[0][2], ???);
1258 //CU_ASSERT_EQUAL(format_max.fmt.sliced.service_lines[0][3], ???);
1259 //CU_ASSERT_EQUAL(format_max.fmt.sliced.service_lines[0][4], ???);
1260 //CU_ASSERT_EQUAL(format_max.fmt.sliced.service_lines[0][5], ???);
1261 //CU_ASSERT_EQUAL(format_max.fmt.sliced.service_lines[0][6], ???);
1262 //CU_ASSERT_EQUAL(format_max.fmt.sliced.service_lines[0][7], ???);
1263 //CU_ASSERT_EQUAL(format_max.fmt.sliced.service_lines[0][8], ???);
1264 //CU_ASSERT_EQUAL(format_max.fmt.sliced.service_lines[0][9], ???);
1265 //CU_ASSERT_EQUAL(format_max.fmt.sliced.service_lines[0][10], ???);
1266 //CU_ASSERT_EQUAL(format_max.fmt.sliced.service_lines[0][11], ???);
1267 //CU_ASSERT_EQUAL(format_max.fmt.sliced.service_lines[0][12], ???);
1268 //CU_ASSERT_EQUAL(format_max.fmt.sliced.service_lines[0][13], ???);
1269 //CU_ASSERT_EQUAL(format_max.fmt.sliced.service_lines[0][14], ???);
1270 //CU_ASSERT_EQUAL(format_max.fmt.sliced.service_lines[0][15], ???);
1271 //CU_ASSERT_EQUAL(format_max.fmt.sliced.service_lines[0][16], ???);
1272 //CU_ASSERT_EQUAL(format_max.fmt.sliced.service_lines[0][17], ???);
1273 //CU_ASSERT_EQUAL(format_max.fmt.sliced.service_lines[0][18], ???);
1274 //CU_ASSERT_EQUAL(format_max.fmt.sliced.service_lines[0][19], ???);
1275 //CU_ASSERT_EQUAL(format_max.fmt.sliced.service_lines[0][20], ???);
1276 //CU_ASSERT_EQUAL(format_max.fmt.sliced.service_lines[0][21], ???);
1277 //CU_ASSERT_EQUAL(format_max.fmt.sliced.service_lines[0][22], ???);
1278 //CU_ASSERT_EQUAL(format_max.fmt.sliced.service_lines[0][23], ???);
1279 CU_ASSERT_EQUAL(format_max.fmt.sliced.
1280 service_lines[1][0], 0);
1281 //CU_ASSERT_EQUAL(format_max.fmt.sliced.service_lines[1][1], ???);
1282 //CU_ASSERT_EQUAL(format_max.fmt.sliced.service_lines[1][2], ???);
1283 //CU_ASSERT_EQUAL(format_max.fmt.sliced.service_lines[1][3], ???);
1284 //CU_ASSERT_EQUAL(format_max.fmt.sliced.service_lines[1][4], ???);
1285 //CU_ASSERT_EQUAL(format_max.fmt.sliced.service_lines[1][5], ???);
1286 //CU_ASSERT_EQUAL(format_max.fmt.sliced.service_lines[1][6], ???);
1287 //CU_ASSERT_EQUAL(format_max.fmt.sliced.service_lines[1][7], ???);
1288 //CU_ASSERT_EQUAL(format_max.fmt.sliced.service_lines[1][8], ???);
1289 //CU_ASSERT_EQUAL(format_max.fmt.sliced.service_lines[1][9], ???);
1290 //CU_ASSERT_EQUAL(format_max.fmt.sliced.service_lines[1][10], ???);
1291 //CU_ASSERT_EQUAL(format_max.fmt.sliced.service_lines[1][11], ???);
1292 //CU_ASSERT_EQUAL(format_max.fmt.sliced.service_lines[1][12], ???);
1293 //CU_ASSERT_EQUAL(format_max.fmt.sliced.service_lines[1][13], ???);
1294 //CU_ASSERT_EQUAL(format_max.fmt.sliced.service_lines[1][14], ???);
1295 //CU_ASSERT_EQUAL(format_max.fmt.sliced.service_lines[1][15], ???);
1296 //CU_ASSERT_EQUAL(format_max.fmt.sliced.service_lines[1][16], ???);
1297 //CU_ASSERT_EQUAL(format_max.fmt.sliced.service_lines[1][17], ???);
1298 //CU_ASSERT_EQUAL(format_max.fmt.sliced.service_lines[1][18], ???);
1299 //CU_ASSERT_EQUAL(format_max.fmt.sliced.service_lines[1][19], ???);
1300 //CU_ASSERT_EQUAL(format_max.fmt.sliced.service_lines[1][20], ???);
1301 //CU_ASSERT_EQUAL(format_max.fmt.sliced.service_lines[1][21], ???);
1302 //CU_ASSERT_EQUAL(format_max.fmt.sliced.service_lines[1][22], ???);
1303 //CU_ASSERT_EQUAL(format_max.fmt.sliced.service_lines[1][23], ???);
1304 //CU_ASSERT_EQUAL(format_max.fmt.sliced.io_size, ???);
1305 CU_ASSERT_EQUAL(format_max.fmt.sliced.
1306 reserved[0], 0);
1307 CU_ASSERT_EQUAL(format_max.fmt.sliced.
1308 reserved[1], 0);
1309
1310 } else {
1311 CU_ASSERT_EQUAL(ret_max, -1);
1312 CU_ASSERT_EQUAL(errno_max, EINVAL);
1313 }
1314
1315 memset(&format_min, 0, sizeof(format_min));
1316 format_min.type = type;
1317 format_min.fmt.pix.pixelformat = fmtdesc.pixelformat;
1318
1319 ret_min =
1320 ioctl(get_video_fd(), VIDIOC_S_FMT, &format_min);
1321 errno_min = errno;
1322
1323 dprintf
1324 ("\t%s:%u: VIDIOC_S_FMT, type=%i, ret_min=%i, errno_min=%i\n",
1325 __FILE__, __LINE__, type, ret_min, errno_min);
1326
1327 if (ret_min == 0) {
1328 CU_ASSERT_EQUAL(ret_enum, 0);
1329 dprintf("\tformat_min = {.type=0x%X, "
1330 ".fmt.sliced = { .service_set = 0x%X, "
1331 ".service_lines = { ... }, "
1332 ".io_size = %u, "
1333 ".reserved[0] = 0x%X, "
1334 ".reserved[1] = 0x%X "
1335 "} }\n",
1336 format_min.type,
1337 format_min.fmt.sliced.service_set,
1338 //format_min.fmt.sliced.service_lines[][],
1339 format_min.fmt.sliced.io_size,
1340 format_min.fmt.sliced.reserved[0],
1341 format_min.fmt.sliced.reserved[1]
1342 );
1343 if (sizeof(format_min.fmt.sliced) <
1344 sizeof(format_min.fmt.raw_data)) {
1345 dprintf1
1346 ("\tformat_min = { ..., .fmt.raw_data[] = { ...");
1347 for (j = sizeof(format_min.fmt.sliced);
1348 j <
1349 sizeof(format_min.fmt.raw_data);
1350 j++) {
1351 dprintf(", 0x%x",
1352 format_min.fmt.
1353 raw_data[j]);
1354 }
1355 dprintf1(" }}\n");
1356 }
1357
1358 /* TODO: check the different fields */
1359 //CU_ASSERT_EQUAL(format_min.fmt.sliced.service_set, ???);
1360 CU_ASSERT_EQUAL(format_min.fmt.sliced.
1361 service_lines[0][0], 0);
1362 //CU_ASSERT_EQUAL(format_min.fmt.sliced.service_lines[0][1], ???);
1363 //CU_ASSERT_EQUAL(format_min.fmt.sliced.service_lines[0][2], ???);
1364 //CU_ASSERT_EQUAL(format_min.fmt.sliced.service_lines[0][3], ???);
1365 //CU_ASSERT_EQUAL(format_min.fmt.sliced.service_lines[0][4], ???);
1366 //CU_ASSERT_EQUAL(format_min.fmt.sliced.service_lines[0][5], ???);
1367 //CU_ASSERT_EQUAL(format_min.fmt.sliced.service_lines[0][6], ???);
1368 //CU_ASSERT_EQUAL(format_min.fmt.sliced.service_lines[0][7], ???);
1369 //CU_ASSERT_EQUAL(format_min.fmt.sliced.service_lines[0][8], ???);
1370 //CU_ASSERT_EQUAL(format_min.fmt.sliced.service_lines[0][9], ???);
1371 //CU_ASSERT_EQUAL(format_min.fmt.sliced.service_lines[0][10], ???);
1372 //CU_ASSERT_EQUAL(format_min.fmt.sliced.service_lines[0][11], ???);
1373 //CU_ASSERT_EQUAL(format_min.fmt.sliced.service_lines[0][12], ???);
1374 //CU_ASSERT_EQUAL(format_min.fmt.sliced.service_lines[0][13], ???);
1375 //CU_ASSERT_EQUAL(format_min.fmt.sliced.service_lines[0][14], ???);
1376 //CU_ASSERT_EQUAL(format_min.fmt.sliced.service_lines[0][15], ???);
1377 //CU_ASSERT_EQUAL(format_min.fmt.sliced.service_lines[0][16], ???);
1378 //CU_ASSERT_EQUAL(format_min.fmt.sliced.service_lines[0][17], ???);
1379 //CU_ASSERT_EQUAL(format_min.fmt.sliced.service_lines[0][18], ???);
1380 //CU_ASSERT_EQUAL(format_min.fmt.sliced.service_lines[0][19], ???);
1381 //CU_ASSERT_EQUAL(format_min.fmt.sliced.service_lines[0][20], ???);
1382 //CU_ASSERT_EQUAL(format_min.fmt.sliced.service_lines[0][21], ???);
1383 //CU_ASSERT_EQUAL(format_min.fmt.sliced.service_lines[0][22], ???);
1384 //CU_ASSERT_EQUAL(format_min.fmt.sliced.service_lines[0][23], ???);
1385 CU_ASSERT_EQUAL(format_min.fmt.sliced.
1386 service_lines[1][0], 0);
1387 //CU_ASSERT_EQUAL(format_min.fmt.sliced.service_lines[1][1], ???);
1388 //CU_ASSERT_EQUAL(format_min.fmt.sliced.service_lines[1][2], ???);
1389 //CU_ASSERT_EQUAL(format_min.fmt.sliced.service_lines[1][3], ???);
1390 //CU_ASSERT_EQUAL(format_min.fmt.sliced.service_lines[1][4], ???);
1391 //CU_ASSERT_EQUAL(format_min.fmt.sliced.service_lines[1][5], ???);
1392 //CU_ASSERT_EQUAL(format_min.fmt.sliced.service_lines[1][6], ???);
1393 //CU_ASSERT_EQUAL(format_min.fmt.sliced.service_lines[1][7], ???);
1394 //CU_ASSERT_EQUAL(format_min.fmt.sliced.service_lines[1][8], ???);
1395 //CU_ASSERT_EQUAL(format_min.fmt.sliced.service_lines[1][9], ???);
1396 //CU_ASSERT_EQUAL(format_min.fmt.sliced.service_lines[1][10], ???);
1397 //CU_ASSERT_EQUAL(format_min.fmt.sliced.service_lines[1][11], ???);
1398 //CU_ASSERT_EQUAL(format_min.fmt.sliced.service_lines[1][12], ???);
1399 //CU_ASSERT_EQUAL(format_min.fmt.sliced.service_lines[1][13], ???);
1400 //CU_ASSERT_EQUAL(format_min.fmt.sliced.service_lines[1][14], ???);
1401 //CU_ASSERT_EQUAL(format_min.fmt.sliced.service_lines[1][15], ???);
1402 //CU_ASSERT_EQUAL(format_min.fmt.sliced.service_lines[1][16], ???);
1403 //CU_ASSERT_EQUAL(format_min.fmt.sliced.service_lines[1][17], ???);
1404 //CU_ASSERT_EQUAL(format_min.fmt.sliced.service_lines[1][18], ???);
1405 //CU_ASSERT_EQUAL(format_min.fmt.sliced.service_lines[1][19], ???);
1406 //CU_ASSERT_EQUAL(format_min.fmt.sliced.service_lines[1][20], ???);
1407 //CU_ASSERT_EQUAL(format_min.fmt.sliced.service_lines[1][21], ???);
1408 //CU_ASSERT_EQUAL(format_min.fmt.sliced.service_lines[1][22], ???);
1409 //CU_ASSERT_EQUAL(format_min.fmt.sliced.service_lines[1][23], ???);
1410 //CU_ASSERT_EQUAL(format_min.fmt.sliced.io_size, ???);
1411 CU_ASSERT_EQUAL(format_min.fmt.sliced.
1412 reserved[0], 0);
1413 CU_ASSERT_EQUAL(format_min.fmt.sliced.
1414 reserved[1], 0);
1415
1416 } else {
1417 CU_ASSERT_EQUAL(ret_min, -1);
1418 CU_ASSERT_EQUAL(errno_min, EINVAL);
1419 }
1420
1421 if (ret_max == -1 && ret_min == -1) {
1422 CU_ASSERT_EQUAL(ret_enum, -1);
1423 CU_ASSERT_EQUAL(errno_enum, EINVAL);
1424 }
1425 break;
1426
1427 case V4L2_BUF_TYPE_PRIVATE:
1428 memset(&format_max, 0xff, sizeof(format_max));
1429 format_max.type = type;
1430
1431 ret_max =
1432 ioctl(get_video_fd(), VIDIOC_S_FMT, &format_max);
1433 errno_max = errno;
1434
1435 dprintf
1436 ("\t%s:%u: VIDIOC_S_FMT, type=%i, ret_max=%i, errno_max=%i\n",
1437 __FILE__, __LINE__, type, ret_max, errno_max);
1438
1439 if (ret_max == 0) {
1440 CU_ASSERT_EQUAL(ret_enum, 0);
1441 dprintf1
1442 ("\tformat_max = { ..., .fmt.raw_data[] = { ");
1443 for (j = 0; j < sizeof(format_max.fmt.raw_data);
1444 j++) {
1445 dprintf("0x%x",
1446 format_max.fmt.raw_data[j]);
1447 if (j < sizeof(format_max.fmt.raw_data)) {
1448 dprintf1(", ");
1449 }
1450 }
1451 dprintf1(" }}\n");
1452
1453 /* TODO: check the different fields */
1454
1455 } else {
1456 CU_ASSERT_EQUAL(ret_max, -1);
1457 CU_ASSERT_EQUAL(errno_max, EINVAL);
1458 }
1459
1460 memset(&format_min, 0, sizeof(format_min));
1461 format_min.type = type;
1462 format_min.fmt.pix.pixelformat = fmtdesc.pixelformat;
1463
1464 ret_min =
1465 ioctl(get_video_fd(), VIDIOC_S_FMT, &format_min);
1466 errno_min = errno;
1467
1468 dprintf
1469 ("\t%s:%u: VIDIOC_S_FMT, type=%i, ret_min=%i, errno_min=%i\n",
1470 __FILE__, __LINE__, type, ret_min, errno_min);
1471
1472 if (ret_min == 0) {
1473 CU_ASSERT_EQUAL(ret_enum, 0);
1474 dprintf1
1475 ("\tformat_min = { ..., .fmt.raw_data[] = { ");
1476 for (j = 0; j < sizeof(format_min.fmt.raw_data);
1477 j++) {
1478 dprintf("0x%x",
1479 format_min.fmt.raw_data[j]);
1480 if (j < sizeof(format_min.fmt.raw_data)) {
1481 dprintf1(", ");
1482 }
1483 }
1484 dprintf1(" }}\n");
1485
1486 /* TODO: check the different fields */
1487
1488 } else {
1489 CU_ASSERT_EQUAL(ret_min, -1);
1490 CU_ASSERT_EQUAL(errno_min, EINVAL);
1491 }
1492
1493 if (ret_max == -1 && ret_min == -1) {
1494 CU_ASSERT_EQUAL(ret_enum, -1);
1495 CU_ASSERT_EQUAL(errno_enum, EINVAL);
1496 }
1497 break;
1498 }
1499
1500 if (ret_enum == 0) {
1501 CU_ASSERT_EQUAL(ret_enum, 0);
1502 } else {
1503 CU_ASSERT_EQUAL(ret_enum, -1);
1504 CU_ASSERT_EQUAL(errno_enum, EINVAL);
1505 }
1506
1507 i++;
1508 } while (ret_enum == 0 && i != 0);
1509
1510 memset(&format_set, 0xff, sizeof(format_set));
1511 format_set = format_orig;
1512
1513 ret_set = ioctl(get_video_fd(), VIDIOC_S_FMT, &format_set);
1514 errno_set = errno;
1515
1516 dprintf("\t%s:%u: VIDIOC_S_FMT, type=%i, ret_set=%i, errno_set=%i\n",
1517 __FILE__, __LINE__, format_orig.type, ret_set, errno_set);
1518
1519 if (ret_get == 0) {
1520 CU_ASSERT_EQUAL(ret_get, 0);
1521 CU_ASSERT_EQUAL(ret_set, 0);
1522
1523 CU_ASSERT_EQUAL(format_orig.type, type);
1524 CU_ASSERT_EQUAL(format_set.type, type);
1525 } else {
1526 CU_ASSERT_EQUAL(ret_get, -1);
1527 CU_ASSERT_EQUAL(errno_get, EINVAL);
1528 CU_ASSERT_EQUAL(ret_set, -1);
1529 CU_ASSERT_EQUAL(errno_set, EINVAL);
1530 }
1531
1532 }
1533
test_VIDIOC_S_FMT_enum()1534 void test_VIDIOC_S_FMT_enum()
1535 {
1536 do_set_formats_enum(V4L2_BUF_TYPE_VIDEO_CAPTURE);
1537 do_set_formats_enum(V4L2_BUF_TYPE_VIDEO_OUTPUT);
1538 do_set_formats_enum(V4L2_BUF_TYPE_VIDEO_OVERLAY);
1539 do_set_formats_enum(V4L2_BUF_TYPE_VBI_CAPTURE);
1540 do_set_formats_enum(V4L2_BUF_TYPE_VBI_OUTPUT);
1541 do_set_formats_enum(V4L2_BUF_TYPE_SLICED_VBI_CAPTURE);
1542 do_set_formats_enum(V4L2_BUF_TYPE_SLICED_VBI_OUTPUT);
1543 do_set_formats_enum(V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY);
1544 do_set_formats_enum(V4L2_BUF_TYPE_PRIVATE);
1545 }
1546
do_set_formats_type(enum v4l2_buf_type type)1547 static void do_set_formats_type(enum v4l2_buf_type type)
1548 {
1549 int ret_set, errno_set;
1550 struct v4l2_format format;
1551 struct v4l2_format format2;
1552
1553 memset(&format, 0, sizeof(format));
1554 format.type = type;
1555
1556 ret_set = ioctl(get_video_fd(), VIDIOC_S_FMT, &format);
1557 errno_set = errno;
1558
1559 dprintf("\t%s:%u: VIDIOC_S_FMT, type=%i, ret_set=%i, errno_set=%i\n",
1560 __FILE__, __LINE__, type, ret_set, errno_set);
1561
1562 CU_ASSERT_EQUAL(ret_set, -1);
1563 CU_ASSERT_EQUAL(errno_set, EINVAL);
1564
1565 /* Check whether the format structure is untouched */
1566 memset(&format2, 0, sizeof(format2));
1567 format2.type = type;
1568 CU_ASSERT_EQUAL(memcmp(&format, &format2, sizeof(format)), 0);
1569
1570 }
1571
test_VIDIOC_S_FMT_type()1572 void test_VIDIOC_S_FMT_type()
1573 {
1574 do_set_formats_type(0);
1575 do_set_formats_type(9);
1576 do_set_formats_type(V4L2_BUF_TYPE_PRIVATE - 1);
1577 do_set_formats_type(S16_MIN);
1578 do_set_formats_type(S16_MAX);
1579 do_set_formats_type(S32_MAX);
1580 }
1581
1582 /* TODO: test cases for VIDIOC_TRY_FMT */
1583
1584 /*
1585 TODO: test case for VIDIOC_TRY_FMT with invalid type
1586
1587 TODO: test case for VIDIOC_S_FMT with type=V4L2_BUF_TYPE_VIDEO_CAPTURE and
1588 V4L2_BUF_TYPE_VIDEO_OUTPUT
1589 - with different field settings
1590 */
1591