Tomb/extras/test/runtests
Jaromil 4d6c0bf5cc Cleaner test environment
now available as 'make test'
2013-06-12 11:12:33 +02:00

125 lines
2.7 KiB
Bash
Executable File

#!/usr/bin/zsh
#
# Iterates through various tests on the tomb script
T="../../tomb"
source ${T} source
notice() { print; yes "${@}"; print; }
error() { _warning " ${@}"; }
tt() {
start_loops=(`sudo losetup -a |cut -d: -f1`)
${T} ${=@}
res=$?
loops=(`sudo losetup -a |cut -d: -f1`)
{ test "${#start_loops}" = "${#loops}" } || { error "loop device limit change to ${#loops}" }
print " Tomb command returns $res"
return $res
}
typeset -A results
tests=(dig forge lock badpass open close resize chksum bind)
rm /tmp/test.tomb{,.key} -f || exit 1
startloops=(`sudo losetup -a |cut -d: -f1`)
notice "Testing creation"
tt dig -s 20 /tmp/test.tomb
{ test $? = 0 } && { results+=(dig SUCCESS) }
tt --ignore-swap --unsecure-dev-mode --tomb-pwd f00za --use-urandom forge /tmp/test.tomb.key
{ test $? = 0 } && { results+=(forge SUCCESS) }
tt --ignore-swap --unsecure-dev-mode --tomb-pwd f00za lock /tmp/test.tomb -k /tmp/test.tomb.key
{ test $? = 0 } && { results+=(lock SUCCESS) }
notice "Testing open with wrong password"
tt --unsecure-dev-mode --tomb-pwd wrongpassword open /tmp/test.tomb
{ test $? = 0 } || { results+=(badpass SUCCESS) }
notice "Testing open with good password"
tt --unsecure-dev-mode --tomb-pwd f00za open /tmp/test.tomb
{ test $? = 0 } && { results+=(open SUCCESS) }
notice "Generating content for file integrity test"
${T} dig -s 10 /media/test.tomb/datacheck.raw
crc="sha256 /media/test.tomb/datacheck.raw"
echo "$crc" > /media/test.tomb/datacheck.sha
tt --unsecure-dev-mode close test
{ test $? = 0 } && { results+=(close SUCCESS) }
notice "Testing resize to 30 MiB"
tt --unsecure-dev-mode --tomb-pwd f00za -k /tmp/test.tomb.key resize /tmp/test.tomb -s 30
{ test $? = 0 } && { results+=(resize SUCCESS) }
${T} --unsecure-dev-mode --tomb-pwd f00za open /tmp/test.tomb
crc2="sha256 /media/test.tomb/datacheck.raw"
{ test "$crc" = "$crc2" } && { results+=(chksum SUCCESS) }
notice "Testing bind hooks"
rnd=$RANDOM
echo $rnd > /media/test.tomb/test-$rnd
echo "test-$rnd test-$rnd" > /media/test.tomb/bind-hooks
touch $HOME/test-$rnd
tt close test
tt --unsecure-dev-mode --tomb-pwd f00za open /tmp/test.tomb
rnd2=`cat $HOME/test-$rnd`
if [ "$rnd" = "$rnd2" ]; then
notice "Bind hook on file matches"
results+=(bind SUCCESS)
tt list test
else
error "Bind hook on file reports incongruence"
fi
sudo umount $HOME/test-$rnd
rm /media/test.tomb/bind-hooks
rm /media/test.tomb/test-$rnd
tt close test
# rm /tmp/test.tomb{,.key} -f || exit 1
endloops=(`sudo losetup -a |cut -d: -f1`)
notice "Test results summary"
print "${#startloops} loop devices busy at start"
for t in $tests; do
echo "$t\t${results[$t]:-FAIL}"
done
print "${#endloops} loop devices busy at end"