On 17/11/09 19:22, Richard W.M. Jones wrote:
+stage Checking initial files exist +[ -n "$(echo *)" ] +[ "$(ls empty hello.txt world.txt)" = "empty +hello.txt +world.txt" ] + +stage Checking initial files contain expected content +[ "$(cat hello.txt)" = "hello" ] +[ "$(cat world.txt)" = "hello world" ] +cat empty ;# should print nothing +[ -z "$(cat empty)" ] + +stage Checking file modes of initial content +[ "$(stat -c %a empty)" = "644" ] +[ "$(stat -c %a hello.txt)" = "644" ] +[ "$(stat -c %a world.txt)" = "644" ]
You need to explicitly set the umask to 022 at the beginning of the script for this to be reliable.
+stage Checking sizes of initial content +[ "$(stat -c %s empty)" -eq 0 ] +[ "$(stat -c %s hello.txt)" -eq 5 ] +[ "$(stat -c %s world.txt)" -eq 11 ]
While you're at it, you could add tests for every other stat field.
+stage Checking unlink +touch new +rm -f new ;# force because file is "owned" by root + +stage Checking symbolic link +ln -s hello.txt symlink +[ -L symlink ] + +stage Checking readlink +[ "$(readlink symlink)" = "hello.txt" ] + +stage Checking hard link +[ "$(stat -c %h hello.txt)" -eq 1 ] +ln hello.txt link +[ "$(stat -c %h link)" -eq 2 ] +[ "$(stat -c %h hello.txt)" -eq 2 ] +rm -f link +[ ! -e link ] + +# This fails because of caching. The problem is that the linked file +# ("hello.txt") is cached with a link count of 2. unlink("link") +# invalidates the cache for "link", but_not_ for "hello.txt" which +# still has the now-incorrect cached value. However there's not much +# we can do about this since searching for all linked inodes of a file +# is an O(n) operation. +#[ "$(stat -c %h hello.txt)" -eq 1 ]
Eurgh. What's the impact of not caching? Alternatively, inotify can spot an updated link count. What's the potential for adding asynchronous cache invalidation from the daemon?
+stage Checking mkdir +mkdir newdir +[ -d newdir ] + +stage Checking rmdir +rmdir newdir +[ ! -e newdir ] + +stage Checking rename +touch old +mv old new +[ -f new ] +[ ! -e old ] +rm -f new + +stage Checking chmod +touch new +chmod a+x new +[ -x new ] +chmod a-x new +[ ! -x new ] +chmod a-w new +[ ! -w new ] +chmod a+w new +[ -w new ] +chmod a-r new +[ ! -r new ] +chmod a+r new +[ -r new ] +rm -f new + +stage Checking truncate +truncate -s 10000 truncated +[ "$(stat -c %s truncated)" -eq 10000 ] +truncate -c -s 1000 truncated +[ "$(stat -c %s truncated)" -eq 1000 ] +truncate -c -s 10 truncated +[ "$(stat -c %s truncated)" -eq 10 ] +truncate -c -s 0 truncated +[ "$(stat -c %s truncated)" -eq 0 ] +rm -f truncated + +stage Checking utimens and timestamps +for ts in 12345 1234567 987654321; do + # NB: It's not possible to set the ctime with touch. + touch -a -d @$ts timestamp + [ "$(stat -c %X timestamp)" -eq $ts ] + touch -m -d @$ts timestamp + [ "$(stat -c %Y timestamp)" -eq $ts ] + touch -d @$ts timestamp + [ "$(stat -c %X timestamp)" -eq $ts ] + [ "$(stat -c %Y timestamp)" -eq $ts ] +done + +# These ones are not yet tested by the current script: +#stage XXX statfs/statvfs +#stage XXX xattr operations + +# These ones cannot easily be tested by the current script, eg because +# this script doesn't run as root: +#stage XXX fsync +#stage XXX chown +#stage XXX mknod -- 1.6.5.2
Looks good. Matt -- Matthew Booth, RHCA, RHCSS Red Hat Engineering, Virtualisation Team M: +44 (0)7977 267231 GPG ID: D33C3490 GPG FPR: 3733 612D 2D05 5458 8A8A 1600 3441 EA19 D33C 3490