1 #! /usr/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 2009 Sun Microsystems, Inc.  All rights reserved.
  25 # Use is subject to license terms.
  26 #
  27 
  28 ################################################################################
  29 #
  30 # __stc_assertion_start
  31 #
  32 # ID: dir_pos001
  33 #
  34 # DESCRIPTION:
  35 #   looply create a large amount of dirs with small files, verify all dirs
  36 #   are created successfully.
  37 #
  38 # STRATEGY:
  39 #   - Create 30 subdirs within test directory.
  40 #   - Recursively create subdirs under each dir. The diretory depth is 30
  41 #     and each dir includes 10 files.
  42 #   - Verify all operations are successful.
  43 #
  44 # TESTABILITY: explicit
  45 #
  46 # TEST_AUTOMATION_LEVEL: automated
  47 #
  48 # __stc_assertion_end
  49 #
  50 ################################################################################
  51 
  52 . ${STF_SUITE}/include/nfsgen.kshlib
  53 
  54 readonly FILE=$(whence -p ${0})
  55 readonly NAME=$(basename $0)
  56 readonly DIR=$(dirname $0)
  57 
  58 export _NFS_STF_DEBUG=$_NFS_STF_DEBUG:$NFSGEN_DEBUG
  59 [[ :$NFSGEN_DEBUG: = *:${NAME}:* \
  60         || :${NFSGEN_DEBUG}: = *:all:* ]] && set -x
  61 
  62 # Extract and print assertion information from this source script to journal
  63 extract_assertion_info $FILE
  64 
  65 function assert_cleanup {
  66         [[ :$NFSGEN_DEBUG: = *:${NAME}:* \
  67                 || :${NFSGEN_DEBUG}: = *:all:* ]] && set -x
  68 
  69         for pid in $pids; do
  70                 ps -p $pid > /dev/null && kill -KILL $pid
  71         done
  72 
  73         rm -rf $testdir
  74         cleanup $1
  75 }
  76 
  77 # Create 30 subdirs in parallel, then recursively create subdir whithin each dir 
  78 # Each dir includes 10 files, and the directory depth is 30.
  79 testdir=${MNTDIR}/${NAME}.`hostname`.$$
  80 num=0
  81 pids=""
  82 while (($num < 30)); do
  83         curdir=$testdir/sub$num
  84         # create dirs and files in parallel
  85         (
  86                 level=0
  87                 while (($level < 30)); do
  88                         RUN_CHECK mkdir -p $curdir && \
  89                                 RUN_CHECK create_small_files $curdir 10 && \
  90                                 touch $STF_TMPDIR/mkdir.$NAME.$num.$level.$$
  91                         curdir=$curdir/$level
  92                         level=$((level + 1))
  93                 done
  94         ) &
  95         pids="$pids $!"
  96         num=$((num + 1))
  97 done
  98 
  99 sleep 60
 100 condition="(( \`ls $STF_TMPDIR/mkdir.$NAME.*.\$\$ \
 101         | wc -l | nawk '{print \$1}'\` == 900 ))"
 102 wait_now 1800 "$condition"
 103 if (( $? != 0 )); then
 104         nnum=$(ls $STF_TMPDIR/mkdir.$NAME.*.$$ \
 105                 | wc -l | nawk '{print $1}')
 106         echo "ERROR: Only $nnum directories are created sucessfully, \c"
 107         echo "but expected 900 directories"
 108         assert_cleanup $STF_FAIL
 109 fi
 110 
 111 assert_cleanup $STF_PASS
 112