• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * v4l-test: Test environment for Video For Linux Two API
3  *
4  * 20 Apr 2009  0.4  Added string content validation
5  * 18 Apr 2009  0.3  More strict check for strings
6  * 28 Mar 2009  0.2  Clean up ret and errno variable names and dprintf() output
7  *  2 Feb 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 #include "v4l2_validator.h"
31 
32 #include "test_VIDIOC_MODULATOR.h"
33 
valid_modulator_sub(__u32 tuner_sub)34 int valid_modulator_sub(__u32 tuner_sub)
35 {
36 	int valid = 0;
37 
38 	CU_ASSERT_EQUAL(V4L2_TUNER_SUB_SAP, V4L2_TUNER_SUB_LANG2);
39 
40 	if ((tuner_sub & ~(V4L2_TUNER_SUB_MONO |
41 			   V4L2_TUNER_SUB_STEREO |
42 			   V4L2_TUNER_SUB_LANG1 |
43 			   V4L2_TUNER_SUB_LANG2 | V4L2_TUNER_SUB_SAP))
44 	    == 0) {
45 		valid = 1;
46 	} else {
47 		valid = 0;
48 	}
49 	return valid;
50 }
51 
do_get_modulator(int f,__u32 index)52 static int do_get_modulator(int f, __u32 index)
53 {
54 	int ret_get, errno_get;
55 	struct v4l2_modulator modulator;
56 	struct v4l2_modulator modulator2;
57 
58 	memset(&modulator, 0xff, sizeof(modulator));
59 	modulator.index = index;
60 	ret_get = ioctl(f, VIDIOC_G_MODULATOR, &modulator);
61 	errno_get = errno;
62 
63 	dprintf("\t%s:%u: VIDIOC_G_MODULATOR, ret_get=%i, errno_get=%i\n",
64 		__FILE__, __LINE__, ret_get, errno_get);
65 
66 	if (ret_get == 0) {
67 		CU_ASSERT_EQUAL(ret_get, 0);
68 
69 		CU_ASSERT_EQUAL(modulator.index, index);
70 
71 		CU_ASSERT(0 < strlen((char *)modulator.name));
72 		CU_ASSERT(valid_string
73 			  ((char *)modulator.name, sizeof(modulator.name)));
74 
75 		CU_ASSERT(valid_modulator_capability(modulator.capability));
76 
77 		CU_ASSERT(modulator.rangelow <= modulator.rangehigh);
78 
79 		CU_ASSERT(valid_modulator_sub(modulator.txsubchans));
80 
81 		CU_ASSERT_EQUAL(modulator.reserved[0], 0);
82 		CU_ASSERT_EQUAL(modulator.reserved[1], 0);
83 		CU_ASSERT_EQUAL(modulator.reserved[2], 0);
84 		CU_ASSERT_EQUAL(modulator.reserved[3], 0);
85 
86 		/* Check if the unused bytes of the name string are also filled
87 		 * with zeros. Also check if there is any padding byte between
88 		 * any two fields then this padding byte is also filled with
89 		 * zeros.
90 		 */
91 		memset(&modulator2, 0, sizeof(modulator2));
92 		modulator2.index = modulator.index;
93 		strncpy((char *)modulator2.name, (char *)modulator.name,
94 			sizeof(modulator2.name));
95 		modulator2.capability = modulator.capability;
96 		modulator2.rangelow = modulator.rangelow;
97 		modulator2.rangehigh = modulator.rangehigh;
98 		modulator2.txsubchans = modulator.txsubchans;
99 		CU_ASSERT_EQUAL(memcmp
100 				(&modulator, &modulator2, sizeof(modulator)),
101 				0);
102 
103 		dprintf("\tmodulator = { "
104 			".index = %u, "
105 			".name = \"%s\", "
106 			".capability = 0x%X, "
107 			".rangelow = %u, "
108 			".rangehigh = %u, "
109 			".txsubchans = %u, "
110 			".reserved[]={ 0x%X, 0x%X, 0x%X, 0x%X } }\n",
111 			modulator.index,
112 			modulator.name,
113 			modulator.capability,
114 			modulator.rangelow,
115 			modulator.rangehigh,
116 			modulator.txsubchans,
117 			modulator.reserved[0],
118 			modulator.reserved[1],
119 			modulator.reserved[2], modulator.reserved[3]
120 		    );
121 
122 	} else {
123 		dprintf("\t%s:%u: ret_get=%d (expected %d)\n", __FILE__,
124 			__LINE__, ret_get, -1);
125 		dprintf("\t%s:%u: errno_get=%d (expected %d)\n", __FILE__,
126 			__LINE__, errno_get, EINVAL);
127 		CU_ASSERT_EQUAL(ret_get, -1);
128 		CU_ASSERT_EQUAL(errno_get, EINVAL);
129 	}
130 
131 	return ret_get;
132 }
133 
test_VIDIOC_G_MODULATOR()134 void test_VIDIOC_G_MODULATOR()
135 {
136 	int ret;
137 	__u32 index;
138 	int f;
139 
140 	f = get_video_fd();
141 
142 	index = 0;
143 	do {
144 		ret = do_get_modulator(f, index);
145 		index++;
146 	} while (ret == 0);
147 
148 }
149 
test_VIDIOC_G_MODULATOR_S32_MAX()150 void test_VIDIOC_G_MODULATOR_S32_MAX()
151 {
152 	int ret_get, errno_get;
153 	__u32 index;
154 	struct v4l2_modulator modulator;
155 
156 	index = (__u32) S32_MAX;
157 
158 	memset(&modulator, 0xff, sizeof(modulator));
159 	modulator.index = index;
160 	ret_get = ioctl(get_video_fd(), VIDIOC_G_MODULATOR, &modulator);
161 	errno_get = errno;
162 
163 	dprintf("\t%s:%u: VIDIOC_G_MODULATOR, ret_get=%i, errno_get=%i\n",
164 		__FILE__, __LINE__, ret_get, errno_get);
165 
166 	dprintf("\t%s:%u: ret_get=%d (expected %d)\n", __FILE__, __LINE__,
167 		ret_get, -1);
168 	dprintf("\t%s:%u: errno_get=%d (expected %d)\n", __FILE__, __LINE__,
169 		errno_get, EINVAL);
170 	CU_ASSERT_EQUAL(ret_get, -1);
171 	CU_ASSERT_EQUAL(errno_get, EINVAL);
172 }
173 
test_VIDIOC_G_MODULATOR_S32_MAX_1()174 void test_VIDIOC_G_MODULATOR_S32_MAX_1()
175 {
176 	int ret_get, errno_get;
177 	__u32 index;
178 	struct v4l2_modulator modulator;
179 
180 	index = (__u32) S32_MAX + 1;
181 
182 	memset(&modulator, 0xff, sizeof(modulator));
183 	modulator.index = index;
184 	ret_get = ioctl(get_video_fd(), VIDIOC_G_MODULATOR, &modulator);
185 	errno_get = errno;
186 
187 	dprintf("VIDIOC_G_MODULATOR, ret_get=%i\n", ret_get);
188 
189 	dprintf("\t%s:%u: ret_get=%d (expected %d)\n", __FILE__, __LINE__,
190 		ret_get, -1);
191 	dprintf("\t%s:%u: errno_get=%d (expected %d)\n", __FILE__, __LINE__,
192 		errno_get, EINVAL);
193 	CU_ASSERT_EQUAL(ret_get, -1);
194 	CU_ASSERT_EQUAL(errno_get, EINVAL);
195 }
196 
test_VIDIOC_G_MODULATOR_U32_MAX()197 void test_VIDIOC_G_MODULATOR_U32_MAX()
198 {
199 	int ret_get, errno_get;
200 	__u32 index;
201 	struct v4l2_modulator modulator;
202 
203 	index = U32_MAX;
204 
205 	memset(&modulator, 0xff, sizeof(modulator));
206 	modulator.index = index;
207 	ret_get = ioctl(get_video_fd(), VIDIOC_G_MODULATOR, &modulator);
208 	errno_get = errno;
209 
210 	dprintf("\t%s:%u: VIDIOC_G_MODULATOR, ret_get=%i, errno_get=%i\n",
211 		__FILE__, __LINE__, ret_get, errno_get);
212 
213 	dprintf("\t%s:%u: ret_get=%d (expected %d)\n", __FILE__, __LINE__,
214 		ret_get, -1);
215 	dprintf("\t%s:%u: errno_get=%d (expected %d)\n", __FILE__, __LINE__,
216 		errno_get, EINVAL);
217 	CU_ASSERT_EQUAL(ret_get, -1);
218 	CU_ASSERT_EQUAL(errno_get, EINVAL);
219 }
220 
test_VIDIOC_G_MODULATOR_NULL()221 void test_VIDIOC_G_MODULATOR_NULL()
222 {
223 	int ret_get, errno_get;
224 	int ret_null, errno_null;
225 	struct v4l2_modulator modulator;
226 
227 	memset(&modulator, 0xff, sizeof(modulator));
228 	modulator.index = 0;
229 	ret_get = ioctl(get_video_fd(), VIDIOC_G_MODULATOR, &modulator);
230 	errno_get = errno;
231 
232 	dprintf("\t%s:%u: VIDIOC_G_MODULATOR, ret_get=%i, errno_get=%i\n",
233 		__FILE__, __LINE__, ret_get, errno_get);
234 
235 	ret_null = ioctl(get_video_fd(), VIDIOC_G_MODULATOR, NULL);
236 	errno_null = errno;
237 
238 	dprintf("\t%s:%u: VIDIOC_G_MODULATOR, ret_null=%i, errno_null=%i\n",
239 		__FILE__, __LINE__, ret_null, errno_null);
240 
241 	/* check if VIDIOC_G_MODULATOR is supported at all or not */
242 	if (ret_get == 0) {
243 		/* VIDIOC_G_MODULATOR is supported, the parameter should be checked */
244 		CU_ASSERT_EQUAL(ret_get, 0);
245 		CU_ASSERT_EQUAL(ret_null, -1);
246 		CU_ASSERT_EQUAL(errno_null, EFAULT);
247 	} else {
248 		/* VIDIOC_G_MODULATOR not supported at all, the parameter should not be evaluated */
249 		CU_ASSERT_EQUAL(ret_get, -1);
250 		CU_ASSERT_EQUAL(errno_get, EINVAL);
251 		CU_ASSERT_EQUAL(ret_null, -1);
252 		CU_ASSERT_EQUAL(errno_null, EINVAL);
253 	}
254 
255 }
256 
257 /* TODO: test cases for VIDIOC_S_MODULATOR */
258