git-svn: trunk@3764
Török Edvin authored on 2008/04/07 22:43:16... | ... |
@@ -165,10 +165,10 @@ END_TEST |
165 | 165 |
START_TEST (test_cl_strerror) |
166 | 166 |
END_TEST |
167 | 167 |
|
168 |
-Suite *test_cl_suite(void) |
|
168 |
+static Suite *test_cl_suite(void) |
|
169 | 169 |
{ |
170 |
- Suite *s = suite_create("cl_api"); |
|
171 |
- TCase *tc_cl = tcase_create("cl_dup"); |
|
170 |
+ Suite *s = suite_create("cl_api"); |
|
171 |
+ TCase *tc_cl = tcase_create("cl_dup"); |
|
172 | 172 |
|
173 | 173 |
suite_add_tcase (s, tc_cl); |
174 | 174 |
tcase_add_test(tc_cl, test_cl_free); |
... | ... |
@@ -194,11 +194,91 @@ Suite *test_cl_suite(void) |
194 | 194 |
return s; |
195 | 195 |
} |
196 | 196 |
|
197 |
+static uint8_t le_data[4] = {0x67,0x45,0x23,0x01}; |
|
198 |
+static int32_t le_expected[4] = { 0x01234567, 0x67012345, 0x45670123, 0x23456701}; |
|
199 |
+uint8_t *data; |
|
200 |
+uint8_t *data2; |
|
201 |
+#define DATA_REP 100 |
|
202 |
+ |
|
203 |
+static void data_setup(void) |
|
204 |
+{ |
|
205 |
+ uint8_t *p; |
|
206 |
+ size_t i; |
|
207 |
+ |
|
208 |
+ fail_unless(posix_memalign((void**)&data, 16, sizeof(le_data)*DATA_REP) == 0, "unable to allocate memory for fixture"); |
|
209 |
+ fail_unless(posix_memalign((void**)&data2, 16, sizeof(le_data)*DATA_REP) == 0, "unable to allocate memory for fixture"); |
|
210 |
+ p = data; |
|
211 |
+ /* make multiple copies of le_data, we need to run readint tests in a loop, so we need |
|
212 |
+ * to give it some data to run it on */ |
|
213 |
+ for(i=0; i<DATA_REP;i++) { |
|
214 |
+ memcpy(p, le_data, sizeof(le_data)); |
|
215 |
+ p += sizeof(le_data); |
|
216 |
+ } |
|
217 |
+ memset(data2, 0, DATA_REP*sizeof(le_data)); |
|
218 |
+} |
|
219 |
+ |
|
220 |
+static void data_teardown(void) |
|
221 |
+{ |
|
222 |
+ free(data); |
|
223 |
+} |
|
224 |
+ |
|
225 |
+/* test reading with different alignments, _i is parameter from tcase_add_loop_test */ |
|
226 |
+START_TEST (test_cli_readint) |
|
227 |
+{ |
|
228 |
+ size_t j; |
|
229 |
+ int32_t value = le_expected[_i&3]; |
|
230 |
+ /* read 4 bytes apart, start is not always aligned*/ |
|
231 |
+ for(j=_i;j < DATA_REP*sizeof(le_data) - 4;j += 4) { |
|
232 |
+ fail_unless(cli_readint32(&data[j]) == value, "(1) data read must be little endian"); |
|
233 |
+ } |
|
234 |
+ value = le_expected[0]; |
|
235 |
+ /* read 4 bytes apart, always aligned*/ |
|
236 |
+ for(j=0;j < DATA_REP*sizeof(le_data) - 4;j += 4) { |
|
237 |
+ fail_unless(cli_readint32(&data[j]) == value, "(2) data read must be little endian"); |
|
238 |
+ } |
|
239 |
+} |
|
240 |
+END_TEST |
|
241 |
+ |
|
242 |
+/* test writing with different alignments, _i is parameter from tcase_add_loop_test */ |
|
243 |
+START_TEST (test_cli_writeint) |
|
244 |
+{ |
|
245 |
+ size_t j; |
|
246 |
+ /* write 4 bytes apart, start is not always aligned*/ |
|
247 |
+ for(j=_i;j < DATA_REP*sizeof(le_data) - 4;j += 4) { |
|
248 |
+ cli_writeint32(&data2[j], 0x12345678); |
|
249 |
+ } |
|
250 |
+ for(j=_i;j < DATA_REP*sizeof(le_data) - 4;j += 4) { |
|
251 |
+ fail_unless(cli_readint32(&data2[j]) == 0x12345678, "write/read mismatch"); |
|
252 |
+ } |
|
253 |
+ /* write 4 bytes apart, always aligned*/ |
|
254 |
+ for(j=0;j < DATA_REP*sizeof(le_data) - 4;j += 4) { |
|
255 |
+ cli_writeint32(&data2[j], 0x12345678); |
|
256 |
+ } |
|
257 |
+ for(j=0;j < DATA_REP*sizeof(le_data) - 4;j += 4) { |
|
258 |
+ fail_unless(cli_readint32(&data2[j]) == 0x12345678, "write/read mismatch"); |
|
259 |
+ } |
|
260 |
+} |
|
261 |
+END_TEST |
|
262 |
+ |
|
263 |
+static Suite *test_cli_suite(void) |
|
264 |
+{ |
|
265 |
+ Suite *s = suite_create("cli"); |
|
266 |
+ TCase *tc_cli_others = tcase_create("byteorder_macros"); |
|
267 |
+ |
|
268 |
+ suite_add_tcase (s, tc_cli_others); |
|
269 |
+ tcase_add_checked_fixture (tc_cli_others, data_setup, data_teardown); |
|
270 |
+ tcase_add_loop_test(tc_cli_others, test_cli_readint, 0, 15); |
|
271 |
+ tcase_add_loop_test(tc_cli_others, test_cli_writeint, 0, 15); |
|
272 |
+ |
|
273 |
+ return s; |
|
274 |
+} |
|
275 |
+ |
|
197 | 276 |
int main(int argc, char **argv) |
198 | 277 |
{ |
199 |
- int nf; |
|
200 |
- Suite *s = test_cl_suite(); |
|
201 |
- SRunner *sr = srunner_create(s); |
|
278 |
+ int nf; |
|
279 |
+ Suite *s = test_cl_suite(); |
|
280 |
+ SRunner *sr = srunner_create(s); |
|
281 |
+ srunner_add_suite(sr, test_cli_suite()); |
|
202 | 282 |
|
203 | 283 |
srunner_set_log(sr, "test.log"); |
204 | 284 |
srunner_run_all(sr, CK_NORMAL); |