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: truncate_pos001
33 #
34 # DESCRIPTION:
35 # Verify file truncatation within nfs
36 #
37 # STRATEGY:
38 # Concurrently perform mulitiple file truncatation with different file size,
39 # block size, offset.
40 # 1. Open a file
41 # 2. Write random blocks in random places, and read them back
42 # 3. Truncate the file
43 # 4. Repeat above two steps
44 # 5. Close the file.
45 #
46 #
47 # TESTABILITY: explicit
48 #
49 # TEST_AUTOMATION_LEVEL: automated
50 #
51 # __stc_assertion_end
52 #
53 ################################################################################
54
55 . ${STF_SUITE}/include/nfsgen.kshlib
56
57 readonly FILE=$(whence -p ${0})
58 readonly NAME=$(basename $0)
59 readonly DIR=$(dirname $0)
60
61 export _NFS_STF_DEBUG=$_NFS_STF_DEBUG:$NFSGEN_DEBUG
62 [[ :$NFSGEN_DEBUG: = *:${NAME}:* \
63 || :${NFSGEN_DEBUG}: = *:all:* ]] && set -x
64
65 # Extract and print assertion information from this source script to journal
66 extract_assertion_info $FILE
67
68 function assert_cleanup {
69 [[ :$NFSGEN_DEBUG: = *:${NAME}:* \
70 || :${NFSGEN_DEBUG}: = *:all:* ]] && set -x
71
72 for pid in $pids; do
73 ps -p $pid > /dev/null && kill -KILL $pid
74 done
75 rm -rf $trunc_dir
76 cleanup $1
77 }
78
79 a_fsize="64 268435456 2147483648" # 256M,2G
80 a_blksize="64 256 1024"
81 a_count="10 100 1000"
82 a_offset="0 1024 268435456"
83
84 trunc_dir=${MNTDIR}/${NAME}.`hostname`.$$
85 RUN_CHECK mkdir -p $trunc_dir || exit $STF_UNINITIATED
86 num=0
87 pids=""
88 echo ""
89 for fsize in $a_fsize; do
90 for blksize in $a_blksize; do
91 for count in $a_count; do
92 for offset in $a_offset; do
93 file_operator -W -c -o 6 -B "$blksize 1 -1" -t $fsize -l $count \
94 $trunc_dir/trunc_$num > $STF_TMPDIR/mv.$NAME.$num.$$ 2>&1 &
95 pids="$pids $!"
96 ((num = num + 1))
97 done
98 done
99 done
100 done
101 echo ""
102
103 condition="(( \`cat $STF_TMPDIR/mv.$NAME.*.\$\$ | grep \"completed successfully\" \
104 | wc -l | nawk '{print \$1}'\` == $num ))"
105 wait_now 1800 "$condition"
106 if (( $? != 0 )); then
107 nnum=$(cat $STF_TMPDIR/mv.$NAME.*.$$ | grep "completed successfully" \
108 | wc -l | nawk '{print $1}')
109 echo "ERROR: Only $nnum files are truncated sucessfully, \c"
110 echo "but expected $num files trucated"
111 typeset -i i=0
112 while ((i < num)); do
113 cat $STF_TMPDIR/mv.$NAME.$i.$$ | grep "completed successfully" > /dev/null 2>&1
114 if (($? != 0 )); then
115 echo "Failures found in $STF_TMPDIR/mv.$NAME.$i.$$ :"
116 cat $STF_TMPDIR/mv.$NAME.$i.$$
117 fi
118 done
119 assert_cleanup $STF_FAIL
120 fi
121
122 assert_cleanup $STF_PASS
123