From 061999ee0d9bde9e79f4735283dfd1382313bccf Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 7 Feb 2007 13:26:11 +0100 Subject: [PATCH] mkswap: add regression test Signed-off-by: Karel Zak --- tests/Makefile.am | 4 +- tests/commands.sh.in | 9 ++-- tests/expected/ts-mkswap-doit | 2 + tests/ts-mkswap-doit | 90 +++++++++++++++++++++++++++++++++++ 4 files changed, 101 insertions(+), 4 deletions(-) create mode 100644 tests/expected/ts-mkswap-doit create mode 100755 tests/ts-mkswap-doit diff --git a/tests/Makefile.am b/tests/Makefile.am index eebb700b..3ab18b0c 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -8,10 +8,12 @@ EXTRA_DIST = commands.sh.in \ ts-ipcs-headers \ ts-ipcs-limits \ ts-ipcs-limits2 \ + ts-mkswap-doit \ expected/ts-mount-paths \ expected/ts-ipcs-headers \ expected/ts-ipcs-limits \ - expected/ts-ipcs-limits2 + expected/ts-ipcs-limits2 \ + expected/ts-mkswap-doit distclean-local: rm -rf output diff diff --git a/tests/commands.sh.in b/tests/commands.sh.in index 061b42b9..866c3947 100644 --- a/tests/commands.sh.in +++ b/tests/commands.sh.in @@ -6,9 +6,12 @@ TS_HELPER_SYSINFO="$TS_TOPDIR/helpers/mnt_test_sysinfo" # paths to commands TS_CMD_MOUNT=${TS_CMD_MOUNT:-"$TOPDIR/mount/mount"} -TS_CMD_UMOUNT=${TS_CMD_MOUNT:-"$TOPDIR/mount/umount"} -TS_CMD_SWAPON=${TS_CMD_MOUNT:-"$TOPDIR/mount/swapon"} -TS_CMD_SWAPOFF=${TS_CMD_MOUNT:-"$TOPDIR/mount/swapoff"} +TS_CMD_UMOUNT=${TS_CMD_UMOUNT:-"$TOPDIR/mount/umount"} +TS_CMD_SWAPON=${TS_CMD_SWAPON:-"$TOPDIR/mount/swapon"} +TS_CMD_SWAPOFF=${TS_CMD_SWAPOFF:-"$TOPDIR/mount/swapoff"} +TS_CMD_LOSETUP=${TS_CMD_LOSETUP:-"$TOPDIR/mount/losetup"} + +TS_CMD_MKSWAP=${TS_CMD_MKSWAP:-"$TOPDIR/disk-utils/mkswap"} TS_CMD_IPCS=${TS_CMD_IPCS:-"$TOPDIR/sys-utils/ipcs"} diff --git a/tests/expected/ts-mkswap-doit b/tests/expected/ts-mkswap-doit new file mode 100644 index 00000000..fa52f3d0 --- /dev/null +++ b/tests/expected/ts-mkswap-doit @@ -0,0 +1,2 @@ +Setting up swapspace version 1, size = 20967 kB +LABEL=testSwap, no uuid diff --git a/tests/ts-mkswap-doit b/tests/ts-mkswap-doit new file mode 100755 index 00000000..6e19b46d --- /dev/null +++ b/tests/ts-mkswap-doit @@ -0,0 +1,90 @@ +#!/bin/bash + +# +# Copyright (C) 2007 Karel Zak +# +# This file is part of util-linux-ng. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License. +# +# This file is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# + +# Test swap device initialization and usage + +. commands.sh +. functions.sh + +TS_COMPONENT="mkswap" +TS_DESC="doit" + +ts_init + +if [ $UID != 0 ]; then + ts_skip "not root permissions" +fi + +set -o pipefail + + +touch $TS_OUTPUT + +IMAGE="$TS_OUTDIR/loop-swap.img" +IMAGE_RE=$( echo $IMAGE | sed 's:/:\\/:g' ) +LABEL="testSwap" + +dd if=/dev/zero of=$IMAGE bs=1M count=20 &> /dev/null + +DEVICE=$( $TS_CMD_LOSETUP -f ) +$TS_CMD_LOSETUP $DEVICE $IMAGE 2>&1 >> $TS_OUTPUT + +# XXX: atomic version: depends on "losetup -a" +## create the device +#$TS_CMD_LOSETUP -f $IMAGE 2>&1 >> $TS_OUTPUT +# +## get the device name +#DEVICE=$( $TS_CMD_LOSETUP -a | gawk 'BEGIN {FS=":"} /'$IMAGE_RE'/ { print $1 }' ) + +# make the swap +$TS_CMD_MKSWAP -L $LABEL $DEVICE 2>&1 >> $TS_OUTPUT + +# check it +blkid -c /dev/null -w /dev/null -s TYPE $DEVICE 2>&1 | grep -q 'TYPE="swap"' 2>&1 >> $TS_OUTPUT + +if [ "$?" != "0" ]; then + echo "Cannot found Linux swap on $DEVICE" >> $TS_OUTPUT + #$TS_CMD_LOSETUP -d $DEVICE 2>&1 >> $TS_OUTPUT + ts_finalize +fi + +# try connect it to system (and found the device by label) +$TS_CMD_SWAPON -L $LABEL 2>&1 >> $TS_OUTPUT + +# check it +grep -q $DEVICE /proc/swaps + +if [ "$?" != "0" ]; then + echo "Cannot found $DEVICE in /proc/swaps" >> $TS_OUTPUT + $TS_CMD_LOSETUP -d $DEVICE 2>&1 >> $TS_OUTPUT + ts_finalize +fi + +# swapoff doesn't exist in build tree +if [ ! -x "$TS_CMD_SWAPOFF" ]; then + ln -sf $TS_CMD_SWAPON $TS_CMD_SWAPOFF + REMSWAPOFF="true" +fi +$TS_CMD_SWAPOFF $DEVICE 2>&1 >> $TS_OUTPUT +$TS_CMD_LOSETUP -d $DEVICE 2>&1 >> $TS_OUTPUT + +if [ -n "$REMSWAPOFF" ]; then + rm -f $TS_CMD_SWAPOFF +fi + +ts_finalize + -- 2.39.5