test.sh revision 0d6e798a784ef0ba6b95512e4453067b2f84a91a
a660c63c551b88136ac6176855b5907cc533e848Kay Sievers# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
a660c63c551b88136ac6176855b5907cc533e848Kay Sievers# ex: ts=8 sw=4 sts=4 et filetype=sh
a660c63c551b88136ac6176855b5907cc533e848Kay Sievers# Uncomment this to debug failures
a660c63c551b88136ac6176855b5907cc533e848Kay SieversDEBUGTOOLS="df free ls stty cat ps ln ip route dmesg dhclient mkdir cp ping dhclient strace less grep id tty touch du sort"
a660c63c551b88136ac6176855b5907cc533e848Kay Sievers # TODO: qemu wrapper script: http://www.spinics.net/lists/kvm/msg72389.html
a660c63c551b88136ac6176855b5907cc533e848Kay Sievers -append "root=/dev/sda1 systemd.log_level=debug raid=noautodetect loglevel=2 init=/usr/lib/systemd/systemd ro console=ttyS0,115200n81 selinux=0 $DEBUGFAIL" || return 1
472780d8b1ec3f3f4ff78eb21a013136e5aa1cfeKay Sievers [[ -e $TESTDIR/root/testok ]] && ret=0
472780d8b1ec3f3f4ff78eb21a013136e5aa1cfeKay Sievers cryptsetup luksOpen ${LOOPDEV}p2 varcrypt <$TESTDIR/keyfile
214daa72cb0c72ea78d1eccd5ffe630a1e04b2f7Sean McGovern systemd-nspawn -b -D $TESTDIR/nspawn-root /usr/lib/systemd/systemd
ad37f393fa97f4274cc3bf97a0d8c388a429037eKay Sievers cp -a $TESTDIR/nspawn-root/var/log/journal $TESTDIR
f610d6de38119b372b377ec41b2a6089872d3294Kay Sievers#run_nspawn || return 1
decd634e801bee2c554edb35383cc9d43417a850Kay Sievers # Create the blank file to use as a root filesystem
decd634e801bee2c554edb35383cc9d43417a850Kay Sievers dd if=/dev/null of=$TESTDIR/rootdisk.img bs=1M seek=200
f610d6de38119b372b377ec41b2a6089872d3294Kay Sievers LOOPDEV=$(losetup --show -P -f $TESTDIR/rootdisk.img)
f610d6de38119b372b377ec41b2a6089872d3294Kay Sievers [ -b $LOOPDEV ] || return 1
f610d6de38119b372b377ec41b2a6089872d3294Kay Sievers sfdisk -C 6400 -H 2 -S 32 -L $LOOPDEV <<EOF
f610d6de38119b372b377ec41b2a6089872d3294Kay Sievers cryptsetup -q luksFormat ${LOOPDEV}p2 $TESTDIR/keyfile
f610d6de38119b372b377ec41b2a6089872d3294Kay Sievers cryptsetup luksOpen ${LOOPDEV}p2 varcrypt <$TESTDIR/keyfile
a660c63c551b88136ac6176855b5907cc533e848Kay Sievers # Create what will eventually be our root filesystem onto an overlay
0260944060426d54d9ecb40930baad985cbd02a1Kay Sievers for i in $initdir/{sbin,bin}/* $initdir/lib/systemd/*; do
0260944060426d54d9ecb40930baad985cbd02a1Kay Sievers echo 'ImportKernel=yes' >> $initdir/etc/systemd/journald.conf
01d183ddae6fb3445c4519cf1d90c6575f17292eKay Sievers eval $(udevadm info --export --query=env --name=/dev/mapper/varcrypt)
01d183ddae6fb3445c4519cf1d90c6575f17292eKay Sievers eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
0035597a30d120f70df2dd7da3d6128fb8ba6051Kay Sievers$DM_NAME UUID=$ID_FS_UUID /etc/varkey
0035597a30d120f70df2dd7da3d6128fb8ba6051Kay Sievers echo -n test > $initdir/etc/varkey
0260944060426d54d9ecb40930baad985cbd02a1Kay SieversLABEL=systemd / ext3 rw 0 1
0035597a30d120f70df2dd7da3d6128fb8ba6051Kay Sievers/dev/mapper/varcrypt /var ext3 defaults 0 1
1328f66ad16b5afeb5684858c27e121a46c1959eKay Sievers cat >$initdir/etc/systemd/system/testsuite.target <<EOF
3c123e0899b56c0587db36420da5e049c56d9e19Lukas NykrynDescription=Testsuite target
0260944060426d54d9ecb40930baad985cbd02a1Kay SieversRequires=multi-user.target
1328f66ad16b5afeb5684858c27e121a46c1959eKay SieversAfter=multi-user.target
de892aea1c486b59e04884268b612081d1660514Kay SieversConflicts=rescue.target
de892aea1c486b59e04884268b612081d1660514Kay SieversAllowIsolate=yes
de892aea1c486b59e04884268b612081d1660514Kay Sievers cat >$initdir/etc/systemd/system/testsuite.service <<EOF
de892aea1c486b59e04884268b612081d1660514Kay SieversDescription=Testsuite service
de892aea1c486b59e04884268b612081d1660514Kay SieversAfter=multi-user.target
de892aea1c486b59e04884268b612081d1660514Kay SieversExecStart=/bin/bash -c 'set -x; systemctl --failed --no-legend --no-pager > /failed ; echo OK > /testok; while : ;do systemd-cat echo "testsuite service waiting for /var/log/journal" ; echo "testsuite service waiting for journal to move to /var/log/journal" > /dev/console ; for i in /var/log/journal/*;do [ -d "\$i" ] && echo "\$i" && break 2; done; sleep 1; done; sleep 1; exit 0;'
f168c27313e4d7b0aabee037dc9c78a5799f0597Thomas Hindoe Paaboel AndersenExecStopPost=/usr/bin/systemctl poweroff
de892aea1c486b59e04884268b612081d1660514Kay Sievers mkdir -p $initdir/etc/systemd/system/testsuite.target.wants
de892aea1c486b59e04884268b612081d1660514Kay Sievers ln -fs ../testsuite.service $initdir/etc/systemd/system/testsuite.target.wants/testsuite.service
b5dd8148730db080b48b874c214f8f74ae787d6bZbigniew Jędrzejewski-Szmek ln -fs testsuite.target $initdir/etc/systemd/system/default.target
b5dd8148730db080b48b874c214f8f74ae787d6bZbigniew Jędrzejewski-Szmek chmod 0755 $initdir/etc/rc.d/rc.local
b5dd8148730db080b48b874c214f8f74ae787d6bZbigniew Jędrzejewski-Szmek dracut_install sh bash setsid loadkeys setfont \
0035597a30d120f70df2dd7da3d6128fb8ba6051Kay Sievers login sushell sulogin gzip sleep echo mount umount cryptsetup
b5dd8148730db080b48b874c214f8f74ae787d6bZbigniew Jędrzejewski-Szmek dracut_install dmsetup modprobe
1328f66ad16b5afeb5684858c27e121a46c1959eKay Sievers type -P dmeventd >/dev/null && dracut_install dmeventd
1328f66ad16b5afeb5684858c27e121a46c1959eKay Sievers inst_rules 10-dm.rules 13-dm-disk.rules 95-dm-notify.rules
d23965a64eb5c2c97b839dc2e3e79fc1613994f1Kay Sievers | while read file; do
0035597a30d120f70df2dd7da3d6128fb8ba6051Kay Sievers [[ -f $i ]] || continue
0035597a30d120f70df2dd7da3d6128fb8ba6051Kay Sievers for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
0035597a30d120f70df2dd7da3d6128fb8ba6051Kay Sievers [ -f ${_terminfodir}/l/linux ] && break
0035597a30d120f70df2dd7da3d6128fb8ba6051Kay Sievers egrep -ho '^Exec[^ ]*=[^ ]+' $initdir/lib/systemd/system/*.service \
641906e9366891e0ad3e6e38b7396a427678c4cfThomas Hindoe Paaboel Andersen | while read i; do
0035597a30d120f70df2dd7da3d6128fb8ba6051Kay Sievers # install plymouth, if found... else remove plymouth service files
0035597a30d120f70df2dd7da3d6128fb8ba6051Kay Sievers # if [ -x /usr/libexec/plymouth/plymouth-populate-initrd ]; then
0035597a30d120f70df2dd7da3d6128fb8ba6051Kay Sievers # PLYMOUTH_POPULATE_SOURCE_FUNCTIONS="$TEST_BASE_DIR/test-functions" \
d23965a64eb5c2c97b839dc2e3e79fc1613994f1Kay Sievers # /usr/libexec/plymouth/plymouth-populate-initrd -t $initdir
214daa72cb0c72ea78d1eccd5ffe630a1e04b2f7Sean McGovern rm -f $initdir/{usr/lib,etc}/systemd/system/plymouth* $initdir/{usr/lib,etc}/systemd/system/*/plymouth*
d23965a64eb5c2c97b839dc2e3e79fc1613994f1Kay Sievers find "$initdir" -perm +111 -type f | xargs strip --strip-unneeded | ddebug
0260944060426d54d9ecb40930baad985cbd02a1Kay Sievers if [[ -d $initdir/lib/modules/$KERNEL_VER ]] && \
bb26309dd042c79de907f103d83f398b9436cde0Rob Clark ddebug "cp -ar $TESTDIR/root $TESTDIR/nspawn-root"