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_static_001.ksh 1.3 09/03/09 SMI"
27 #
28
29 LOGFILE=${LOGDIR}/mkdir.out
30 . ${TET_SUITE_ROOT}/lofi-tests/lib/fs_common
31 . ${TET_SUITE_ROOT}/lofi-tests/lib/util_common
32
33 #
34 # start __stc_assertion__
35 #
36 # ASSERTION: compression_static_001
37 #
38 # DESCRIPTION
39 # An attempt to compress a file that's currently associated with a
40 # lofi device should fail.
41 #
42 # STRATEGY:
43 # Setup
44 # - Create a file of default size
45 # - Add a lofi device using the file
46 # Assert
47 # - Attempt to compress the file via 'lofiadm -C'
48 # Cleanup
49 # - Delete the lofi device
50 # - Remove the file
51 #
52 # end __stc_assertion__
53 #
54 function tp_compression_static_001 {
55 typeset -r ASSERTION="compression_static_001"
56 typeset -r TP_NAME=tp_${ASSERTION}
57 typeset -r ME=$(whence -p ${0})
58 typeset -r ASSERT_DESC="Try to compress in use lofi file"
59 typeset lofi_file=${SCRATCH_DIR}/$$_$ASSERTION
60 typeset status=0
61
62 extract_assertion_info $(dirname $ME)/$TP_NAME
63
64 cti_assert $ASSERTION "$ASSERT_DESC"
65 create_execution_record
66 execution_phase_setup
67
68 # First off, verify that compression is supported by the version of
69 # lofiadm on the test system.
70 typeset compression_supported=`get_supported_compression_types`
71 if [[ ! -n $compression_supported ]]; then
72 cti_untested "Skipping assertion $ITERATION as lofi" \
73 "compression is not supported on this OS version"
74 return
75 fi
76
77 # This test uses default compression type, so make sure that the
78 # user hasn't set COMPRESSION_TYPES to exclude 'default'.
79 tp_within_parameters COMPRESSION_TYPES default
80 if (( $? != 0 )); then
81 cti_untested "Skipping assertion as compression type" \
82 "'default' not in COMPRESSION_TYPES ($COMPRESSION_TYPES)"
83 return
84 fi
85
86 #
87 # Create the file that we're going to use
88 #
89 make_and_verify_file $DEFAULT_FILE_SIZE $lofi_file
90 if (( $? != 0 )); then
91 cti_unresolved "Unable to test '$assert_desc' because" \
92 "creation of file failed"
93 display_execution_record
94 return
95 fi
96
97 #
98 # Add a lofi device using the file. We'll capture the name of the
99 # lofi device printed by the add_lofi_device function even though
100 # we're not going to use it -- otherwise, it will get printed out
101 # in the terminal where the test suite is being executed.
102 #
103 typeset lofi_dev=`add_lofi_device $lofi_file`
104 if (( $? == 0 )); then
105 cti_report "File created and lofi device successfully" \
106 "associated with it"
107
108 # Now execute the actual assertion, where we attempt to
109 # compress the file via 'lofiadm -C gzip' while it's in use.
110 execution_phase_assert
111 typeset cmd="$LOFIADM -C $lofi_file"
112 record_cmd_execution "$cmd"
113 cti_execute "PASS" "$cmd"
114 if (( $? == 0 )); then
115 cti_fail "Error: '$cmd' succeeded when it should" \
116 "have failed."
117 cti_report "Should not be able to compress file that" \
118 "is currently associated with a lofi device"
119 status=1
120 else
121 cti_pass "Compression while file was in use failed" \
122 "as expected"
123 fi
124
125 #
126 # Clean up after ourselves.
127 #
128 execution_phase_cleanup
129 del_lofi_dev_and_file $lofi_file
130 if (( $? != 0 )); then
131 cti_fail "Cleanup of lofi device and/or file" \
132 "$lofi_file failed"
133 status=1
134 fi
135 else
136 #
137 # The addition of the lofi device failed.
138 #
139 cti_fail "Unable to test '$assert_desc' because addition of" \
140 "lofi device failed"
141 status=1
142 fi
143
144 if [[ -n "$VERBOSE" ]] || (( $status != 0 )); then
145 display_execution_record
146 else
147 delete_execution_record
148 fi
149 }