• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * v4l-test: Test environment for Video For Linux Two API
3  *
4  * 20 Apr 2009  0.7  Added string content validation
5  * 18 Apr 2009  0.6  More strict check for strings
6  * 29 Mar 2009  0.5  Clean up test case for NULL parameter
7  * 28 Mar 2009  0.4  Clean up ret and errno variable names and dprintf() output
8  *  1 Jan 2009  0.3  Added index=S32_MAX, S32_MAX+1 and U32_MAX
9  * 22 Dec 2008  0.2  Test case with NULL parameter added
10  * 18 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 #include <CUnit/Basic.h>
30 
31 #include "v4l2_test.h"
32 #include "dev_video.h"
33 #include "video_limits.h"
34 #include "v4l2_validator.h"
35 
36 #include "test_VIDIOC_ENUMAUDIO.h"
37 
test_VIDIOC_ENUMAUDIO()38 void test_VIDIOC_ENUMAUDIO()
39 {
40 	int ret_enum, errno_enum;
41 	struct v4l2_audio audio;
42 	struct v4l2_audio audio2;
43 	__u32 i;
44 
45 	i = 0;
46 	do {
47 		memset(&audio, 0xff, sizeof(audio));
48 		audio.index = i;
49 		ret_enum = ioctl(get_video_fd(), VIDIOC_ENUMAUDIO, &audio);
50 		errno_enum = errno;
51 
52 		dprintf
53 		    ("\t%s:%u: VIDIOC_ENUMAUDIO, ret_enum=%i, errno_enum=%i\n",
54 		     __FILE__, __LINE__, ret_enum, errno_enum);
55 
56 		if (ret_enum == 0) {
57 			CU_ASSERT_EQUAL(ret_enum, 0);
58 			CU_ASSERT_EQUAL(audio.index, i);
59 
60 			CU_ASSERT(0 < strlen((char *)audio.name));
61 			CU_ASSERT(valid_string
62 				  ((char *)audio.name, sizeof(audio.name)));
63 
64 			//CU_ASSERT_EQUAL(audio.capability, ?);
65 			//CU_ASSERT_EQUAL(audio.mode, ?);
66 			CU_ASSERT_EQUAL(audio.reserved[0], 0);
67 			CU_ASSERT_EQUAL(audio.reserved[1], 0);
68 
69 			/* Check if the unused bytes of the name string are
70 			 * also filled with zeros. Also check if there is any
71 			 * padding byte between any two fields then this
72 			 * padding byte is also filled with zeros.
73 			 */
74 			memset(&audio2, 0, sizeof(audio2));
75 			audio2.index = audio.index;
76 			strncpy((char *)audio2.name, (char *)audio.name,
77 				sizeof(audio2.name));
78 			audio2.capability = audio.capability;
79 			audio2.mode = audio.mode;
80 			CU_ASSERT_EQUAL(memcmp(&audio, &audio2, sizeof(audio)),
81 					0);
82 
83 			dprintf("\taudio = {.index=%u, .name=\"%s\", "
84 				".capability=0x%X, .mode=0x%X, "
85 				".reserved[]={ 0x%X, 0x%X } }\n",
86 				audio.index,
87 				audio.name,
88 				audio.capability,
89 				audio.mode, audio.reserved[0], audio.reserved[1]
90 			    );
91 
92 		} else {
93 			CU_ASSERT_EQUAL(ret_enum, -1);
94 			CU_ASSERT_EQUAL(errno_enum, EINVAL);
95 
96 			memset(&audio2, 0xff, sizeof(audio2));
97 			audio2.index = i;
98 			CU_ASSERT_EQUAL(memcmp(&audio, &audio2, sizeof(audio)),
99 					0);
100 
101 		}
102 		i++;
103 	} while (ret_enum == 0);
104 
105 }
106 
test_VIDIOC_ENUMAUDIO_S32_MAX()107 void test_VIDIOC_ENUMAUDIO_S32_MAX()
108 {
109 	int ret_enum, errno_enum;
110 	struct v4l2_audio audio;
111 	struct v4l2_audio audio2;
112 
113 	memset(&audio, 0xff, sizeof(audio));
114 	audio.index = (__u32) S32_MAX;
115 	ret_enum = ioctl(get_video_fd(), VIDIOC_ENUMAUDIO, &audio);
116 	errno_enum = errno;
117 
118 	CU_ASSERT_EQUAL(ret_enum, -1);
119 	CU_ASSERT_EQUAL(errno_enum, EINVAL);
120 
121 	/* Check whether the original audio struct is untouched */
122 	memset(&audio2, 0xff, sizeof(audio2));
123 	audio2.index = (__u32) S32_MAX;
124 	CU_ASSERT_EQUAL(memcmp(&audio, &audio2, sizeof(audio)), 0);
125 }
126 
test_VIDIOC_ENUMAUDIO_S32_MAX_1()127 void test_VIDIOC_ENUMAUDIO_S32_MAX_1()
128 {
129 	int ret_enum, errno_enum;
130 	struct v4l2_audio audio;
131 	struct v4l2_audio audio2;
132 
133 	memset(&audio, 0xff, sizeof(audio));
134 	audio.index = ((__u32) S32_MAX) + 1;
135 	ret_enum = ioctl(get_video_fd(), VIDIOC_ENUMAUDIO, &audio);
136 	errno_enum = errno;
137 
138 	CU_ASSERT_EQUAL(ret_enum, -1);
139 	CU_ASSERT_EQUAL(errno_enum, EINVAL);
140 
141 	/* Check whether the original audio struct is untouched */
142 	memset(&audio2, 0xff, sizeof(audio2));
143 	audio2.index = ((__u32) S32_MAX) + 1;
144 	CU_ASSERT_EQUAL(memcmp(&audio, &audio2, sizeof(audio)), 0);
145 }
146 
test_VIDIOC_ENUMAUDIO_U32_MAX()147 void test_VIDIOC_ENUMAUDIO_U32_MAX()
148 {
149 	int ret_enum, errno_enum;
150 	struct v4l2_audio audio;
151 	struct v4l2_audio audio2;
152 
153 	memset(&audio, 0xff, sizeof(audio));
154 	audio.index = U32_MAX;
155 	ret_enum = ioctl(get_video_fd(), VIDIOC_ENUMAUDIO, &audio);
156 	errno_enum = errno;
157 
158 	CU_ASSERT_EQUAL(ret_enum, -1);
159 	CU_ASSERT_EQUAL(errno_enum, EINVAL);
160 
161 	/* Check whether the original audio struct is untouched */
162 	memset(&audio2, 0xff, sizeof(audio2));
163 	audio2.index = U32_MAX;
164 	CU_ASSERT_EQUAL(memcmp(&audio, &audio2, sizeof(audio)), 0);
165 }
166 
test_VIDIOC_ENUMAUDIO_NULL()167 void test_VIDIOC_ENUMAUDIO_NULL()
168 {
169 	int ret_enum, errno_enum;
170 	int ret_null, errno_null;
171 	struct v4l2_audio audio;
172 
173 	memset(&audio, 0, sizeof(audio));
174 	audio.index = 0;
175 	ret_enum = ioctl(get_video_fd(), VIDIOC_ENUMAUDIO, &audio);
176 	errno_enum = errno;
177 
178 	dprintf("\t%s:%u: VIDIOC_ENUMAUDIO, ret_enum=%i, errno_enum=%i\n",
179 		__FILE__, __LINE__, ret_enum, errno_enum);
180 
181 	ret_null = ioctl(get_video_fd(), VIDIOC_ENUMAUDIO, NULL);
182 	errno_null = errno;
183 
184 	dprintf("\t%s:%u: VIDIOC_ENUMAUDIO, ret_null=%i, errno_null=%i\n",
185 		__FILE__, __LINE__, ret_null, errno_null);
186 
187 	if (ret_enum == 0) {
188 		CU_ASSERT_EQUAL(ret_enum, 0);
189 		CU_ASSERT_EQUAL(ret_null, -1);
190 		CU_ASSERT_EQUAL(errno_null, EFAULT);
191 	} else {
192 		CU_ASSERT_EQUAL(ret_enum, -1);
193 		CU_ASSERT_EQUAL(errno_enum, EINVAL);
194 		CU_ASSERT_EQUAL(ret_null, -1);
195 		CU_ASSERT_EQUAL(errno_null, EINVAL);
196 	}
197 
198 }
199