Cleaner test environment

now available as 'make test'
This commit is contained in:
Jaromil 2013-06-12 11:12:33 +02:00
parent bc3177141d
commit 4d6c0bf5cc
4 changed files with 129 additions and 46 deletions

View File

@ -9,3 +9,6 @@ all:
install:
@install -Dm755 ${PROG} ${DESTDIR}${PREFIX}/bin/${PROG}
@install -Dm666 doc/${PROG}.1 ${DESTDIR}${MANDIR}/man1/${PROG}.1
test:
make -C extras/test

2
extras/test/Makefile Normal file
View File

@ -0,0 +1,2 @@
all:
@./runtests

View File

@ -1,46 +0,0 @@
#!/usr/bin/zsh
T="../../tomb"
source utils.sh
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
}
rm /tmp/test.tomb{,.key} -f || exit 1
notice "Testing creation"
tt dig -s 10 /tmp/test.tomb
tt --ignore-swap --unsecure-dev-mode --tomb-pwd f00za --use-urandom forge /tmp/test.tomb.key
tt --ignore-swap --unsecure-dev-mode --tomb-pwd f00za lock /tmp/test.tomb -k /tmp/test.tomb.key
# sanity_tomb /tmp/asd.tomb
notice "Testing open with wrong password"
tt --unsecure-dev-mode --tomb-pwd wrongpassword open /tmp/test.tomb
notice "Testing open with good password"
tt --unsecure-dev-mode --tomb-pwd f00za open /tmp/test.tomb
tt --unsecure-dev-mode close test
notice "Testing resize to 20MiB"
tt --unsecure-dev-mode --tomb-pwd f00za -k /tmp/test.tomb.key resize /tmp/test.tomb -s 20
# rm /tmp/test.tomb{,.key} -f || exit 1

124
extras/test/runtests Executable file
View File

@ -0,0 +1,124 @@
#!/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"