/tests/zfs-tests/tests/functional/arc/dbufstats_001_pos.ksh

https://github.com/adilger/zfs · Korn Shell · 84 lines · 31 code · 17 blank · 36 comment · 3 complexity · 9d332f4d705fc7bfa3a26aefa6a31484 MD5 · raw file

  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. # Copyright (c) 2017, Lawrence Livermore National Security, LLC.
  24. #
  25. . $STF_SUITE/include/libtest.shlib
  26. . $STF_SUITE/include/math.shlib
  27. #
  28. # DESCRIPTION:
  29. # Ensure stats presented in /proc/spl/kstat/zfs/dbufstats are correct
  30. # based on /proc/spl/kstat/zfs/dbufs.
  31. #
  32. # STRATEGY:
  33. # 1. Generate a file with random data in it
  34. # 2. Store output from dbufs kstat
  35. # 3. Store output from dbufstats kstat
  36. # 4. Compare stats presented in dbufstats with stat generated using
  37. # dbufstat and the dbufs kstat output
  38. #
  39. DBUFSTATS_FILE=$(mktemp $TEST_BASE_DIR/dbufstats.out.XXXXXX)
  40. DBUFS_FILE=$(mktemp $TEST_BASE_DIR/dbufs.out.XXXXXX)
  41. function cleanup
  42. {
  43. log_must rm -f $TESTDIR/file $DBUFS_FILE $DBUFSTATS_FILE
  44. }
  45. function testdbufstat # stat_name dbufstat_filter
  46. {
  47. name=$1
  48. filter=""
  49. [[ -n "$2" ]] && filter="-F $2"
  50. from_dbufstat=$(grep -w "$name" "$DBUFSTATS_FILE" | awk '{ print $3 }')
  51. from_dbufs=$(dbufstat -bxn -i "$DBUFS_FILE" "$filter" | wc -l)
  52. within_tolerance $from_dbufstat $from_dbufs 15 \
  53. || log_fail "Stat $name exceeded tolerance"
  54. }
  55. verify_runnable "both"
  56. log_assert "dbufstats produces correct statistics"
  57. log_onexit cleanup
  58. log_must file_write -o create -f "$TESTDIR/file" -b 1048576 -c 20 -d R
  59. log_must zpool sync
  60. log_must eval "cat /proc/spl/kstat/zfs/dbufs > $DBUFS_FILE"
  61. log_must eval "cat /proc/spl/kstat/zfs/dbufstats > $DBUFSTATS_FILE"
  62. for level in {0..11}; do
  63. testdbufstat "cache_level_$level" "dbc=1,level=$level"
  64. done
  65. testdbufstat "cache_count" "dbc=1"
  66. testdbufstat "hash_elements" ""
  67. log_pass "dbufstats produces correct statistics passed"