mirror of
https://github.com/linux-apfs/apfstests.git
synced 2026-05-01 15:01:44 -07:00
92 lines
2.5 KiB
Bash
92 lines
2.5 KiB
Bash
|
|
#! /bin/bash
|
||
|
|
# FS QA Test No. 472
|
||
|
|
#
|
||
|
|
# Test various swapfile activation oddities.
|
||
|
|
#
|
||
|
|
#-----------------------------------------------------------------------
|
||
|
|
# Copyright (c) 2018 Oracle. All Rights Reserved.
|
||
|
|
#
|
||
|
|
# This program is free software; you can redistribute it and/or
|
||
|
|
# modify it under the terms of the GNU General Public License as
|
||
|
|
# published by the Free Software Foundation.
|
||
|
|
#
|
||
|
|
# This program is distributed in the hope that it would be useful,
|
||
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
|
# GNU General Public License for more details.
|
||
|
|
#
|
||
|
|
# You should have received a copy of the GNU General Public License
|
||
|
|
# along with this program; if not, write the Free Software Foundation,
|
||
|
|
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||
|
|
#
|
||
|
|
#-----------------------------------------------------------------------
|
||
|
|
|
||
|
|
seq=`basename $0`
|
||
|
|
seqres=$RESULT_DIR/$seq
|
||
|
|
echo "QA output created by $seq"
|
||
|
|
|
||
|
|
here=`pwd`
|
||
|
|
tmp=/tmp/$$
|
||
|
|
status=1 # failure is the default!
|
||
|
|
trap "_cleanup; exit \$status" 0 1 2 3 15
|
||
|
|
|
||
|
|
_cleanup()
|
||
|
|
{
|
||
|
|
cd /
|
||
|
|
swapoff $swapfile 2> /dev/null
|
||
|
|
rm -f $tmp.*
|
||
|
|
}
|
||
|
|
|
||
|
|
# get standard environment, filters and checks
|
||
|
|
. ./common/rc
|
||
|
|
. ./common/filter
|
||
|
|
|
||
|
|
# remove previous $seqres.full before test
|
||
|
|
rm -f $seqres.full
|
||
|
|
|
||
|
|
# real QA test starts here
|
||
|
|
_supported_fs generic
|
||
|
|
_supported_os Linux
|
||
|
|
_require_scratch_swapfile
|
||
|
|
_require_test_program mkswap
|
||
|
|
_require_test_program swapon
|
||
|
|
|
||
|
|
rm -f $seqres.full
|
||
|
|
_scratch_mkfs >>$seqres.full 2>&1
|
||
|
|
_scratch_mount >>$seqres.full 2>&1
|
||
|
|
|
||
|
|
swapfile=$SCRATCH_MNT/swap
|
||
|
|
len=$((2 * 1048576))
|
||
|
|
page_size=$(get_page_size)
|
||
|
|
|
||
|
|
swapfile_cycle() {
|
||
|
|
local swapfile="$1"
|
||
|
|
|
||
|
|
# Swap files must be nocow on Btrfs.
|
||
|
|
$CHATTR_PROG +C $swapfile >> $seqres.full 2>&1
|
||
|
|
"$here/src/mkswap" $swapfile >> $seqres.full
|
||
|
|
"$here/src/swapon" $swapfile 2>&1 | _filter_scratch
|
||
|
|
swapoff $swapfile 2>> $seeqres.full
|
||
|
|
rm -f $swapfile
|
||
|
|
}
|
||
|
|
|
||
|
|
# Create a regular swap file
|
||
|
|
echo "regular swap" | tee -a $seqres.full
|
||
|
|
_pwrite_byte 0x58 0 $len $swapfile >> $seqres.full
|
||
|
|
swapfile_cycle $swapfile
|
||
|
|
|
||
|
|
# Create a swap file with a little too much junk on the end
|
||
|
|
echo "too long swap" | tee -a $seqres.full
|
||
|
|
_pwrite_byte 0x58 0 $((len + 3)) $swapfile >> $seqres.full
|
||
|
|
swapfile_cycle $swapfile
|
||
|
|
|
||
|
|
# Create a ridiculously small swap file. Each swap file must have at least
|
||
|
|
# two pages after the header page.
|
||
|
|
echo "tiny swap" | tee -a $seqres.full
|
||
|
|
tiny_len=$((page_size * 3))
|
||
|
|
_pwrite_byte 0x58 0 $tiny_len $swapfile >> $seqres.full
|
||
|
|
swapfile_cycle $swapfile
|
||
|
|
|
||
|
|
status=0
|
||
|
|
exit
|