1#!/bin/sh 2 3# 4# Copyright (c) 2024 Peter Holm <pho@FreeBSD.org> 5# 6# SPDX-License-Identifier: BSD-2-Clause 7# 8 9# A SEEK_HOLE / SEEK_DATA test scenario, variation of tmpfs24.sh 10 11# A regression test for "40c1672e886b - main - swap_pager: fix 12# seek_data with invalid first page" 13 14[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 15 16. ../default.cfg 17 18prog=$(basename "$0" .sh) 19exp=/tmp/$prog.exp 20here=`pwd` 21log=/tmp/$prog.log 22 23cc -o /tmp/lsholes -Wall -Wextra -O2 $here/../tools/lsholes.c | exit 1 24cat > $exp <<EXP 25Min hole size is 4096, file size is 524288000. 26data #1 @ 0, size=4096) 27hole #2 @ 4096, size=4096 28data #3 @ 8192, size=4096) 29hole #4 @ 12288, size=4096 30data #5 @ 16384, size=4096) 31hole #6 @ 20480, size=524267520 32EXP 33 34set -eu 35mount -t tmpfs dummy $mntpoint 36set +e 37 38file=$mntpoint/file 39copy=$mntpoint/copy 40truncate -s 500m $file 41bs=`getconf MIN_HOLE_SIZE $file` 42printf "\001" | dd of=$file seek=$((0*bs)) bs=1 count=1 conv=notrunc status=none 43printf "\002" | dd of=$file seek=$((2*bs)) bs=1 count=1 conv=notrunc status=none 44printf "\003" | dd of=$file seek=$((4*bs)) bs=1 count=1 conv=notrunc status=none 45s1=0 46s2=0 47s3=0 48/tmp/lsholes $file > $log 2>&1 || s1=1 49 50cmp -s $exp $log || { s2=2; sdiff $exp $log; } 51 52$here/../testcases/swap/swap -t 2m -i 20 -h > /dev/null & 53sleep 10 54cp $file $copy 55while pkill swap; do :; done 56wait 57cmp $file $copy || { echo "copy error"; s3=4; } 58 59umount $mntpoint 60rm -f /tmp/lsholes $exp $log 61exit $((s1 + s2 + s3)) 62