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