From 3bd20bde1e49ab664cc53262ec5ebb3e6323d3f6 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Tue, 21 Jul 2009 22:11:47 +0200 Subject: make tests separate reusable files + make the testing thing a bit better --- tests/lib/framework-runtime | 35 ++++++++++++++++++++++ tests/lib/setup-file | 5 ++++ tests/lib/test-file | 6 ++++ tests/lib/test-lvm-lv | 9 ++++++ tests/lib/test-mount | 6 ++++ tests/lib/test-nofile | 6 ++++ tests/lib/test-nopackage | 11 +++++++ tests/lib/test-ping | 7 +++++ tests/lib/test-swap | 5 ++++ .../perform_test.sh | 26 +++++++++------- .../automatic-lvm-dmcrypt-install-sda/profile | 2 +- 11 files changed, 106 insertions(+), 12 deletions(-) create mode 100644 tests/lib/framework-runtime create mode 100644 tests/lib/setup-file create mode 100644 tests/lib/test-file create mode 100644 tests/lib/test-lvm-lv create mode 100644 tests/lib/test-mount create mode 100644 tests/lib/test-nofile create mode 100644 tests/lib/test-nopackage create mode 100644 tests/lib/test-ping create mode 100644 tests/lib/test-swap (limited to 'tests') diff --git a/tests/lib/framework-runtime b/tests/lib/framework-runtime new file mode 100644 index 0000000..c1b16fd --- /dev/null +++ b/tests/lib/framework-runtime @@ -0,0 +1,35 @@ +#!/bin/bash +lib="/usr/share/aif/tests/lib" +STATUS=0 + +# $1 name of test +# $2... other args +function aiftest () { + name=$1 + shift + if [ ! -f $lib/test-$name ] + then + echo "NO SUCH TEST: $lib/test-$1" >&2 + return 2 + else + $lib/test-$name "$@" + ret=$? + if [ $ret -eq 0 ] + then + "$NAME : OK" + else + "$NAME [ $ret ] : NOT OK" + fi + [ $ret -gt $STATUS ] && STATUS=$ret +} + +aiftest-done () { + if [ $STATUS -eq 0 ] + then + echo 'ALL TESTS ENDED SUCCESSFULLY' + exit 0 + else + echo 'ONE OR MORE TESTS FAILED!' >&2 + exit $STATUS + fi +} diff --git a/tests/lib/setup-file b/tests/lib/setup-file new file mode 100644 index 0000000..eeb8b17 --- /dev/null +++ b/tests/lib/setup-file @@ -0,0 +1,5 @@ +#!/bin/bash +for i in "$@" +do + touch $i/test_file +done diff --git a/tests/lib/test-file b/tests/lib/test-file new file mode 100644 index 0000000..b1504ae --- /dev/null +++ b/tests/lib/test-file @@ -0,0 +1,6 @@ +#!/bin/bash +# $1 filename + +NAME="FILE TEST, $1" + +[ -f "$1" ] diff --git a/tests/lib/test-lvm-lv b/tests/lib/test-lvm-lv new file mode 100644 index 0000000..2c6a6bc --- /dev/null +++ b/tests/lib/test-lvm-lv @@ -0,0 +1,9 @@ +#!/bin/bash +# $1 VG +# $2 LV +# $2 SIZE eg '800.00 MB' + +NAME="LOGICAL VOLUME CHECK, /dev/mapper/$1-$2" + +lvdisplay | grep -A 5 'LV Name.*/dev/mapper/'$1-$2 | grep -q available || exit 1 +lvdisplay | grep -A 7 'LV Name.*/dev/mapper/'$1-$2 | grep -q 'LV Size.*'"$2" || exit 2 diff --git a/tests/lib/test-mount b/tests/lib/test-mount new file mode 100644 index 0000000..e45715a --- /dev/null +++ b/tests/lib/test-mount @@ -0,0 +1,6 @@ +#!/bin/bash +# $1 mount output string + +NAME="MOUNT CHECK, $1" + +mount | grep -q '/dev/mapper/cryptpool-crypthome on /home type xfs (rw)' diff --git a/tests/lib/test-nofile b/tests/lib/test-nofile new file mode 100644 index 0000000..f5e13c5 --- /dev/null +++ b/tests/lib/test-nofile @@ -0,0 +1,6 @@ +#!/bin/bash +# $1 filename + +NAME="NOFILE TEST, $1" + +[ ! -f "$1" ] diff --git a/tests/lib/test-nopackage b/tests/lib/test-nopackage new file mode 100644 index 0000000..62bfc36 --- /dev/null +++ b/tests/lib/test-nopackage @@ -0,0 +1,11 @@ +#!/bin/bash +# $1 packagename + +NAME="NO PACKAGE, $1" + +if pacman -Qi $1 +then + exit 1 +else + exit 0 +fi diff --git a/tests/lib/test-ping b/tests/lib/test-ping new file mode 100644 index 0000000..2fba015 --- /dev/null +++ b/tests/lib/test-ping @@ -0,0 +1,7 @@ +#!/bin/bash +# $1 iterations +# $2 host + +NAME="PING CHECK ON $2" + +ping -c $1 $2 diff --git a/tests/lib/test-swap b/tests/lib/test-swap new file mode 100644 index 0000000..892815d --- /dev/null +++ b/tests/lib/test-swap @@ -0,0 +1,5 @@ +#!/bin/bash + +name="SWAP CHECK, SIZE $1" + +free -m | grep -q 'Swap:.*'$1'.*' \ No newline at end of file diff --git a/tests/runtime/automatic-lvm-dmcrypt-install-sda/perform_test.sh b/tests/runtime/automatic-lvm-dmcrypt-install-sda/perform_test.sh index d0a20b0..390ee63 100644 --- a/tests/runtime/automatic-lvm-dmcrypt-install-sda/perform_test.sh +++ b/tests/runtime/automatic-lvm-dmcrypt-install-sda/perform_test.sh @@ -1,20 +1,24 @@ -#!/bin/sh +#!/bin/bash +source /usr/share/aif/tests/lib/framework-runtime -free -m | grep 'Swap:.*20.*' || echo 'SWAP CHECK FAILED' +aiftest swap 19 +aiftest lvm-lv cryptpool cryptroot '800.00 MB' +aiftest mount '/dev/mapper/cryptpool-cryptroot on / type xfs (rw)' +aiftest mount '/dev/mapper/cryptpool-crypthome on /home type xfs (rw)' +for i in /etc/ / /root/ /home/ /var/ +do + aiftest file "$i"/test_file +done +aiftest file /usr/bin/ssh +aiftest nofile /sbin/mkfs.reiserfs +aiftest nopackage sudo +aiftest ping 2 archlinux.org -lvdisplay | grep -A 5 'LV Name.*/dev/mapper/cryptpool-cryptroot' | grep available || echo 'LV ROOT CHECK FAILED' -lvdisplay | grep -A 7 'LV Name.*/dev/mapper/cryptpool-cryptroot' | grep 'LV Size.*800.00 MB' || echo 'LV ROOT CHECK FAILED' +aiftest-done -mount | grep '/dev/mapper/cryptpool-cryptroot on / type xfs (rw)' || echo 'ROOT FS CHECK FAILED' -mount | grep '/dev/mapper/cryptpool-crypthome on /home type xfs (rw)' || echo 'HOME FS CHECK FAILED' -for i in /etc/ / /root/ /home/ /var/ -do [ -f "$i/test_file" ] || echo "TEST FAILED. NO FILE $i/test_file" -done -[ -x /usr/bin/ssh ] || echo 'PACKAGE INSTALLATION CHECK SSH FAILED' -[ -f /sbin/mkfs.reiserfs ] && echo 'PACKAGE INSTALLATION CHECK REISERFS FAILED' ping -c 2 archlinux.org || echo 'PING CHECK FAILED' diff --git a/tests/runtime/automatic-lvm-dmcrypt-install-sda/profile b/tests/runtime/automatic-lvm-dmcrypt-install-sda/profile index 1494d3a..484de8e 100644 --- a/tests/runtime/automatic-lvm-dmcrypt-install-sda/profile +++ b/tests/runtime/automatic-lvm-dmcrypt-install-sda/profile @@ -11,7 +11,7 @@ RUNTIME_PACKAGES= # packages to install TARGET_GROUPS=base TARGET_PACKAGES_EXCLUDE='reiserfsprogs' -TARGET_PACKAGES=openssh +TARGET_PACKAGES='openssh aif' worker_configure_system () { sed -i 's/filesystems/usbinput keymap encrypt lvm2 filesystems/' $var_TARGET_DIR/etc/mkinitcpio.conf -- cgit v1.2.2