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
35 _require_scratch_swapfile
36 _require_test_program mkswap
37 _require_test_program swapon
40 _scratch_mkfs >>$seqres.full 2>&1
41 _scratch_mount >>$seqres.full 2>&1
43 swapfile=$SCRATCH_MNT/swap
51 # Swap files must be nocow on Btrfs.
52 $CHATTR_PROG +C $swapfile >> $seqres.full 2>&1
53 _pwrite_byte 0x58 0 $len $swapfile >> $seqres.full
54 "$here/src/mkswap" $swapfile >> $seqres.full
55 "$here/src/swapon" $swapfile 2>&1 | _filter_scratch
56 swapoff $swapfile 2>> $seqres.full
60 # Create a regular swap file
61 echo "regular swap" | tee -a $seqres.full
62 swapfile_cycle $swapfile $len
64 # Create a swap file with a little too much junk on the end
65 echo "too long swap" | tee -a $seqres.full
66 swapfile_cycle $swapfile $((len + 3))
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 swapfile_cycle $swapfile $(($(get_page_size) * 3))