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_fs_dynamic.ksh  1.2     08/12/19 SMI"
  27 #
  28 
  29 . ${TET_SUITE_ROOT}/lofi-tests/lib/fs_common
  30 . ${TET_SUITE_ROOT}/lofi-tests/lib/util_common
  31 
  32 
  33 #
  34 # start __stc_assertion__
  35 #
  36 # ASSERTION: fs_dynamic
  37 #
  38 # DESCRIPTION:
  39 #       This test purpose dynamically generates a set of test cases that
  40 #       tests combinations of valid lofi file sizes and filesystem types.
  41 #       Each test case is an iteration that identifies a specific set of
  42 #       parameters.
  43 #
  44 # STRATEGY:
  45 #    Setup:
  46 #       1. Create a list of parameter combinations (performed by tc file).
  47 #    Assertion
  48 #       2. For each set of parameter combinations:
  49 #               2.01 Create a file.
  50 #               2.02 Create and populate filesystem on file (method depends on
  51 #                    type of FS being created).
  52 #               2.03 Disassociate lofi device from file.
  53 #               2.04 Associate decompressed file with lofi device.
  54 #               2.05 Mount filesystem with default options
  55 #               2.06 Verify contents of FS on file.
  56 #               2.07 Unmount FS.
  57 #               2.08 Disassociate lofi device from file.
  58 #    Cleanup:
  59 #               2.09 Remove file
  60 #       
  61 # end __stc_assertion__
  62 #
  63 function tp_fs_dynamic {
  64 
  65         cti_pass
  66 
  67         # Extract and print assertion information for the test
  68         typeset -r ASSERTION="fs_dynamic"
  69         typeset -r TP_NAME=tp_${ASSERTION}
  70         typeset -r ME=$(whence -p ${0})
  71 
  72         typeset status=0
  73 
  74         # ic_num is the number of test purposes that are not dynamic.
  75         # this may change if other test purposes are added.
  76         let counter=$TET_TPNUMBER
  77         typeset -r ITERATION=${ASSERTION}_$counter
  78 
  79         # Rather than reusing the same lofi dev number over and over, we'll
  80         # use a different one each time (based on our counter).  As there's
  81         # a limit to lofi dev numbers, we'll wrap around to lower numbers
  82         # if the counter exceeds LOFI_DEV_NUM_LIMIT.
  83         lofi_dev_num=$(($counter % ($LOFI_DEV_NUM_LIMIT + 1) ))
  84         typeset desired_lofi_dev=/dev/lofi/$lofi_dev_num
  85 
  86         # TET_TPNUMBER could change if other test purposes are added.
  87         # This check is so that the assertion is not reprinted for
  88         # every iteration of the test purpose.
  89         ((assert_check = $ic_num + 1))
  90         if (( $TET_TPNUMBER == $assert_check )); then
  91                 extract_assertion_info $(dirname $ME)/$TP_NAME
  92         fi
  93 
  94         # Parameters used to build the test cases
  95         typeset pos_or_neg file_size_param file_system_param
  96         typeset lofi_file=${SCRATCH_DIR}/lofi_file_$$_$counter
  97         cti_report "lofi_file = '$lofi_file'"
  98 
  99         # Get the line corresponding to this iteration (matching
 100         # $counter) from the dynamic config file.
 101         cp $dynamic_config_file /tmp/dynamic_config_file
 102         typeset config_line=`extract_line_from_file $dynamic_config_file \
 103             $counter`
 104         if (( $? != 0 )) || [[ -z "$config_line" ]]; then
 105                 cti_uninitiated "Could not extract line $counter from" \
 106                     "dynamic confile file $dynamic_config_file"
 107                 return
 108         fi
 109 
 110         # Extract the individual elements from the line that was read from
 111         # the dynamic configuration file.
 112         set $config_line
 113         pos_or_neg="$1"
 114         file_size_param="$2"
 115         file_system_param="$3"
 116         skip_iteration="$4"
 117         if [[ "$pos_or_neg" = "neg" ]]; then
 118                 pos_or_neg_text=" (expected to fail)"
 119         fi
 120 
 121         # Build and display the assertion description
 122         typeset atxt="Testing the following parameters - file size"
 123         atxt="$atxt '$file_size_param' file system '$file_system_param'"
 124         atxt="$atxt $pos_or_neg_text"
 125         cti_assert $ITERATION "$atxt"
 126 
 127         if [[ -n "$skip_iteration" ]]; then
 128                 cti_untested "Skipping assertion $ITERATION as RUNMODE is" \
 129                     "'$RUNMODE'"
 130                 return
 131         fi
 132 
 133         # If the user has placed limits on which parameters to test, make
 134         # sure our current list of parameters falls within the list.
 135         tp_within_parameters FS_TYPES $file_system_param
 136         if (( $? != 0 )); then
 137                 cti_untested "Skipping assertion $ITERATION"
 138                 return
 139         fi
 140 
 141         create_execution_record         # Record cmds; will display on failure
 142         execution_phase_setup           # Record setup cmds
 143 
 144         typeset zpool_name zpool_arg
 145         if [[ "$file_system_param" = "zfs" ]]; then
 146                 zpool_name="lofi_pool_${counter}"
 147                 zpool_arg="-z $zpool_name"
 148         fi
 149 
 150         execution_phase_assert          # Record assertion commands
 151 
 152         # Call function that takes care of creating a populated filesystem
 153         # on the specified file (via lofi).  $reference_tree is a directory
 154         # hierarchy and set of files created during the startup phase of the
 155         # 'tc' file that runs this test purpose.
 156         create_populated_fs_in_file -l $lofi_file -f $file_system_param \
 157             -r $file_size_param -s $reference_tree $zpool_arg
 158         if (( $? != 0 )); then
 159                 display_execution_record
 160                 status=1
 161         fi
 162 
 163         # If filesystem creation succeeded, verify the contents.
 164         if (( $status == 0 )); then
 165                 # After the filesystem was created and populated, it was
 166                 # unmounted and the lofi device associated with the file
 167                 # containing the filesystem was torn down.  Make sure that the
 168                 # filesystem is still accessible when the file is once again
 169                 # associated with a lofi device.
 170                 verify_populated_fs_in_file -l $lofi_file \
 171                     -f $file_system_param -s $reference_tree $zpool_arg
 172                 if (( $? != 0 )); then
 173                         cti_fail "Verification of $file_system_param" \
 174                             "filesystem on lofi device failed."
 175                         status=1
 176                 fi
 177         fi
 178 
 179         # Clean up after ourselves
 180         execution_phase_cleanup
 181         lofi_and_fs_tidy_up -f $lofi_file -d
 182         if (( $? != 0 )); then
 183                 status=1
 184         fi
 185 
 186         if [[ -n "$VERBOSE" ]] || (( $status != 0 )); then
 187                 display_execution_record
 188         else
 189                 delete_execution_record
 190         fi
 191 }