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_dynamic.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 # start __stc_assertion__
  34 #
  35 # ASSERTION: add_dynamic_N (multiple dynamically generated assertions)
  36 #
  37 # DESCRIPTION:
  38 #       Users should be able to add lofi devices based on files, by specifying
  39 #       no lofi path (lofiadm will pick one), block device lofi path, or
  40 #       char device lofi path.  Invalid parameters should be caught by the
  41 #       lofiadm command.
  42 #
  43 #       Set of dynamically-generated assertions for testing various
  44 #       valid and invalid conbinations of parameters during lofi device
  45 #       creation.  Each iteration will identify the specific values of
  46 #       the parameters used.
  47 #
  48 # STRATEGY:
  49 #    Setup:
  50 #       1. Create a list of parameter combinations containing both
  51 #          positive and negative test cases (performed by tc file).
  52 #       2. For each set of parameter combinations:
  53 #               2.01 Create a file.
  54 #    Assertion:
  55 #               2.02 Add lofi device based on the file created during setup.
  56 #    Cleanup:
  57 #               2.03 Delete lofi device
  58 #               2.04 Delete file
  59 #
  60 # end __stc_assertion__
  61 #
  62 function tp_add_dynamic {
  63         typeset pos_or_neg lofi_dev_param file_name_param file_size_param
  64         typeset pos_or_neg_text
  65         typeset lofi_dev_arg add_status invalid_lofi_path cmd
  66         typeset lofi_file=${SCRATCH_DIR}/lofi_file_$$_$TET_TPNUMBER
  67         typeset status=0
  68 
  69         base_asrt_id="add_dynamic"
  70         asrt_num=$TET_TPNUMBER
  71         if (( $asrt_num < 10 )); then
  72                 asrt_num="00$asrt_num"
  73         elif (( $asrt_num < 100 )); then
  74                 asrt_num="0$asrt_num"
  75         fi
  76         asrt_id="${base_asrt_id}_${asrt_num}"
  77 
  78         # Get the line corresponding to this iteration (matching
  79         # $TET_TPNUMBER) from the dynamic config file.
  80         typeset config_line=`extract_line_from_file $dynamic_config_file $TET_TPNUMBER`
  81         if (( $? != 0 )) || [[ -z $config_line ]]; then
  82                 cti_assert $asrt_id
  83                 cti_uninitiated "Could not extract line $TET_TPNUMBER from" \
  84                     "$dynamic_config_file"
  85                 return
  86         fi
  87 
  88         # Extract the individual elements from the line that was read from
  89         # the dynamic configuration file.
  90         set $config_line
  91         pos_or_neg="$1"
  92         lofi_dev_param="$2"
  93         file_name_param="$3"
  94         file_size_param="$4"
  95         if [[ "$pos_or_neg" = "neg" ]]; then
  96                 pos_or_neg_text=" (expected to fail)"
  97         fi
  98 
  99         cti_assert $asrt_id "lofi device '$lofi_dev_param', file name '$file_name_param', file size '$file_size_param'$pos_or_neg_text"
 100 
 101         create_execution_record         # Record cmds; will display on failure
 102         execution_phase_setup           # Record setup cmds
 103 
 104         if [[ "$file_name_param" != "none" ]]; then
 105                 if [[ "$file_size_param" = "zero" ]]; then
 106                         file_size="0"
 107                 else
 108                         file_size="$DEFAULT_FILE_SIZE"
 109                 fi
 110                 make_and_verify_file $file_size $lofi_file
 111                 if (( $? != 0 )); then
 112                         # File creation failed.  Set unresolved status, display
 113                         # the commands executed up to this point, and return.
 114                         cti_unresolved
 115                         display_execution_record
 116                         return
 117                 fi
 118         fi
 119 
 120         # Create the file parameter we'll pass to 'lofiadm -a'
 121         if [[ "$file_name_param" = "full_path" ]]; then
 122                 file_name_arg="$lofi_file"
 123         elif [[ "$file_name_param" = "partial" ]]; then
 124                 file_name_arg=`echo $lofi_file | basename`
 125         fi
 126 
 127         # Create the lofi device parameter we'll pass to 'lofiadm -a'.
 128         if [[ "$lofi_dev_param" = "full_path_block" ]]; then
 129                 lofi_dev_arg="/dev/lofi/$TET_TPNUMBER"
 130         elif [[ "$lofi_dev_param" = "full_path_char" ]]; then
 131                 lofi_dev_arg="/dev/rlofi/$TET_TPNUMBER"
 132         elif [[ "$lofi_dev_param" = "partial_path" ]]; then
 133                 lofi_dev_arg="$TET_TPNUMBER"
 134         elif [[ "$lofi_dev_param" = "non_lofi_path" ]]; then
 135                 invalid_lofi_path="$SCRATCH_DIR/non_lofi_path_$$"
 136                 lofi_dev_arg="$invalid_lofi_path"
 137         fi
 138 
 139         execution_phase_assert          # Record assertion cmds
 140         lofi_dev_returned=`add_lofi_device $file_name_arg $lofi_dev_arg`
 141         add_status=$?
 142 
 143         if (( $add_status == 0)) || (( $add_status == 2 )); then
 144                 if [[ "$pos_or_neg" = "pos" ]]; then
 145                         cti_pass "Creation of lofi device succeeded as" \
 146                             "expected"
 147                 else
 148                         cti_fail "Creation of lofi device was expected to fail"
 149                         status=1
 150                 fi
 151         elif (( $add_status == 1 )); then
 152                 if [[ "$pos_or_neg" = "neg" ]]; then
 153                         cti_pass "Creation of lofi device failed as" \
 154                             "expected"
 155                 else
 156                         cti_fail "Creation of lofi device failed when it was" \
 157                             "expected to succeed"
 158                         status=1
 159                 fi
 160         fi
 161 
 162         # Clean up after ourselves.
 163         execution_phase_cleanup
 164 
 165         # Return code 0 or 2 means that 'lofiadm -a' succeeded.  If so, then
 166         # we need to delete the lofi device.
 167         if (( $add_status == 0 )) || (( $add_status == 2 )); then
 168                 del_lofi_device $lofi_file
 169                 if (( $? == 0 )); then
 170                         cti_report "Deletion of lofi device associated with" \
 171                            "$lofi_file succeeded"
 172                 else
 173                         cti_fail "Unable to delete lofi device associated" \
 174                             "with $lofi_file"
 175                         status=1
 176                 fi
 177         fi
 178 
 179         if [[ -f "$lofi_file" ]]; then
 180                 # A file was created for use during lofi addition; delete it.
 181                 cmd="$RM $lofi_file"
 182                 record_cmd_execution $cmd
 183                 cti_execute "PASS" "$cmd"
 184                 if (( $? != 0 )); then
 185                         cti_fail "Unable to remove file $lofi_file used to" \
 186                             "for lofi device.  Possible lofi is still using" \
 187                             "it."
 188                         status=1
 189                 fi
 190         fi
 191 
 192         if [[ -f "$invalid_lofi_path" ]]; then
 193                 # A file was created to test out giving an invalid path for a
 194                 # lofi device; delete it.
 195                 cmd="$RM $invalid_lofi_path"
 196                 record_cmd_execution $cmd
 197                 cti_execute "PASS" "$cmd"
 198         fi
 199 
 200         if [[ -n $VERBOSE ]] || (( $status != 0)); then
 201                 display_execution_record
 202         else
 203                 delete_execution_record
 204         fi
 205 
 206         cti_pass
 207 }