From 5577584b8a50baa958f832ddb9418986e3e38847 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Mon, 13 Aug 2012 19:20:28 -0500 Subject: [PATCH] Test suite This commit introduces a primitive test suite for wimlib. It consists of a shell script that runs some tests on the 'imagex' program. Run it with `make check'; only works with in-tree builds. As a result of writing the test suite I also fixed two issues: mount.c: Allow opening empty files in read-only filesystem mount.c: Implement utimens() for WIM filesystem --- Makefile.am | 8 +- src/mount.c | 28 ++- src/timestamp.h | 6 +- src/wim.c | 4 +- tests/dir/comp.c | 1 + tests/dir/comp.h | 1 + tests/dir/decomp.c | 1 + tests/dir/decomp.h | 1 + tests/dir/dentry.c | 1 + tests/dir/dentry.h | 1 + tests/dir/endianness.h | 1 + tests/dir/extract.c | 1 + tests/dir/header.c | 1 + tests/dir/integrity.c | 1 + tests/dir/io.h | 1 + tests/dir/join.c | 1 + tests/dir/lookup_table.c | 1 + tests/dir/lookup_table.h | 1 + tests/dir/lz.c | 1 + tests/dir/lzx-common.c | 1 + tests/dir/lzx-comp.c | 1 + tests/dir/lzx-decomp.c | 1 + tests/dir/lzx.h | 1 + tests/dir/modify.c | 1 + tests/dir/mount.c | 1 + tests/dir/resource.c | 1 + tests/dir/security.c | 1 + tests/dir/security.h | 1 + tests/dir/sha1.c | 1 + tests/dir/sha1.h | 1 + tests/dir/split.c | 1 + tests/dir/subdir/empty_file | 0 tests/dir/subdir/identical_file1 | 1 + tests/dir/subdir/identical_file2 | 1 + tests/dir/subdir/short_file | 1 + tests/dir/subdir/zeroes | Bin 0 -> 512 bytes tests/dir/timestamp.h | 1 + tests/dir/util.c | 1 + tests/dir/util.h | 1 + tests/dir/wim.c | 1 + tests/dir/wimlib.h | 1 + tests/dir/wimlib_internal.h | 1 + tests/dir/write.c | 1 + tests/dir/xml.c | 1 + tests/dir/xml.h | 1 + tests/dir/xpress-comp.c | 1 + tests/dir/xpress-decomp.c | 1 + tests/dir/xpress.h | 1 + tests/dir2/imagex.c | 1 + tests/dir2/mkwinpeimg | 1 + tests/test-imagex | 321 +++++++++++++++++++++++++++++++ 51 files changed, 405 insertions(+), 6 deletions(-) create mode 120000 tests/dir/comp.c create mode 120000 tests/dir/comp.h create mode 120000 tests/dir/decomp.c create mode 120000 tests/dir/decomp.h create mode 120000 tests/dir/dentry.c create mode 120000 tests/dir/dentry.h create mode 120000 tests/dir/endianness.h create mode 120000 tests/dir/extract.c create mode 120000 tests/dir/header.c create mode 120000 tests/dir/integrity.c create mode 120000 tests/dir/io.h create mode 120000 tests/dir/join.c create mode 120000 tests/dir/lookup_table.c create mode 120000 tests/dir/lookup_table.h create mode 120000 tests/dir/lz.c create mode 120000 tests/dir/lzx-common.c create mode 120000 tests/dir/lzx-comp.c create mode 120000 tests/dir/lzx-decomp.c create mode 120000 tests/dir/lzx.h create mode 120000 tests/dir/modify.c create mode 120000 tests/dir/mount.c create mode 120000 tests/dir/resource.c create mode 120000 tests/dir/security.c create mode 120000 tests/dir/security.h create mode 120000 tests/dir/sha1.c create mode 120000 tests/dir/sha1.h create mode 120000 tests/dir/split.c create mode 100644 tests/dir/subdir/empty_file create mode 100644 tests/dir/subdir/identical_file1 create mode 100644 tests/dir/subdir/identical_file2 create mode 100644 tests/dir/subdir/short_file create mode 100644 tests/dir/subdir/zeroes create mode 120000 tests/dir/timestamp.h create mode 120000 tests/dir/util.c create mode 120000 tests/dir/util.h create mode 120000 tests/dir/wim.c create mode 120000 tests/dir/wimlib.h create mode 120000 tests/dir/wimlib_internal.h create mode 120000 tests/dir/write.c create mode 120000 tests/dir/xml.c create mode 120000 tests/dir/xml.h create mode 120000 tests/dir/xpress-comp.c create mode 120000 tests/dir/xpress-decomp.c create mode 120000 tests/dir/xpress.h create mode 120000 tests/dir2/imagex.c create mode 120000 tests/dir2/mkwinpeimg create mode 100755 tests/test-imagex diff --git a/Makefile.am b/Makefile.am index 5f5b12d0..58d23671 100644 --- a/Makefile.am +++ b/Makefile.am @@ -84,7 +84,9 @@ EXTRA_DIST = \ COPYING.LIB \ build-aux/strip_fPIC.sh \ debian \ - programs/install.cmd + programs/install.cmd \ + tests/dir \ + tests/dir2 pkgconfigdir = @pkgconfigdir@ pkgconfig_DATA = wimlib.pc @@ -108,3 +110,7 @@ man1_MANS = \ doc/mkwinpeimg.1 $(man1_MANS): config.status + +dist_check_SCRIPTS = tests/test-imagex +TESTS = $(dist_check_SCRIPTS) + diff --git a/src/mount.c b/src/mount.c index 53a7f364..f3043c2b 100644 --- a/src/mount.c +++ b/src/mount.c @@ -32,6 +32,7 @@ #include "sha1.h" #include "lookup_table.h" #include "xml.h" +#include "timestamp.h" #include #include #include @@ -118,7 +119,11 @@ static int remove_file_or_directory(const char *fpath, const struct stat *sb, */ static inline int delete_staging_dir() { - return nftw(staging_dir_name, remove_file_or_directory, 10, FTW_DEPTH); + int ret; + + ret = nftw(staging_dir_name, remove_file_or_directory,10, FTW_DEPTH); + staging_dir_name = NULL; + return ret; } /* Name and message queue descriptors for message queues between the filesystem @@ -630,10 +635,14 @@ static int wimfs_open(const char *path, struct fuse_file_info *fi) } } else { /* no lookup table entry, so the file must be empty. Create a - * lookup table entry for the file. */ + * lookup table entry for the file, unless it's a read-only + * filesystem. */ char *tmpfile_name; int fd; + if (!staging_dir_name) /* Read-only filesystem */ + return 0; + lte = new_lookup_table_entry(); if (!lte) return -ENOMEM; @@ -981,6 +990,20 @@ static int wimfs_unlink(const char *path) return 0; } +static int wimfs_utimens(const char *path, const struct timespec tv[2]) +{ + struct dentry *dentry = get_dentry(w, path); + if (!dentry) + return -ENOENT; + time_t last_access_t = (tv[0].tv_nsec == UTIME_NOW) ? + time(NULL) : tv[0].tv_sec; + dentry->last_access_time = unix_timestamp_to_ms(last_access_t); + time_t last_mod_t = (tv[1].tv_nsec == UTIME_NOW) ? + time(NULL) : tv[1].tv_sec; + dentry->last_write_time = unix_timestamp_to_ms(last_mod_t); + return 0; +} + /* Writes to a file in the WIM filesystem. */ static int wimfs_write(const char *path, const char *buf, size_t size, off_t offset, struct fuse_file_info *fi) @@ -1054,6 +1077,7 @@ static struct fuse_operations wimfs_oper = { .rmdir = wimfs_rmdir, .truncate = wimfs_truncate, .unlink = wimfs_unlink, + .utimens = wimfs_utimens, .write = wimfs_write, }; diff --git a/src/timestamp.h b/src/timestamp.h index 819047d4..5ad0b355 100644 --- a/src/timestamp.h +++ b/src/timestamp.h @@ -14,13 +14,17 @@ #define intervals_1601_to_1970 (years_1601_to_1970 * intervals_per_year \ + leap_years_1601_to_1970 * intervals_per_day) +static inline u64 unix_timestamp_to_ms(time_t t) +{ + return (u64)intervals_1601_to_1970 + t * intervals_per_second; +} /* * Returns the number of 100-nanosecond intervals that have elapsed since * 12:00 A.M., January 1, 1601 UTC. */ static inline u64 get_timestamp() { - return (u64)intervals_1601_to_1970 + (u64)time(NULL) * intervals_per_second; + return unix_timestamp_to_ms(time(NULL)); } /* Converts a timestamp as used in the WIM file to a UNIX timestamp as used in diff --git a/src/wim.c b/src/wim.c index 268b3811..73288788 100644 --- a/src/wim.c +++ b/src/wim.c @@ -81,14 +81,14 @@ int for_image(WIMStruct *w, int image, int (*visitor)(WIMStruct *)) i = image; end = image; } - do { + for (; i <= end; i++) { ret = wimlib_select_image(w, i); if (ret != 0) return ret; ret = visitor(w); if (ret != 0) return ret; - } while (i++ != end); + } return 0; } diff --git a/tests/dir/comp.c b/tests/dir/comp.c new file mode 120000 index 00000000..1678379c --- /dev/null +++ b/tests/dir/comp.c @@ -0,0 +1 @@ +../../src/comp.c \ No newline at end of file diff --git a/tests/dir/comp.h b/tests/dir/comp.h new file mode 120000 index 00000000..b259940e --- /dev/null +++ b/tests/dir/comp.h @@ -0,0 +1 @@ +../../src/comp.h \ No newline at end of file diff --git a/tests/dir/decomp.c b/tests/dir/decomp.c new file mode 120000 index 00000000..cc67a227 --- /dev/null +++ b/tests/dir/decomp.c @@ -0,0 +1 @@ +../../src/decomp.c \ No newline at end of file diff --git a/tests/dir/decomp.h b/tests/dir/decomp.h new file mode 120000 index 00000000..22a22266 --- /dev/null +++ b/tests/dir/decomp.h @@ -0,0 +1 @@ +../../src/decomp.h \ No newline at end of file diff --git a/tests/dir/dentry.c b/tests/dir/dentry.c new file mode 120000 index 00000000..d8642099 --- /dev/null +++ b/tests/dir/dentry.c @@ -0,0 +1 @@ +../../src/dentry.c \ No newline at end of file diff --git a/tests/dir/dentry.h b/tests/dir/dentry.h new file mode 120000 index 00000000..10cc7353 --- /dev/null +++ b/tests/dir/dentry.h @@ -0,0 +1 @@ +../../src/dentry.h \ No newline at end of file diff --git a/tests/dir/endianness.h b/tests/dir/endianness.h new file mode 120000 index 00000000..48fd8d3c --- /dev/null +++ b/tests/dir/endianness.h @@ -0,0 +1 @@ +../../src/endianness.h \ No newline at end of file diff --git a/tests/dir/extract.c b/tests/dir/extract.c new file mode 120000 index 00000000..44480bca --- /dev/null +++ b/tests/dir/extract.c @@ -0,0 +1 @@ +../../src/extract.c \ No newline at end of file diff --git a/tests/dir/header.c b/tests/dir/header.c new file mode 120000 index 00000000..0a3f05ea --- /dev/null +++ b/tests/dir/header.c @@ -0,0 +1 @@ +../../src/header.c \ No newline at end of file diff --git a/tests/dir/integrity.c b/tests/dir/integrity.c new file mode 120000 index 00000000..997d4731 --- /dev/null +++ b/tests/dir/integrity.c @@ -0,0 +1 @@ +../../src/integrity.c \ No newline at end of file diff --git a/tests/dir/io.h b/tests/dir/io.h new file mode 120000 index 00000000..32882dba --- /dev/null +++ b/tests/dir/io.h @@ -0,0 +1 @@ +../../src/io.h \ No newline at end of file diff --git a/tests/dir/join.c b/tests/dir/join.c new file mode 120000 index 00000000..dcffc6c5 --- /dev/null +++ b/tests/dir/join.c @@ -0,0 +1 @@ +../../src/join.c \ No newline at end of file diff --git a/tests/dir/lookup_table.c b/tests/dir/lookup_table.c new file mode 120000 index 00000000..a685a898 --- /dev/null +++ b/tests/dir/lookup_table.c @@ -0,0 +1 @@ +../../src/lookup_table.c \ No newline at end of file diff --git a/tests/dir/lookup_table.h b/tests/dir/lookup_table.h new file mode 120000 index 00000000..fd64815a --- /dev/null +++ b/tests/dir/lookup_table.h @@ -0,0 +1 @@ +../../src/lookup_table.h \ No newline at end of file diff --git a/tests/dir/lz.c b/tests/dir/lz.c new file mode 120000 index 00000000..0a3c8509 --- /dev/null +++ b/tests/dir/lz.c @@ -0,0 +1 @@ +../../src/lz.c \ No newline at end of file diff --git a/tests/dir/lzx-common.c b/tests/dir/lzx-common.c new file mode 120000 index 00000000..cd782314 --- /dev/null +++ b/tests/dir/lzx-common.c @@ -0,0 +1 @@ +../../src/lzx-common.c \ No newline at end of file diff --git a/tests/dir/lzx-comp.c b/tests/dir/lzx-comp.c new file mode 120000 index 00000000..a0c4e9e4 --- /dev/null +++ b/tests/dir/lzx-comp.c @@ -0,0 +1 @@ +../../src/lzx-comp.c \ No newline at end of file diff --git a/tests/dir/lzx-decomp.c b/tests/dir/lzx-decomp.c new file mode 120000 index 00000000..2235acfb --- /dev/null +++ b/tests/dir/lzx-decomp.c @@ -0,0 +1 @@ +../../src/lzx-decomp.c \ No newline at end of file diff --git a/tests/dir/lzx.h b/tests/dir/lzx.h new file mode 120000 index 00000000..2b55c6b7 --- /dev/null +++ b/tests/dir/lzx.h @@ -0,0 +1 @@ +../../src/lzx.h \ No newline at end of file diff --git a/tests/dir/modify.c b/tests/dir/modify.c new file mode 120000 index 00000000..007b89e2 --- /dev/null +++ b/tests/dir/modify.c @@ -0,0 +1 @@ +../../src/modify.c \ No newline at end of file diff --git a/tests/dir/mount.c b/tests/dir/mount.c new file mode 120000 index 00000000..d1ee2fcc --- /dev/null +++ b/tests/dir/mount.c @@ -0,0 +1 @@ +../../src/mount.c \ No newline at end of file diff --git a/tests/dir/resource.c b/tests/dir/resource.c new file mode 120000 index 00000000..02de13cd --- /dev/null +++ b/tests/dir/resource.c @@ -0,0 +1 @@ +../../src/resource.c \ No newline at end of file diff --git a/tests/dir/security.c b/tests/dir/security.c new file mode 120000 index 00000000..55e2465f --- /dev/null +++ b/tests/dir/security.c @@ -0,0 +1 @@ +../../src/security.c \ No newline at end of file diff --git a/tests/dir/security.h b/tests/dir/security.h new file mode 120000 index 00000000..fa9a3d74 --- /dev/null +++ b/tests/dir/security.h @@ -0,0 +1 @@ +../../src/security.h \ No newline at end of file diff --git a/tests/dir/sha1.c b/tests/dir/sha1.c new file mode 120000 index 00000000..bf0a00bf --- /dev/null +++ b/tests/dir/sha1.c @@ -0,0 +1 @@ +../../src/sha1.c \ No newline at end of file diff --git a/tests/dir/sha1.h b/tests/dir/sha1.h new file mode 120000 index 00000000..4902ee8c --- /dev/null +++ b/tests/dir/sha1.h @@ -0,0 +1 @@ +../../src/sha1.h \ No newline at end of file diff --git a/tests/dir/split.c b/tests/dir/split.c new file mode 120000 index 00000000..c8b67592 --- /dev/null +++ b/tests/dir/split.c @@ -0,0 +1 @@ +../../src/split.c \ No newline at end of file diff --git a/tests/dir/subdir/empty_file b/tests/dir/subdir/empty_file new file mode 100644 index 00000000..e69de29b diff --git a/tests/dir/subdir/identical_file1 b/tests/dir/subdir/identical_file1 new file mode 100644 index 00000000..ce013625 --- /dev/null +++ b/tests/dir/subdir/identical_file1 @@ -0,0 +1 @@ +hello diff --git a/tests/dir/subdir/identical_file2 b/tests/dir/subdir/identical_file2 new file mode 100644 index 00000000..ce013625 --- /dev/null +++ b/tests/dir/subdir/identical_file2 @@ -0,0 +1 @@ +hello diff --git a/tests/dir/subdir/short_file b/tests/dir/subdir/short_file new file mode 100644 index 00000000..56a6051c --- /dev/null +++ b/tests/dir/subdir/short_file @@ -0,0 +1 @@ +1 \ No newline at end of file diff --git a/tests/dir/subdir/zeroes b/tests/dir/subdir/zeroes new file mode 100644 index 0000000000000000000000000000000000000000..a64a5a93fb4aef4d5f63d79cb2582731b9ac5063 GIT binary patch literal 512 NcmZQz7zHCa1ONg600961 literal 0 HcmV?d00001 diff --git a/tests/dir/timestamp.h b/tests/dir/timestamp.h new file mode 120000 index 00000000..499c216d --- /dev/null +++ b/tests/dir/timestamp.h @@ -0,0 +1 @@ +../../src/timestamp.h \ No newline at end of file diff --git a/tests/dir/util.c b/tests/dir/util.c new file mode 120000 index 00000000..87f5cc34 --- /dev/null +++ b/tests/dir/util.c @@ -0,0 +1 @@ +../../src/util.c \ No newline at end of file diff --git a/tests/dir/util.h b/tests/dir/util.h new file mode 120000 index 00000000..82c8f13b --- /dev/null +++ b/tests/dir/util.h @@ -0,0 +1 @@ +../../src/util.h \ No newline at end of file diff --git a/tests/dir/wim.c b/tests/dir/wim.c new file mode 120000 index 00000000..742ee978 --- /dev/null +++ b/tests/dir/wim.c @@ -0,0 +1 @@ +../../src/wim.c \ No newline at end of file diff --git a/tests/dir/wimlib.h b/tests/dir/wimlib.h new file mode 120000 index 00000000..50fea462 --- /dev/null +++ b/tests/dir/wimlib.h @@ -0,0 +1 @@ +../../src/wimlib.h \ No newline at end of file diff --git a/tests/dir/wimlib_internal.h b/tests/dir/wimlib_internal.h new file mode 120000 index 00000000..d8b284fe --- /dev/null +++ b/tests/dir/wimlib_internal.h @@ -0,0 +1 @@ +../../src/wimlib_internal.h \ No newline at end of file diff --git a/tests/dir/write.c b/tests/dir/write.c new file mode 120000 index 00000000..b7406c5e --- /dev/null +++ b/tests/dir/write.c @@ -0,0 +1 @@ +../../src/write.c \ No newline at end of file diff --git a/tests/dir/xml.c b/tests/dir/xml.c new file mode 120000 index 00000000..b8a30e83 --- /dev/null +++ b/tests/dir/xml.c @@ -0,0 +1 @@ +../../src/xml.c \ No newline at end of file diff --git a/tests/dir/xml.h b/tests/dir/xml.h new file mode 120000 index 00000000..240aa392 --- /dev/null +++ b/tests/dir/xml.h @@ -0,0 +1 @@ +../../src/xml.h \ No newline at end of file diff --git a/tests/dir/xpress-comp.c b/tests/dir/xpress-comp.c new file mode 120000 index 00000000..20276483 --- /dev/null +++ b/tests/dir/xpress-comp.c @@ -0,0 +1 @@ +../../src/xpress-comp.c \ No newline at end of file diff --git a/tests/dir/xpress-decomp.c b/tests/dir/xpress-decomp.c new file mode 120000 index 00000000..3a60d8f4 --- /dev/null +++ b/tests/dir/xpress-decomp.c @@ -0,0 +1 @@ +../../src/xpress-decomp.c \ No newline at end of file diff --git a/tests/dir/xpress.h b/tests/dir/xpress.h new file mode 120000 index 00000000..14c0399f --- /dev/null +++ b/tests/dir/xpress.h @@ -0,0 +1 @@ +../../src/xpress.h \ No newline at end of file diff --git a/tests/dir2/imagex.c b/tests/dir2/imagex.c new file mode 120000 index 00000000..9da744bd --- /dev/null +++ b/tests/dir2/imagex.c @@ -0,0 +1 @@ +../../programs/imagex.c \ No newline at end of file diff --git a/tests/dir2/mkwinpeimg b/tests/dir2/mkwinpeimg new file mode 120000 index 00000000..80b48053 --- /dev/null +++ b/tests/dir2/mkwinpeimg @@ -0,0 +1 @@ +../../programs/mkwinpeimg \ No newline at end of file diff --git a/tests/test-imagex b/tests/test-imagex new file mode 100755 index 00000000..94a38516 --- /dev/null +++ b/tests/test-imagex @@ -0,0 +1,321 @@ +#!/bin/sh + +# 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 +cd tests + +imagex() { + echo "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; then + fusermount -u tmp > /dev/null; + fi + rm -rf tmp* *.wim *.swm dir3 +} +trap cleanup exit + +# Capturing and applying WIM with None, LZX, and XPRESS compression + +echo "Testing capture and application of uncompressed WIM" +imagex capture dir dir.wim +imagex apply dir.wim tmp +test "`imagex info dir.wim | grep Compression | awk '{print $2}'`" = "None"; +diff -q -r dir tmp +rm -rf dir.wim tmp + +echo "Testing capture and application of LZX-compressed WIM" +imagex capture dir dir.wim --compress=maximum +imagex apply dir.wim tmp +test "`imagex info dir.wim | grep Compression | awk '{print $2}'`" = "LZX"; +diff -q -r dir tmp +rm -rf dir.wim tmp + +echo "Testing capture and application of XPRESS-compressed WIM" +imagex capture dir dir.wim --compress=fast +imagex apply dir.wim tmp +test "`imagex info dir.wim | grep Compression | awk '{print $2}'`" = "XPRESS"; +diff -q -r dir tmp +rm -rf dir.wim tmp + +# Capturing and modifying name, description, and bootable flag + +echo "Testing capture of WIM with default name and description" +imagex capture dir dir.wim +test "`imagex info dir.wim | grep Name | awk '{print $2}'`" = "dir"; +test "`imagex info dir.wim | grep Description | awk '{print $2}'`" = ""; +rm -rf dir.wim tmp + +echo "Testing capture of WIM with default boot flag" +imagex capture dir dir.wim +test "`imagex info dir.wim | grep Boot | awk '{print $3}'`" = "0"; +echo "Testing changing image bootable flag" +imagex info dir.wim 1 --boot +test "`imagex info dir.wim | grep Boot | awk '{print $3}'`" = "1"; +echo "Testing changing image bootable flag" +imagex info dir.wim 0 --boot +test "`imagex info dir.wim | grep Boot | awk '{print $3}'`" = "0"; +echo "Testing changing image bootable flag to invalid image (this should generate errors)" +! imagex info dir.wim 2 --boot +test "`imagex info dir.wim | grep Boot | awk '{print $3}'`" = "0"; +rm -rf dir.wim tmp + +echo "Testing capture of WIM with name and description" +imagex capture dir dir.wim "myname" "mydesc" +test "`imagex info dir.wim | grep Name | awk '{print $2}'`" = "myname"; +test "`imagex info dir.wim | grep Description | awk '{print $2}'`" = "mydesc"; +echo "Testing printing WIM lookup table" +imagex info --lookup-table dir.wim +echo "Testing printing WIM header" +imagex info --header dir.wim +echo "Testing printing WIM XML info" +imagex info --xml dir.wim +echo "Testing extracting WIM XML info" +imagex info --extract-xml=dir.xml dir.wim +echo "Testing printing WIM metadata" +imagex info --metadata dir.wim +rm -rf dir.wim tmp dir.xml + +echo "Testing capture of bootable WIM" +imagex capture dir dir.wim --boot +test "`imagex info dir.wim | grep Boot | awk '{print $3}'`" = "1"; +rm -rf dir.wim tmp + +# Integrity table + +echo "Testing capture of WIM with integrity table" +imagex capture dir dir.wim --check +test "`imagex info dir.wim | grep Integrity | awk '{print $3}'`" = "yes"; +imagex apply --check dir.wim tmp +diff -q -r dir tmp +rm -rf dir.wim tmp + +# Appending and deleting images + +echo "Testing appending WIM image" +imagex capture dir dir.wim +imagex append dir2 dir.wim +test "`imagex info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 2; +echo "Testing appending WIM image with existing name (this should generate errors)" +! imagex append dir2 dir.wim +echo "Testing appending WIM image with new name" +imagex append dir2 dir.wim "newname" +echo "Testing appending WIM image with integrity check" +imagex append dir2 dir.wim "newname2" --check +test "`imagex info dir.wim | grep Integrity | awk '{print $3}'`" = "yes"; +echo "Testing appending WIM image with no integrity check" +imagex append dir2 dir.wim "newname3" +test "`imagex info dir.wim | grep Integrity | awk '{print $3}'`" = "no"; +test "`imagex info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 5; +echo "Testing deleting first WIM image" +imagex delete dir.wim 1 +test "`imagex info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 4; +echo "Testing deleting last WIM image" +imagex delete dir.wim 4 +test "`imagex info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 3; +echo "Testing deleting invalid WIM image (this should generate errors)" +! imagex delete dir.wim 4 +test "`imagex info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 3; +echo "Testing deleting all WIM images" +imagex delete dir.wim all +test "`imagex info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 0; +echo "Testing appending directory to empty WIM and making it bootable" +imagex append dir dir.wim "myname" "mydesc" --check --boot +test "`imagex info dir.wim | grep Integrity | awk '{print $3}'`" = "yes"; +test "`imagex info dir.wim | grep Boot | awk '{print $3}'`" = "1"; +echo "Testing appending non-directory (should generate errors)" +! imagex append dir.wim dir.wim +echo "Testing appending non-existent file (should generate errors)" +! imagex append SOME_NONEXISTENT_FILE dir.wim +echo "Testing appending directory containing unreadable file (should generate errors)" +mkdir -p dir3 +touch dir3/file +chmod -r dir3/file +! imagex append dir3 dir.wim +rm -rf dir3 dir.wim + +# Applying multiple images, applying with hardlinks/symlinks + +imagex capture dir dir.wim +imagex append dir dir.wim "myname" +echo "Testing application of multiple images" +imagex apply dir.wim all tmp +diff -q -r tmp/dir tmp/myname +test `stat -c %h tmp/dir/lz.c` = 1; +test `stat -c %h tmp/myname/lz.c` = 1; +test `stat -c %i tmp/myname/lz.c` != `stat -c %i tmp/dir/lz.c`; +rm -rf tmp +echo "Testing application of multiple images with hardlinks" +imagex apply dir.wim all tmp --hardlink +diff -q -r tmp/dir tmp/myname +test `stat -c %h tmp/dir/lz.c` = 2; +test `stat -c %h tmp/myname/lz.c` = 2; +test `stat -c %i tmp/myname/lz.c` = `stat -c %i tmp/dir/lz.c`; +rm -rf tmp +echo "Testing application of single image containing identical files" +imagex apply dir.wim 1 tmp +test `stat -c %h tmp/subdir/identical_file1` = 1; +test `stat -c %h tmp/subdir/identical_file2` = 1; +test `stat -c %i tmp/subdir/identical_file1` != `stat -c %i tmp/subdir/identical_file2`; +! readlink tmp/subdir/identical_file1 && ! readlink tmp/subdir/identical_file2 +rm -rf tmp + +echo "Testing application of single image containing identical files with hardlinks" +imagex apply dir.wim 1 tmp --hardlink +test `stat -c %h tmp/subdir/identical_file1` = 2; +test `stat -c %h tmp/subdir/identical_file2` = 2; +test `stat -c %i tmp/subdir/identical_file1` = `stat -c %i tmp/subdir/identical_file2`; +! readlink tmp/subdir/identical_file1 && ! readlink tmp/subdir/identical_file2 +rm -rf tmp + +echo "Testing application of single image containing identical files with symlinks" +imagex apply dir.wim 1 tmp --symlink +test `stat -c %h tmp/subdir/identical_file1` = 1; +test `stat -c %h tmp/subdir/identical_file2` = 1; +test `stat -c %i tmp/subdir/identical_file1` != `stat -c %i tmp/subdir/identical_file2`; +readlink tmp/subdir/identical_file1 > /dev/null || \ + readlink tmp/subdir/identical_file2 > /dev/null +rm -rf dir.wim tmp + +# imagex mount + +for flag in "--compress=none" "--compress=maximum" "--compress=fast"; do + echo "Using flag $flag" + echo "Testing mounting WIM read-only" + imagex capture dir dir.wim $flag + mkdir tmp + imagex mount dir.wim dir tmp + echo "Testing extracting file from mounted read-only WIM" + cp tmp/lz.c lz.c + diff -q dir/lz.c lz.c + diff -q tmp/lz.c dir/lz.c + rm -f lz.c + echo "Testing modifying mounted read-only WIM (should fail)" + ! rm tmp/lz.c + ! touch tmp/newfile + ! echo 3 > tmp/newfile + echo "Testing diff of mounted read-only WIM with original directory" + diff -q -r tmp dir + echo "Testing unmount of read-only filesystem" + imagex unmount tmp + echo "Testing unmount of read-only filesystem with --commit given" + imagex mount dir.wim dir tmp + imagex unmount tmp --commit + rm -rf tmp dir.wim +done + +# imagex mountrw +for flag in "--compress=none" "--compress=maximum" "--compress=fast"; do + echo "Using flag $flag" + echo "Testing mounting WIM read-write" + imagex capture dir dir.wim $flag + mkdir tmp + imagex mountrw dir.wim dir tmp + echo "Testing unmounting WIM unmodified" + imagex unmount tmp + echo "Testing unmounting WIM unmodified with --commit and --check" + imagex mountrw dir.wim dir tmp + imagex unmount tmp --commit --check + echo "Testing removing file from mounted WIM" + imagex mountrw dir.wim dir tmp + rm tmp/lz.c + test ! -e tmp/lz.c + echo "Testing making directory in mounted WIM" + mkdir tmp/newdir + test -d tmp/newdir + echo "Testing making new empty file in mounted WIM" + touch tmp/newdir/empty_file + test -e tmp/newdir/empty_file + test `stat -c %s tmp/newdir/empty_file` = 0; + echo "Testing making new non-empty file in mounted WIM" + dd if=/dev/zero of=tmp/newdir/zeroes1 bs=1 count=4096 + dd if=/dev/zero of=tmp/newdir/zeroes2 bs=4096 count=1 + cmp tmp/newdir/zeroes1 tmp/newdir/zeroes2 + echo "Unmounting WIM with changes committed and --check" + imagex unmount tmp --commit --check + test "`imagex info dir.wim | grep Integrity | awk '{print $3}'`" = "yes"; + rm -rf tmp + imagex apply dir.wim tmp + cmp tmp/newdir/zeroes1 tmp/newdir/zeroes2 + test `stat -c %s tmp/newdir/empty_file` = 0; + test `stat -c %s tmp/newdir/zeroes1` = 4096; + rm -rf tmp dir.wim +done + +# imagex split, imagex join + +echo "Creating random files to test WIM splitting on" +mkdir tmp +for i in `seq 1 100`; do + dd if=/dev/urandom of=tmp/file$i bs=4096 count=10 &> /dev/null +done +for flag in "--compress=none" "--compress=maximum" "--compress=fast"; do + echo "Using flag $flag" + imagex capture tmp tmp.wim $flag + echo "Splitting WIM into 1 MiB chunks" + imagex split tmp.wim tmp.swm 1 + echo "Verifying the split WIMs (some errors expected)" + test "`imagex info tmp.swm | grep 'Part Number' | awk '{print $3}'`" = "1/4" + imagex dir tmp.swm > /dev/null + test -e tmp2.swm && ! imagex dir tmp2.swm + ! imagex info tmp.swm --boot 0 # Unsupported, should fail + echo "Joining the split WIMs and applying the result" + imagex join tmp2.wim tmp*.wim + imagex apply tmp2.wim tmp2 + imagex apply tmp.wim tmp3 + diff -q -r tmp tmp2 + diff -q -r tmp tmp3 + rm -f *.wim *.swm + rm -rf tmp2 tmp3 +done +rm -rf 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; +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; +echo "Testing export of single image to existing WIM using wrong compression type" +! imagex export dir.wim dir2 new.wim newname --compress=maximum +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 +echo "Testing export of multiple images to existing WIM" +imagex export dir.wim all new.wim +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 +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 -- 2.43.0