diff --git a/Makefile b/Makefile index 5f9878d1..0208d6dd 100644 --- 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 index 00000000..38bfecc5 --- /dev/null +++ b/test/Makefile @@ -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 index 00000000..2ef573df --- /dev/null +++ b/test/TEST-10-RAID/Makefile @@ -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 index 00000000..a854a4e2 --- /dev/null +++ b/test/TEST-10-RAID/test.sh @@ -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-server-root b/test/TEST-20-NFS/make-server-root similarity index 100% rename from test/make-server-root rename to test/TEST-20-NFS/make-server-root diff --git a/test/server-init b/test/TEST-20-NFS/server-init similarity index 100% rename from test/server-init rename to test/TEST-20-NFS/server-init diff --git a/test/make-test-root b/test/make-test-root deleted file mode 100755 index 93d9e0f1..00000000 --- a/test/make-test-root +++ /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 index 00000000..0e18e975 --- /dev/null +++ b/test/test-functions @@ -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 index 5ee03364..00000000 --- a/test/test-initramfs +++ /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