1 #!/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 # ident "@(#)tc_compression_dynamic.ksh 1.3     09/03/09 SMI"
  28 #
  29 
  30 . ${TET_SUITE_ROOT}/lofi-tests/lib/startup_cleanup_common
  31 
  32 tet_startup=startup
  33 tet_cleanup=cleanup
  34 
  35 reference_tree=$SCRATCH_DIR/$$_ref_tree
  36 
  37 function startup {
  38         cti_report "In startup"
  39 
  40         typical_startup_checks
  41         if (( $? != 0 )); then
  42                 exit 1
  43         fi
  44 
  45         cti_report "Building 'reference tree' $reference_tree"
  46         build_reference_tree $reference_tree
  47         if (( $? != 0 )); then
  48                 exit 1
  49         fi
  50 }
  51 
  52 
  53 function cleanup {
  54         cti_report "In cleanup"
  55         if [[ -d $reference_tree ]]; then
  56                 cti_report "Deleting 'reference tree' $reference_tree"
  57                 cti_execute "FAIL" "$RM -rf $reference_tree"
  58                 if (( $? != 0 )); then
  59                         exit 1
  60                 fi
  61         fi
  62 
  63         # cleanup /dev/lofi to prepare for the next test
  64         if [ -d /dev/lofi ]; then
  65                 rm -rf /dev/lofi
  66         fi
  67 }
  68 
  69 
  70 #
  71 # NAME
  72 #       runmode_skip
  73 #
  74 # SYNOPSIS
  75 #       runmode_skip <file size parameter> <one in N (for medium mode)>
  76 #
  77 # DESCRIPTION
  78 #       Determine if the assertion with the given set of parameters
  79 #       should be skipped based on the value of RUNMODE.  For long
  80 #       mode, no tests are skipped.  For medium mode, only one test
  81 #       for a particular combination of file size, compression type,
  82 #       and segment size is run and all other occurances of that
  83 #       combination are skipped.  Short mode skips all of the same
  84 #       tests that medium mode does, plus all but one of the tests
  85 #       that involve the largest file size.
  86 #
  87 #       The intention is for medium and short mode to still provide
  88 #       good general coverage while significantly reducing the
  89 #       execution time compared to long mode.
  90 #
  91 # RETURN VALUES
  92 #       Undefined
  93 #
  94 function runmode_skip {
  95         typeset used_combo_file="$1"
  96         typeset file_size_param="$2"
  97         typeset filesystem_param="$3"
  98         typeset compression_type_param="$4"
  99         typeset segment_size_param="$5"
 100 
 101         typeset combo last_line
 102         typeset prev_file_size prev_filesystem prev_compression_type
 103         typeset prev_segment_size
 104 
 105         # In short mode we only do the first 'large file' (1g) test that comes
 106         # up and skip any subsequent ones.
 107         if [[ "$RUNMODE" = "short" && "$file_size_param" = "1g" ]]; then
 108                 if grep "^1g" $used_combo_file >/dev/null
 109                 then
 110                         # A combination using a 'large file' has been done.
 111                         echo "skip=$RUNMODE"
 112                         return
 113                 fi
 114         fi
 115 
 116         # Always execute the tests for the smallest file size.  If size isn't
 117         # the smallest, then for 'short' and 'medium' run modes we may not
 118         # run this test.
 119         if [[ "$file_size_param" != "65m" ]]; then
 120                 if [[ "$RUNMODE" = "medium" || "$RUNMODE" = "short" ]]; then
 121                         last_line=`tail -1 $used_combo_file`
 122                         if [[ -n "$last_line" ]]; then
 123                                 # Get the set of parameters for the last
 124                                 # combination that was actually used.
 125                                 echo "'$last_line'" >> /tmp/last_line
 126                                 set $last_line
 127                                 prev_file_size=$1
 128                                 prev_filesystem=$2
 129                                 prev_compression_type=$3
 130                                 prev_segment_size=$4
 131 
 132                                 # If we've already done a combo with this file
 133                                 # size, compression type, and segment size then
 134                                 # skip it.
 135                                 if grep "^$file_size_param .* $compression_type_param $segment_size_param" \
 136                                     $used_combo_file >/dev/null
 137                                 then
 138                                         echo "skip=$RUNMODE"
 139                                         return
 140                                 fi
 141                         fi
 142                 fi
 143         fi
 144 
 145         # The current combination is one we will test.  Don't echo anything
 146         # (so the caller won't skip this test) and add the current set of
 147         # parameters to the list of combinations used.
 148         combo="$file_size_param $filesystem_param $compression_type_param"
 149         combo="$combo $segment_size_param"
 150         echo "$combo" >> $used_combo_file
 151 }
 152 
 153 
 154 # Set this parameter equal to the number of invocable components
 155 # from above. This parameter is the base starting number for the
 156 # dynamic test cases created below.
 157 ic_num=2
 158 
 159 
 160 # Build the dynamic configuration files for tp_compression_dynamic_001
 161 dynamic_config_file="$CTI_LOGDIR/tc_lofi_compress_create.cfg"
 162 cat /dev/null > $dynamic_config_file
 163 
 164 # These variables contain the various parameters that will be used to
 165 # generate the dynamic test cases.  Note that the lofi/config/test_config
 166 # file specifies environment variables that can be set to restrict some
 167 # of the parameters that get tested.  When adding a parameter value to one of
 168 # these lists, comments for the appropriate env var name in the test_config
 169 # file should be updated to list the parameter.
 170 #
 171 # The size parameters were chosen to test a variety of file sizes as well
 172 # as one value that is not a multiple of 128k (as that's the default segment
 173 # size).  In order to work with ZFS, all sizes must be above 64M.
 174 #
 175 #                                                       Env var name affected
 176 # List and values                                       in test_config file
 177 # ---------------------------------------------------   ---------------------
 178 file_size_pos_params="65m 100m 1g 68157440"             # N/A
 179 filesystem_pos_params="zfs ufs hsfs"                    # FS_TYPES
 180 compress_pos_params="default gzip gzip-6 gzip-9 lzma"   # COMPRESSION_TYPES
 181 segmentsize_pos_params="default 128k 64k 1m"            # COMPRESSION_SEG_SIZES
 182 compress_neg_params="invalid"                           # COMPRESSION_TYPES
 183 segmentsize_neg_params="none kkk 0"                     # COMPRESSION_SEG_SIZES
 184 
 185 # For ZFS we'll only execute on one file size (details in comments
 186 # where this variable is used in the loop).
 187 first_file_size_pos_param=`echo $file_size_pos_params | awk ' { print $1 } ' `
 188 
 189 # This value keeps track of the number of compression tests that
 190 # will be created.
 191 ic_num=1
 192 num_comp_tests=0
 193 used_combo_file="${SCRATCH_DIR}/$$_used_combos"
 194 typeset skip_arg=""
 195 rm -f $used_combo_file >/dev/null
 196 touch $used_combo_file
 197 
 198 # This blocks builds the set of all possible combinations of all positive
 199 # test case parameters for compression tests.
 200 for file_size_pos_param in $file_size_pos_params
 201 do
 202         for compress_pos_param in $compress_pos_params
 203         do
 204                 for segmentsize_pos_param in $segmentsize_pos_params
 205                 do
 206                         for filesystem_pos_param in $filesystem_pos_params
 207                         do
 208                                 # As compressed zpools can't be used, all we
 209                                 # can do with a compressed zpool is run 'fstyp'
 210                                 # on it.  That being the case, there's no point
 211                                 # in working through all of the possible file
 212                                 # sizes -- we'll only do the first one.
 213                                 if [[ $filesystem_pos_param = "zfs" ]]; then
 214                                         if [[ $file_size_pos_param != \
 215                                             "$first_file_size_pos_param" ]]
 216                                         then
 217                                                 continue
 218                                         fi
 219                                 fi
 220 
 221                                 skip_arg=`runmode_skip $used_combo_file $file_size_pos_param $filesystem_pos_param $compress_pos_param $segmentsize_pos_param`
 222                                 echo "pos $file_size_pos_param" \
 223                                     "$filesystem_pos_param" \
 224                                     "$compress_pos_param" \
 225                                     "$segmentsize_pos_param $skip_arg">>\
 226                                     $dynamic_config_file
 227                                 ((ic_num = $ic_num + 1))
 228 
 229                         done
 230                 done
 231         done
 232 done
 233 rm -f $used_combo_file >/dev/null
 234 touch $used_combo_file
 235 
 236 # This step builds test cases for the negative compression parameters.
 237 # There is only one negative parameter for each negative test case.
 238 for file_size_pos_param in $file_size_pos_params
 239 do
 240         for compress_neg_param in $compress_neg_params
 241         do
 242                 for segmentsize_pos_param in $segmentsize_pos_params
 243                 do
 244                         for filesystem_pos_param in $filesystem_pos_params
 245                         do
 246                                 skip_arg=`runmode_skip $used_combo_file $file_size_pos_param $filesystem_pos_param $compress_pos_param $segmentsize_pos_param`
 247                                 echo "neg $file_size_pos_param" \
 248                                     "$filesystem_pos_param" \
 249                                     "$compress_neg_param" \
 250                                     "$segmentsize_pos_param" \
 251                                     "$skip_arg" >>\
 252                                     $dynamic_config_file
 253                                 ((ic_num = $ic_num + 1))
 254 
 255                                 if [[ $filesystem_pos_param == "hsfs" ]]; then
 256                                         # Segment sizes judged not so
 257                                         # interesting for HSFS, so don't
 258                                         # run through all for that fs.
 259                                         continue 4
 260                                 fi
 261                         done
 262                 done
 263         done
 264 done
 265 rm -f $used_combo_file >/dev/null
 266 touch $used_combo_file
 267 
 268 # This step builds test cases for the negative segment size parameters.
 269 # There is only one negative parameter for each negative test case.
 270 for file_size_pos_param in $file_size_pos_params
 271 do
 272         for compress_pos_param in $compress_pos_params
 273         do
 274                 for segmentsize_neg_param in $segmentsize_neg_params
 275                 do
 276                         for filesystem_pos_param in $filesystem_pos_params
 277                         do
 278                                 skip_arg=`runmode_skip $used_combo_file $file_size_pos_param $filesystem_pos_param $compress_pos_param $segmentsize_pos_param`
 279                                 echo "neg $file_size_pos_param" \
 280                                     "$filesystem_pos_param" \
 281                                     "$compress_pos_param" \
 282                                     "$segmentsize_neg_param" \
 283                                     "$skip_arg" >>\
 284                                      $dynamic_config_file
 285                                 ((ic_num = $ic_num + 1))
 286                         done
 287                 done
 288         done
 289 done
 290 rm -f $used_combo_file >/dev/null
 291 
 292 # Build the 'icN' and 'iclist' variables to add to the iclist.
 293 iclist=""
 294 counter=1
 295 while (( counter < $ic_num )); do
 296         eval ic$counter=\"tp_compression_dynamic_001\"
 297         eval iclist=\"$iclist ic$counter\"
 298         ((counter = $counter + 1))
 299 done
 300 
 301 . ./tp_compression_dynamic_001  # Contains 'compression' test purpose 001
 302 
 303 . ${TET_ROOT:?}/common/lib/ctiutils.ksh
 304 . ${TET_ROOT}/lib/ksh/tcm.ksh
 305 . ${TET_SUITE_ROOT}/src/lib/ksh/fs_common.ksh