1 #
2 # CDDL HEADER START
3 #
4 # The contents of this file are subject to the terms of the
5 # Common Development and Distribution License (the "License").
6 # You may not use this file except in compliance with the License.
7 #
8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 # or http://www.opensolaris.org/os/licensing.
10 # See the License for the specific language governing permissions
11 # and limitations under the License.
12 #
13 # When distributing Covered Code, include this CDDL HEADER in each
14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 # If applicable, add the following below this CDDL HEADER, with the
16 # fields enclosed by brackets "[]" replaced with your own identifying
17 # information: Portions Copyright [yyyy] [name of copyright owner]
18 #
19 # CDDL HEADER END
20 #
21
22 #
23 # Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 # Use is subject to license terms.
25 #
26 # ident "@(#)tp_add_static_001.ksh 1.2 08/12/19 SMI"
27 #
28
29 LOGFILE=${LOGDIR}/mkdir.out
30 . ${TET_SUITE_ROOT}/lofi-tests/lib/fs_common
31
32 #
33 # NAME
34 # test_cleanup
35 #
36 # SYNOPSIS
37 # test_cleanup <filename prefix> <file count> <lofi device count>
38 #
39 # DESCRIPTION
40 # Clean up the lofi devices and files created by the test purpose.
41 #
42 # RETURN VALUES
43 # 0 Cleanup was successful
44 # 1 Problems encountered during cleanup
45 #
46 function test_cleanup {
47 typeset filename_prefix="$1"
48 typeset file_count="$2"
49 typeset lofi_dev_count="$3"
50 typeset status=0
51 typeset cmd
52 typeset current_file_num=$file_count
53
54 execution_phase_cleanup
55
56 # For every file that was created...
57 while (( $current_file_num > 0 )); do
58 filename=${filename_prefix}$current_file_num
59
60 # Had we associated a lofi device with this file? If so, we
61 # need to clear the lofi device before removing the file.
62 if (( $current_file_num <= $lofi_dev_count )); then
63 del_lofi_device $filename
64 if (( $? != 0 )); then
65 status=1
66 cti_report "Could not clear lofi device" \
67 "associated with $filename and so" \
68 "cannot delete the file"
69 continue
70 fi
71 fi
72
73 # Remove the file
74 cmd="$RM $filename"
75 record_cmd_execution "$cmd"
76 cti_execute "FAIL" "$cmd"
77 if (( $? != 0 )); then
78 cti_report "Unable to delete file $filename"
79 status=1
80 fi
81 ((current_file_num = $current_file_num - 1))
82 done
83
84 return $status
85 }
86
87 #
88 # start __stc_assertion__
89 #
90 # ASSERTION: add_static_001
91 #
92 # DESCRIPTION:
93 # Up to 127 lofi devices can be created, but the 128th will fail.
94 #
95 # STRATEGY:
96 # Setup
97 # - Create 128 smallish files
98 # Assert
99 # - Associate lofi devices with the first 127 files. This
100 # should succeed.
101 # - Attempt to associate a lofi device with the 128th file.
102 # This should fail.
103 # Cleanup
104 # - Remove each file created after first having deleted the
105 # associated lofi device.
106 #
107 # end __stc_assertion__
108 #
109 function tp_add_static_001 {
110 typeset -r LOFI_MAX_DEVICES=127
111 typeset cmd lofi_add_status
112
113 typeset -r ASSERTION="add_static_001"
114 typeset -r TP_NAME=tp_${ASSERTION}
115 typeset -r ME=$(whence -p ${0})
116 extract_assertion_info $(dirname $ME)/$TP_NAME
117 typeset filename_prefix="${SCRATCH_DIR}/lofi_file_$$_$TET_TPNUMBER_"
118 typeset cmd filename
119 typeset status=0
120
121 # Initialization
122 cti_assert $ASSERTION "Create maximum number of lofi devices"
123
124 # Creating all the lofi devices is time consuming, so skip this test
125 # if the run mode is set to short.
126 if [[ -n "$RUNMODE" && "$RUNMODE" = "short" ]]; then
127 cti_untested "Assertion $ASSERTION skipped as RUNMODE is set" \
128 "to '$RUNMODE'"
129 return
130 fi
131
132 cti_pass
133 create_execution_record # Record cmds; will display on failure
134 execution_phase_setup # Record setup cmds
135
136 # Create all the files we'll need, which is one beyond LOFI_MAX_DEVICES
137 typeset file_counter=0
138 typeset file_number
139 ((files_to_create = $LOFI_MAX_DEVICES + 1))
140 while (( $file_counter < $files_to_create )); do
141 ((file_number = $file_counter + 1))
142 filename=${filename_prefix}$file_number
143 cmd="mkfile 128k $filename"
144 record_cmd_execution $cmd
145 cti_execute "FAIL" "$cmd"
146 if (( $? != 0 )); then
147 cti_report "Error: Unable to create file $filename"
148 if (( $file_counter != 0 )); then
149 test_cleanup $filename_prefix $file_counter 0
150 fi
151 display_execution_record
152 return
153 fi
154 ((file_counter = $file_counter + 1))
155 done
156
157 execution_phase_assert # Record assertion commands
158
159 # Add lofi devices up to LOFI_MAX_DEVICES. All of these should
160 # succeed.
161 typeset lofi_counter=0
162 while (( $lofi_counter < $LOFI_MAX_DEVICES )); do
163 ((file_number = $lofi_counter + 1))
164 filename=${filename_prefix}$file_number
165 cmd="add_lofi_device $filename"
166 record_cmd_execution $cmd
167 cti_execute "FAIL" "$cmd"
168 if (( $? != 0 )); then
169 cti_report "Error: Unable to associate lofi device" \
170 "with file $filename"
171 test_cleanup $filename_prefix $file_counter \
172 $lofi_counter
173 display_execution_record
174 return
175 fi
176 ((lofi_counter = $lofi_counter + 1))
177 done
178
179 # Now try to add one more lofi file beyond the limit. This should
180 # fail.
181 filename=${filename_prefix}$file_counter
182 cmd="add_lofi_device $filename"
183 record_cmd_execution $cmd
184 cti_execute "PASS" "$cmd"
185 if (( $? != 0 )); then
186 cti_report "Attempted addition of ${file_counter}th lofi" \
187 "device failed as expected"
188 else
189 cti_fail "Error: addition of ${file_counter} lofi device" \
190 "succeeded when it was expected to fail"
191 lofi_counter=$file_counter
192 display_execution_record
193 status=1
194 fi
195
196 # Clean up after ourselves.
197 test_cleanup $filename_prefix $file_counter $lofi_counter
198 if (( $? != 0 )); then
199 status=1
200 fi
201
202 if [[ -n "$VERBOSE" ]] || (( $status != 0 )); then
203 display_execution_record
204 else
205 delete_execution_record
206 fi
207 }