PageRenderTime 35ms CodeModel.GetById 8ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/sys/cddl/zfs/tests/link_count/link_count_001.ksh

https://bitbucket.org/freebsd/freebsd-base
Korn Shell | 102 lines | 33 code | 15 blank | 54 comment | 7 complexity | 956019582f3cde12d244de023b0ebe2f MD5 | raw file
  1. #!/usr/local/bin/ksh93 -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. # $FreeBSD$
  23. #
  24. # Copyright 2007 Sun Microsystems, Inc. All rights reserved.
  25. # Use is subject to license terms.
  26. #
  27. # ident "@(#)link_count_001.ksh 1.2 07/01/09 SMI"
  28. #
  29. . $STF_SUITE/include/libtest.kshlib
  30. ################################################################################
  31. #
  32. # __stc_assertion_start
  33. #
  34. # ID: link_count_001
  35. #
  36. # DESCRIPTION:
  37. # Verify file link count is zero on zfs
  38. #
  39. # STRATEGY:
  40. # 1. Make sure this test executes on multi-processes system
  41. # 2. Make zero size files and remove them in the background
  42. # 3. Call the binary
  43. # 4. Make sure the files can be removed successfully
  44. #
  45. # TESTABILITY: explicit
  46. #
  47. # TEST_AUTOMATION_LEVEL: automated
  48. #
  49. # CODING_STATUS: COMPLETED (2006-07-13)
  50. #
  51. # __stc_assertion_end
  52. #
  53. ################################################################################
  54. verify_runnable "both"
  55. log_assert "Verify file link count is zero on zfs"
  56. # Detect and make sure this test must be executed on a multi-process system
  57. NCPUS=`sysctl -n kern.smp.cpus`
  58. #NCPUS=`sysctl -a | awk -F '"' '/cpu count="[0-9+]"/ {print $2; exit}'`
  59. if [[ $? -ne 0 || -z "$NCPUS" || "$NCPUS" -le 1 ]]; then
  60. log_unsupported "This test must be executed on a multi-processor system."
  61. fi
  62. log_must $MKDIR -p ${TESTDIR}/tmp
  63. typeset -i i=0
  64. while [ $i -lt $NUMFILES ]; do
  65. (( i = i + 1 ))
  66. $TOUCH ${TESTDIR}/tmp/x$i > /dev/null 2>&1
  67. done
  68. sleep 3
  69. $RM -f ${TESTDIR}/tmp/x* >/dev/null 2>&1
  70. $RM_LNKCNT_ZERO_FILE ${TESTDIR}/tmp/test${TESTCASE_ID} > /dev/null 2>&1 &
  71. PID=$!
  72. log_note "$RM_LNKCNT_ZERO_FILE ${TESTDIR}/tmp/test${TESTCASE_ID} pid: $PID"
  73. i=0
  74. while [ $i -lt $ITERS ]; do
  75. if ! $PGREP $RM_LNKCNT_ZERO_FILE > /dev/null ; then
  76. log_note "$RM_LNKCNT_ZERO_FILE completes"
  77. break
  78. fi
  79. log_must $SLEEP 10
  80. (( i = i + 1 ))
  81. done
  82. if $PGREP $RM_LNKCNT_ZERO_FILE > /dev/null; then
  83. log_must $KILL -9 $PID
  84. log_fail "file link count is zero"
  85. fi
  86. log_must $RM -f ${TESTDIR}/tmp/test${TESTCASE_ID}*
  87. log_pass "Verify file link count is zero on zfs"