]> wimlib.net Git - wimlib/blob - tests/win32-test-imagex-capture_and_apply.bat
libFuzzer: add encoding fuzzer
[wimlib] / tests / win32-test-imagex-capture_and_apply.bat
1 @echo off\r
2 \r
3 REM\r
4 REM win32-test-imagex-capture_and_apply.bat\r
5 REM\r
6 REM Run some tests on the Windows version of wimlib-imagex.\r
7 REM\r
8 REM This must be run with Administrator privileges, in a directory containing\r
9 REM the wimlib-imagex, win32-tree-cmp, and set_reparse_point programs.\r
10 \r
11 setlocal EnableDelayedExpansion\r
12 set WIMLIB_IMAGEX=%cd%\wimlib-imagex\r
13 set WIN32_TREE_CMP=%cd%\win32-tree-cmp\r
14 set SET_REPARSE_POINT=%cd%\set_reparse_point\r
15 \r
16 if exist in.dir rd /S /Q in.dir\r
17 if exist out.dir rd /S /Q out.dir\r
18 md in.dir\r
19 cd in.dir\r
20 \r
21 REM\r
22 REM BEGIN TESTS\r
23 REM\r
24 \r
25 call :msg "empty directory"\r
26 call :do_test\r
27 \r
28 call :msg "single file"\r
29 echo 1 > file\r
30 call :do_test\r
31 \r
32 call :msg "different files"\r
33 echo 1 > file\r
34 echo 2 > anotherfile\r
35 call :do_test\r
36 \r
37 call :msg "identical files"\r
38 echo 1 > file\r
39 echo 1 > identicalfile\r
40 call :do_test\r
41 \r
42 call :msg "hard linked file"\r
43 echo 1 > file\r
44 mklink /h link file > nul\r
45 call :do_test\r
46 \r
47 call :msg "hard linked file, with other identical files"\r
48 echo 1 > file\r
49 mklink /h link file > nul\r
50 echo 1 > identicalfile\r
51 call :do_test\r
52 \r
53 call :msg "empty file"\r
54 type nul > emptyfile\r
55 call :do_test\r
56 \r
57 call :msg "hard linked empty file"\r
58 type nul > file\r
59 mklink /h link file > nul\r
60 REM Use skip_dism_cmp=1 due to DISM bug\r
61 call :do_test_with_params 0 1\r
62 \r
63 call :msg "various hard linked, identical, different, and empty files"\r
64 echo 1 > file\r
65 echo 5 > file\r
66 mklink /h link1 file > nul\r
67 mklink /h link2 file > nul\r
68 type nul > emptyfile\r
69 type nul > emptyfile2\r
70 mklink /h emptyfilelink emptyfile > nul\r
71 echo 5 > identicalfile\r
72 echo 1 > 1file\r
73 mklink /h 1filelink 1file > nul\r
74 REM Use skip_dism_cmp=1 due to DISM bug\r
75 call :do_test_with_params 0 1\r
76 \r
77 call :msg "multiple subdirectories, some empty, some not"\r
78 md subdir1\r
79 md subdir2\r
80 md subdir3\r
81 echo 1 > subdir1\1\r
82 echo 5 > subdir1\5\r
83 mklink /h link subdir1\1 > nul\r
84 md subdir2\subdir2subdir\r
85 type nul > subdir2\emptyfile\r
86 call :do_test\r
87 \r
88 REM FIXME: win32-tree-cmp can't handle this case.\r
89 REM\r
90 REM call :msg "file with custom security descriptor"\r
91 REM echo hello > file\r
92 REM icacls file /deny Administrator:F > nul\r
93 REM call :do_test\r
94 \r
95 call :msg "directory with custom security descriptor (inheritence enabled)"\r
96 md subdir\r
97 icacls subdir /inheritance:e > nul\r
98 call :do_test\r
99 \r
100 call :msg "directory with custom security descriptor (inheritence disabled)"\r
101 md subdir\r
102 icacls subdir /inheritance:d > nul\r
103 call :do_test\r
104 \r
105 REM FIXME: win32-tree-cmp can't handle this case.\r
106 REM\r
107 REM call :msg "file with custom security descriptor (all inherited ACEs removed)"\r
108 REM echo hello > file\r
109 REM icacls file /inheritance:r > nul\r
110 REM call :do_test\r
111 \r
112 call :msg "file with custom integrity level"\r
113 echo hello > file\r
114 icacls file /setintegritylevel H > nul\r
115 REM Use skip_dism_cmp=1 due to DISM bug\r
116 call :do_test_with_params 0 1\r
117 \r
118 call :msg "relative symlink"\r
119 mklink relink dest > nul\r
120 call :do_test\r
121 \r
122 call :msg "absolute symlink, with drive letter"\r
123 mklink abslink C:\absolute\target > nul\r
124 call :do_test\r
125 \r
126 call :msg "absolute symlink, without drive letter"\r
127 mklink abslink \absolute\target > nul\r
128 call :do_test\r
129 \r
130 call :msg "relative symlink, with file target"\r
131 echo 1 > 1\r
132 mklink relink 1 > nul\r
133 call :do_test\r
134 \r
135 call :msg "relative symlink, with directory target"\r
136 md subdir\r
137 mklink reldlink subdir > nul\r
138 call :do_test\r
139 \r
140 call :msg "junction"\r
141 md subdir\r
142 mklink /j junction subdir > nul\r
143 call :do_test\r
144 \r
145 call :msg "symlinks, junctions, files, subdirectories, etc."\r
146 echo 1 > 1\r
147 mklink relink 1 > nul\r
148 mklink rellinklink relink > nul\r
149 mklink /j junction . > nul\r
150 md subdir\r
151 mklink /h subdir\hardlink 1 > nul\r
152 echo "hello world!!!!" > hello\r
153 mklink subdir\hello hello > nul\r
154 mklink abslink C:\Users > nul\r
155 md subdir2\r
156 type nul > emptyfile\r
157 type nul > subdir2\emptyfile\r
158 md subdir2\s\r
159 md subdir2\s\s\r
160 md subdir2\s\s\s\r
161 echo "hello world!!!!" > subdir2\otherfile\r
162 call :do_test\r
163 \r
164 call :msg "reparse point that is neither a symlink nor a junction"\r
165 type nul > file\r
166 %SET_REPARSE_POINT% file\r
167 call :do_test\r
168 \r
169 call :msg "reparse point with named data streams"\r
170 type nul > file\r
171 echo 11 > file:a\r
172 echo 1 > file:aa\r
173 %SET_REPARSE_POINT% file\r
174 call :do_test\r
175 \r
176 call :msg "reparse point with unnamed data stream"\r
177 echo "test" > file\r
178 %SET_REPARSE_POINT% file\r
179 REM Use skip_dism_apply=1 due to DISM bug\r
180 call :do_test_with_params 1 0\r
181 \r
182 call :msg "reparse point with unnamed data stream and named data streams"\r
183 echo "test" > file\r
184 echo 11 > file:a\r
185 echo 1 > file:aa\r
186 %SET_REPARSE_POINT% file\r
187 REM Use skip_dism_apply=1 due to DISM bug\r
188 call :do_test_with_params 1 0\r
189 \r
190 call :msg "empty reparse point"\r
191 type nul > file\r
192 %SET_REPARSE_POINT% file 0\r
193 call :do_test\r
194 \r
195 call :msg "empty reparse point with unnamed data stream"\r
196 echo hello > file\r
197 %SET_REPARSE_POINT% file 0\r
198 call :do_test\r
199 \r
200 call :msg "empty reparse point with unnamed data stream and named data streams"\r
201 echo hello > file\r
202 echo hello > file:ads1\r
203 type nul > file:ads2\r
204 %SET_REPARSE_POINT% file 0\r
205 REM Use skip_dism_apply=1 due to DISM bug\r
206 call :do_test_with_params 1 0\r
207 \r
208 call :msg "maximum length reparse point"\r
209 type nul > file\r
210 %SET_REPARSE_POINT% file 16376\r
211 call :do_test\r
212 \r
213 call :msg "directory reparse point that is neither a symlink nor a junction"\r
214 md subdir\r
215 %SET_REPARSE_POINT% subdir\r
216 call :do_test\r
217 \r
218 call :msg "directory reparse point with named data streams"\r
219 md subdir\r
220 echo 11 > subdir:a\r
221 echo 1 > subdir:aa\r
222 %SET_REPARSE_POINT% subdir\r
223 call :do_test\r
224 \r
225 call :msg "compressed file"\r
226 echo "test" > test\r
227 compact /C test > nul\r
228 call :do_test\r
229 \r
230 call :msg "compressed directory"\r
231 md subdir\r
232 compact /C subdir > nul\r
233 call :do_test\r
234 \r
235 call :msg "compressed directory with files in it"\r
236 md subdir\r
237 compact /C subdir > nul\r
238 echo 1 > subdir\file1\r
239 echo 2 > subdir\file2\r
240 echo 1 > subdir\file1\r
241 md subdir\subsubdir\r
242 mklink /h subdir\hardlink subdir\file1 > nul\r
243 mklink /j subdir\j subdir\subsubdir > nul\r
244 call :do_test\r
245 \r
246 call :msg "compressed directory with some uncompressed files in it"\r
247 md subdir\r
248 compact /C subdir > nul\r
249 echo 1 > subdir\1\r
250 echo 5 > subdir\5\r
251 compact /U subdir\1 > nul\r
252 call :do_test\r
253 \r
254 call :msg "file with alternate data stream"\r
255 echo 1 > file\r
256 echo 5 > file:ads\r
257 call :do_test\r
258 \r
259 call :msg "file with multiple alternate data streams"\r
260 echo 1 > file\r
261 echo a > file:a\r
262 echo aa > file:aa\r
263 echo aaa > file:aaa\r
264 echo aaaa > file:aaaa\r
265 call :do_test\r
266 \r
267 call :msg "file with multiple alternate data streams, with hard link"\r
268 echo 1 > file\r
269 echo a > file:a\r
270 echo aa > file:aa\r
271 echo aaa > file:aaa\r
272 echo aaaa > file:aaaa\r
273 mklink /h link file > nul\r
274 call :do_test\r
275 \r
276 call :msg "files with multiple alternate data streams, some identical, with hard link"\r
277 echo 1 > file\r
278 echo 5 > file2\r
279 echo 1 > file:1\r
280 echo 1 > file:1again\r
281 echo aaa > file:aaa\r
282 echo 5 > file:5\r
283 mklink /h link file > nul\r
284 echo aaa > file2:aaa\r
285 call :do_test\r
286 \r
287 call :msg "file with empty alternate data stream"\r
288 echo 1 > file\r
289 type nul > file:ads\r
290 call :do_test\r
291 \r
292 call :msg "directory with empty alternate data stream"\r
293 md subdir\r
294 type nul > subdir:ads\r
295 REM Use skip_dism_apply=1 due to DISM bug\r
296 call :do_test_with_params 1 0\r
297 \r
298 call :msg "root directory with alternate data stream"\r
299 echo 1 > ..\in.dir:ads\r
300 REM Use skip_dism_apply=1 due to DISM bug\r
301 call :do_test_with_params 1 0\r
302 \r
303 call :msg "root directory with empty alternate data stream"\r
304 type nul > ..\in.dir:ads\r
305 REM Use skip_dism_apply=1 due to DISM bug\r
306 call :do_test_with_params 1 0\r
307 \r
308 call :msg "subdirectory with alternate data streams"\r
309 md subdir\r
310 echo 1 > subdir:1\r
311 echo 2 > subdir:2\r
312 echo 2 > subdir:2again\r
313 REM Use skip_dism_apply=1 due to DISM bug\r
314 call :do_test_with_params 1 0\r
315 \r
316 call :msg "subdirectories and files with alternate data streams"\r
317 md subdir\r
318 echo hello > hello\r
319 echo hello > subdir:hello\r
320 echo hello > subdir:helloagain\r
321 echo hello > helloagain\r
322 mklink /h hellolink hello > nul\r
323 echo 1 > helloagain:1\r
324 echo 8 > helloagain:8\r
325 echo 1 > 1\r
326 type nul > helloagain:dummy\r
327 REM Use skip_dism_apply=1 due to DISM bug\r
328 call :do_test_with_params 1 0\r
329 \r
330 call :msg "symbolic link and hard link, to file with alternate data streams"\r
331 echo 1 > 1\r
332 echo test > .\1:test\r
333 mklink symlink 1 > nul\r
334 mklink /h hardlink 1 > nul\r
335 REM Use skip_dism_apply=1 due to DISM bug\r
336 call :do_test_with_params 1 0\r
337 \r
338 call :msg "compressed file with alternate data streams"\r
339 echo 1 > 1\r
340 echo 1 > .\1:1\r
341 echo 2 > .\1:2\r
342 compact /C 1 > nul\r
343 call :do_test\r
344 \r
345 call :msg "hidden file"\r
346 echo 1 > hidden\r
347 attrib +h hidden\r
348 call :do_test\r
349 \r
350 call :msg "hidden system file"\r
351 echo 1 > file\r
352 attrib +h +s file\r
353 call :do_test\r
354 \r
355 call :msg "hidden, readonly, system file"\r
356 echo 1 > file\r
357 attrib +h +r +s file\r
358 call :do_test\r
359 \r
360 call :msg "hidden directory"\r
361 md subdir\r
362 attrib +h subdir\r
363 call :do_test\r
364 \r
365 call :msg "hidden system directory"\r
366 md subdir\r
367 attrib +h +s subdir\r
368 call :do_test\r
369 \r
370 call :msg "hidden, readonly, system directory"\r
371 md subdir\r
372 attrib +h +r +s subdir\r
373 call :do_test\r
374 \r
375 call :msg "readonly directory with named data stream"\r
376 md subdir\r
377 echo foo > subdir:ads\r
378 attrib +r subdir\r
379 REM Use skip_dism_apply=1 due to DISM bug\r
380 call :do_test_with_params 1 0\r
381 \r
382 call :msg "encrypted file"\r
383 echo "hello" > encrypted\r
384 cipher /e encrypted > nul\r
385 call :do_test\r
386 \r
387 call :msg "identical encrypted files"\r
388 echo "hello" > encrypted1\r
389 echo "hello" > encrypted2\r
390 cipher /e encrypted1 > nul\r
391 cipher /e encrypted2 > nul\r
392 call :do_test\r
393 \r
394 call :msg "encrypted directory"\r
395 md subdir\r
396 cipher /e subdir > nul\r
397 call :do_test\r
398 \r
399 call :msg "encrypted directory with encrypted file in it"\r
400 md subdir\r
401 echo 1 > subdir\1\r
402 cipher /e subdir > nul\r
403 cipher /e subdir\1 > nul\r
404 call :do_test\r
405 \r
406 call :msg "encrypted directory with unencrypted file in it"\r
407 md subdir\r
408 echo 1 > subdir\1\r
409 cipher /e subdir > nul\r
410 cipher /d subdir\1 > nul\r
411 call :do_test\r
412 \r
413 REM FIXME: apply fails with STATUS_ACCESS_DENIED\r
414 REM\r
415 REM call :msg "encrypted root directory"\r
416 REM cd ..\r
417 REM cipher /e in.dir > nul\r
418 REM cd in.dir\r
419 REM echo "hello" > encrypted\r
420 REM call :do_test\r
421 \r
422 call :msg "unencrypted file in encrypted directory in compressed directory"\r
423 md 1\r
424 md 1\2\r
425 compact /c 1 > nul\r
426 cipher /e 1\2 > nul\r
427 echo hello > 1\2\file\r
428 cipher /d 1\2\file > nul\r
429 call :do_test\r
430 \r
431 call :msg "encrypted directory with alternate data streams"\r
432 md subdir\r
433 cipher /e subdir > nul\r
434 echo ads1 > subdir:ads1\r
435 echo ads2 > subdir:ads2\r
436 call :do_test\r
437 \r
438 call :msg "hardlinked, encrypted file with alternate data streams"\r
439 echo hello > file\r
440 echo hello > file:ads\r
441 cipher /e file > nul\r
442 mklink /h link file > nul\r
443 call :do_test\r
444 \r
445 REM Note: since object IDs must be unique per filesystem, we can't expect them\r
446 REM to preserved using our testing scheme.  Therefore, win32-tree-cmp doesn't\r
447 REM compare them, and the below tests really just ensure the object ID code is\r
448 REM run to some extent.\r
449 \r
450 call :msg "file with object ID"\r
451 echo hello > file\r
452 fsutil objectid create file > nul\r
453 call :do_test\r
454 \r
455 call :msg "directory with object ID"\r
456 md subdir\r
457 fsutil objectid set f67394c12b17608e1d050d181ba8ffd2 7df80cbdf620f4c82c79b9e6799147b6 97621aff72915ade05abb96b15dea1a3 e0bda4caa9e33cfd461c92c16be9713d subdir\r
458 call :do_test\r
459 \r
460 call :msg "sparse files"\r
461 fsutil file createnew sparse 1000000 > nul\r
462 fsutil sparse setflag sparse\r
463 fsutil sparse setrange sparse 0 1000000\r
464 \r
465 fsutil file createnew mostly_sparse 1000000 > nul\r
466 fsutil sparse setflag mostly_sparse\r
467 fsutil sparse setrange mostly_sparse 0 1000000\r
468 echo hello >> mostly_sparse\r
469 type sparse >> mostly_sparse\r
470 fsutil sparse setrange mostly_sparse 1000100 2000000\r
471 call :do_test\r
472 \r
473 call :msg "sparse and compressed files"\r
474 fsutil file createnew sparse 1000000 > nul\r
475 fsutil sparse setflag sparse\r
476 fsutil sparse setrange sparse 0 1000000\r
477 compact /c sparse > nul\r
478 \r
479 fsutil file createnew mostly_sparse 1000000 > nul\r
480 fsutil sparse setflag mostly_sparse\r
481 fsutil sparse setrange mostly_sparse 0 1000000\r
482 echo hello >> mostly_sparse\r
483 type sparse >> mostly_sparse\r
484 fsutil sparse setrange mostly_sparse 1000100 2000000\r
485 compact /c mostly_sparse > nul\r
486 \r
487 type nul > compressed_first\r
488 compact /c compressed_first > nul\r
489 type sparse >> compressed_first\r
490 fsutil sparse setflag compressed_first\r
491 fsutil sparse setrange compressed_first 0 500000\r
492 call :do_test\r
493 \r
494 :rpfix_tests\r
495 \r
496 echo Testing rpfix junction\r
497 md subdir\r
498 echo 1 > subdir\file\r
499 mklink /j junction subdir > nul\r
500 cd ..\r
501 %WIMLIB_IMAGEX% capture in.dir test.wim > nul\r
502 rd /s /q in.dir\r
503 %WIMLIB_IMAGEX% apply test.wim out.dir > nul\r
504 echo 1 > tmp1\r
505 type out.dir\junction\file > tmp2\r
506 fc tmp1 tmp2 > nul\r
507 if %errorlevel% neq 0 goto :fail\r
508 rd /s /q out.dir\r
509 del tmp1 tmp2\r
510 md in.dir\r
511 cd in.dir\r
512 \r
513 echo Testing rpfix relative\r
514 echo 1 > file\r
515 mklink relink file > nul\r
516 cd ..\r
517 %WIMLIB_IMAGEX% capture in.dir test.wim > nul\r
518 %WIMLIB_IMAGEX% apply test.wim out.dir > nul\r
519 type out.dir\relink > out.dir\tmp\r
520 if %errorlevel% neq 0 goto :fail\r
521 fc in.dir\file out.dir\tmp > nul\r
522 if %errorlevel% neq 0 goto :fail\r
523 rd /s /q in.dir out.dir\r
524 md in.dir\r
525 cd in.dir\r
526 \r
527 REM\r
528 REM END OF TESTS\r
529 REM\r
530 \r
531 cd ..\r
532 del test.wim\r
533 rd /s /q in.dir\r
534 exit /b 0\r
535 \r
536 :do_test\r
537 call :do_test_with_params 0 0\r
538 goto :eof\r
539 \r
540 :do_test_with_params\r
541 set skip_dism_apply=%1\r
542 set skip_dism_cmp=%2\r
543 cd ..\r
544 echo   wimlib test (first time)\r
545 %WIMLIB_IMAGEX% capture in.dir test.wim --norpfix > NUL\r
546 if %errorlevel% neq 0 goto :fail\r
547 %WIMLIB_IMAGEX% apply test.wim out.dir > NUL\r
548 if %errorlevel% neq 0 goto :fail\r
549 %WIN32_TREE_CMP% in.dir out.dir\r
550 if %errorlevel% neq 0 goto :fail\r
551 \r
552 REM  apply a second time so we test the case where the files already exist\r
553 echo   wimlib test (second time)\r
554 %WIMLIB_IMAGEX% apply test.wim out.dir > NUL\r
555 if %errorlevel% neq 0 goto :fail\r
556 %WIN32_TREE_CMP% in.dir out.dir\r
557 if %errorlevel% neq 0 goto :fail\r
558 \r
559 REM  compatibility test: apply the image with DISM\r
560 echo   DISM test\r
561 rd /S /Q out.dir\r
562 md out.dir\r
563 if %skip_dism_apply% neq 1 (\r
564     dism /apply-image /imagefile:test.wim /index:1 /applydir:out.dir > nul\r
565     if !errorlevel! neq 0 (\r
566         echo ERROR: DISM apply failed!\r
567         goto :fail\r
568     )\r
569     if %skip_dism_cmp% neq 1 (\r
570         %WIN32_TREE_CMP% in.dir out.dir\r
571         if !errorlevel! neq 0 (\r
572             echo ERROR: DISM comparison failed!\r
573             goto :fail\r
574         )\r
575     )\r
576 )\r
577 \r
578 rd /S /Q in.dir out.dir\r
579 md in.dir\r
580 cd in.dir\r
581 goto :eof\r
582 \r
583 :msg\r
584 echo Testing capture and apply of %~1\r
585 goto :eof\r
586 \r
587 :fail\r
588 echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\r
589 echo            TEST FAILED!!!!!!!\r
590 echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\r
591 exit %errorlevel%\r