xref: /freebsd/tools/test/stress2/misc/sparse.sh (revision d4eeb02986980bf33dd56c41ceb9fc5f180c0d47)
1#!/bin/sh
2#
3# Copyright (c) 2018 Dell EMC Isilon
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:
9# 1. Redistributions of source code must retain the above copyright
10#    notice unmodified, this list of conditions and the following
11#    disclaimer.
12# 2. Redistributions in binary form must reproduce the above copyright
13#    notice, this list of conditions and the following disclaimer in the
14#    documentation and/or other materials provided with the distribution.
15#
16# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26# SUCH DAMAGE.
27#
28
29# Test sparse file read
30# No problems seen.
31
32. ../default.cfg
33
34set -e
35mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint
36[ -c /dev/md$mdstart ] &&  mdconfig -d -u $mdstart
37mdconfig -a -t swap -s 5g -u $mdstart
38newfs $newfs_flags md$mdstart > /dev/null
39mount /dev/md$mdstart $mntpoint
40set +e
41
42in=$mntpoint/in
43out=$mntpoint/out
44
45size=`jot -r 1 1 2048`
46size=$((size * 1024 * 1024))
47truncate -s $size $in
48
49for i in `jot $(jot -r 1 10 100)`; do
50	bs=`jot -r 1 1 4096`
51	pos=`jot -r 1 0 $((size - bs))`
52	pos=$((pos / bs)) # in blocks
53	[ $((pos + bs)) -gt $size ] && { echo "seek error"; exit 1; }
54	dd if=/dev/random of=$in seek=$pos bs=$bs count=1 conv=notrunc \
55	    status=none
56done
57[ `stat -f%z $in` -ne $size ] && { ls -l $in; exit 1; }
58
59cp $in $out
60md1=`md5 < $in`
61md2=`md5 < $out`
62[ $md1 == $md2 ] && s=0 ||
63	{ echo "md5 differs: $in: $md1, $out: $md2"; s=1
64	ls -l $in $out; }
65rm -f $in $out
66for i in `jot 6`; do
67	mount | grep -q "on $mntpoint " || break
68	umount $mntpoint && break || sleep 10
69	[ $i -eq 6 ] &&
70	    { echo FATAL; fstat -mf $mntpoint; exit 1; }
71done
72mdconfig -d -u $mdstart
73exit $s
74