]> err.no Git - util-linux/commitdiff
mkswap: add regression test
authorKarel Zak <kzak@redhat.com>
Wed, 7 Feb 2007 12:26:11 +0000 (13:26 +0100)
committerKarel Zak <kzak@redhat.com>
Wed, 7 Feb 2007 12:26:11 +0000 (13:26 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
tests/Makefile.am
tests/commands.sh.in
tests/expected/ts-mkswap-doit [new file with mode: 0644]
tests/ts-mkswap-doit [new file with mode: 0755]

index eebb700b73723d12c618943d48036eeb4d997318..3ab18b0c09fdfbdb31ec4e6f4d4faf509e9e250a 100644 (file)
@@ -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
index 061b42b9488fd1c08ce3c460723c9c8b75b03392..866c3947cbb3a18409f6355d6d8cfe0110f91710 100644 (file)
@@ -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 (file)
index 0000000..fa52f3d
--- /dev/null
@@ -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 (executable)
index 0000000..6e19b46
--- /dev/null
@@ -0,0 +1,90 @@
+#!/bin/bash
+
+# 
+# Copyright (C) 2007 Karel Zak <kzak@redhat.com>
+# 
+# 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
+