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: mv_pos001
  33 #
  34 # DESCRIPTION:
  35 #   move a large amount of files between dirs with same policy
  36 #
  37 # STRATEGY:
  38 #   - Create a directory including 1000 small files and 5 large files
  39 #   - Move all files in this directory to another directory
  40 #   - Verify all files are moved sucessfully.
  41 #
  42 # TESTABILITY: explicit
  43 #
  44 # TEST_AUTOMATION_LEVEL: automated
  45 #
  46 # __stc_assertion_end
  47 #
  48 ################################################################################
  49 
  50 . ${STF_SUITE}/include/nfsgen.kshlib
  51 
  52 readonly FILE=$(whence -p ${0})
  53 readonly NAME=$(basename $0)
  54 readonly DIR=$(dirname $0)
  55 
  56 export _NFS_STF_DEBUG=$_NFS_STF_DEBUG:$NFSGEN_DEBUG
  57 [[ :$NFSGEN_DEBUG: = *:${NAME}:* \
  58         || :${NFSGEN_DEBUG}: = *:all:* ]] && set -x
  59 
  60 # Extract and print assertion information from this source script to journal
  61 extract_assertion_info $FILE
  62 
  63 srcdir=${MNTDIR}/${NAME}_src.`hostname`.$$
  64 dstdir=${MNTDIR}/${NAME}_dst.`hostname`.$$
  65 
  66 function assert_cleanup {
  67         [[ :$NFSGEN_DEBUG: = *:${NAME}:* \
  68                 || :${NFSGEN_DEBUG}: = *:all:* ]] && set -x
  69 
  70         for pid in $pids; do
  71                 ps -p $pid > /dev/null && kill -KILL $pid
  72         done
  73         rm -rf $srcdir $dstdir
  74         cleanup $1
  75 }
  76 
  77 # move all files in one directory to another directory
  78 function mv_files
  79 {
  80         [[ :$NFSGEN_DEBUG: = *:${NAME}:* \
  81                 || :${NFSGEN_DEBUG}: = *:all:* ]] && set -x
  82 
  83         src=$1
  84         dst=$2
  85 
  86         files=`find $1  -type f -print`
  87         num=0
  88         pids=""
  89         for file in $files; do
  90                 mv $file $dst 2>$STF_TMPDIR/mv.$NAME.$num.$$ \
  91                         && echo "PASS" > $STF_TMPDIR/mv.$NAME.$num.$$ &
  92                 pids="$pids $!"
  93                 ((num = num + 1))
  94         done
  95 
  96         condition="(( \`cat $STF_TMPDIR/mv.$NAME.*.\$\$ | grep PASS \
  97                 | wc -l | nawk '{print \$1}'\` == $num ))"
  98         wait_now 600 "$condition"
  99         if (( $? != 0 )); then
 100                 nnum=$(cat $STF_TMPDIR/mv.$NAME.*.$$ | grep PASS \
 101                         | wc -l | nawk '{print $1}')
 102                 echo "ERROR: Only $nnum files are moved into $dst \c"
 103                 echo "successfully, but expected $num files"
 104                 cat $STF_TMPDIR/mv.$NAME.*.$$
 105                 return 1
 106         fi
 107 
 108         # we also check the number of the files
 109         count_files $dst $num || return 1
 110         count_files $src 0 || return 1
 111         return 0
 112 }
 113 
 114 # Create a large amount of files in source directory.
 115 num=1000
 116 RUN_CHECK mkdir -p $srcdir $dstdir || exit $STF_UNINITIATED
 117 RUN_CHECK create_small_files $srcdir $num || exit $STF_UNINITIATED
 118 # Also create five large files in the directory.
 119 RUN_CHECK mkfile 30m $srcdir/file_30m || exit $STF_UNINITIATED
 120 RUN_CHECK mkfile 500m $srcdir/file_500m || exit $STF_UNINITIATED
 121 #RUN_CHECK mkfile 1g $srcdir/file_1g || exit $STF_UNINITIATED
 122 #RUN_CHECK mkfile 2g $srcdir/file_2g || exit $STF_UNINITIATED
 123 #RUN_CHECK mkfile 3g $srcdir/file_3g || exit $STF_UNINITIATED
 124 
 125 # move all files into target directory
 126 RUN_CHECK mv_files $srcdir $dstdir && assert_cleanup $STF_PASS \
 127         || assert_cleanup $STF_FAIL