xref: /freebsd/tools/test/stress2/misc/sparse.sh (revision 6be3386466ab79a84b48429ae66244f21526d3df)
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
38bsdlabel -w md$mdstart auto
39newfs $newfs_flags md${mdstart}$part > /dev/null
40mount /dev/md${mdstart}$part $mntpoint
41set +e
42
43in=$mntpoint/in
44out=$mntpoint/out
45
46size=`jot -r 1 1 2048`
47size=$((size * 1024 * 1024))
48truncate -s $size $in
49
50for i in `jot $(jot -r 1 10 100)`; do
51	bs=`jot -r 1 1 4096`
52	pos=`jot -r 1 0 $((size - bs))`
53	pos=$((pos / bs)) # in blocks
54	[ $((pos + bs)) -gt $size ] && { echo "seek error"; exit 1; }
55	dd if=/dev/random of=$in seek=$pos bs=$bs count=1 conv=notrunc \
56	    status=none
57done
58[ `stat -f%z $in` -ne $size ] && { ls -l $in; exit 1; }
59
60cp $in $out
61md1=`md5 < $in`
62md2=`md5 < $out`
63[ $md1 == $md2 ] && s=0 ||
64	{ echo "md5 differs: $in: $md1, $out: $md2"; s=1
65	ls -l $in $out; }
66rm -f $in $out
67for i in `jot 6`; do
68	mount | grep -q "on $mntpoint " || break
69	umount $mntpoint && break || sleep 10
70	[ $i -eq 6 ] &&
71	    { echo FATAL; fstat -mf $mntpoint; exit 1; }
72done
73mdconfig -d -u $mdstart
74exit $s
75