udftools

- Main Page
- Classes
- Files

- File List
- File Members

All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
test.c
Go to the documentation of this file.
1
2 #include "config.h"
3
4 #include <stdarg.h>
5 #include <stddef.h>
6 #include <setjmp.h>
7 #include <cmocka.h>
8
9 #include <unistd.h>
10 #include <stdio.h>
11 #include <string.h>
12 #include <errno.h>
13 #include <sys/wait.h>
14 #include <sys/stat.h>
15 #include <sys/types.h>
16 #include <fcntl.h>
17 #include <time.h>
18
19 // UDF fsck error codes
20 #define NO_ERR 0
21 #define ERR_FIXED 1
22 #define ERR_UNFIXED 4
23 #define PROG_ERR 8
24 #define WRONG_PARS 16
25 #define USER_INTERRUPT 32
26
38 int fsck_wrapper(const char * medium, char *const args, char *const argB) {
39 char cwd[1024];
40 if (getcwd(cwd, sizeof(cwd)) != NULL) {
41 strcpy(cwd + strlen(cwd), "/udffsck");
42 } else {
43 printf("getcwd error. Aborting.\n");
44 return -1;
45 }
46
47
48 char medpwd[10240];
49 #if BASIC_TESTS
50 sprintf(medpwd, "../../udf-samples/%s.img", medium);
51 #elif EXTRA_TESTS
52 sprintf(medpwd, "../../udf-samples-extra/%s.img", medium);
53 #else
54 #error NO TEST DEFINED
55 #endif
56 printf("Medium: %s\n", medpwd);
57 char * const pars[] = {
58 cwd,
59 medpwd,
60 args,
61 argB,
62 NULL
63 };
64
65 time_t t = time(NULL);
66 struct tm tm = *localtime(&t);
67 char fout[1024];
68 char ferr[1024];
69 #if BASIC_TESTS
70 sprintf(fout, "../../udf-samples/%d-%02d-%02d-%02d-%02d-%02d_%s.img.out", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, medium);
71 sprintf(ferr, "../../udf-samples/%d-%02d-%02d-%02d-%02d-%02d_%s.img.err", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, medium);
72 #endif
73 #if EXTRA_TESTS
74 sprintf(fout, "../../udf-samples-extra/%d-%02d-%02d-%02d-%02d-%02d_%s.img.out", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, medium);
75 sprintf(ferr, "../../udf-samples-extra/%d-%02d-%02d-%02d-%02d-%02d_%s.img.err", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, medium);
76 #endif
77
78 int pipefd[3];
79 pipe(pipefd);
80
81 int statval, exitval;
82 if(fork() == 0) {
83 int fdout = open(fout, O_RDWR | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR);
84 int fderr = open(ferr, O_RDWR | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR);
85 dup2(fdout, 1); // make stdout go to file
86 dup2(fderr, 2); // make stderr go to file
87 close(fdout); // fd no longer needed - the dup'ed handles are sufficient
88 close(fderr); // fd no longer needed - the dup'ed handles are sufficient
89
90 execv(cwd, pars);
91 } else {
92 wait(&statval);
93 if(WIFEXITED(statval)) {
94 printf("Child's exit code %d\n", WEXITSTATUS(statval));
95 exitval = WEXITSTATUS(statval);
96 } else {
97 printf("Child did not terminate with exit\n");
98 exitval = -1;
99 }
100 return exitval;
101 }
102 return 0;
103 }
104
105 static void blank_pass(void **state) {
106 (void) state;
107
108 assert_int_equal(2, 2);
109 }
110
111 static void blank_fail(void **state) {
112 (void) state;
113
114 assert_int_equal(2, -3);
115 }
116
125 static void bs2048_dirty_file_tree_1(void **state) {
126 (void) state;
127 char *medium = "bs2048-r0201-dirty-file-tree";
128 assert_int_equal(fsck_wrapper(medium, "-vvc", "-B 2048"), 4); //Check it
129 assert_int_equal(fsck_wrapper(medium, "-vvp", "-B 2048"), 1); //Fix it
130 assert_int_equal(fsck_wrapper(medium, "-vvc", "-B 2048"), 0); //Check it
131 }
132
141 static void bs2048_dirty_file_tree_2(void **state) {
142 (void) state;
143 char *medium = "bs2048-r0201-dirty-file-tree-deleted-peregrine";
144 assert_int_equal(fsck_wrapper(medium, "-vvc", "-B 2048"), 4); //Check it
145 assert_int_equal(fsck_wrapper(medium, "-vvp", "-B 2048"), 1); //Fix it
146 assert_int_equal(fsck_wrapper(medium, "-vvc", "-B 2048"), 0); //Check it
147 }
148
158 static void bs2048_dirty_file_tree_3(void **state) {
159 (void) state;
160 char *medium = "bs2048-r0201-broken-UUIDs";
161 assert_int_equal(fsck_wrapper(medium, "-vvc", "-B 2048"), 4); //Check it
162 assert_int_equal(fsck_wrapper(medium, "-vvp", "-B 2048"), 1); //Fix it
163 assert_int_equal(fsck_wrapper(medium, "-vvc", "-B 2048"), 0); //Check it
164 }
165
171 static void bs2048_clean(void **state) {
172 (void) state;
173 char *medium = "bs2048-r0201-clean";
174 assert_int_equal(fsck_wrapper(medium, "-vvc", "-B 2048"), 0); //Check it
175 }
176
182 static void bs2048_apple_r0260(void **state) {
183 (void) state;
184 char *medium = "bs2048-r0260-apple";
185 assert_int_equal(fsck_wrapper(medium, "-vvc", "-B 2048"), 8); //Check it
186 }
187
194 static void bs2048_apple_r0150(void **state) {
195 (void) state;
196 char *medium = "bs2048-r0150-apple";
197 assert_int_equal(fsck_wrapper(medium, "-vvc", "-B 2048"), 0); //Check it
198 }
199
206 static void bs512_windows7(void **state) {
207 (void) state;
208 char *medium = "udf-hdd-win7";
209 assert_int_equal(fsck_wrapper(medium, "-vvc", "-B 512"), 0); //Check it
210 }
211
218 static void bs2048_udfclient_075(void **state) {
219 (void) state;
220 char *medium = "udf-hdd-udfclient-0.7.5";
221 assert_int_equal(fsck_wrapper(medium, "-vvc", ""), 0); //Check it
222 }
223
230 static void bs2048_udfclient_077(void **state) {
231 (void) state;
232 char *medium = "udf-hdd-udfclient-0.7.7";
233 assert_int_equal(fsck_wrapper(medium, "-vvc", ""), 0); //Check it
234 }
235
242 static void bs512_blocksize_detection_test(void **state) {
243 (void) state;
244 char *medium = "bs512-r0150";
245 assert_int_equal(fsck_wrapper(medium, "-vvc", ""), 0); //Check it
246 }
247
254 static void bs1024_blocksize_detection_test(void **state) {
255 (void) state;
256 char *medium = "bs1024-r0150";
257 assert_int_equal(fsck_wrapper(medium, "-vvc", ""), 0); //Check it
258 }
259
266 static void bs2048_blocksize_detection_test(void **state) {
267 (void) state;
268 char *medium = "bs2048-r0201";
269 assert_int_equal(fsck_wrapper(medium, "-vvc", ""), 0); //Check it
270 }
271
278 static void bs4096_blocksize_detection_test(void **state) {
279 (void) state;
280 char *medium = "bs4096";
281 assert_int_equal(fsck_wrapper(medium, "-vvc", ""), 0); //Check it
282 }
283
290 static void bs1024_unclosed_medium(void **state) {
291 (void) state;
292 char *medium = "bs1024-r0150-unclosed";
293 assert_int_equal(fsck_wrapper(medium, "-vvc", ""), 4); //Check it
294 assert_int_equal(fsck_wrapper(medium, "-vvc", "-B 1024"), 0); //Check it
295 }
296
303 static void bs512_defect_primary_vds(void **state) {
304 (void) state;
305 char *medium = "bs512-defect-primary-vds";
306 assert_int_equal(fsck_wrapper(medium, "-vvc", ""), 4); //Check it
307 assert_int_equal(fsck_wrapper(medium, "-vvp", ""), 1); //Fix it
308 assert_int_equal(fsck_wrapper(medium, "-vvc", ""), 0); //Check it
309 }
310
317 static void bs2048_defect_avdp1(void **state) {
318 (void) state;
319 char *medium = "bs2048-r0201-brokenAVDP1";
320 assert_int_equal(fsck_wrapper(medium, "-vvc", ""), 4); //Check it
321 assert_int_equal(fsck_wrapper(medium, "-vvp", ""), 1); //Fix it
322 assert_int_equal(fsck_wrapper(medium, "-vvc", ""), 0); //Check it
323 }
324
333 static void bs512_crossplatform_1(void **state) {
334 (void) state;
335 char *medium = "bs512_windows7_udf0201";
336 assert_int_equal(fsck_wrapper(medium, "-vvc", ""), 0); //Check it
337 }
338
347 static void bs512_crossplatform_2(void **state) {
348 (void) state;
349 char *medium = "bs512_windows7_udf0201_broken_file_tree";
350 assert_int_equal(fsck_wrapper(medium, "-vvc", ""), 4); //Check it
351 assert_int_equal(fsck_wrapper(medium, "-vvp", ""), 1); //fix it
352 assert_int_equal(fsck_wrapper(medium, "-vvc", ""), 0); //Check it
353 }
354
363 static void bs512_crossplatform_3(void **state) {
364 (void) state;
365 char *medium = "bs512_windows7_udf0201_chkdsk";
366 assert_int_equal(fsck_wrapper(medium, "-vvc", ""), 4); //Check it
367 assert_int_equal(fsck_wrapper(medium, "-vvp", ""), 1); //Fix it
368 assert_int_equal(fsck_wrapper(medium, "-vvc", ""), 0); //Check it
369 }
370
379 static void bs512_crossplatform_4(void **state) {
380 (void) state;
381 char *medium = "bs512_windows7_udf0201-serial-broken-linux-written";
382 assert_int_equal(fsck_wrapper(medium, "-vvc", ""), 4); //Check it
383 assert_int_equal(fsck_wrapper(medium, "-vvp", ""), 1); //Fix it
384 assert_int_equal(fsck_wrapper(medium, "-vvc", ""), 0); //Check it
385 }
386
395 static void bs512_crossplatform_5(void **state) {
396 (void) state;
397 char *medium = "bs512_windows7_udf0201-serial-broken-linux-written-afterfix-win-write";
398 assert_int_equal(fsck_wrapper(medium, "-vvc", ""), 0); //Check it
399 }
400
409 static void bs512_crossplatform_6(void **state) {
410 (void) state;
411 char *medium = "bs512_windows7_udf0201-aed-test-lot-of-files-open-integrity";
412 assert_int_equal(fsck_wrapper(medium, "-vvc", ""), 4); //Check it
413 assert_int_equal(fsck_wrapper(medium, "-vvp", ""), 1); //Fix it
414 assert_int_equal(fsck_wrapper(medium, "-vvc", ""), 0); //Check it
415 }
416
425 static void bs512_crossplatform_7(void **state) {
426 (void) state;
427 char *medium = "bs512_windows7_udf0201-linux-before-fix";
428 assert_int_equal(fsck_wrapper(medium, "-vvc", ""), 4); //Check it
429 assert_int_equal(fsck_wrapper(medium, "-vvp", ""), 1); //Fix it
430 assert_int_equal(fsck_wrapper(medium, "-vvc", ""), 0); //Check it
431 }
432
433 int main(void) {
434 const struct CMUnitTest tests[] = {
435 #ifdef DEMO
436 cmocka_unit_test(blank_fail),
437 cmocka_unit_test(blank_pass),
438 #endif
439 #if BASIC_TESTS
440 cmocka_unit_test(bs2048_dirty_file_tree_1),
441 cmocka_unit_test(bs2048_dirty_file_tree_2),
442 cmocka_unit_test(bs2048_dirty_file_tree_3),
443 cmocka_unit_test(bs2048_clean),
444 cmocka_unit_test(bs2048_apple_r0150),
445 cmocka_unit_test(bs2048_apple_r0260),
446 cmocka_unit_test(bs512_windows7),
447 cmocka_unit_test(bs2048_udfclient_075),
448 cmocka_unit_test(bs2048_udfclient_077),
449 cmocka_unit_test(bs512_blocksize_detection_test),
450 cmocka_unit_test(bs1024_blocksize_detection_test),
451 cmocka_unit_test(bs2048_blocksize_detection_test),
452 cmocka_unit_test(bs4096_blocksize_detection_test),
453 cmocka_unit_test(bs1024_unclosed_medium),
454 cmocka_unit_test(bs512_defect_primary_vds),
455 cmocka_unit_test(bs2048_defect_avdp1),
456 cmocka_unit_test(bs512_crossplatform_6),
457 #endif
458 #if EXTRA_TESTS
459 cmocka_unit_test(bs512_crossplatform_1),
460 cmocka_unit_test(bs512_crossplatform_2),
461 cmocka_unit_test(bs512_crossplatform_3),
462 cmocka_unit_test(bs512_crossplatform_4),
463 cmocka_unit_test(bs512_crossplatform_5),
464 cmocka_unit_test(bs512_crossplatform_7),
465 #endif
466 };
467
468 return cmocka_run_group_tests(tests, NULL, NULL);
469 }
blank_pass
static void blank_pass(void **state)
Definition: test.c:105
bs2048_defect_avdp1
static void bs2048_defect_avdp1(void **state)
Defective AVDP1.
Definition: test.c:317
bs1024_unclosed_medium
static void bs1024_unclosed_medium(void **state)
Unclosed medium check.
Definition: test.c:290
bs2048_udfclient_075
static void bs2048_udfclient_075(void **state)
Test against udfclient 0.7.5.
Definition: test.c:218
bs512_crossplatform_4
static void bs512_crossplatform_4(void **state)
Crosplatform medium test no. 4.
Definition: test.c:379
bs4096_blocksize_detection_test
static void bs4096_blocksize_detection_test(void **state)
Blocksize detection test.
Definition: test.c:278
bs2048_apple_r0150
static void bs2048_apple_r0150(void **state)
This medium should be clean.
Definition: test.c:194
medium
enum MEDIUM medium
Definition: wrudf.c:20
bs512_crossplatform_3
static void bs512_crossplatform_3(void **state)
Crosplatform medium test no. 3.
Definition: test.c:363
bs2048_blocksize_detection_test
static void bs2048_blocksize_detection_test(void **state)
Blocksize detection test.
Definition: test.c:266
bs512_windows7
static void bs512_windows7(void **state)
Test against UDF from Windows.
Definition: test.c:206
bs512_crossplatform_2
static void bs512_crossplatform_2(void **state)
Crosplatform medium test no. 2.
Definition: test.c:347
main
int main(void)
Definition: test.c:433
bs512_crossplatform_5
static void bs512_crossplatform_5(void **state)
Crosplatform medium test no. 5.
Definition: test.c:395
bs512_crossplatform_1
static void bs512_crossplatform_1(void **state)
Crosplatform medium test no. 1.
Definition: test.c:333
bs512_defect_primary_vds
static void bs512_defect_primary_vds(void **state)
Defective primary VDS.
Definition: test.c:303
fsck_wrapper
int fsck_wrapper(const char *medium, char *const args, char *const argB)
UDF fsck exec wrapper for simplified test writing.
Definition: test.c:38
blank_fail
static void blank_fail(void **state)
Definition: test.c:111
bs2048_udfclient_077
static void bs2048_udfclient_077(void **state)
Test against udfclient 0.7.7.
Definition: test.c:230
bs2048_dirty_file_tree_1
static void bs2048_dirty_file_tree_1(void **state)
Test against unfinished write operation. Medium was not more used.
Definition: test.c:125
bs512_crossplatform_6
static void bs512_crossplatform_6(void **state)
Crosplatform medium test no. 6.
Definition: test.c:409
bs512_blocksize_detection_test
static void bs512_blocksize_detection_test(void **state)
Blocksize detection test.
Definition: test.c:242
bs512_crossplatform_7
static void bs512_crossplatform_7(void **state)
Crosplatform medium test no. 7.
Definition: test.c:425
bs2048_apple_r0260
static void bs2048_apple_r0260(void **state)
This medium should be clean, but too new. Should fail.
Definition: test.c:182
bs1024_blocksize_detection_test
static void bs1024_blocksize_detection_test(void **state)
Blocksize detection test.
Definition: test.c:254
bs2048_dirty_file_tree_3
static void bs2048_dirty_file_tree_3(void **state)
Test against unfinished write operation. After that, more files were written.
Definition: test.c:158
bs2048_dirty_file_tree_2
static void bs2048_dirty_file_tree_2(void **state)
Test against unfinished write operation. After that, another file was deleted.
Definition: test.c:141
bs2048_clean
static void bs2048_clean(void **state)
This medium should be clean, so this is test for positive result.
Definition: test.c:171