# This script does some sanity testing of the 'imagex' program. It by no means
# tests every aspect of wimlib comprehensively.
-# Assume an in-tree build.
set -e
+srcdir=${srcdir:-.}
+srcdir=`realpath $srcdir`
cd tests
imagex() {
echo "imagex $@"
- ../imagex $@
+ ../imagex $@
}
-#diff() {
- #echo "diff $@"
- #/usr/bin/env diff $@
-#}
-
-#dd() {
- #echo "dd $@"
- #/usr/bin/env dd $@
-#}
-#stat() {
- #echo "stat $@" 1>&2
- #/usr/bin/env stat $@
-#}
-#cmp() {
- #echo "cmp $@"
- #/usr/bin/env cmp $@
-#}
cleanup() {
if [ -d tmp ] && mountpoint tmp > /dev/null; then
rm -rf dir* tmp* *.wim *.swm
}
trap cleanup exit
+fusermount -u tmp || true
+rm -rf tmp || true
# Make test directory
mkdir dir
-cp ../src/*.c ../src/*.h dir
+cp $srcdir/src/*.c $srcdir/src/*.h dir
mkdir dir/subdir
echo 'hello' > dir/subdir/hello
echo 'hello' > dir/subdir/hello2
if imagex append SOME_NONEXISTENT_FILE dir.wim; then
error "Incorrectly succeeded to append non-existent file to WIM"
fi
-echo "Testing appending directory containing unreadable file (should generate errors)"
-mkdir -p dir3
-touch dir3/file
-chmod -r dir3/file
-if imagex append dir3 dir.wim; then
- error "Incorrectly succeeded in capturing directory with unreadable file"
+if [ `id -u` != 0 ]; then
+ echo "Testing appending directory containing unreadable file (should generate errors)"
+ mkdir -p dir3
+ echo 1 > dir3/file
+ chmod -r dir3/file
+ if imagex append dir3 dir.wim; then
+ error "Incorrectly succeeded in capturing directory with unreadable file"
+ fi
fi
rm -rf dir3 dir.wim
if test "`stat -c %i tmp/subdir/hello`" = "`stat -c %i tmp/subdir/hello2`"; then
error "Incorrect inode number"
fi
-if ! test -L tmp/subdir/hello || ! test -L tmp/subdir/hello2; then
+if ! test -L tmp/subdir/hello -o -L tmp/subdir/hello2 -o -L tmp/subdir/hellolink; then
error "Expected symlinks, but found non-symlinks"
fi
rm -rf dir.wim tmp
# imagex export
echo "Testing export of single image to new WIM"
-imagex capture dir dir.wim
-imagex append dir2 dir.wim
-imagex export dir.wim dir new.wim
-test "`imagex info new.wim | grep 'Image Count' | awk '{print $3}'`" = 1;
+if ! imagex capture dir dir.wim; then
+ error "Failed to capture test WIM"
+fi
+if ! imagex append dir2 dir.wim; then
+ error "Failed to append image to test WIM"
+fi
+if ! imagex export dir.wim dir new.wim; then
+ error "Failed to export single image to new WIM"
+fi
+if test "`imagex info new.wim | grep 'Image Count' | awk '{print $3}'`" != 1; then
+ error "Exporting single image to new WIM wasn't done correctly"
+fi
echo "Testing export of single image to existing WIM"
-imagex export dir.wim dir2 new.wim
-test "`imagex info new.wim | grep 'Image Count' | awk '{print $3}'`" = 2;
+if ! imagex export dir.wim dir2 new.wim; then
+ error "Failed to export single image to existing WIM"
+fi
+if test "`imagex info new.wim | grep 'Image Count' | awk '{print $3}'`" != 2; then
+ error "Exporting single image to existing WIM wasn't done correctly"
+fi
echo "Testing export of single image to existing WIM using wrong compression type"
-! imagex export dir.wim dir2 new.wim newname --compress=maximum
+if imagex export dir.wim dir2 new.wim newname --compress=maximum; then
+ error "Successfully exported image using wrong compression type"
+fi
rm -f new.wim
echo "Testing export of multiple images to new WIM"
-imagex export dir.wim all new.wim
-test "`imagex info new.wim | grep 'Image Count' | awk '{print $3}'`" = 2;
-imagex capture dir2 new.wim newname
+if ! imagex export dir.wim all new.wim; then
+ error "Failed to export multiple images to new WIM"
+fi
+if test "`imagex info new.wim | grep 'Image Count' | awk '{print $3}'`" != 2; then
+ error "Exporting multiple images to new WIM wasn't done correctly"
+fi
+if ! imagex capture dir2 new.wim newname; then
+ error "Failed to capture test WIM"
+fi
echo "Testing export of multiple images to existing WIM"
-imagex export dir.wim all new.wim
+if ! imagex export dir.wim all new.wim; then
+ error "Failed to export multiple images to existing WIM"
+fi
echo "Testing export of multiple images to existing WIM with --boot"
-imagex capture dir2 new.wim newname
-imagex info dir.wim --boot 1
-imagex export dir.wim all new.wim --boot
+if ! imagex capture dir2 new.wim newname; then
+ error "Failed to capture test WIM"
+fi
+if ! imagex info dir.wim --boot 1; then
+ error "Failed to set boot index on test WIM"
+fi
+if ! imagex export dir.wim all new.wim --boot; then
+ error "Failed to export multiple images to existing WIM with bootable image"
+fi
echo "Testing export of multiple images to existing WIM with --boot, but no bootable image (errors expected)"
-imagex capture dir2 new.wim newname
-imagex info dir.wim --boot 0
-! imagex export dir.wim all new.wim --boot
+if ! imagex capture dir2 new.wim newname; then
+ error "Failed to capture test WIM"
+fi
+if ! imagex info dir.wim --boot 0; then
+ error "Failed to clear boot index on test WIM"
+fi
+if imagex export dir.wim all new.wim --boot; then
+ error "Successfully exported multiple images with --boot but with no bootable images"
+fi
+
+# Test exporting an image to another WIM, then applying it.
+# We try with 5 different combinations of compression types to make sure we go
+# through all paths in the resource-handling code.
+for i in `seq 1 3`; do
+ case $i in
+ 1)
+ cflag1="--compress=none";
+ cflag2="--compress=none";
+ ;;
+ 2)
+ cflag1="--compress=xpress";
+ cflag2="--compress=xpress";
+ ;;
+ 3)
+ cflag1="--compress=xpress"
+ cflag2="--compress=lzx"
+ ;;
+ 4)
+ cflag1="--compress=none"
+ cflag2="--compress=xpress"
+ ;;
+ 5)
+ cflag1="--compress=xpress"
+ cflag2="--compress=none"
+ ;;
+ esac
+ echo "Testing exporting then applying an image (\"$cflag1\" => \"$cflag2\")"
+ rm -rf dir.wim new.wim tmp tmp2
+ imagex capture dir dir.wim $cflag1
+ imagex capture dir2 dir2.wim $cflag2
+ imagex export dir.wim dir dir2.wim
+ imagex apply dir.wim dir tmp
+ if ! imagex apply dir2.wim dir tmp2; then
+ error "Failed to apply image that was exported to a WIM"
+ fi
+ if ! diff -r tmp tmp2; then
+ error "Image that was exported to a WIM was not applied correctly"
+ fi
+done
+
+echo "**********************************************************"
+echo " Basic imagex tests passed "
+echo "**********************************************************"