+++ /dev/null
-Setting up swapspace version 1, size = 5238 kB
-LABEL=testSwap, no uuid
function ts_skip {
echo " IGNORE ($1)"
+ if [ -n "$2" ] && [ -b "$2" ]; then
+ ts_device_deinit "$2"
+ fi
exit 0
}
TS_INPUT="$TS_INPUTDIR/$TS_NAME"
rm -f $TS_OUTPUT
+ touch $TS_OUTPUT
printf "%15s: %-25s ..." "$TS_COMPONENT" "$TS_DESC"
}
fi
}
+function ts_die {
+ echo "$1" >> $TS_OUTPUT
+ if [ -n "$2" ] && [ -b "$2" ]; then
+ ts_device_deinit "$2"
+ fi
+ ts_finalize
+}
+
function ts_device_init {
- IMAGE="$TS_OUTDIR/$TS_NAME.img"
- IMAGE_RE=$( echo "$IMAGE" | sed 's:/:\\/:g' )
+ local IMAGE="$TS_OUTDIR/$TS_NAME.img"
+ local IMAGE_RE=$( echo "$IMAGE" | sed 's:/:\\/:g' )
+ local DEV=""
dd if=/dev/zero of="$IMAGE" bs=1M count=5 &> /dev/null
$TS_CMD_LOSETUP -f "$IMAGE" 2>&1 >> $TS_OUTPUT
- DEVICE=$( $TS_CMD_LOSETUP -a | gawk 'BEGIN {FS=":"} /'$IMAGE_RE'/ { print $1 }' )
+ DEV=$( $TS_CMD_LOSETUP -a | gawk 'BEGIN {FS=":"} /'$IMAGE_RE'/ { print $1 }' )
- if [ -z "$DEVICE" ]; then
- ts_device_deinit
+ if [ -z "$DEV" ]; then
+ ts_device_deinit $DEV
return 1 # error
fi
+ echo $DEV
return 0 # succes
}
function ts_device_deinit {
- if [ -b "$DEVICE" ]; then
- $TS_CMD_UMOUNT "$DEVICE" &> /dev/null
- $TS_CMD_LOSETUP -d "$DEVICE" &> /dev/null
- rm -f "$IMAGE" &> /dev/null
+ local DEV="$1"
+
+ if [ -b "$DEV" ]; then
+ $TS_CMD_UMOUNT "$DEV" &> /dev/null
+ $TS_CMD_LOSETUP -d "$DEV" &> /dev/null
fi
}
-function ts_udev_loop_support {
+function ts_udev_dev_support {
ldd $TS_CMD_MOUNT | grep -q 'libvolume_id' 2>&1 >> $TS_OUTPUT
if [ "$?" == "0" ]; then
- HAS_VOLUMEID="yes"
+ local HAS_VOLUMEID="yes"
fi
- if [ -n "$HAS_VOLUMEID" ] && [ ! -L "/dev/disk/by-label/$1" ]; then
+ if [ -n "$HAS_VOLUMEID" ] && [ ! -L "/dev/disk/$1/$2" ]; then
return 1
fi
return 0
local TAG="$1"
local VAL="$2"
local DEV="$3"
+ local vl=""
case $TAG in
"TYPE") vl=$(ts_fstype_by_devname $DEV);;
fi
return 1
}
+
+function ts_device_has_uuid {
+ ts_uuid_by_devname "$1" | egrep -q '^[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12}$'
+ return $?
+}
+
+function ts_swapoff {
+ local DEV="$1"
+
+ # 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 $DEV 2>&1 >> $TS_OUTPUT
+ if [ -n "$REMSWAPOFF" ]; then
+ rm -f $TS_CMD_SWAPOFF
+ fi
+}
echo "create cramfs image" >> $TS_OUTPUT
$TS_CMD_MKCRAMFS -n $LABEL $IMAGE_DATA $IMAGE 2>&1 >> $TS_OUTPUT
-
-if [ ! -s "$IMAGE" ]; then
- echo "Cannot create $IMAGE" >> $TS_OUTPUT
- ts_finalize
-fi
+[ -s "$IMAGE" ] || ts_die "Cannot create $IMAGE"
echo "count MD5 from the image" >> $TS_OUTPUT
md5sum $IMAGE 2>&1 >> $TS_OUTPUT
$TS_CMD_LOSETUP $DEVICE $IMAGE 2>&1 >> $TS_OUTPUT
echo "check the image" >> $TS_OUTPUT
-if [ "$($TS_CMD_MOUNT --guess-fstype $DEVICE)" != "cramfs" ]; then
- echo "Cannot found cramfs on $DEVICE" >> $TS_OUTPUT
- ts_finalize
-fi
+ts_device_has "TYPE" "cramfs" $DEVICE
+[ "$?" == "0" ] || ts_die "Cannot found cramfs on $DEVICE" $DEVICE
-ts_udev_loop_support $LABEL
-if [ "$?" != "0" ]; then
- ts_device_deinit;
- ts_skip "udev ignores /dev/loop*"
-fi
+ts_udev_dev_support "by-label" $LABEL
+[ "$?" == "0" ] || ts_skip "udev ignores /dev/loop*" $DEVICE
echo "mount the image" >> $TS_OUTPUT
$TS_CMD_MOUNT -L $LABEL $MOUNTPOINT 2>&1 >> $TS_OUTPUT
# check it
grep -q $DEVICE /proc/mounts
-
-if [ "$?" != "0" ]; then
- echo "Cannot found $DEVICE in /proc/mounts" >> $TS_OUTPUT
-fi
+[ "$?" == "0" ] || ts_die "Cannot found $DEVICE in /proc/mounts" $DEVICE
echo "list the image" >> $TS_OUTPUT
ls -laR $MOUNTPOINT >> $TS_OUTPUT
+++ /dev/null
-#!/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
-ts_skip_nonroot
-
-set -o pipefail
-
-touch $TS_OUTPUT
-
-LABEL="testSwap"
-
-ts_device_init || ts_finalize
-$TS_CMD_MKSWAP -L $LABEL $DEVICE 2>&1 >> $TS_OUTPUT
-
-# check it
-if [ "$($TS_CMD_MOUNT --guess-fstype $DEVICE)" != "swap" ]; then
- echo "Cannot found Linux swap on $DEVICE" >> $TS_OUTPUT
- ts_device_deinit
- ts_finalize
-fi
-
-ts_udev_loop_support $LABEL
-if [ "$?" != "0" ]; then
- ts_device_deinit;
- ts_skip "udev ignores /dev/loop*"
-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_device_deinit
- 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_device_deinit
-
-if [ -n "$REMSWAPOFF" ]; then
- rm -f $TS_CMD_SWAPOFF
-fi
-
-ts_finalize
-
#
# test for mount -o remount,ro
#
-
. commands.sh
. functions.sh
ts_init
ts_skip_nonroot
-touch $TS_OUTPUT
-
# mountpoint
MOUNTPOINT="$(pwd)/$TS_OUTDIR/mnt-remount"
mkdir -p $MOUNTPOINT
-ts_device_init || ts_finalize
+DEVICE=$(ts_device_init)
+[ "$?" == 0 ] || ts_die "Cannot init device"
+
mkfs.ext2 $DEVICE &> /dev/null
+[ "$?" == "0" ] || ts_die "Cannot make ext2 on $DEVICE" $DEVICE
# mount read-write
$TS_CMD_MOUNT $DEVICE $MOUNTPOINT
+[ "$?" == "0" ] || ts_die "Cannot mount $MOUNTPOINT" $DEVICE
# check the mount
egrep -q "^$DEVICE $MOUNTPOINT" /etc/mtab
-
-if [ "$?" != "0" ]; then
- echo "Cannot found $MOUNTPOINT in /etc/mtab" >> $TS_OUTPUT
- ts_device_deinit
- ts_finalize
-fi
+[ "$?" == "0" ] || ts_die "Cannot found $MOUNTPOINT in /etc/mtab" $DEVICE
# remount
$TS_CMD_MOUNT -o remount,ro $MOUNTPOINT
+[ "$?" == "0" ] || ts_die "Cannot remount $MOUNTPOINT" $DEVICE
# check the remount
egrep -q "^$DEVICE $MOUNTPOINT ext2 ro 0 0" /etc/mtab
+[ "$?" == "0" ] || ts_die "Cannot found remounted $MOUNTPOINT in /etc/mtab" $DEVICE
-if [ "$?" != "0" ]; then
- echo "Cannot found remounted $MOUNTPOINT in /etc/mtab" >> $TS_OUTPUT
- ts_device_deinit
- ts_finalize
-fi
-
-ts_device_deinit
+ts_device_deinit $DEVICE
echo "Success" >> $TS_OUTPUT
ts_finalize
--- /dev/null
+#!/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.
+#
+
+. commands.sh
+. functions.sh
+
+TS_COMPONENT="swapon"
+TS_DESC="label"
+
+LABEL="testSwapLabel"
+
+ts_init
+ts_skip_nonroot
+
+set -o pipefail
+
+DEVICE=$(ts_device_init)
+[ "$?" == 0 ] || ts_die "Cannot init device"
+
+$TS_CMD_MKSWAP -L $LABEL $DEVICE > /dev/null 2>> $TS_OUTPUT
+[ "$?" == "0" ] || ts_die "Cannot make swap on $DEVICE" $DEVICE
+
+ts_device_has "LABEL" $LABEL $DEVICE
+[ "$?" == "0" ] || ts_die "Cannot found LABEL '$LABEL' on $DEVICE" $DEVICE
+
+ts_udev_dev_support "by-label" $LABEL
+[ "$?" == "0" ] || ts_skip "udev ignores /dev/loop*" $DEVICE
+
+$TS_CMD_SWAPON -L $LABEL 2>&1 >> $TS_OUTPUT
+
+grep -q $DEVICE /proc/swaps
+[ "$?" == "0" ] || ts_die "Cannot found $DEVICE in /proc/swaps" $DEVICE
+
+ts_swapoff $DEVICE
+ts_device_deinit $DEVICE
+
+echo "Success" >> $TS_OUTPUT
+ts_finalize
+