• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1  /*
2   * v4l-test: Test environment for Video For Linux Two API
3   *
4   *  3 Apr 2009  0.6  Test case for with NULL parameter reworked
5   * 28 Mar 2009  0.5  Clean up ret and errno variable names and dprintf() output
6   *  7 Mar 2009  0.4  Typo corrected
7   *  9 Feb 2009  0.3  Modify test_VIDIOC_CROPCAP_enum_INPUT() to support drivers
8   *                   without any inputs
9   *  3 Feb 2009  0.2  Typo fixed
10   * 21 Dec 2008  0.1  First release
11   *
12   * Written by M�rton N�meth <nm127@freemail.hu>
13   * Released under GPL
14   */
15  
16  #include <stdio.h>
17  #include <sys/types.h>
18  #include <sys/stat.h>
19  #include <fcntl.h>
20  #include <unistd.h>
21  #include <sys/ioctl.h>
22  #include <errno.h>
23  #include <string.h>
24  
25  #include <linux/videodev2.h>
26  #include <linux/errno.h>
27  
28  #include <CUnit/CUnit.h>
29  
30  #include "v4l2_test.h"
31  #include "dev_video.h"
32  #include "video_limits.h"
33  
34  #include "test_VIDIOC_CROPCAP.h"
35  
do_ioctl_VIDIOC_CROPCAP(enum v4l2_buf_type buf_type,int expected_ret)36  static void do_ioctl_VIDIOC_CROPCAP(enum v4l2_buf_type buf_type,
37  				    int expected_ret)
38  {
39  	int ret_cap, errno_cap;
40  	struct v4l2_cropcap cropcap;
41  	struct v4l2_cropcap cropcap2;
42  
43  	memset(&cropcap, 0xff, sizeof(cropcap));
44  	cropcap.type = buf_type;
45  	ret_cap = ioctl(get_video_fd(), VIDIOC_CROPCAP, &cropcap);
46  	errno_cap = errno;
47  
48  	dprintf("\t%s:%u: type=%i, ret_cap=%i, errno_cap=%i, expected_ret=%i\n",
49  		__FILE__, __LINE__, buf_type, ret_cap, errno_cap, expected_ret);
50  
51  	if (expected_ret != 0) {
52  		CU_ASSERT_EQUAL(ret_cap, expected_ret);
53  	}
54  	if (ret_cap == 0) {
55  		CU_ASSERT_EQUAL(ret_cap, 0);
56  		CU_ASSERT_EQUAL(cropcap.type, buf_type);
57  
58  		/*     |   left                                   x   */
59  		/* ----+----+-------------------------------------->  */
60  		/*     |    :                                         */
61  		/* top +    +-------- cropcap ------------+  ^        */
62  		/*     |    |                             |  |        */
63  		/*     |    | +------- defrect ---------+ |  |        */
64  		/*     |    | |                         | |  |        */
65  		/*     |    | |                         | |  |        */
66  		/*     |    | |                         | |  | height */
67  		/*     |    | +-------------------------+ |  |        */
68  		/*     |    |                             |  |        */
69  		/*     |    |                             |  |        */
70  		/*     |    +-----------------------------+  v        */
71  		/*     |    :                             :           */
72  		/*     |    <---------- width ------------>           */
73  		/*     |                                              */
74  		/*     v y                                            */
75  
76  		/* top left corner */
77  		CU_ASSERT(cropcap.bounds.left <= cropcap.defrect.left);
78  		CU_ASSERT(cropcap.bounds.top <= cropcap.defrect.top);
79  
80  		/* size of default cropping rectangle should be smaller or */
81  		/* equal to the cropping bounds */
82  		CU_ASSERT(cropcap.defrect.width <= cropcap.bounds.width);
83  		CU_ASSERT(cropcap.defrect.height <= cropcap.bounds.height);
84  
85  		/* the right bottom corner should not exceed bounds */
86  		CU_ASSERT(cropcap.defrect.left + cropcap.defrect.width <=
87  			  cropcap.bounds.left + cropcap.bounds.width);
88  		CU_ASSERT(cropcap.defrect.top + cropcap.defrect.height <=
89  			  cropcap.bounds.top + cropcap.bounds.height);
90  
91  		//CU_ASSERT_EQUAL(cropcap.pixelaspect.numerator, ?);
92  		CU_ASSERT_NOT_EQUAL(cropcap.pixelaspect.numerator, 0);
93  		//CU_ASSERT_EQUAL(cropcap.pixelaspect.denominator, ?);
94  		CU_ASSERT_NOT_EQUAL(cropcap.pixelaspect.denominator, 0);
95  
96  		dprintf("\tcropcap = { .type = %i, "
97  			".bounds = { .left = %i, .top = %i, .width = %i, .height = %i }, "
98  			".defrect = { .left = %i, .top = %i, .width = %i, .height = %i }, "
99  			".pixelaspect = { .numerator = %u, .denominator = %u } "
100  			"}\n",
101  			cropcap.type,
102  			cropcap.bounds.left,
103  			cropcap.bounds.top,
104  			cropcap.bounds.width,
105  			cropcap.bounds.height,
106  			cropcap.defrect.left,
107  			cropcap.defrect.top,
108  			cropcap.defrect.width,
109  			cropcap.defrect.height,
110  			cropcap.pixelaspect.numerator,
111  			cropcap.pixelaspect.denominator);
112  
113  	} else {
114  		CU_ASSERT_EQUAL(ret_cap, -1);
115  		CU_ASSERT_EQUAL(errno_cap, EINVAL);
116  
117  		memset(&cropcap2, 0xff, sizeof(cropcap2));
118  		cropcap2.type = buf_type;
119  		CU_ASSERT_EQUAL(memcmp(&cropcap, &cropcap2, sizeof(cropcap)),
120  				0);
121  
122  	}
123  
124  }
125  
test_VIDIOC_CROPCAP()126  void test_VIDIOC_CROPCAP()
127  {
128  
129  	do_ioctl_VIDIOC_CROPCAP(0, -1);
130  	do_ioctl_VIDIOC_CROPCAP(V4L2_BUF_TYPE_VIDEO_CAPTURE, 0);
131  	do_ioctl_VIDIOC_CROPCAP(V4L2_BUF_TYPE_VIDEO_OUTPUT, 0);
132  	do_ioctl_VIDIOC_CROPCAP(V4L2_BUF_TYPE_VIDEO_OVERLAY, 0);
133  	do_ioctl_VIDIOC_CROPCAP(V4L2_BUF_TYPE_VBI_CAPTURE, -1);
134  	do_ioctl_VIDIOC_CROPCAP(V4L2_BUF_TYPE_VBI_OUTPUT, -1);
135  	do_ioctl_VIDIOC_CROPCAP(V4L2_BUF_TYPE_SLICED_VBI_CAPTURE, -1);
136  	do_ioctl_VIDIOC_CROPCAP(V4L2_BUF_TYPE_SLICED_VBI_OUTPUT, -1);
137  	do_ioctl_VIDIOC_CROPCAP(V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY, -1);
138  	do_ioctl_VIDIOC_CROPCAP(V4L2_BUF_TYPE_PRIVATE - 1, -1);
139  	do_ioctl_VIDIOC_CROPCAP(V4L2_BUF_TYPE_PRIVATE, 0);
140  	do_ioctl_VIDIOC_CROPCAP(V4L2_BUF_TYPE_PRIVATE + 1, 0);
141  	do_ioctl_VIDIOC_CROPCAP(S32_MAX, -1);
142  	do_ioctl_VIDIOC_CROPCAP(((__u32) S32_MAX) + 1, -1);
143  	do_ioctl_VIDIOC_CROPCAP(U32_MAX - 1, -1);
144  	do_ioctl_VIDIOC_CROPCAP(U32_MAX, -1);
145  
146  }
147  
test_VIDIOC_CROPCAP_enum_INPUT()148  void test_VIDIOC_CROPCAP_enum_INPUT()
149  {
150  	int ret_get, errno_get;
151  	int ret_set, errno_set;
152  	int enum_ret;
153  	__u32 input_index_orig;
154  	struct v4l2_input input;
155  	__u32 i;
156  	int f;
157  
158  	f = get_video_fd();
159  
160  	memset(&input_index_orig, 0xff, sizeof(input_index_orig));
161  	ret_get = ioctl(f, VIDIOC_G_INPUT, &input_index_orig);
162  	errno_get = errno;
163  
164  	if (ret_get == 0) {
165  		CU_ASSERT_EQUAL(ret_get, 0);
166  		i = 0;
167  		do {
168  			memset(&input, 0xff, sizeof(input));
169  			input.index = i;
170  			enum_ret = ioctl(f, VIDIOC_ENUMINPUT, &input);
171  
172  			dprintf
173  			    ("\t%s:%u: ENUMINPUT: i=%u, enum_ret=%i, errno=%i\n",
174  			     __FILE__, __LINE__, i, enum_ret, errno);
175  
176  			if (enum_ret == 0) {
177  				ret_set =
178  				    ioctl(f, VIDIOC_S_INPUT, &input.index);
179  				errno_set = errno;
180  
181  				dprintf
182  				    ("\t%s:%u: input.index=0x%X, ret_set=%i, errno_set=%i\n",
183  				     __FILE__, __LINE__, input.index, ret_set,
184  				     errno_set);
185  
186  				CU_ASSERT_EQUAL(ret_set, 0);
187  				if (ret_set == 0) {
188  					test_VIDIOC_CROPCAP();
189  				}
190  
191  			}
192  			i++;
193  		} while (enum_ret == 0 && i != 0);
194  
195  		/* Setting the original input_id should not fail */
196  		ret_set = ioctl(f, VIDIOC_S_INPUT, &input_index_orig);
197  		errno_set = errno;
198  
199  		CU_ASSERT_EQUAL(ret_set, 0);
200  	} else {
201  		CU_ASSERT_EQUAL(ret_get, -1);
202  		CU_ASSERT_EQUAL(errno_get, EINVAL);
203  	}
204  }
205  
test_VIDIOC_CROPCAP_NULL()206  void test_VIDIOC_CROPCAP_NULL()
207  {
208  	int ret_capture, errno_capture;
209  	int ret_output, errno_output;
210  	int ret_overlay, errno_overlay;
211  	int ret_private, errno_private;
212  	int ret_private_1, errno_private_1;
213  	int ret_null, errno_null;
214  	struct v4l2_cropcap cropcap;
215  
216  	memset(&cropcap, 0xff, sizeof(cropcap));
217  	cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
218  	ret_capture = ioctl(get_video_fd(), VIDIOC_CROPCAP, &cropcap);
219  	errno_capture = errno;
220  
221  	dprintf("\t%s:%u: VIDIOC_CROPCAP, ret_capture=%i, errno_capture=%i\n",
222  		__FILE__, __LINE__, ret_capture, errno_capture);
223  
224  	memset(&cropcap, 0xff, sizeof(cropcap));
225  	cropcap.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
226  	ret_output = ioctl(get_video_fd(), VIDIOC_CROPCAP, &cropcap);
227  	errno_output = errno;
228  
229  	dprintf("\t%s:%u: VIDIOC_CROPCAP, ret_output=%i, errno_output=%i\n",
230  		__FILE__, __LINE__, ret_output, errno_output);
231  
232  	memset(&cropcap, 0xff, sizeof(cropcap));
233  	cropcap.type = V4L2_BUF_TYPE_VIDEO_OVERLAY;
234  	ret_overlay = ioctl(get_video_fd(), VIDIOC_CROPCAP, &cropcap);
235  	errno_overlay = errno;
236  
237  	dprintf("\t%s:%u: VIDIOC_CROPCAP, ret_overlay=%i, errno_overlay=%i\n",
238  		__FILE__, __LINE__, ret_overlay, errno_overlay);
239  
240  	memset(&cropcap, 0xff, sizeof(cropcap));
241  	cropcap.type = V4L2_BUF_TYPE_PRIVATE;
242  	ret_private = ioctl(get_video_fd(), VIDIOC_CROPCAP, &cropcap);
243  	errno_private = errno;
244  
245  	dprintf("\t%s:%u: VIDIOC_CROPCAP, ret_private=%i, errno_private=%i\n",
246  		__FILE__, __LINE__, ret_private, errno_private);
247  
248  	memset(&cropcap, 0xff, sizeof(cropcap));
249  	cropcap.type = V4L2_BUF_TYPE_PRIVATE + 1;
250  	ret_private_1 = ioctl(get_video_fd(), VIDIOC_CROPCAP, &cropcap);
251  	errno_private_1 = errno;
252  
253  	dprintf
254  	    ("\t%s:%u: VIDIOC_CROPCAP, ret_private_1=%i, errno_private_1=%i\n",
255  	     __FILE__, __LINE__, ret_private_1, errno_private_1);
256  
257  	ret_null = ioctl(get_video_fd(), VIDIOC_CROPCAP, NULL);
258  	errno_null = errno;
259  
260  	dprintf("\t%s:%u: VIDIOC_CROPCAP, ret_null=%i, errno_null=%i\n",
261  		__FILE__, __LINE__, ret_null, errno_null);
262  
263  	/* Check if at least one type was supported */
264  	if (ret_capture == 0 || ret_output == 0 || ret_overlay == 0 ||
265  	    ret_private == 0 || ret_private_1 == 0) {
266  		/* the parameter shall be validated */
267  		CU_ASSERT_EQUAL(ret_null, -1);
268  		CU_ASSERT_EQUAL(errno_null, EFAULT);
269  	} else {
270  		/* VIDIOC_CROPCAP is not supported at all, the parameter
271  		 * shall also not be checked.
272  		 */
273  		CU_ASSERT_EQUAL(ret_capture, -1);
274  		CU_ASSERT_EQUAL(errno_capture, EINVAL);
275  		CU_ASSERT_EQUAL(ret_output, -1);
276  		CU_ASSERT_EQUAL(errno_output, EINVAL);
277  		CU_ASSERT_EQUAL(ret_overlay, -1);
278  		CU_ASSERT_EQUAL(errno_overlay, EINVAL);
279  		CU_ASSERT_EQUAL(ret_private, -1);
280  		CU_ASSERT_EQUAL(errno_private, EINVAL);
281  		CU_ASSERT_EQUAL(ret_private_1, -1);
282  		CU_ASSERT_EQUAL(errno_private_1, EINVAL);
283  		CU_ASSERT_EQUAL(ret_null, -1);
284  		CU_ASSERT_EQUAL(errno_null, EINVAL);
285  	}
286  
287  }
288