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_static.ksh  1.3     09/03/09 SMI"
  28 #
  29 
  30 . ${TET_SUITE_ROOT}/lofi-tests/lib/fs_common
  31 . ${TET_SUITE_ROOT}/lofi-tests/lib/startup_cleanup_common
  32 
  33 startup=startup
  34 cleanup=cleanup
  35 
  36 test_list="
  37         tp_compression_static_001 \
  38         tp_compression_static_002 \
  39         tp_compression_static_003 \
  40         tp_compression_static_004 \
  41         tp_compression_static_005 \
  42         tp_compression_static_006 \
  43 "
  44 
  45 function startup {
  46         cti_report "In startup"
  47 
  48         typical_startup_checks
  49         if (( $? != 0 )); then
  50                 exit 1
  51         fi
  52 }
  53 
  54 function cleanup {
  55         cti_report "In cleanup"
  56         #
  57         # cleanup /dev/lofi to prepare for the next test
  58         #
  59         if [ -d /dev/lofi ]; then
  60                 rm -rf /dev/lofi
  61         fi
  62 }
  63 
  64 #
  65 # NAME
  66 #       zero_size_test
  67 #
  68 # SYNOPSIS
  69 #       zero_size_test <assert #> <compression type>
  70 #
  71 # DESCRIPTION
  72 #       This function contains the code used to test the special case of
  73 #       zero-length files and lofiadm compression.  All of the test code
  74 #       for these cases is in this function.  The test purpose files for
  75 #       these cases just pass in the assertion ID number, the type of
  76 #       compression used, and the name of the tp file (so the assertion
  77 #       comments can be extracted from it).  This function then takes care
  78 #       of the actual test.
  79 #
  80 #       Tests for additional compression types that may be added later can
  81 #       be accomplished by just copying one of the existing zero-size tp
  82 #       files and updating the assertion ID number and type of compression
  83 #       in it.
  84 #
  85 # RETURN VALUE
  86 #       Undefined
  87 #
  88 function zero_size_test {
  89         typeset assert_num="$1"
  90         typeset compression_type="$2"
  91         typeset tp_file="$3"
  92         typeset compression_arg
  93 
  94         typeset assertion="compression_static_${assert_num}"
  95         typeset tp_name=tp_${assertion}
  96         typeset assert_desc="Compress/uncompress zero-length file using"
  97         assert_desc="$assert_desc compression of '$compression_type'"
  98         typeset lofi_file=${SCRATCH_DIR}/$$_$assertion
  99         typeset status=0
 100 
 101         extract_assertion_info $(dirname $tp_file)/$tp_name
 102 
 103         cti_assert $assertion "$assert_desc"
 104         create_execution_record
 105         execution_phase_setup
 106 
 107         # Make sure that, if the user has specified which compression types
 108         # to test, that the current compression type is on the list.
 109         tp_within_parameters COMPRESSION_TYPES $compression_type
 110         if (( $? != 0 )); then
 111                 cti_untested "Skipping assertion $assertion"
 112                 return
 113         fi
 114 
 115         if [[ "$compression_type" = "default" ]]; then
 116                 # No arg after "-C" for default compression
 117                 compression_arg=""
 118         else
 119                 compression_arg="$compression_type"
 120         fi
 121 
 122         # Check system for compression support
 123         is_compression_type_supported $compression_type
 124         typeset comp_type_rc=$?
 125 
 126         # Verify that compression is supported by the version of lofiadm on
 127         # the test system.
 128         if (( $comp_type_rc == 2 )); then
 129                 cti_untested "Skipping assertion $ITERATION as lofi" \
 130                     "compression is not supported on this OS version"
 131                 return
 132         fi
 133 
 134         # Make sure the compression type specified is supported.
 135         if [[ $compression_type != "default" ]]; then
 136                 if (( $comp_type_rc == 1 )); then
 137                         cti_untested "Skipping assertion $ITERATION as " \
 138                             "$compression_type compression is not supported " \
 139                             "by lofi on this system"
 140                         return
 141                 fi
 142         fi
 143 
 144         #
 145         # Create the file that we're going to use
 146         #
 147         $RM -rf $lofi_file 2>&1
 148         cmd="touch $lofi_file"
 149         record_cmd_execution "$cmd"
 150         cti_execute "FAIL" "$cmd"
 151         if (( $? != 0 )); then
 152                 cti_unresolved "Unable to test '$assert_desc' because" \
 153                     "creation of file '$lofi_file' failed"
 154                 display_execution_record
 155                 return
 156         fi
 157 
 158         #
 159         # Compress the file
 160         #
 161         execution_phase_assert
 162         cmd="lofiadm -C $compression_arg $lofi_file"
 163         record_cmd_execution "$cmd"
 164         cti_execute "FAIL" "$cmd"
 165         if (( $? == 0 )); then
 166                 cti_report "Compression of zero-length file succeeded"
 167                 cmd="$LS -l $lofi_file"
 168                 record_cmd_execution "$cmd"
 169                 typeset current_size=`$cmd | awk ' { print $5 } '`
 170                 if (( $current_size == 0 )); then
 171                         cti_report "File size after compression is '0' as" \
 172                             "expected"
 173                 else
 174                         cti_fail "File size after compression should be '0';"
 175                             "got '$current_size' instead"
 176                         status=1
 177                 fi
 178 
 179                 #
 180                 # Decompress the file
 181                 #
 182                 cmd="lofiadm -U $lofi_file"
 183                 record_cmd_execution "$cmd"
 184                 cti_execute "FAIL" "$cmd"
 185                 if (( $? == 0 )); then
 186                         cti_report "Decompression of zero-length file succeeded"
 187                         cmd="$LS -l $lofi_file"
 188                         record_cmd_execution "$cmd"
 189                         typeset current_size=`$cmd | awk ' { print $5 } '`
 190                         if (( "$current_size" == 0 )); then
 191                                 cti_pass "File size after decompression is" \
 192                                     "'0' as expected"
 193                         else
 194                                 cti_fail "File size after decompression" \
 195                                     "should be '0' got '$current_size' instead"
 196                                 status=1
 197                         fi
 198                 fi
 199         else
 200                 cti_report "Compression of zero-length file failed when it" \
 201                     "was expected to succeed"
 202                 status=1
 203         fi
 204 
 205         #
 206         # Clean up
 207         #
 208         execution_phase_cleanup
 209         cmd="$RM $lofi_file"
 210         cti_execute "FAIL" "$cmd"
 211         if (( $? != 0 )); then
 212                 status=1
 213         fi
 214 
 215         if [[ -n "$VERBOSE" ]] || (( $status != 0)); then
 216                 display_execution_record
 217         else
 218                 delete_execution_record
 219         fi
 220 }
 221 
 222 . ./tp_compression_static_001   # Contains static 'compression' test purpose 1
 223 . ./tp_compression_static_002   # Contains static 'compression' test purpose 2
 224 . ./tp_compression_static_003   # Contains static 'compression' test purpose 3
 225 . ./tp_compression_static_004   # Contains static 'compression' test purpose 4
 226 . ./tp_compression_static_005   # Contains static 'compression' test purpose 5
 227 . ./tp_compression_static_006   # Contains static 'compression' test purpose 6
 228 
 229 . ${TET_ROOT:?}/common/lib/ctilib.ksh