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