898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer#!/bin/bash
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer# ex: ts=8 sw=4 sts=4 et filetype=sh
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald HoyerTEST_DESCRIPTION="Basic systemd setup"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
fff87a35d9e26c0d4ea41273a963c0eb20e18da4Zbigniew Jędrzejewski-Szmek. $TEST_BASE_DIR/test-functions
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevaliercheck_result_qemu() {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer ret=1
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer mkdir -p $TESTDIR/root
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer mount ${LOOPDEV}p1 $TESTDIR/root
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ -e $TESTDIR/root/testok ]] && ret=0
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier [[ -f $TESTDIR/root/failed ]] && cp -a $TESTDIR/root/failed $TESTDIR
278d5115470919319c514ea37d7b14e3f7d0580bEvgeny Vereshchagin cp -a $TESTDIR/root/var/log/journal $TESTDIR
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer umount $TESTDIR/root
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier [[ -f $TESTDIR/failed ]] && cat $TESTDIR/failed
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer ls -l $TESTDIR/journal/*/*.journal
32d965851d8cbb39f8ee0eeaf76a89e8f5fc174fLennart Poettering test -s $TESTDIR/failed && ret=$(($ret+1))
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer return $ret
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer}
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
d9890f4ed47c0d565915360d8bae3b7a1428f285Harald Hoyertest_run() {
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier if run_qemu; then
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier check_result_qemu || return 1
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer else
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier dwarn "can't run QEMU, skipping"
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer fi
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer if check_nspawn; then
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier run_nspawn
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier check_result_nspawn || return 1
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer else
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer dwarn "can't run systemd-nspawn, skipping"
7b17d413b11bfbdb4442c87b1db25b37ed5162acHarald Hoyer fi
d9890f4ed47c0d565915360d8bae3b7a1428f285Harald Hoyer return 0
d9890f4ed47c0d565915360d8bae3b7a1428f285Harald Hoyer}
d9890f4ed47c0d565915360d8bae3b7a1428f285Harald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyertest_setup() {
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier create_empty_image
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer mkdir -p $TESTDIR/root
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer mount ${LOOPDEV}p1 $TESTDIR/root
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer # Create what will eventually be our root filesystem onto an overlay
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer (
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer LOG_LEVEL=5
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier setup_basic_environment
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer # setup the testsuite service
6b197f2a03fa03a2a853cf726d47be2ea4c623b6Harald Hoyer cat >$initdir/etc/systemd/system/testsuite.service <<EOF
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer[Unit]
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald HoyerDescription=Testsuite service
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald HoyerAfter=multi-user.target
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer[Service]
5c404f1ab8e96efedb983806443ca982a1b2a372Evgeny VereshchaginExecStart=/bin/sh -x -c 'systemctl --failed --no-legend --no-pager > /failed ; echo OK > /testok'
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald HoyerType=oneshot
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald HoyerEOF
c90feab4ff8bc23d88d4f9c67d9652ba189cb51bMichal Schmidt
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier setup_testsuite
cd949ee7348982d90fb8bdf4a37128928b82925fEvgeny Vereshchagin ) || return 1
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier setup_nspawn_root
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer
6f9d3b08cf3e50d3903282d2ce36244bb86c7b7cDaniel Mack # mask some services that we do not want to run in these tests
6f9d3b08cf3e50d3903282d2ce36244bb86c7b7cDaniel Mack ln -s /dev/null $initdir/etc/systemd/system/systemd-hwdb-update.service
6f9d3b08cf3e50d3903282d2ce36244bb86c7b7cDaniel Mack ln -s /dev/null $initdir/etc/systemd/system/systemd-journal-catalog-update.service
6f9d3b08cf3e50d3903282d2ce36244bb86c7b7cDaniel Mack ln -s /dev/null $initdir/etc/systemd/system/systemd-networkd.service
6f9d3b08cf3e50d3903282d2ce36244bb86c7b7cDaniel Mack ln -s /dev/null $initdir/etc/systemd/system/systemd-networkd.socket
6f9d3b08cf3e50d3903282d2ce36244bb86c7b7cDaniel Mack ln -s /dev/null $initdir/etc/systemd/system/systemd-resolved.service
6f9d3b08cf3e50d3903282d2ce36244bb86c7b7cDaniel Mack
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer ddebug "umount $TESTDIR/root"
d9890f4ed47c0d565915360d8bae3b7a1428f285Harald Hoyer umount $TESTDIR/root
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer}
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyertest_cleanup() {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer umount $TESTDIR/root 2>/dev/null
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [[ $LOOPDEV ]] && losetup -d $LOOPDEV
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer return 0
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer}
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyerdo_test "$@"