5 export BUP_DIR="$TOP/buptest.tmp"
12 # Very simple metadata tests -- create a test tree then check that bup
13 # meta can reproduce the metadata correctly (according to bup xstat)
14 # via create, extract, start-extract, and finish-extract. The current
15 # tests are crude, and this does not fully test devices, varying
16 # users/groups, acls, attrs, etc.
21 export PATH="$TOP:$PATH" # pick up bup
22 # Skip atime (test elsewhere) to avoid the observer effect.
23 find . | sort | xargs bup xstat --exclude-fields ctime,atime,size
29 test "$(whoami)" == root -a -z "$FAKEROOTKEY"
34 if ! actually-root; then
37 # Go to greater lengths to deal with any test detritus.
39 test -e "$@" || continue
40 chattr -fR = "$@" || true
47 test-src-create-extract()
49 # Test bup meta create/extract for ./src -> ./src-restore.
50 # Also writes to ./src-stat and ./src-restore-stat.
52 (cd src && WVPASS genstat) > src-stat
53 WVPASS bup meta --create --recurse --file src.meta src
55 force-delete src-restore
58 WVPASS bup meta --extract --file ../src.meta
60 (cd src && genstat >../../src-restore-stat) || WVFAIL
61 WVPASS diff -U5 ../src-stat ../src-restore-stat
62 # Test start/finish extract.
64 WVPASS bup meta --start-extract --file ../src.meta
66 WVPASS bup meta --finish-extract --file ../src.meta
67 (cd src && genstat >../../src-restore-stat) || WVFAIL
68 WVPASS diff -U5 ../src-stat ../src-restore-stat
72 if actually-root; then
73 umount "$TOP/bupmeta.tmp/testfs" || true
76 force-delete "$BUP_DIR"
77 force-delete "$TOP/bupmeta.tmp"
82 rm -rf "$TOP/bupmeta.tmp/src"
83 mkdir -p "$TOP/bupmeta.tmp/src"
84 #cp -a Documentation cmd lib t "$TOP/bupmeta.tmp"/src
85 cp -pPR Documentation cmd lib t "$TOP/bupmeta.tmp"/src
86 t/mksock "$TOP/bupmeta.tmp/src/test-socket" || true
89 # Use the test tree to check bup meta.
90 WVSTART 'meta - general'
93 test-src-create-extract
95 # Test a top-level file (not dir).
97 WVPASS bup meta -cf src-file.meta src-file
100 WVPASS bup meta -xf ../src-file.meta
103 # Root-only tests: ACLs, Linux attr, Linux xattr, etc.
104 if actually-root; then
109 umount "$TOP/bupmeta.tmp/testfs" || true
112 trap cleanup_at_exit EXIT
114 WVSTART 'meta - general (as root)'
115 WVPASS cd "$TOP/bupmeta.tmp"
116 umount testfs || true
117 dd if=/dev/zero of=testfs.img bs=1M count=32
118 mke2fs -F -j -m 0 testfs.img
120 mount -o loop,acl,user_xattr testfs.img testfs
121 # Hide, so that tests can't create risks.
122 chown root:root testfs
125 #cp -a src testfs/src
126 cp -pPR src testfs/src
127 (cd testfs && test-src-create-extract)
129 WVSTART 'meta - atime (as root)'
130 force-delete testfs/src
135 PYTHONPATH="$TOP/lib" \
136 python -c "from bup import xstat; \
137 x = xstat.timespec_to_nsecs((42, 0));\
138 xstat.utime('testfs/src/foo', (x, x));\
139 xstat.utime('testfs/src/bar', (x, x));"
141 WVPASS bup meta -v --create --recurse --file src.meta src
142 bup meta -tvf src.meta
144 force-delete src-restore
147 WVPASS bup meta --extract --file ../src.meta
148 WVPASSEQ "$(bup xstat --include-fields=atime src/foo)" "atime: 42"
149 WVPASSEQ "$(bup xstat --include-fields=atime src/bar)" "atime: 42"
150 # Test start/finish extract.
152 WVPASS bup meta --start-extract --file ../src.meta
154 WVPASS bup meta --finish-extract --file ../src.meta
155 WVPASSEQ "$(bup xstat --include-fields=atime src/foo)" "atime: 42"
156 WVPASSEQ "$(bup xstat --include-fields=atime src/bar)" "atime: 42"
159 WVSTART 'meta - Linux attr (as root)'
160 force-delete testfs/src
165 chattr +acdeijstuADST testfs/src/foo
166 chattr +acdeijstuADST testfs/src/bar
167 (cd testfs && test-src-create-extract)
170 WVSTART 'meta - Linux xattr (as root)'
171 force-delete testfs/src
176 attr -s foo -V bar testfs/src/foo
177 attr -s foo -V bar testfs/src/bar
178 (cd testfs && test-src-create-extract)
181 WVSTART 'meta - POSIX.1e ACLs (as root)'
182 force-delete testfs/src
187 setfacl -m u:root:r testfs/src/foo
188 setfacl -m u:root:r testfs/src/bar
189 (cd testfs && test-src-create-extract)