misc: move exit status into trap handler
[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 _require_scratch_swapfile
35 _require_test_program mkswap
36 _require_test_program swapon
37
38 rm -f $seqres.full
39 _scratch_mkfs >>$seqres.full 2>&1
40 _scratch_mount >>$seqres.full 2>&1
41
42 swapfile=$SCRATCH_MNT/swap
43 len=$((2 * 1048576))
44
45 swapfile_cycle() {
46         local swapfile="$1"
47         local len="$2"
48
49         touch $swapfile
50         # Swap files must be nocow on Btrfs.
51         $CHATTR_PROG +C $swapfile >> $seqres.full 2>&1
52         _pwrite_byte 0x58 0 $len $swapfile >> $seqres.full
53         "$here/src/mkswap" $swapfile >> $seqres.full
54         "$here/src/swapon" $swapfile 2>&1 | _filter_scratch
55         swapoff $swapfile 2>> $seqres.full
56         rm -f $swapfile
57 }
58
59 # Create a regular swap file
60 echo "regular swap" | tee -a $seqres.full
61 swapfile_cycle $swapfile $len
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 swapfile_cycle $swapfile $((len + 3))
66
67 # Create a ridiculously small swap file.  Each swap file must have at least
68 # two pages after the header page.
69 echo "tiny swap" | tee -a $seqres.full
70 swapfile_cycle $swapfile $(($(get_page_size) * 3))
71
72 status=0
73 exit