2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 Oracle. All Rights Reserved.
7 # Test various swapfile activation oddities.
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
15 status=1 # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
21 swapoff $swapfile 2> /dev/null
25 # get standard environment, filters and checks
29 # remove previous $seqres.full before test
32 # real QA test starts here
34 _require_scratch_swapfile
35 _require_test_program mkswap
36 _require_test_program swapon
39 _scratch_mkfs >>$seqres.full 2>&1
40 _scratch_mount >>$seqres.full 2>&1
42 swapfile=$SCRATCH_MNT/swap
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
59 # Create a regular swap file
60 echo "regular swap" | tee -a $seqres.full
61 swapfile_cycle $swapfile $len
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))
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))