• 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  * 25 Mar 2009  0.2  Typos corrected, cleaned up dprintf() outputs;
7  *                   cleaned up ret and errno variable names
8  *  1 Jan 2009  0.1  First release
9  *
10  * Written by M�rton N�meth <nm127@freemail.hu>
11  * Released under GPL
12  *
13  * Note: in ioctl VIDIOC_ENUMAUDOUT reference (doc/spec/r8304.htm)
14  * the description text mentions the VIDIOC_G_AUDOUT should
15  * be called. This is a typo in the V4L2 specification (revision 0.24).
16  * To enumerate the audio outputs the VIDIOC_ENUMAUDOUT should be
17  * called.
18  *
19  */
20 
21 #include <stdio.h>
22 #include <sys/types.h>
23 #include <sys/stat.h>
24 #include <fcntl.h>
25 #include <unistd.h>
26 #include <sys/ioctl.h>
27 #include <errno.h>
28 #include <string.h>
29 
30 #include <linux/videodev2.h>
31 #include <linux/errno.h>
32 
33 #include <CUnit/CUnit.h>
34 #include <CUnit/Basic.h>
35 
36 #include "v4l2_test.h"
37 #include "dev_video.h"
38 #include "video_limits.h"
39 #include "v4l2_validator.h"
40 
41 #include "test_VIDIOC_ENUMAUDOUT.h"
42 
test_VIDIOC_ENUMAUDOUT()43 void test_VIDIOC_ENUMAUDOUT()
44 {
45 	int ret_enum, errno_enum;
46 	struct v4l2_audioout audioout;
47 	struct v4l2_audioout audioout2;
48 	__u32 i;
49 
50 	i = 0;
51 	do {
52 		memset(&audioout, 0xff, sizeof(audioout));
53 		audioout.index = i;
54 		ret_enum = ioctl(get_video_fd(), VIDIOC_ENUMAUDOUT, &audioout);
55 		errno_enum = errno;
56 
57 		dprintf("\tVIDIOC_ENUMAUDOUT, ret_enum=%i, errno_enum=%i\n",
58 			ret_enum, errno_enum);
59 
60 		if (ret_enum == 0) {
61 			CU_ASSERT_EQUAL(ret_enum, 0);
62 			CU_ASSERT_EQUAL(audioout.index, i);
63 
64 			CU_ASSERT(0 < strlen((char *)audioout.name));
65 			CU_ASSERT(valid_string
66 				  ((char *)audioout.name,
67 				   sizeof(audioout.name)));
68 
69 			//CU_ASSERT_EQUAL(audioout.capability, ?);
70 			//CU_ASSERT_EQUAL(audioout.mode, ?);
71 			CU_ASSERT_EQUAL(audioout.reserved[0], 0);
72 			CU_ASSERT_EQUAL(audioout.reserved[1], 0);
73 
74 			/* Check if the unused bytes of the name string are
75 			 * also filled with zeros. Also check if there is any
76 			 * padding byte between any two fields then this
77 			 * padding byte is also filled with zeros.
78 			 */
79 			memset(&audioout2, 0, sizeof(audioout2));
80 			audioout2.index = audioout.index;
81 			strncpy((char *)audioout2.name, (char *)audioout.name,
82 				sizeof(audioout2.name));
83 			audioout2.capability = audioout.capability;
84 			audioout2.mode = audioout.mode;
85 			CU_ASSERT_EQUAL(memcmp
86 					(&audioout, &audioout2,
87 					 sizeof(audioout)), 0);
88 
89 			dprintf("\taudioout = {.index=%u, .name=\"%s\", "
90 				".capability=0x%X, .mode=0x%X, "
91 				".reserved[]={ 0x%X, 0x%X } }\n",
92 				audioout.index,
93 				audioout.name,
94 				audioout.capability,
95 				audioout.mode,
96 				audioout.reserved[0], audioout.reserved[1]
97 			    );
98 
99 		} else {
100 			CU_ASSERT_EQUAL(ret_enum, -1);
101 			CU_ASSERT_EQUAL(errno_enum, EINVAL);
102 
103 			/* check whether the structure is untouched */
104 			memset(&audioout2, 0xff, sizeof(audioout2));
105 			audioout2.index = i;
106 			CU_ASSERT_EQUAL(memcmp
107 					(&audioout, &audioout2,
108 					 sizeof(audioout)), 0);
109 
110 		}
111 		i++;
112 	} while (ret_enum == 0);
113 
114 }
115 
test_VIDIOC_ENUMAUDOUT_S32_MAX()116 void test_VIDIOC_ENUMAUDOUT_S32_MAX()
117 {
118 	int ret_enum, errno_enum;
119 	struct v4l2_audioout audioout;
120 	struct v4l2_audioout audioout2;
121 
122 	memset(&audioout, 0xff, sizeof(audioout));
123 	audioout.index = (__u32) S32_MAX;
124 	ret_enum = ioctl(get_video_fd(), VIDIOC_ENUMAUDOUT, &audioout);
125 	errno_enum = errno;
126 
127 	CU_ASSERT_EQUAL(ret_enum, -1);
128 	CU_ASSERT_EQUAL(errno_enum, EINVAL);
129 
130 	/* Check whether the original audioout struct is untouched */
131 	memset(&audioout2, 0xff, sizeof(audioout2));
132 	audioout2.index = (__u32) S32_MAX;
133 	CU_ASSERT_EQUAL(memcmp(&audioout, &audioout2, sizeof(audioout)), 0);
134 }
135 
test_VIDIOC_ENUMAUDOUT_S32_MAX_1()136 void test_VIDIOC_ENUMAUDOUT_S32_MAX_1()
137 {
138 	int ret_enum, errno_enum;
139 	struct v4l2_audioout audioout;
140 	struct v4l2_audioout audioout2;
141 
142 	memset(&audioout, 0xff, sizeof(audioout));
143 	audioout.index = ((__u32) S32_MAX) + 1;
144 	ret_enum = ioctl(get_video_fd(), VIDIOC_ENUMAUDOUT, &audioout);
145 	errno_enum = errno;
146 
147 	CU_ASSERT_EQUAL(ret_enum, -1);
148 	CU_ASSERT_EQUAL(errno_enum, EINVAL);
149 
150 	/* Check whether the original audioout struct is untouched */
151 	memset(&audioout2, 0xff, sizeof(audioout2));
152 	audioout2.index = ((__u32) S32_MAX) + 1;
153 	CU_ASSERT_EQUAL(memcmp(&audioout, &audioout2, sizeof(audioout)), 0);
154 }
155 
test_VIDIOC_ENUMAUDOUT_U32_MAX()156 void test_VIDIOC_ENUMAUDOUT_U32_MAX()
157 {
158 	int ret_enum, errno_enum;
159 	struct v4l2_audioout audioout;
160 	struct v4l2_audioout audioout2;
161 
162 	memset(&audioout, 0xff, sizeof(audioout));
163 	audioout.index = U32_MAX;
164 	ret_enum = ioctl(get_video_fd(), VIDIOC_ENUMAUDOUT, &audioout);
165 	errno_enum = errno;
166 
167 	CU_ASSERT_EQUAL(ret_enum, -1);
168 	CU_ASSERT_EQUAL(errno_enum, EINVAL);
169 
170 	/* Check whether the original audioout struct is untouched */
171 	memset(&audioout2, 0xff, sizeof(audioout2));
172 	audioout2.index = U32_MAX;
173 	CU_ASSERT_EQUAL(memcmp(&audioout, &audioout2, sizeof(audioout)), 0);
174 }
175 
test_VIDIOC_ENUMAUDOUT_NULL()176 void test_VIDIOC_ENUMAUDOUT_NULL()
177 {
178 	int ret_enum, errno_enum;
179 	struct v4l2_audioout audioout;
180 	int ret_null, errno_null;
181 
182 	memset(&audioout, 0, sizeof(audioout));
183 	audioout.index = 0;
184 	ret_enum = ioctl(get_video_fd(), VIDIOC_ENUMAUDOUT, &audioout);
185 	errno_enum = errno;
186 
187 	dprintf("\t%s:%u: VIDIOC_ENUMAUDOUT, ret_enum=%i, errno_enum=%i\n",
188 		__FILE__, __LINE__, ret_enum, errno_enum);
189 
190 	ret_null = ioctl(get_video_fd(), VIDIOC_ENUMAUDOUT, NULL);
191 	errno_null = errno;
192 
193 	dprintf("\t%s:%u: VIDIOC_ENUMAUDOUT, ret_null=%i, errno_null=%i\n",
194 		__FILE__, __LINE__, ret_null, errno_null);
195 
196 	if (ret_enum == 0) {
197 		CU_ASSERT_EQUAL(ret_enum, 0);
198 		CU_ASSERT_EQUAL(ret_null, -1);
199 		CU_ASSERT_EQUAL(errno_null, EFAULT);
200 	} else {
201 		CU_ASSERT_EQUAL(ret_enum, -1);
202 		CU_ASSERT_EQUAL(errno_enum, EINVAL);
203 		CU_ASSERT_EQUAL(ret_null, -1);
204 		CU_ASSERT_EQUAL(errno_null, EINVAL);
205 	}
206 
207 }
208