lib/: spdx license conversion
[xfstests-dev.git] / tests / generic / 472
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 Oracle.  All Rights Reserved.
4 #
5 # FS QA Test No. 472
6 #
7 # Test various swapfile activation oddities.
8 #
9 seq=`basename $0`
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
12
13 here=`pwd`
14 tmp=/tmp/$$
15 status=1        # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
17
18 _cleanup()
19 {
20         cd /
21         swapoff $swapfile 2> /dev/null
22         rm -f $tmp.*
23 }
24
25 # get standard environment, filters and checks
26 . ./common/rc
27 . ./common/filter
28
29 # remove previous $seqres.full before test
30 rm -f $seqres.full
31
32 # real QA test starts here
33 _supported_fs generic
34 _supported_os Linux
35 _require_scratch_swapfile
36 _require_test_program mkswap
37 _require_test_program swapon
38
39 rm -f $seqres.full
40 _scratch_mkfs >>$seqres.full 2>&1
41 _scratch_mount >>$seqres.full 2>&1
42
43 swapfile=$SCRATCH_MNT/swap
44 len=$((2 * 1048576))
45 page_size=$(get_page_size)
46
47 swapfile_cycle() {
48         local swapfile="$1"
49
50         # Swap files must be nocow on Btrfs.
51         $CHATTR_PROG +C $swapfile >> $seqres.full 2>&1
52         "$here/src/mkswap" $swapfile >> $seqres.full
53         "$here/src/swapon" $swapfile 2>&1 | _filter_scratch
54         swapoff $swapfile 2>> $seeqres.full
55         rm -f $swapfile
56 }
57
58 # Create a regular swap file
59 echo "regular swap" | tee -a $seqres.full
60 _pwrite_byte 0x58 0 $len $swapfile >> $seqres.full
61 swapfile_cycle $swapfile
62
63 # Create a swap file with a little too much junk on the end
64 echo "too long swap" | tee -a $seqres.full
65 _pwrite_byte 0x58 0 $((len + 3)) $swapfile >> $seqres.full
66 swapfile_cycle $swapfile
67
68 # Create a ridiculously small swap file.  Each swap file must have at least
69 # two pages after the header page.
70 echo "tiny swap" | tee -a $seqres.full
71 tiny_len=$((page_size * 3))
72 _pwrite_byte 0x58 0 $tiny_len $swapfile >> $seqres.full
73 swapfile_cycle $swapfile
74
75 status=0
76 exit