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 2009 Sun Microsystems, Inc.  All rights reserved.
  24 # Use is subject to license terms.
  25 #
  26 # ident "@(#)tp_compression_dynamic_001.ksh     1.3     09/03/09 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: compression_dynamic_001
  37 #
  38 # DESCRIPTION:
  39 #       This test purpose dynamically generates a set of test cases that
  40 #       tests combinations of valid and invalid lofi compression parameters. 
  41 #       Each test case is an iteration that identifies a specific set of
  42 #       parameters. The combination of parameters form either a positive test
  43 #       case (pos) or a negative test case (neg). Only one negative parameter
  44 #       will be tested in each negative test case.
  45 #
  46 # STRATEGY:
  47 #    Setup:
  48 #       1. Create a list of parameter combinations containing both
  49 #          positive and negative test cases (performed by tc file).
  50 #       2. For each set of parameter combinations:
  51 #               2.01 Create a file.
  52 #               2.02 Create and populate filesystem on file (method depends on
  53 #                    type of FS being created).
  54 #    Assertion:
  55 #               2.03 Compress file using 'lofiadm -C <compression parameter>'.
  56 #               2.04 Associate compressed file with lofi device.
  57 #               2.05 Execute 'fstype' agains lofi device to verify correct FS
  58 #                    type is reported.
  59 #               2.06 For UFS FS, attempt to mount FS with read-write
  60 #                    permissions, which should fail.
  61 #               2.07 For UFS and HSFS FS, mount FS read-only.
  62 #               2.08 For UFS and HSFS FS, verify contents of FS on compressed
  63 #                    file.
  64 #               2.09 For UFS and HSFS FS, unmount FS.
  65 #               2.10 Disassociate lofi device from file.
  66 #               2.11 Decompress file.
  67 #               2.12 Associate decompressed file with lofi device.
  68 #               2.13 Mount filesystem with default options
  69 #               2.14 Verify contents of FS on file.
  70 #               2.15 Unmount FS.
  71 #               2.16 Disassociate lofi device from file.
  72 #    Cleanup:
  73 #               Remove file
  74 #       
  75 # end __stc_assertion__
  76 #
  77 function tp_compression_dynamic_001 {
  78 
  79         cti_pass
  80 
  81         # Extract and print assertion information for the test
  82         typeset -r ASSERTION="compression_dynamic_001"
  83         typeset -r TP_NAME=tp_${ASSERTION}
  84         typeset -r ME=$(whence -p ${0})
  85 
  86         typeset status=0
  87 
  88         # ic_num is the number of test purposes that are not dynamic.
  89         # this may change if other test purposes are added.
  90         let counter=$TET_TPNUMBER
  91         typeset -r ITERATION=${ASSERTION}_$counter
  92 
  93         # Rather than reusing the same lofi dev number over and over, we'll
  94         # use a different one each time (based on our counter).  As there's
  95         # a limit to lofi dev numbers, we'll wrap around to lower numbers
  96         # if the counter exceeds LOFI_DEV_NUM_LIMIT.
  97         if (( $counter <= 128 )); then
  98                 lofi_dev_num=$counter
  99         else
 100                 lofi_dev_num=$(( ($counter % $LOFI_DEV_NUM_LIMIT) +1 ))
 101         fi
 102         typeset desired_lofi_dev=/dev/lofi/$lofi_dev_num
 103 
 104         # TET_TPNUMBER could change if other test purposes are added.
 105         # This check is so that the assertion is not reprinted for
 106         # every iteration of the test purpose.
 107         ((assert_check = $ic_num + 1))
 108         if (( $TET_TPNUMBER == $assert_check )); then
 109                 extract_assertion_info $(dirname $ME)/$TP_NAME
 110         fi
 111 
 112         # Parameters used to build the test cases
 113         typeset pos_or_neg file_size_param file_system_param compress_param
 114         typeset lofi_file=${SCRATCH_DIR}/lofi_file_$$_$counter
 115         cti_report "lofi_file = '$lofi_file'"
 116 
 117         # Get the line corresponding to this iteration (matching
 118         # $counter) from the dynamic config file.
 119         cp $dynamic_config_file /tmp/dynamic_config_file
 120         typeset config_line=`extract_line_from_file $dynamic_config_file \
 121             $counter`
 122         if (( $? != 0 )) || [[ -z "$config_line" ]]; then
 123                 cti_uninitiated "Could not extract line $counter from" \
 124                     "dynamic confile file $dynamic_config_file"
 125                 return
 126         fi
 127 
 128         # Extract the individual elements from the line that was read from
 129         # the dynamic configuration file.
 130         set $config_line
 131         pos_or_neg="$1"
 132         file_size_param="$2"
 133         file_system_param="$3"
 134         compress_param="$4"
 135         segment_size_param="$5"
 136         skip_iteration="$6"
 137         if [[ "$pos_or_neg" = "neg" ]]; then
 138                 pos_or_neg_text=" (expected to fail)"
 139         fi
 140 
 141         # Build and display the assertion description
 142         typeset atxt="Testing the following parameters - file size"
 143         atxt="$atxt '$file_size_param' file system '$file_system_param'"
 144         atxt="$atxt compression algorithm '$compress_param' segment size"
 145         atxt="$atxt '$segment_size_param' $pos_or_neg_text"
 146         cti_assert $ITERATION "$atxt"
 147 
 148         # Determine compression support
 149         is_compression_type_supported $compress_param
 150         typeset comp_type_rc=$?
 151 
 152         # There are several reasons why we might choose not to run this test
 153         # assertion.  First is if the OS we're running on doesn't include any
 154         # lofi compression support.
 155         if (( $comp_type_rc == 2 )); then
 156                 cti_untested "Skipping assertion $ITERATION as lofi" \
 157                     "compression is not supported on this OS version"
 158                 return
 159         fi
 160 
 161         # Second reason not to run is if the OS supports lofi compression
 162         # in general but doesn't support the specific compression algorithm
 163         # specified.
 164         if [[ $compress_param != 'default' && $compress_param != 'invalid' ]]
 165         then
 166                 if (( $comp_type_rc == 1 )); then
 167                         cti_untested "Skipping assertion $ITERATION " \
 168                             "as lofi compression type '$compress_param' is " \
 169                             "not supported on this OS version"
 170                         return
 171                 fi
 172         fi
 173 
 174         # Third reason not to run is if this iteration was flagged to be
 175         # skipped due to the value of RUNMODE.
 176         if [[ -n "$skip_iteration" ]]; then
 177                 cti_untested "This test skipped as RUNMODE is '$RUNMODE'"
 178                 return
 179         fi
 180 
 181         # Fourth reason not to run is if the user has placed limits on which
 182         # parameters to test and the current list of parameters doesn't fall
 183         # within those limits.
 184         tp_within_parameters FS_TYPES $file_system_param COMPRESSION_TYPES \
 185             $compress_param COMPRESSION_SEG_SIZES $segment_size_param
 186         if (( $? != 0 )); then
 187                 cti_untested "Skipping assertion $ITERATION"
 188                 return
 189         fi
 190 
 191         # If we've gotten this far, we're going to attempt to execute the test
 192         # assertion.
 193 
 194         create_execution_record         # Record cmds; will display on failure
 195         execution_phase_setup           # Record setup cmds
 196 
 197         typeset zpool_name zpool_arg
 198         if [[ "$file_system_param" = "zfs" ]]; then
 199                 zpool_name="lofi_pool_${counter}"
 200                 zpool_arg="-z $zpool_name"
 201         fi
 202 
 203         # Call function that takes care of creating a populated filesystem
 204         # on the specified file (via lofi).  $reference_tree is a directory
 205         # hierarchy and set of files created during the startup phase of the
 206         # 'tc' file that runs this test purpose.
 207         create_populated_fs_in_file -l $lofi_file -f $file_system_param \
 208             -r $file_size_param -s $reference_tree $zpool_arg
 209         if (( $? != 0 )); then
 210                 cti_fail "Unable to create populated $file_system_param" \
 211                     "filesystem on file $lofi_file using lofi"
 212                 display_execution_record
 213                 return
 214         fi
 215 
 216         # We now have a populated filesystem in a lofi-usable file.  Time
 217         # to get to the meat of this assertion, which is the compression/
 218         # decompression functionality.
 219 
 220         execution_phase_assert           # Record assertion cmds
 221 
 222         # For any compression parameter other than "default" we place the
 223         # compression type the -C flag.  For "default", no compression
 224         # type is specified.
 225         typeset compress_value
 226         if [[ "$compress_param" != "default" ]]; then
 227                 compress_value="$compress_param"
 228         fi
 229 
 230         # For any sement size other than "default" we place the segment size
 231         # after the -s flag.  For "default", no segment size type is specified.
 232         typeset segment_size_arg=""
 233         if [[ "$segment_size_param" != "default" ]]; then
 234                 segment_size_arg="-s $segment_size_param"
 235         fi
 236 
 237         cmd="lofiadm -C $compress_value $segment_size_arg $lofi_file"
 238         record_cmd_execution "$cmd"
 239 
 240         # Whether the compression command is expected to pass or fail
 241         # depends on if this is a positive or negative test case.
 242         typeset on_fail
 243         if [[ "$pos_or_neg" = "pos" ]]; then
 244                 on_fail="FAIL"
 245         else
 246                 on_fail="PASS"
 247         fi
 248         cti_execute $on_fail "$cmd"
 249         typeset compression_status=$?
 250 
 251         typeset exit_due_to_compression_status
 252         if (( $compression_status == 0 )); then
 253                 if [[ "$pos_or_neg" = "neg" ]]; then
 254                         cti_fail "Error: Compression succeeded when it" \
 255                             "was expected to fail"
 256                         exit_due_to_compression_status=1
 257                 fi
 258         else
 259                 if [[ "$pos_or_neg" = "neg" ]]; then
 260                         cti_report "Attempted compression failed as expected"
 261                         exit_due_to_compression_status=1
 262                 else
 263                         cti_fail "Attempted compression failed when it was" \
 264                             "expected to pass"
 265                         exit_due_to_compression_status=1
 266                 fi
 267         fi
 268 
 269         # If compression failed, or succeeded when it was expected to fail,
 270         # clean up and return.
 271         if [[ -n "$exit_due_to_compression_status" ]]; then
 272                 execution_phase_cleanup
 273                 lofi_and_fs_tidy_up -f $lofi_file -d
 274                 display_execution_record
 275                 return
 276         fi
 277 
 278         cti_report "Compressed file $lofi_file with compression type" \
 279             "'$compress_value' and segment size '$segment_size_param'"
 280 
 281         # Verify the filesystem contents after compression.
 282         verify_populated_fs_in_file -l $lofi_file -f $file_system_param \
 283             -s $reference_tree $zpool_arg -c
 284         if (( $? == 0 )); then
 285                 cti_report "Verified filesystem on file $lofi_file following" \
 286                     "compression"
 287         else
 288                 cti_fail "Verification of compressed $file_system_param" \
 289                     "filesystem on file $lofi_file failed."
 290 
 291                 # Don't return yet as we still need to find out if the
 292                 # filesystem looks ok after decompression.
 293                 status=1
 294         fi
 295 
 296         # Decompress the file containing the file system.
 297         cmd="lofiadm -U $lofi_file"
 298         record_cmd_execution "$cmd"
 299         cti_execute "FAIL" "$cmd"
 300         if (( $? != 0 )); then
 301                 cti_report "Could not decompress file $lofi_file"
 302                 lofi_and_fs_tidy_up -f $lofi_file -d
 303                 display_execution_record
 304                 return
 305         fi
 306 
 307         cti_report "Decompression of $lofi_file succeeded."
 308 
 309         # Verify the filesystem contents after decompression.
 310         verify_populated_fs_in_file -l $lofi_file -f $file_system_param \
 311             -s $reference_tree $zpool_arg
 312         if (( $? == 0 )); then
 313                 cti_report "Verified filesystem on file $lofi_file following" \
 314                     "decompression"
 315         else
 316                 cti_report "Verification of filesystem on file $lofi_file" \
 317                     "following decompression failed"
 318                 status=1
 319         fi
 320 
 321         # Clean up
 322         execution_phase_cleanup
 323         lofi_and_fs_tidy_up -f $lofi_file -d
 324         if (( $? != 0 )); then
 325                 status=1
 326         fi
 327 
 328         if [[ -n "$VERBOSE" ]] || (( $status != 0 )); then
 329                 display_execution_record
 330         else
 331                 delete_execution_record
 332         fi
 333 }