]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
introduce modular test suite
authorHarald Hoyer <harald@redhat.com>
Mon, 25 May 2009 12:43:03 +0000 (14:43 +0200)
committerHarald Hoyer <harald@redhat.com>
Mon, 25 May 2009 13:32:26 +0000 (15:32 +0200)
Makefile
test/Makefile [new file with mode: 0644]
test/TEST-10-RAID/Makefile [new file with mode: 0644]
test/TEST-10-RAID/test.sh [new file with mode: 0755]
test/TEST-20-NFS/make-server-root [moved from test/make-server-root with 100% similarity]
test/TEST-20-NFS/server-init [moved from test/server-init with 100% similarity]
test/make-test-root [deleted file]
test/test-functions [new file with mode: 0644]
test/test-initramfs [deleted file]

index 5f9878d1c5f5cb9d578825b87c5445c99209b14c..0208d6dd37d9a48c94f9aabee33dfb161795c23a 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -6,7 +6,7 @@ modules.d/99base/switch_root: switch_root.c
 
 all: modules.d/99base/switch_root
 
-.PHONY: install clean archive rpm testimage test
+.PHONY: install clean archive rpm testimage test all check
 
 install:
        mkdir -p $(DESTDIR)/usr/lib/dracut
@@ -22,8 +22,7 @@ clean:
        rm -f *~
        rm -f modules.d/99base/switch_root
        rm -f test-*.img
-       rm -f test/initramfs.*
-       rm -f test/root.ext2
+       make -C test clean
 
 archive: dracut-$(VERSION)-$(GITVERSION).tar.bz2
 
@@ -34,19 +33,11 @@ rpm: dracut-$(VERSION)-$(GITVERSION).tar.bz2
        rpmbuild --define "_topdir $$PWD" --define "_sourcedir $$PWD" --define "_specdir $$PWD" --define "_srcrpmdir $$PWD" --define "_rpmdir $$PWD" --define "gittag $(GITVERSION)" -ba dracut.spec 
        rm -fr BUILD BUILDROOT
 
-test: test/root.ext2 test/initramfs.testing all
-       sudo APPEND="$(APPEND)" DRACUTOPTS="$(DRACUTOPTS)" test/test-initramfs
-
-test/initramfs.testing:
-       sudo ./dracut $(DRACUTOPTS) -c test/dracut.conf.test -l -f test/initramfs.testing
-
-test/root.ext2: test/test-init test/make-test-root
-       sudo test/make-test-root
-
-check:
+check: all
        @ret=0;for i in modules.d/99base/init modules.d/*/*.sh; do \
                dash -n "$$i" ; ret=$$(($$ret+$$?)); \
        done;exit $$ret
+       make -C test check
 
 testimage: all
        ./dracut -v -l -f test-$(shell uname -r).img $(shell uname -r)
diff --git a/test/Makefile b/test/Makefile
new file mode 100644 (file)
index 0000000..38bfecc
--- /dev/null
@@ -0,0 +1,18 @@
+.PHONY: all check clean
+
+check:
+       @for i in TEST-[0-9]*; do \
+               [ -d $$i ] || continue ; \
+               [ -f $$i/Makefile ] || continue ; \
+               make -C $$i all ; \
+       done
+
+clean:
+       @for i in TEST-[0-9]*; do \
+               [ -d $$i ] || continue ; \
+               [ -f $$i/Makefile ] || continue ; \
+               make -C $$i clean ; \
+       done
+
+all:
+
diff --git a/test/TEST-10-RAID/Makefile b/test/TEST-10-RAID/Makefile
new file mode 100644 (file)
index 0000000..2ef573d
--- /dev/null
@@ -0,0 +1,10 @@
+all:
+       make -C ../.. all
+       @basedir=../.. testdir=../ ./test.sh --all
+setup:
+       make -C ../.. all
+       @basedir=../.. testdir=../ ./test.sh --setup
+clean:
+       @basedir=../.. testdir=../ ./test.sh --clean
+run:
+       @basedir=../.. testdir=../ ./test.sh --run
diff --git a/test/TEST-10-RAID/test.sh b/test/TEST-10-RAID/test.sh
new file mode 100755 (executable)
index 0000000..a854a4e
--- /dev/null
@@ -0,0 +1,56 @@
+TEST_DESCRIPTION="root filesystem on an encrypted LVM PV"
+
+
+
+test_run() {
+    $testdir/run-qemu -hda root.ext2 -m 512M -nographic \
+       -net nic,macaddr=52:54:00:12:34:57 -net socket,mcast=230.0.0.1:1234 \
+       -kernel /boot/vmlinuz-$(uname -r) \
+       -append "root=/dev/dracut/root rw console=ttyS0,115200n81" \
+       -initrd initramfs.testing
+}
+
+test_setup() {
+    # This script creates a root filesystem on an encrypted LVM PV
+    dd if=/dev/zero of=root.ext2 bs=1M count=20
+
+    initdir=mnt
+    kernel=$(uname -r)
+    (
+       . $basedir/dracut-functions
+       dracut_install sh df free ls shutdown poweroff stty cat ps ln ip route \
+           /lib/terminfo/l/linux mount dmesg ifconfig dhclient mkdir cp ping dhclient 
+       inst "$basedir/modules.d/40network/dhclient-script" "/sbin/dhclient-script"
+       inst "$basedir/modules.d/40network/ifup" "/sbin/ifup"
+       dracut_install grep
+       inst $testdir/test-init /sbin/init
+       find_binary plymouth >/dev/null && dracut_install plymouth
+       (cd "$initdir"; mkdir -p dev sys proc etc var/run tmp )
+    )
+    targetfs="$initdir"
+    unset initdir
+
+    # create an initramfs that will create the target root filesystem.
+    # We do it this way because creating it directly in the host OS
+    # results in cryptsetup not being able to unlock the LVM PV.
+    # Probably a bug in cryptsetup, but...
+    $basedir/dracut -l -i "$targetfs" /source \
+       -m "dash kernel-modules test crypt lvm mdraid udev-rules base rootfs-block" \
+       -d "ata_piix ext2 sd_mod" \
+       -f initramfs.makeroot || return 1
+
+    # Invoke KVM and/or QEMU to actually create the target filesystem.
+    $testdir/run-qemu -hda root.ext2 -m 512M -nographic -net none \
+       -kernel "/boot/vmlinuz-$kernel" \
+       -append "root=/dev/dracut/root rw rootfstype=ext2 quiet console=ttyS0,115200n81" \
+       -initrd initramfs.makeroot  || return 1
+
+    sudo $basedir/dracut -l -f initramfs.testing  || return 1
+}
+
+test_cleanup() {
+    rm -fr mnt
+    rm -f root.ext2 initramfs.makeroot initramfs.testing
+}
+
+. $testdir/test-functions
\ No newline at end of file
diff --git a/test/make-test-root b/test/make-test-root
deleted file mode 100755 (executable)
index 93d9e0f..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-#!/bin/bash
-
-# This script creates a root filesystem on an encrypted LVM PV
-
-dd if=/dev/zero of=test/root.ext2 bs=1M count=20
-
-initdir=test/mnt
-kernel=$(uname -r)
-(
-    . ./dracut-functions
-    dracut_install sh df free ls shutdown poweroff stty cat ps ln ip route \
-       /lib/terminfo/l/linux mount dmesg ifconfig dhclient mkdir cp ping dhclient 
-    inst "modules.d/40network/dhclient-script" "/sbin/dhclient-script"
-    inst "modules.d/40network/ifup" "/sbin/ifup"
-    dracut_install grep
-    inst test/test-init /sbin/init
-    find_binary plymouth >/dev/null && dracut_install plymouth
-    (cd "$initdir"; mkdir -p dev sys proc etc var/run tmp )
-)
-targetfs="$initdir"
-unset initdir
-
-# create an initramfs that will create the target root filesystem.
-# We do it this way because creating it directly in the host OS
-# results in cryptsetup not being able to unlock the LVM PV.
-# Probably a bug in cryptsetup, but...
-./dracut -l -i "$targetfs" /source \
-    -m "dash kernel-modules test crypt lvm mdraid udev-rules base rootfs-block" \
-    -d "ata_piix ext2 sd_mod" \
-    -f test/initramfs.makeroot
-
-# Invoke KVM and/or QEMU to actually create the target filesystem.
-test/run-qemu -hda test/root.ext2 -m 512M -nographic -net none \
-    -kernel "/boot/vmlinuz-$kernel" \
-    -append "root=/dev/dracut/root rw rootfstype=ext2 quiet console=ttyS0,115200n81" \
-    -initrd test/initramfs.makeroot
diff --git a/test/test-functions b/test/test-functions
new file mode 100644 (file)
index 0000000..0e18e97
--- /dev/null
@@ -0,0 +1,28 @@
+while (($# > 0)); do
+    case $1 in
+        --run) 
+           echo "TEST RUN: $TEST_DESCRIPTION";
+           test_run;
+           exit $?;;
+        --setup) 
+           echo "TEST SETUP: $TEST_DESCRIPTION";
+           test_setup;
+           exit $?;;
+        --clean) 
+           echo "TEST CLEANUP: $TEST_DESCRIPTION";
+           test_cleanup;
+           exit $?;;
+        --all) 
+           echo "TEST: $TEST_DESCRIPTION";
+           test_setup && test_run && test_cleanup;
+           ret=$?;
+           if [ $ret -eq 0 ]; then
+              echo "$TEST_DESCRIPTION [OK]";
+           else
+              echo "$TEST_DESCRIPTION [FAILED]";
+           fi
+           exit $?;;
+        *) break ;;
+    esac
+    shift
+done
diff --git a/test/test-initramfs b/test/test-initramfs
deleted file mode 100755 (executable)
index 5ee0336..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-#!/bin/bash
-[[ -f test/root.ext2 ]] || test/make-test-root
-
-test/run-qemu -hda test/root.ext2 -m 512M -nographic \
-    -net nic,macaddr=52:54:00:12:34:57 -net socket,mcast=230.0.0.1:1234 \
-    -kernel /boot/vmlinuz-$(uname -r) \
-    -append "root=/dev/dracut/root rw console=ttyS0,115200n81 $APPEND" \
-    -initrd test/initramfs.testing