introduce modular test suite

master
Harald Hoyer 2009-05-25 14:43:03 +02:00
parent 2f692e8ff8
commit c00f04f57a
9 changed files with 116 additions and 57 deletions

View File

@ -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)

18
test/Makefile Normal file
View File

@ -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:

View File

@ -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

56
test/TEST-10-RAID/test.sh Executable file
View File

@ -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

View File

@ -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

28
test/test-functions Normal file
View File

@ -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

View File

@ -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