1 /*
2 * v4l-test: Test environment for Video For Linux Two API
3 *
4 * 18 Apr 2009 0.4 More cleanup in frequency scan test case
5 * 28 Mar 2009 0.3 Clean up ret and errno variable names and dprintf() output
6 * 1 Feb 2009 0.2 Added test cases for VIDIOC_S_FREQUENCY
7 * 31 Jan 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
27 #include "v4l2_test.h"
28 #include "dev_video.h"
29 #include "video_limits.h"
30
31 #include "test_VIDIOC_FREQUENCY.h"
32
test_VIDIOC_G_FREQUENCY()33 void test_VIDIOC_G_FREQUENCY()
34 {
35 int ret_get, errno_get;
36 __u32 tuner;
37 struct v4l2_frequency freq;
38
39 tuner = 0;
40
41 memset(&freq, 0xff, sizeof(freq));
42 freq.tuner = tuner;
43 ret_get = ioctl(get_video_fd(), VIDIOC_G_FREQUENCY, &freq);
44 errno_get = errno;
45
46 dprintf("\t%s:%u: VIDIOC_G_FREQUENCY, ret_get=%i, errno_get=%i\n",
47 __FILE__, __LINE__, ret_get, errno_get);
48
49 if (ret_get == 0) {
50 CU_ASSERT_EQUAL(ret_get, 0);
51
52 CU_ASSERT_EQUAL(freq.tuner, tuner);
53
54 //CU_ASSERT(freq.type, ???);
55 //CU_ASSERT_EQUAL(freq.frequency, ???);
56
57 CU_ASSERT_EQUAL(freq.reserved[0], 0);
58 CU_ASSERT_EQUAL(freq.reserved[1], 0);
59 CU_ASSERT_EQUAL(freq.reserved[2], 0);
60 CU_ASSERT_EQUAL(freq.reserved[3], 0);
61 CU_ASSERT_EQUAL(freq.reserved[4], 0);
62 CU_ASSERT_EQUAL(freq.reserved[5], 0);
63 CU_ASSERT_EQUAL(freq.reserved[6], 0);
64 CU_ASSERT_EQUAL(freq.reserved[7], 0);
65
66 dprintf("\tfreq = { "
67 ".tuner = %u, "
68 ".type = 0x%X, "
69 ".frequency = %u "
70 ".reserved[]={ 0x%X, 0x%X, 0x%X, 0x%X, 0x%X, 0x%X, 0x%X, 0x%X } }\n",
71 freq.tuner,
72 freq.type,
73 freq.frequency,
74 freq.reserved[0],
75 freq.reserved[1],
76 freq.reserved[2],
77 freq.reserved[3],
78 freq.reserved[4],
79 freq.reserved[5], freq.reserved[6], freq.reserved[7]
80 );
81 } else {
82 CU_ASSERT_EQUAL(ret_get, -1);
83 CU_ASSERT_EQUAL(errno_get, EINVAL);
84 }
85
86 }
87
test_VIDIOC_G_FREQUENCY_S32_MAX()88 void test_VIDIOC_G_FREQUENCY_S32_MAX()
89 {
90 int ret_get, errno_get;
91 __u32 tuner;
92 struct v4l2_frequency freq;
93
94 tuner = (__u32) S32_MAX;
95
96 memset(&tuner, 0xff, sizeof(tuner));
97 freq.tuner = tuner;
98 ret_get = ioctl(get_video_fd(), VIDIOC_G_FREQUENCY, &freq);
99 errno_get = errno;
100
101 dprintf("\t%s:%u: VIDIOC_G_FREQUENCY, ret_get=%i, errno_get=%i\n",
102 __FILE__, __LINE__, ret_get, errno_get);
103
104 CU_ASSERT_EQUAL(ret_get, -1);
105 CU_ASSERT_EQUAL(errno_get, EINVAL);
106 }
107
test_VIDIOC_G_FREQUENCY_S32_MAX_1()108 void test_VIDIOC_G_FREQUENCY_S32_MAX_1()
109 {
110 int ret_get, errno_get;
111 __u32 tuner;
112 struct v4l2_frequency freq;
113
114 tuner = (__u32) S32_MAX + 1;
115
116 memset(&tuner, 0xff, sizeof(tuner));
117 freq.tuner = tuner;
118 ret_get = ioctl(get_video_fd(), VIDIOC_G_FREQUENCY, &freq);
119 errno_get = errno;
120
121 dprintf("\t%s:%u: VIDIOC_G_FREQUENCY, ret_get=%i, errno_get=%i\n",
122 __FILE__, __LINE__, ret_get, errno_get);
123
124 CU_ASSERT_EQUAL(ret_get, -1);
125 CU_ASSERT_EQUAL(errno_get, EINVAL);
126 }
127
test_VIDIOC_G_FREQUENCY_U32_MAX()128 void test_VIDIOC_G_FREQUENCY_U32_MAX()
129 {
130 int ret_get, errno_get;
131 __u32 tuner;
132 struct v4l2_frequency freq;
133
134 tuner = U32_MAX;
135
136 memset(&tuner, 0xff, sizeof(tuner));
137 freq.tuner = tuner;
138 ret_get = ioctl(get_video_fd(), VIDIOC_G_FREQUENCY, &freq);
139 errno_get = errno;
140
141 dprintf("\t%s:%u: VIDIOC_G_FREQUENCY, ret_get=%i, errno_get=%i\n",
142 __FILE__, __LINE__, ret_get, errno_get);
143
144 CU_ASSERT_EQUAL(ret_get, -1);
145 CU_ASSERT_EQUAL(errno_get, EINVAL);
146 }
147
test_VIDIOC_G_FREQUENCY_NULL()148 void test_VIDIOC_G_FREQUENCY_NULL()
149 {
150 int ret_get, errno_get;
151 int ret_null, errno_null;
152 struct v4l2_frequency freq;
153 __u32 tuner;
154
155 tuner = 0;
156
157 memset(&freq, 0xff, sizeof(freq));
158 freq.tuner = tuner;
159 freq.type = V4L2_TUNER_ANALOG_TV;
160 ret_get = ioctl(get_video_fd(), VIDIOC_G_FREQUENCY, &freq);
161 errno_get = errno;
162
163 dprintf("\t%s:%u: VIDIOC_G_FREQUENCY, ret_get=%i, errno_get=%i\n",
164 __FILE__, __LINE__, ret_get, errno_get);
165
166 ret_null = ioctl(get_video_fd(), VIDIOC_G_FREQUENCY, NULL);
167 errno_null = errno;
168
169 dprintf("\t%s:%u: VIDIOC_G_FREQUENCY, ret_null=%i, errno_null=%i\n",
170 __FILE__, __LINE__, ret_null, errno_null);
171
172 /* check if VIDIOC_G_FREQUENCY is supported at all or not */
173 if (ret_get == 0) {
174 /* VIDIOC_G_FREQUENCY is supported, the parameter should be checked */
175 CU_ASSERT_EQUAL(ret_null, -1);
176 CU_ASSERT_EQUAL(errno_null, EFAULT);
177 } else {
178 /* VIDIOC_G_FREQUENCY not supported at all, the parameter should not be evaluated */
179 CU_ASSERT_EQUAL(ret_null, -1);
180 CU_ASSERT_EQUAL(errno_null, EINVAL);
181 }
182 }
183
test_VIDIOC_S_FREQUENCY()184 void test_VIDIOC_S_FREQUENCY()
185 {
186 int ret_get, errno_get;
187 int ret_set, errno_set;
188 __u32 tuner;
189 struct v4l2_frequency orig_freq;
190 struct v4l2_frequency freq;
191 struct v4l2_frequency new_freq;
192
193 tuner = 0;
194
195 /* fetch the current frequency setting */
196 memset(&orig_freq, 0xff, sizeof(orig_freq));
197 orig_freq.tuner = tuner;
198 ret_get = ioctl(get_video_fd(), VIDIOC_G_FREQUENCY, &orig_freq);
199 errno_get = errno;
200
201 dprintf("\t%s:%u: VIDIOC_G_FREQUENCY, ret_get=%i, errno_get=%i\n",
202 __FILE__, __LINE__, ret_get, errno_get);
203
204 if (ret_get == 0) {
205 CU_ASSERT_EQUAL(orig_freq.tuner, tuner);
206
207 /* try to set the frequency again to the actual value */
208 memset(&freq, 0xff, sizeof(freq));
209 freq.tuner = tuner;
210 freq.frequency = orig_freq.frequency;
211 freq.type = V4L2_TUNER_ANALOG_TV;
212 ret_set = ioctl(get_video_fd(), VIDIOC_S_FREQUENCY, &orig_freq);
213 errno_set = errno;
214
215 dprintf
216 ("\t%s:%u: VIDIOC_S_FREQUENCY, ret_set=%i, errno_set=%i\n",
217 __FILE__, __LINE__, ret_set, errno_set);
218
219 CU_ASSERT_EQUAL(ret_set, 0);
220 if (ret_set == 0) {
221
222 /* check wheteher the frequency has not been changed */
223 memset(&new_freq, 0xff, sizeof(new_freq));
224 new_freq.tuner = tuner;
225 ret_get =
226 ioctl(get_video_fd(), VIDIOC_G_FREQUENCY,
227 &new_freq);
228 errno_get = errno;
229
230 dprintf
231 ("\t%s:%u: VIDIOC_G_FREQUENCY, ret_get=%i, errno_get=%i\n",
232 __FILE__, __LINE__, ret_get, errno_get);
233
234 CU_ASSERT_EQUAL(ret_get, 0);
235 if (ret_get == 0) {
236 dprintf
237 ("\t%s:%u: current frequency=%u (expected %u)\n",
238 __FILE__, __LINE__, new_freq.frequency,
239 orig_freq.frequency);
240 CU_ASSERT_EQUAL(new_freq.frequency,
241 orig_freq.frequency);
242 }
243
244 }
245
246 } else {
247 CU_ASSERT_EQUAL(ret_get, -1);
248 CU_ASSERT_EQUAL(errno_get, EINVAL);
249
250 /* VIDIOC_G_FREQUENCY not supported, so shall be VIDIOC_S_FREQUENCY */
251
252 memset(&freq, 0, sizeof(freq));
253 freq.tuner = tuner;
254 freq.type = V4L2_TUNER_ANALOG_TV;
255 freq.frequency = 0;
256 ret_set = ioctl(get_video_fd(), VIDIOC_S_FREQUENCY, &freq);
257 errno_set = errno;
258
259 dprintf
260 ("\t%s:%u: VIDIOC_S_FREQUENCY, ret_set=%i, errno_set=%i\n",
261 __FILE__, __LINE__, ret_set, errno_set);
262
263 CU_ASSERT_EQUAL(ret_set, -1);
264 CU_ASSERT_EQUAL(errno_set, EINVAL);
265
266 }
267
268 }
269
test_VIDIOC_S_FREQUENCY_boundaries()270 void test_VIDIOC_S_FREQUENCY_boundaries()
271 {
272 int ret_g_tuner = 0;
273 int ret_g_freq = 0;
274 int errno_g_tuner = 0;
275 int errno_g_freq = 0;
276 int ret;
277 __u32 index;
278 struct v4l2_frequency orig_freq;
279 struct v4l2_frequency freq;
280 struct v4l2_frequency new_freq;
281 struct v4l2_tuner tuner;
282
283 /* this test case depends on working VIDIOC_G_TUNER and VIDIOC_G_FREQUENCY commands */
284
285 index = 0;
286
287 /* fetch the minimum (tuner.rangelow) and maximum (tuner.rangehigh) frequency */
288 memset(&tuner, 0xff, sizeof(tuner));
289 tuner.index = index;
290 ret_g_tuner = ioctl(get_video_fd(), VIDIOC_G_TUNER, &tuner);
291 errno_g_tuner = errno;
292
293 dprintf
294 ("\t%s:%u: VIDIOC_G_TUNER, ret=%i, tuner.rangelow=%u, tuner.rangehigh=%u\n",
295 __FILE__, __LINE__, ret_g_tuner, tuner.rangelow, tuner.rangehigh);
296 CU_ASSERT_EQUAL(tuner.index, index);
297
298 /* fetch the current frequency setting */
299 memset(&orig_freq, 0xff, sizeof(orig_freq));
300 orig_freq.tuner = index;
301 ret_g_freq = ioctl(get_video_fd(), VIDIOC_G_FREQUENCY, &orig_freq);
302 errno_g_freq = errno;
303
304 dprintf
305 ("\t%s:%u: VIDIOC_G_FREQUENCY, ret_g_freq=%i, orig_freq.frequency=%u\n",
306 __FILE__, __LINE__, ret_g_freq, orig_freq.frequency);
307 CU_ASSERT_EQUAL(orig_freq.tuner, index);
308
309 if (ret_g_tuner == 0 && ret_g_freq == 0) {
310 CU_ASSERT_EQUAL(orig_freq.tuner, index);
311
312 /* try to set the frequency to zero */
313 memset(&freq, 0xff, sizeof(freq));
314 freq.tuner = index;
315 freq.type = orig_freq.type;
316 freq.frequency = 0;
317 ret = ioctl(get_video_fd(), VIDIOC_S_FREQUENCY, &freq);
318 dprintf("\t%s:%u: set to %u: VIDIOC_S_FREQUENCY, ret=%i\n",
319 __FILE__, __LINE__, 0, ret);
320
321 CU_ASSERT_EQUAL(ret, 0);
322 if (ret == 0) {
323
324 /* check wheteher the frequency has been changed to the lowest
325 * possible value
326 */
327 memset(&new_freq, 0xff, sizeof(new_freq));
328 new_freq.tuner = index;
329 ret =
330 ioctl(get_video_fd(), VIDIOC_G_FREQUENCY,
331 &new_freq);
332
333 dprintf
334 ("\t%s:%u: VIDIOC_G_FREQUENCY, ret=%i, new_freq.frequency=%u\n",
335 __FILE__, __LINE__, ret, new_freq.frequency);
336
337 CU_ASSERT_EQUAL(ret, 0);
338 if (ret == 0) {
339 CU_ASSERT_EQUAL(new_freq.frequency,
340 tuner.rangelow);
341 }
342 }
343
344 /* try to set the frequency to tuner.rangelow-1, if applicable */
345 if (0 < tuner.rangelow) {
346 memset(&freq, 0xff, sizeof(freq));
347 freq.tuner = index;
348 freq.type = orig_freq.type;
349 freq.frequency = tuner.rangelow - 1;
350 ret = ioctl(get_video_fd(), VIDIOC_S_FREQUENCY, &freq);
351
352 dprintf
353 ("\t%s:%u: set to %u: VIDIOC_S_FREQUENCY, ret=%i\n",
354 __FILE__, __LINE__, tuner.rangelow - 1, ret);
355
356 CU_ASSERT_EQUAL(ret, 0);
357 if (ret == 0) {
358
359 /* check wheteher the frequency has been changed to the lowest
360 * possible value
361 */
362 memset(&new_freq, 0xff, sizeof(new_freq));
363 new_freq.tuner = index;
364 ret =
365 ioctl(get_video_fd(), VIDIOC_G_FREQUENCY,
366 &new_freq);
367
368 dprintf
369 ("\t%s:%u: VIDIOC_G_FREQUENCY, ret=%i, new_freq.frequency=%u\n",
370 __FILE__, __LINE__, ret,
371 new_freq.frequency);
372 CU_ASSERT_EQUAL(ret, 0);
373 if (ret == 0) {
374 dprintf
375 ("\t%s:%u: current frequency=%u (expected %u)\n",
376 __FILE__, __LINE__,
377 new_freq.frequency,
378 tuner.rangelow);
379 CU_ASSERT_EQUAL(new_freq.frequency,
380 tuner.rangelow);
381 }
382 }
383 }
384
385 /* try to set the frequency to tuner.rangelow */
386 memset(&freq, 0xff, sizeof(freq));
387 freq.tuner = index;
388 freq.type = orig_freq.type;
389 freq.frequency = tuner.rangelow;
390 ret = ioctl(get_video_fd(), VIDIOC_S_FREQUENCY, &freq);
391
392 dprintf("\t%s:%u: set to %u: VIDIOC_S_FREQUENCY, ret=%i\n",
393 __FILE__, __LINE__, tuner.rangelow, ret);
394
395 CU_ASSERT_EQUAL(ret, 0);
396 if (ret == 0) {
397
398 /* check wheteher the frequency has been changed to the lowest
399 * possible value
400 */
401 memset(&new_freq, 0xff, sizeof(new_freq));
402 new_freq.tuner = index;
403 ret =
404 ioctl(get_video_fd(), VIDIOC_G_FREQUENCY,
405 &new_freq);
406
407 dprintf
408 ("\t%s:%u: VIDIOC_G_FREQUENCY, ret=%i, new_freq.frequency=%u\n",
409 __FILE__, __LINE__, ret, new_freq.frequency);
410
411 CU_ASSERT_EQUAL(ret, 0);
412 if (ret == 0) {
413 dprintf
414 ("\t%s:%u: current frequency=%u (expected %u)\n",
415 __FILE__, __LINE__, new_freq.frequency,
416 tuner.rangelow);
417 CU_ASSERT_EQUAL(new_freq.frequency,
418 tuner.rangelow);
419 }
420 }
421
422 /* try to set the frequency to tuner.rangehigh */
423 memset(&freq, 0xff, sizeof(freq));
424 freq.tuner = index;
425 freq.type = orig_freq.type;
426 freq.frequency = tuner.rangehigh;
427 ret = ioctl(get_video_fd(), VIDIOC_S_FREQUENCY, &freq);
428
429 dprintf("\t%s:%u: set to %u: VIDIOC_S_FREQUENCY, ret=%i\n",
430 __FILE__, __LINE__, tuner.rangehigh, ret);
431
432 CU_ASSERT_EQUAL(ret, 0);
433 if (ret == 0) {
434
435 /* check wheteher the frequency has been changed to the highest
436 * possible value
437 */
438 memset(&new_freq, 0xff, sizeof(new_freq));
439 new_freq.tuner = index;
440 ret =
441 ioctl(get_video_fd(), VIDIOC_G_FREQUENCY,
442 &new_freq);
443
444 dprintf
445 ("\t%s:%u: VIDIOC_G_FREQUENCY, ret=%i, new_freq.frequency=%u\n",
446 __FILE__, __LINE__, ret, new_freq.frequency);
447
448 CU_ASSERT_EQUAL(ret, 0);
449 if (ret == 0) {
450 dprintf
451 ("\t%s:%u: current frequency=%u (expected %u)\n",
452 __FILE__, __LINE__, new_freq.frequency,
453 tuner.rangehigh);
454 CU_ASSERT_EQUAL(new_freq.frequency,
455 tuner.rangehigh);
456 }
457 }
458
459 /* try to set the frequency to tuner.rangehigh+1, if applicable */
460 if (tuner.rangehigh < U32_MAX) {
461 memset(&freq, 0xff, sizeof(freq));
462 freq.tuner = index;
463 freq.type = orig_freq.type;
464 freq.frequency = tuner.rangehigh + 1;
465 ret = ioctl(get_video_fd(), VIDIOC_S_FREQUENCY, &freq);
466
467 dprintf
468 ("\t%s:%u: set to %u: VIDIOC_S_FREQUENCY, ret=%i\n",
469 __FILE__, __LINE__, tuner.rangehigh + 1, ret);
470
471 CU_ASSERT_EQUAL(ret, 0);
472 if (ret == 0) {
473
474 /* check wheteher the frequency has been changed to the highest
475 * possible value
476 */
477 memset(&new_freq, 0xff, sizeof(new_freq));
478 new_freq.tuner = index;
479 ret =
480 ioctl(get_video_fd(), VIDIOC_G_FREQUENCY,
481 &new_freq);
482
483 dprintf
484 ("\t%s:%u: VIDIOC_G_FREQUENCY, ret=%i, new_freq.frequency=%u\n",
485 __FILE__, __LINE__, ret,
486 new_freq.frequency);
487
488 CU_ASSERT_EQUAL(ret, 0);
489 if (ret == 0) {
490 dprintf
491 ("\t%s:%u: current frequency=%u (expected %u)\n",
492 __FILE__, __LINE__,
493 new_freq.frequency,
494 tuner.rangehigh);
495 CU_ASSERT_EQUAL(new_freq.frequency,
496 tuner.rangehigh);
497 }
498 }
499 }
500
501 /* try to set the frequency to U32_MAX */
502 memset(&freq, 0xff, sizeof(freq));
503 freq.tuner = index;
504 freq.type = orig_freq.type;
505 freq.frequency = U32_MAX;
506 ret = ioctl(get_video_fd(), VIDIOC_S_FREQUENCY, &freq);
507
508 dprintf("\t%s:%u: set to %u: VIDIOC_S_FREQUENCY, ret=%i\n",
509 __FILE__, __LINE__, U32_MAX, ret);
510 CU_ASSERT_EQUAL(ret, 0);
511 if (ret == 0) {
512
513 /* check wheteher the frequency has been changed to the highest
514 * possible value
515 */
516 memset(&new_freq, 0xff, sizeof(new_freq));
517 new_freq.tuner = index;
518 ret =
519 ioctl(get_video_fd(), VIDIOC_G_FREQUENCY,
520 &new_freq);
521
522 dprintf
523 ("\t%s:%u: VIDIOC_G_FREQUENCY, ret=%i, new_freq.frequency=%u\n",
524 __FILE__, __LINE__, ret, new_freq.frequency);
525
526 CU_ASSERT_EQUAL(ret, 0);
527 if (ret == 0) {
528 dprintf
529 ("\t%s:%u: current frequency=%u (expected %u)\n",
530 __FILE__, __LINE__, new_freq.frequency,
531 tuner.rangehigh);
532 CU_ASSERT_EQUAL(new_freq.frequency,
533 tuner.rangehigh);
534 }
535 }
536
537 /* try restore the original frequency settings */
538 memset(&freq, 0xff, sizeof(freq));
539 freq.tuner = index;
540 freq.type = orig_freq.type;
541 freq.frequency = orig_freq.frequency;
542 ret = ioctl(get_video_fd(), VIDIOC_S_FREQUENCY, &freq);
543
544 dprintf("\t%s:%u: set to %u: VIDIOC_S_FREQUENCY, ret=%i\n",
545 __FILE__, __LINE__, orig_freq.frequency, ret);
546
547 CU_ASSERT_EQUAL(ret, 0);
548 if (ret == 0) {
549
550 /* check wheteher the frequency has been restored */
551 memset(&new_freq, 0xff, sizeof(new_freq));
552 new_freq.tuner = index;
553 ret =
554 ioctl(get_video_fd(), VIDIOC_G_FREQUENCY,
555 &new_freq);
556
557 dprintf
558 ("\t%s:%u: VIDIOC_G_FREQUENCY, ret=%i, new_freq.frequency=%u\n",
559 __FILE__, __LINE__, ret, new_freq.frequency);
560
561 CU_ASSERT_EQUAL(ret, 0);
562 if (ret == 0) {
563 dprintf
564 ("\t%s:%u: current frequency=%u (expected %u)\n",
565 __FILE__, __LINE__, new_freq.frequency,
566 orig_freq.frequency);
567 CU_ASSERT_EQUAL(new_freq.frequency,
568 orig_freq.frequency);
569 }
570 }
571 }
572
573 if (ret_g_freq != 0) {
574 dprintf("\t%s:%u: ret_g_freq=%d (expected %d)\n", __FILE__,
575 __LINE__, ret_g_freq, -1);
576 dprintf("\t%s:%u: errno_g_freq=%d (expected %d)\n", __FILE__,
577 __LINE__, errno_g_freq, EINVAL);
578 CU_ASSERT_EQUAL(ret_g_freq, -1);
579 CU_ASSERT_EQUAL(errno, EINVAL);
580 }
581
582 if (ret_g_tuner != 0) {
583 dprintf("\t%s:%u: ret_g_tuner=%d (expected %d)\n", __FILE__,
584 __LINE__, ret_g_tuner, -1);
585 dprintf("\t%s:%u: errno_g_tuner=%d (expected %d)\n", __FILE__,
586 __LINE__, errno_g_tuner, EINVAL);
587 CU_ASSERT_EQUAL(ret_g_tuner, -1);
588 CU_ASSERT_EQUAL(errno, EINVAL);
589 }
590
591 }
592
test_VIDIOC_S_FREQUENCY_scan()593 void test_VIDIOC_S_FREQUENCY_scan()
594 {
595 int ret_g_tuner, errno_g_tuner;
596 int ret_g_freq, errno_g_freq;
597 int ret_get, errno_get;
598 int ret_set, errno_set;
599 __u32 index;
600 struct v4l2_frequency orig_freq;
601 struct v4l2_frequency freq;
602 struct v4l2_frequency new_freq;
603 struct v4l2_frequency prev_freq;
604 struct v4l2_tuner tuner;
605 __u32 i;
606
607 /* this test case depends on working VIDIOC_G_FREQUENCY command */
608
609 index = 0;
610
611 /* fetch the minimum (tuner.rangelow) and maximum (tuner.rangehigh) frequency */
612 memset(&tuner, 0xff, sizeof(tuner));
613 tuner.index = index;
614 ret_g_tuner = ioctl(get_video_fd(), VIDIOC_G_TUNER, &tuner);
615 errno_g_tuner = errno;
616
617 dprintf("\t%s:%u: VIDIOC_G_TUNER, ret_g_tuner=%i, errno_g_tuner=%i\n",
618 __FILE__, __LINE__, ret_g_tuner, errno_g_tuner);
619 CU_ASSERT_EQUAL(tuner.index, index);
620
621 /* fetch the current frequency setting */
622 memset(&orig_freq, 0xff, sizeof(orig_freq));
623 orig_freq.tuner = index;
624 ret_g_freq = ioctl(get_video_fd(), VIDIOC_G_FREQUENCY, &orig_freq);
625 errno_g_freq = errno;
626
627 dprintf
628 ("\t%s:%u: VIDIOC_G_FREQUENCY, ret_g_freq=%i, errno_g_freq=%i, orig_freq.frequency=%u\n",
629 __FILE__, __LINE__, ret_g_freq, errno_g_freq, orig_freq.frequency);
630 CU_ASSERT_EQUAL(orig_freq.tuner, index);
631
632 if (ret_g_freq == 0) {
633 CU_ASSERT_EQUAL(orig_freq.tuner, index);
634
635 dprintf("\t%s:%u: tuner.rangelow=%u, tuner.rangehigh=%u\n",
636 __FILE__, __LINE__, tuner.rangelow, tuner.rangehigh);
637
638 i = tuner.rangelow;
639 prev_freq.frequency = 0;
640 do {
641 /* try to set the frequency */
642 memset(&freq, 0xff, sizeof(freq));
643 freq.tuner = index;
644 freq.type = orig_freq.type;
645
646 freq.frequency = i;
647 ret_set =
648 ioctl(get_video_fd(), VIDIOC_S_FREQUENCY, &freq);
649 errno_set = errno;
650 dprintf
651 ("\t%s:%u: VIDIOC_S_FREQUENCY, ret_set=%i, errno_set=%i, freq.frequency=%u\n",
652 __FILE__, __LINE__, ret_set, errno_set, i);
653
654 CU_ASSERT_EQUAL(ret_set, 0);
655 if (ret_set == 0) {
656
657 memset(&new_freq, 0xff, sizeof(new_freq));
658 new_freq.tuner = index;
659 ret_get =
660 ioctl(get_video_fd(), VIDIOC_G_FREQUENCY,
661 &new_freq);
662 errno_get = errno;
663
664 dprintf
665 ("\t%s:%u: VIDIOC_G_FREQUENCY, ret_get=%i, errno_get=%i, new_freq.frequency=%u\n",
666 __FILE__, __LINE__, ret_get, errno_get,
667 new_freq.frequency);
668
669 CU_ASSERT_EQUAL(ret_get, 0);
670 if (ret_get == 0) {
671 CU_ASSERT(prev_freq.frequency <=
672 new_freq.frequency);
673 CU_ASSERT(tuner.rangelow <=
674 new_freq.frequency);
675 CU_ASSERT(new_freq.frequency <=
676 tuner.rangehigh);
677 prev_freq = new_freq;
678 }
679 } else {
680 printf("\tError %i while setting to %u\n",
681 errno_set, i);
682 }
683 i++;
684 } while (i <= tuner.rangehigh);
685
686 /* try restore the original frequency settings */
687 memset(&freq, 0xff, sizeof(freq));
688 freq.tuner = index;
689 freq.type = orig_freq.type;
690 freq.frequency = orig_freq.frequency;
691 ret_set = ioctl(get_video_fd(), VIDIOC_S_FREQUENCY, &freq);
692 errno_set = errno;
693
694 dprintf
695 ("\t%s:%u: VIDIOC_S_FREQUENCY, ret_set=%i, errno_set=%i\n",
696 __FILE__, __LINE__, ret_set, errno_set);
697
698 CU_ASSERT_EQUAL(ret_set, 0);
699 if (ret_set == 0) {
700
701 /* check wheteher the frequency has been restored */
702 memset(&new_freq, 0xff, sizeof(new_freq));
703 new_freq.tuner = index;
704 ret_get =
705 ioctl(get_video_fd(), VIDIOC_G_FREQUENCY,
706 &new_freq);
707 errno_get = errno;
708
709 dprintf
710 ("\t%s:%u: VIDIOC_G_FREQUENCY, ret_get=%i, errno_get=%i, new_freq.frequency=%u\n",
711 __FILE__, __LINE__, ret_get, errno_get,
712 new_freq.frequency);
713
714 CU_ASSERT_EQUAL(ret_get, 0);
715 if (ret_get == 0) {
716 CU_ASSERT_EQUAL(new_freq.frequency,
717 orig_freq.frequency);
718 }
719 }
720 }
721
722 if (ret_g_freq != 0) {
723 CU_ASSERT_EQUAL(ret_g_freq, -1);
724 CU_ASSERT_EQUAL(errno, EINVAL);
725 }
726
727 if (ret_g_tuner != 0) {
728 CU_ASSERT_EQUAL(ret_g_tuner, -1);
729 CU_ASSERT_EQUAL(errno, EINVAL);
730 }
731
732 }
733
test_VIDIOC_S_FREQUENCY_NULL()734 void test_VIDIOC_S_FREQUENCY_NULL()
735 {
736 int ret_get, errno_get;
737 int ret_set, errno_set;
738 int ret_null, errno_null;
739 struct v4l2_frequency freq_orig;
740 struct v4l2_frequency freq;
741 __u32 tuner;
742
743 tuner = 0;
744
745 memset(&freq_orig, 0, sizeof(freq_orig));
746 freq_orig.tuner = tuner;
747 freq_orig.type = V4L2_TUNER_ANALOG_TV;
748 ret_get = ioctl(get_video_fd(), VIDIOC_G_FREQUENCY, &freq_orig);
749 errno_get = errno;
750
751 dprintf("\t%s:%u: VIDIOC_G_FREQUENCY, ret_get=%i, errno_get=%i\n",
752 __FILE__, __LINE__, ret_get, errno_get);
753
754 memset(&freq, 0, sizeof(freq));
755 freq.tuner = 0;
756 freq.type = V4L2_TUNER_ANALOG_TV;
757 freq.frequency = freq_orig.frequency;
758 ret_set = ioctl(get_video_fd(), VIDIOC_S_FREQUENCY, &freq_orig);
759 errno_set = errno;
760
761 dprintf("\t%s:%u: VIDIOC_G_FREQUENCY, ret_set=%i, errno_set=%i\n",
762 __FILE__, __LINE__, ret_set, errno_set);
763
764 ret_null = ioctl(get_video_fd(), VIDIOC_S_FREQUENCY, NULL);
765 errno_null = errno;
766
767 dprintf("\t%s:%u: VIDIOC_S_FREQUENCY, ret_null=%i, errno_null=%i\n",
768 __FILE__, __LINE__, ret_null, errno_null);
769
770 /* Check whether any of VIDIOC_S_FREQUENCY or VIDIOC_G_FREQUENCY
771 * is supported at all or not
772 */
773 if (ret_get == 0 || ret_set == 0) {
774 /* VIDIOC_G_FREQUENCY or VIDIOC_S_FREQUENCY is supported, so
775 * the parameter of VIDIOC_S_FREQUENCY should be checked
776 */
777 CU_ASSERT_EQUAL(ret_null, -1);
778 CU_ASSERT_EQUAL(errno_null, EFAULT);
779 } else {
780 /* none of VIDIOC_G_FREQUENCY and VIDIOC_S_FREQUENCY is supported,
781 * the parameter should not be evaluated
782 */
783 CU_ASSERT_EQUAL(ret_get, -1);
784 CU_ASSERT_EQUAL(errno_get, EINVAL);
785 CU_ASSERT_EQUAL(ret_set, -1);
786 CU_ASSERT_EQUAL(errno_set, EINVAL);
787 CU_ASSERT_EQUAL(ret_null, -1);
788 CU_ASSERT_EQUAL(errno_null, EINVAL);
789 }
790
791 }
792