]> git.ipfire.org Git - thirdparty/util-linux.git/blob - tests/ts/swapon/fixsig
tests: fix grep expressions for devices
[thirdparty/util-linux.git] / tests / ts / swapon / fixsig
1 #!/bin/bash
2
3 TS_TOPDIR="${0%/*}/../.."
4 TS_DESC="fix signature"
5
6 . $TS_TOPDIR/functions.sh
7 ts_init "$*"
8
9 ts_check_test_command "$TS_CMD_MKSWAP"
10 ts_check_test_command "$TS_CMD_SWAPON"
11 ts_check_test_command "$TS_CMD_SWAPOFF"
12 ts_check_test_command "$TS_HELPER_SYSINFO"
13
14 ts_skip_nonroot
15 ts_check_losetup
16
17 PAGESIZE=$($TS_HELPER_SYSINFO pagesize)
18
19 #
20 # Create a swap-area
21 #
22 ts_device_init
23 DEVICE=$TS_LODEV
24
25 $TS_CMD_MKSWAP $DEVICE > /dev/null 2>> $TS_OUTPUT \
26 || ts_die "Cannot make swap $DEVICE"
27
28 ts_device_has "TYPE" "swap" $DEVICE || ts_die "Cannot find swap on $DEVICE"
29
30 #
31 # Rewrite signature to swsuspend
32 #
33 echo "S2SUSPEND " > $TS_OUTPUT.signature
34 dd if=$TS_OUTPUT.signature of=$DEVICE \
35 seek=$(( $PAGESIZE - 10 )) count=10 bs=1 conv=notrunc &> /dev/null
36
37 ts_device_has "TYPE" "swsuspend" $DEVICE || ts_die "Cannot find swsuspend on $DEVICE"
38
39 #
40 # Swapon
41 #
42 $TS_CMD_SWAPON $DEVICE &> /dev/null
43
44 grep -q "^$DEVICE\b" /proc/swaps || ts_die "Cannot find $DEVICE in /proc/swaps"
45
46 $TS_CMD_SWAPOFF $DEVICE
47
48 # swapon/mkswap warns if system sets different permissions for loop devices
49 sed --in-place '/insecure permissions .*, 0660 suggested/d' $TS_OUTPUT
50
51 ts_log "Success"
52 ts_finalize
53