7290 ZFS test suite needs to control what utilities it can run
[unleashed.git] / usr / src / test / zfs-tests / tests / functional / nopwrite / nopwrite.shlib
blob1c0f0517db551303a2aba7e209fd44e0c0abc1d7
2 # This file and its contents are supplied under the terms of the
3 # Common Development and Distribution License ("CDDL"), version 1.0.
4 # You may only use this file in accordance with the terms of version
5 # 1.0 of the CDDL.
7 # A full copy of the text of the CDDL should have accompanied this
8 # source.  A copy of the CDDL is also available via the Internet at
9 # http://www.illumos.org/license/CDDL.
13 # Copyright (c) 2012, 2016 by Delphix. All rights reserved.
16 . $STF_SUITE/include/math.shlib
18 export TESTVOL="testvol.nopwrite"
19 export VOLSIZE="256M"
20 export MEGS="64"
22 function verify_nopwrite
24         typeset origin=$1
25         typeset snap=$2
26         typeset clone=$3
27         typeset low=1
28         typeset high=99
30         sync
31         for i in origin snap clone; do
32                 for j in used refer usedbychildren written; do
33                         typeset ${i}_$j=$(get_prop $j $(eval echo \$$i))
34                 done
35         done
37         #
38         # If we are dealing with a volume, deduct the refreserv from the used
39         # value to prevent real failures from being masked by the unexpected
40         # extra space. Also, volumes use more space for metadata, so adjust the
41         # percentages to be more forgiving.
42         #
43         if [[ "$(get_prop type $origin)" = "volume" ]]; then
44                 typeset rr=$(get_prop refreserv $origin)
45                 ((origin_used -= rr ))
46                 low=2
47                 high=98
48         fi
50         # These values should differ greatly with nopwrite.
51         within_percent $origin_used $clone_used $low && return 1
52         within_percent $origin_refer $origin_usedbychildren $low && return 1
53         within_percent $snap_written $clone_written $low && return 1
55         # These values should be nearly the same with nopwrite.
56         within_percent $origin_used $clone_refer $high || return 1
57         within_percent $origin_used $snap_refer $high || return 1
59         #
60         # The comparisons below should pass regardless of nopwrite. They're
61         # here for sanity.
62         #
63         typeset deadlist=$(zdb -Pddd $clone | awk '/Deadlist:/ {print $2}')
64         within_percent $deadlist $clone_written $high || return 1
65         within_percent $snap_refer $snap_written $high || return 1
67         return 0