]> wimlib.net Git - wimlib/blob - tests/win32-test-imagex-capture_and_apply.bat
mount_image.c: add fallback definitions of RENAME_* constants
[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 call :do_test\r
180 \r
181 call :msg "reparse point with unnamed data stream and named data streams"\r
182 echo "test" > file\r
183 echo 11 > file:a\r
184 echo 1 > file:aa\r
185 %SET_REPARSE_POINT% file\r
186 call :do_test\r
187 \r
188 call :msg "empty reparse point"\r
189 type nul > file\r
190 %SET_REPARSE_POINT% file 0\r
191 call :do_test\r
192 \r
193 call :msg "empty reparse point with unnamed data stream"\r
194 echo hello > file\r
195 %SET_REPARSE_POINT% file 0\r
196 call :do_test\r
197 \r
198 call :msg "empty reparse point with unnamed data stream and named data streams"\r
199 echo hello > file\r
200 echo hello > file:ads1\r
201 type nul > file:ads2\r
202 %SET_REPARSE_POINT% file 0\r
203 call :do_test\r
204 \r
205 call :msg "maximum length reparse point"\r
206 type nul > file\r
207 %SET_REPARSE_POINT% file 16376\r
208 call :do_test\r
209 \r
210 call :msg "directory reparse point that is neither a symlink nor a junction"\r
211 md subdir\r
212 %SET_REPARSE_POINT% subdir\r
213 call :do_test\r
214 \r
215 call :msg "directory reparse point with named data streams"\r
216 md subdir\r
217 echo 11 > subdir:a\r
218 echo 1 > subdir:aa\r
219 %SET_REPARSE_POINT% subdir\r
220 call :do_test\r
221 \r
222 call :msg "compressed file"\r
223 echo "test" > test\r
224 compact /C test > nul\r
225 call :do_test\r
226 \r
227 call :msg "compressed directory"\r
228 md subdir\r
229 compact /C subdir > nul\r
230 call :do_test\r
231 \r
232 call :msg "compressed directory with files in it"\r
233 md subdir\r
234 compact /C subdir > nul\r
235 echo 1 > subdir\file1\r
236 echo 2 > subdir\file2\r
237 echo 1 > subdir\file1\r
238 md subdir\subsubdir\r
239 mklink /h subdir\hardlink subdir\file1 > nul\r
240 mklink /j subdir\j subdir\subsubdir > nul\r
241 call :do_test\r
242 \r
243 call :msg "compressed directory with some uncompressed files in it"\r
244 md subdir\r
245 compact /C subdir > nul\r
246 echo 1 > subdir\1\r
247 echo 5 > subdir\5\r
248 compact /U subdir\1 > nul\r
249 call :do_test\r
250 \r
251 call :msg "file with alternate data stream"\r
252 echo 1 > file\r
253 echo 5 > file:ads\r
254 call :do_test\r
255 \r
256 call :msg "file with multiple alternate data streams"\r
257 echo 1 > file\r
258 echo a > file:a\r
259 echo aa > file:aa\r
260 echo aaa > file:aaa\r
261 echo aaaa > file:aaaa\r
262 call :do_test\r
263 \r
264 call :msg "file with multiple alternate data streams, with hard link"\r
265 echo 1 > file\r
266 echo a > file:a\r
267 echo aa > file:aa\r
268 echo aaa > file:aaa\r
269 echo aaaa > file:aaaa\r
270 mklink /h link file > nul\r
271 call :do_test\r
272 \r
273 call :msg "files with multiple alternate data streams, some identical, with hard link"\r
274 echo 1 > file\r
275 echo 5 > file2\r
276 echo 1 > file:1\r
277 echo 1 > file:1again\r
278 echo aaa > file:aaa\r
279 echo 5 > file:5\r
280 mklink /h link file > nul\r
281 echo aaa > file2:aaa\r
282 call :do_test\r
283 \r
284 call :msg "file with empty alternate data stream"\r
285 echo 1 > file\r
286 type nul > file:ads\r
287 call :do_test\r
288 \r
289 call :msg "directory with empty alternate data stream"\r
290 md subdir\r
291 type nul > subdir:ads\r
292 call :do_test\r
293 \r
294 call :msg "root directory with alternate data stream"\r
295 echo 1 > ..\in.dir:ads\r
296 call :do_test\r
297 \r
298 call :msg "root directory with empty alternate data stream"\r
299 type nul > ..\in.dir:ads\r
300 call :do_test\r
301 \r
302 call :msg "subdirectory with alternate data streams"\r
303 md subdir\r
304 echo 1 > subdir:1\r
305 echo 2 > subdir:2\r
306 echo 2 > subdir:2again\r
307 call :do_test\r
308 \r
309 call :msg "subdirectories and files with alternate data streams"\r
310 md subdir\r
311 echo hello > hello\r
312 echo hello > subdir:hello\r
313 echo hello > subdir:helloagain\r
314 echo hello > helloagain\r
315 mklink /h hellolink hello > nul\r
316 echo 1 > helloagain:1\r
317 echo 8 > helloagain:8\r
318 echo 1 > 1\r
319 type nul > helloagain:dummy\r
320 call :do_test\r
321 \r
322 call :msg "symbolic link and hard link, to file with alternate data streams"\r
323 echo 1 > 1\r
324 echo test > .\1:test\r
325 mklink symlink 1 > nul\r
326 mklink /h hardlink 1 > nul\r
327 call :do_test\r
328 \r
329 call :msg "compressed file with alternate data streams"\r
330 echo 1 > 1\r
331 echo 1 > .\1:1\r
332 echo 2 > .\1:2\r
333 compact /C 1 > nul\r
334 call :do_test\r
335 \r
336 call :msg "hidden file"\r
337 echo 1 > hidden\r
338 attrib +h hidden\r
339 call :do_test\r
340 \r
341 call :msg "hidden system file"\r
342 echo 1 > file\r
343 attrib +h +s file\r
344 call :do_test\r
345 \r
346 call :msg "hidden, readonly, system file"\r
347 echo 1 > file\r
348 attrib +h +r +s file\r
349 call :do_test\r
350 \r
351 call :msg "hidden directory"\r
352 md subdir\r
353 attrib +h subdir\r
354 call :do_test\r
355 \r
356 call :msg "hidden system directory"\r
357 md subdir\r
358 attrib +h +s subdir\r
359 call :do_test\r
360 \r
361 call :msg "hidden, readonly, system directory"\r
362 md subdir\r
363 attrib +h +r +s subdir\r
364 call :do_test\r
365 \r
366 call :msg "readonly directory with named data stream"\r
367 md subdir\r
368 echo foo > subdir:ads\r
369 attrib +r subdir\r
370 call :do_test\r
371 \r
372 call :msg "encrypted file"\r
373 echo "hello" > encrypted\r
374 cipher /e encrypted > nul\r
375 call :do_test\r
376 \r
377 call :msg "identical encrypted files"\r
378 echo "hello" > encrypted1\r
379 echo "hello" > encrypted2\r
380 cipher /e encrypted1 > nul\r
381 cipher /e encrypted2 > nul\r
382 REM Use skip_dism_cmp=1 due to DISM bug where it fails to preserve short names:\r
383 REM DIFFERENCE: in.dir\encrypted1 and out.dir\encrypted1 do not have the same short name (ENCRYP~1 vs. ENCRYP~2)\r
384 REM DIFFERENCE: in.dir\encrypted2 and out.dir\encrypted2 do not have the same short name (ENCRYP~2 vs. ENCRYP~1)\r
385 call :do_test_with_params 0 1\r
386 \r
387 call :msg "encrypted directory"\r
388 md subdir\r
389 cipher /e subdir > nul\r
390 call :do_test\r
391 \r
392 call :msg "encrypted directory with encrypted file in it"\r
393 md subdir\r
394 echo 1 > subdir\1\r
395 cipher /e subdir > nul\r
396 cipher /e subdir\1 > nul\r
397 call :do_test\r
398 \r
399 call :msg "encrypted directory with unencrypted file in it"\r
400 md subdir\r
401 echo 1 > subdir\1\r
402 cipher /e subdir > nul\r
403 cipher /d subdir\1 > nul\r
404 call :do_test\r
405 \r
406 REM FIXME: apply fails with STATUS_ACCESS_DENIED\r
407 REM\r
408 REM call :msg "encrypted root directory"\r
409 REM cd ..\r
410 REM cipher /e in.dir > nul\r
411 REM cd in.dir\r
412 REM echo "hello" > encrypted\r
413 REM call :do_test\r
414 \r
415 call :msg "unencrypted file in encrypted directory in compressed directory"\r
416 md 1\r
417 md 1\2\r
418 compact /c 1 > nul\r
419 cipher /e 1\2 > nul\r
420 echo hello > 1\2\file\r
421 cipher /d 1\2\file > nul\r
422 call :do_test\r
423 \r
424 call :msg "encrypted directory with alternate data streams"\r
425 md subdir\r
426 cipher /e subdir > nul\r
427 echo ads1 > subdir:ads1\r
428 echo ads2 > subdir:ads2\r
429 call :do_test\r
430 \r
431 call :msg "hardlinked, encrypted file with alternate data streams"\r
432 echo hello > file\r
433 echo hello > file:ads\r
434 cipher /e file > nul\r
435 mklink /h link file > nul\r
436 call :do_test\r
437 \r
438 REM Note: since object IDs must be unique per filesystem, we can't expect them\r
439 REM to preserved using our testing scheme.  Therefore, win32-tree-cmp doesn't\r
440 REM compare them, and the below tests really just ensure the object ID code is\r
441 REM run to some extent.\r
442 \r
443 call :msg "file with object ID"\r
444 echo hello > file\r
445 fsutil objectid create file > nul\r
446 call :do_test\r
447 \r
448 call :msg "directory with object ID"\r
449 md subdir\r
450 fsutil objectid set f67394c12b17608e1d050d181ba8ffd2 7df80cbdf620f4c82c79b9e6799147b6 97621aff72915ade05abb96b15dea1a3 e0bda4caa9e33cfd461c92c16be9713d subdir\r
451 call :do_test\r
452 \r
453 call :msg "sparse files"\r
454 fsutil file createnew sparse 1000000 > nul\r
455 fsutil sparse setflag sparse\r
456 fsutil sparse setrange sparse 0 1000000\r
457 \r
458 fsutil file createnew mostly_sparse 1000000 > nul\r
459 fsutil sparse setflag mostly_sparse\r
460 fsutil sparse setrange mostly_sparse 0 1000000\r
461 echo hello >> mostly_sparse\r
462 type sparse >> mostly_sparse\r
463 fsutil sparse setrange mostly_sparse 1000100 2000000\r
464 call :do_test\r
465 \r
466 call :msg "sparse and compressed files"\r
467 fsutil file createnew sparse 1000000 > nul\r
468 fsutil sparse setflag sparse\r
469 fsutil sparse setrange sparse 0 1000000\r
470 compact /c sparse > nul\r
471 \r
472 fsutil file createnew mostly_sparse 1000000 > nul\r
473 fsutil sparse setflag mostly_sparse\r
474 fsutil sparse setrange mostly_sparse 0 1000000\r
475 echo hello >> mostly_sparse\r
476 type sparse >> mostly_sparse\r
477 fsutil sparse setrange mostly_sparse 1000100 2000000\r
478 compact /c mostly_sparse > nul\r
479 \r
480 type nul > compressed_first\r
481 compact /c compressed_first > nul\r
482 type sparse >> compressed_first\r
483 fsutil sparse setflag compressed_first\r
484 fsutil sparse setrange compressed_first 0 500000\r
485 call :do_test\r
486 \r
487 :rpfix_tests\r
488 \r
489 echo Testing rpfix junction\r
490 md subdir\r
491 echo 1 > subdir\file\r
492 mklink /j junction subdir > nul\r
493 cd ..\r
494 %WIMLIB_IMAGEX% capture in.dir test.wim > nul\r
495 rd /s /q in.dir\r
496 %WIMLIB_IMAGEX% apply test.wim out.dir > nul\r
497 echo 1 > tmp1\r
498 type out.dir\junction\file > tmp2\r
499 fc tmp1 tmp2 > nul\r
500 if %errorlevel% neq 0 goto :fail\r
501 rd /s /q out.dir\r
502 del tmp1 tmp2\r
503 md in.dir\r
504 cd in.dir\r
505 \r
506 echo Testing rpfix relative\r
507 echo 1 > file\r
508 mklink relink file > nul\r
509 cd ..\r
510 %WIMLIB_IMAGEX% capture in.dir test.wim > nul\r
511 %WIMLIB_IMAGEX% apply test.wim out.dir > nul\r
512 type out.dir\relink > out.dir\tmp\r
513 if %errorlevel% neq 0 goto :fail\r
514 fc in.dir\file out.dir\tmp > nul\r
515 if %errorlevel% neq 0 goto :fail\r
516 rd /s /q in.dir out.dir\r
517 md in.dir\r
518 cd in.dir\r
519 \r
520 REM\r
521 REM END OF TESTS\r
522 REM\r
523 \r
524 cd ..\r
525 del test.wim\r
526 rd /s /q in.dir\r
527 exit /b 0\r
528 \r
529 :do_test\r
530 call :do_test_with_params 0 0\r
531 goto :eof\r
532 \r
533 :do_test_with_params\r
534 set skip_dism_apply=%1\r
535 set skip_dism_cmp=%2\r
536 cd ..\r
537 echo   wimlib test (first time)\r
538 %WIMLIB_IMAGEX% capture in.dir test.wim --norpfix > NUL\r
539 if %errorlevel% neq 0 goto :fail\r
540 %WIMLIB_IMAGEX% apply test.wim out.dir > NUL\r
541 if %errorlevel% neq 0 goto :fail\r
542 %WIN32_TREE_CMP% in.dir out.dir\r
543 if %errorlevel% neq 0 goto :fail\r
544 \r
545 REM  apply a second time so we test the case where the files already exist\r
546 echo   wimlib test (second time)\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  compatibility test: apply the image with DISM\r
553 echo   DISM test\r
554 rd /S /Q out.dir\r
555 md out.dir\r
556 if %skip_dism_apply% neq 1 (\r
557     dism /apply-image /imagefile:test.wim /index:1 /applydir:out.dir > nul\r
558     if !errorlevel! neq 0 (\r
559         echo ERROR: DISM apply failed!\r
560         goto :fail\r
561     )\r
562     if %skip_dism_cmp% neq 1 (\r
563         %WIN32_TREE_CMP% in.dir out.dir\r
564         if !errorlevel! neq 0 (\r
565             echo ERROR: DISM comparison failed!\r
566             goto :fail\r
567         )\r
568     )\r
569 )\r
570 \r
571 rd /S /Q in.dir out.dir\r
572 md in.dir\r
573 cd in.dir\r
574 goto :eof\r
575 \r
576 :msg\r
577 echo Testing capture and apply of %~1\r
578 goto :eof\r
579 \r
580 :fail\r
581 echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\r
582 echo            TEST FAILED!!!!!!!\r
583 echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\r
584 exit %errorlevel%\r