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