]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/contrib/openzfs/tests/zfs-tests/tests/functional/arc/dbufstats_001_pos.ksh
Update OpenZFS to 2.0.0-rc3-gfc5966
[FreeBSD/FreeBSD.git] / sys / contrib / openzfs / tests / zfs-tests / tests / functional / arc / dbufstats_001_pos.ksh
1 #!/bin/ksh -p
2 #
3 # CDDL HEADER START
4 #
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
8 #
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
13 #
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
19 #
20 # CDDL HEADER END
21 #
22
23 #
24 # Copyright (c) 2017, Lawrence Livermore National Security, LLC.
25 #
26
27 . $STF_SUITE/include/libtest.shlib
28 . $STF_SUITE/include/math.shlib
29
30 #
31 # DESCRIPTION:
32 # Ensure stats presented in /proc/spl/kstat/zfs/dbufstats are correct
33 # based on /proc/spl/kstat/zfs/dbufs.
34 #
35 # STRATEGY:
36 # 1. Generate a file with random data in it
37 # 2. Store output from dbufs kstat
38 # 3. Store output from dbufstats kstat
39 # 4. Compare stats presented in dbufstats with stat generated using
40 #    dbufstat and the dbufs kstat output
41 #
42
43 DBUFSTATS_FILE=$(mktemp $TEST_BASE_DIR/dbufstats.out.XXXXXX)
44 DBUFS_FILE=$(mktemp $TEST_BASE_DIR/dbufs.out.XXXXXX)
45
46 function cleanup
47 {
48         log_must rm -f $TESTDIR/file $DBUFS_FILE $DBUFSTATS_FILE
49 }
50
51 function testdbufstat # stat_name dbufstat_filter
52 {
53         name=$1
54         filter=""
55
56         [[ -n "$2" ]] && filter="-F $2"
57
58         if is_linux; then
59                 from_dbufstat=$(grep -w "$name" "$DBUFSTATS_FILE" |
60                     awk '{ print $3 }')
61         else
62                 from_dbufstat=$(awk "/dbufstats\.$name:/ { print \$2 }" \
63                     "$DBUFSTATS_FILE")
64         fi
65         from_dbufs=$(dbufstat -bxn -i "$DBUFS_FILE" "$filter" | wc -l)
66
67         within_tolerance $from_dbufstat $from_dbufs 15 \
68             || log_fail "Stat $name exceeded tolerance"
69 }
70
71 verify_runnable "both"
72
73 log_assert "dbufstats produces correct statistics"
74
75 log_onexit cleanup
76
77 log_must file_write -o create -f "$TESTDIR/file" -b 1048576 -c 20 -d R
78 log_must zpool sync
79
80 log_must eval "kstat dbufs > $DBUFS_FILE"
81 log_must eval "kstat dbufstats '' > $DBUFSTATS_FILE"
82
83 for level in {0..11}; do
84         testdbufstat "cache_level_$level" "dbc=1,level=$level"
85 done
86
87 testdbufstat "cache_count" "dbc=1"
88 testdbufstat "hash_elements" ""
89
90 log_pass "dbufstats produces correct statistics passed"