]> git.proxmox.com Git - ceph.git/blob - ceph/src/isa-l/programs/igzip_cli_check.sh
import quincy beta 17.1.0
[ceph.git] / ceph / src / isa-l / programs / igzip_cli_check.sh
1 #! /bin/bash
2 set -o pipefail
3
4 CWD=$PWD
5 SRC_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
6 IGZIP="$SRC_DIR/igzip $@"
7 TEST_DIR="/tmp/igzip_cli_test_$$/"
8 TEST_FILE=$SRC_DIR/igzip
9 DIFF="diff -q"
10
11 mkdir -p $TEST_DIR
12 cd $TEST_DIR
13
14 cleanup ()
15 {
16 cd $CWD
17 rm -rf $TEST_DIR
18 exit $1
19 }
20
21 clear_dir ()
22 {
23 cd /tmp/
24 rm -rf $TEST_DIR
25 mkdir -p $TEST_DIR
26 cd $TEST_DIR
27 }
28
29 pass_check()
30 {
31 if [ $1 -eq 0 ]; then
32 echo -e "\e[1;32mPass\e[0;39m: " $2
33 else
34 echo -e "\e[1;31mFail\e[0;39m: " $2
35 cleanup 1
36 fi
37 }
38
39 fail_check()
40 {
41 if [ $1 -ne 0 ]; then
42 echo -e "\e[1;32mPass\e[0;39m: " $2
43 else
44 echo -e "\e[1;31mFail\e[0;39m: " $2
45 cleanup 1
46 fi
47 }
48
49 file1=tmp
50 file2=jnk
51 file3=blah
52 bad_file=not_a_file
53 dir=this_is_a_directory
54
55 default_suffix=".gz"
56 ds=$default_suffix
57 gzip_standard_suffixes=(".gz" ".z")
58 bad_suffix=".bad"
59 custom_suffix=".custom"
60
61 # Test basic compression and decompression
62 ret=0
63 cp $TEST_FILE $file1
64 $IGZIP $file1 && rm $file1 || ret=1
65 for suffix in ${gzip_standard_suffixes[@]}; do
66 if [ "$ds" != "$suffix" ]; then
67 cp -u $file1$ds $file1$suffix
68 fi
69 $IGZIP -d $file1$suffix && $DIFF $file1 $TEST_FILE || ret=1
70 rm $file1
71 done
72 pass_check $ret "Basic compression and decompression"
73 clear_dir
74
75 # Test piping
76 cat $TEST_FILE | $IGZIP | $IGZIP -d | $DIFF $TEST_FILE - || ret=1
77 cat $TEST_FILE | $IGZIP - | $IGZIP -d - | $DIFF $TEST_FILE - || ret=1
78 pass_check $ret "Piping compression and decompression"
79
80 # Test multiple concatenated gzip files
81 ret=0
82 (for i in `seq 3`; do $IGZIP -c $TEST_FILE ; done) | $IGZIP -t || ret=1
83 pass_check $ret "Multiple gzip concatenated files"
84
85 if command -V md5sum >/dev/null 2>&1; then
86 sum1=$((for i in `seq 15`; do $IGZIP -c $TEST_FILE; done) | $IGZIP -cd | md5sum)
87 sum2=$((for i in `seq 15`; do cat $TEST_FILE; done) | md5sum)
88 [[ "$sum1" == "$sum2" ]] && ret=0 || ret=1
89 pass_check $ret "Multiple large gzip concat test"
90 clear_dir
91 else
92 echo "Skip: Multiple large gzip concat test"
93 fi
94
95
96 #Test outifle options
97 $IGZIP $TEST_FILE -o $file2$ds && $IGZIP $file2$ds -d -o $file1 && \
98 test -f $file2$ds && test -f $file1 && $DIFF $TEST_FILE $file1
99 pass_check $? "Setting outfile name"
100 clear_dir
101
102 # Not a file test
103 ret=0
104 $IGZIP $bad_file &> /dev/null && ret=1
105 test -f $bad_file$ds && ret=1
106 pass_check $ret "Bad file"
107 clear_dir
108
109 # Multiple files
110 cp $TEST_FILE $file1 && cp $TEST_FILE $file2 && cp $TEST_FILE $file3 && \
111 $IGZIP $file1 $file2 $file3 && rm $file1 && rm $file2 && rm $file3 && \
112 $IGZIP -d $file1$ds $file2$ds $file3$ds && \
113 $DIFF $TEST_FILE $file1 && $DIFF $TEST_FILE $file2 && $DIFF $TEST_FILE $file3
114 pass_check $? "Multiple files compression and decompression"
115 clear_dir
116
117 # Multiple files, one doesn't exist
118 ret=0
119 cp $TEST_FILE $file1 && cp $TEST_FILE $file2 || ret=1
120 $IGZIP $file1 $bad_file $file2 &> /dev/null && ret=1
121 rm $file1 && rm $file2 || ret=1
122 $IGZIP -d $file1$ds $bad_file$ds $file2$ds &> /dev/null && ret=1
123 $DIFF $TEST_FILE $file1 && $DIFF $TEST_FILE $file2 || ret=1
124 pass_check $ret "Multiple files with a bad file"
125 clear_dir
126
127 # Custom suffix test
128 cp $TEST_FILE $file1 && $IGZIP -S $custom_suffix $file1 && rm $file1 && \
129 $IGZIP -d -S $custom_suffix $file1$custom_suffix && $DIFF $TEST_FILE $file1
130 pass_check $? "Custom suffix"
131
132 # Bad suffix test
133 ret=0
134 cp $TEST_FILE $file1 && $IGZIP -S $bad_suffix $file1 && rm $file1 || ret=1
135 $IGZIP -d $file1$custom_suffix &> /dev/null && ret=1
136 pass_check $ret "Bad suffix"
137 clear_dir
138
139 # Remove file test
140 ret=0
141 cp $TEST_FILE $file1 && $IGZIP --rm $file1 || ret=1
142 test -f $file1 && ret=1
143 $IGZIP --rm -d $file1$ds || ret=1
144 test -f $file1$ds && ret=1
145 pass_check $ret "Remove file"
146 clear_dir
147
148 # Pass a directory negative test
149 ret=0
150 mkdir -p $dir || ret=0
151 $IGZIP $dir &> /dev/null && ret=1
152 clear_dir
153
154 mkdir -p $dir$ds || ret=1
155 $IGZIP -d $dir &> /dev/null && ret=1
156 pass_check $ret "Compress/Decompress Directory without -r"
157 clear_dir
158
159 # Write permissions test
160 cp $TEST_FILE $file1
161 chmod 400 $file1
162 chmod 500 $TEST_DIR
163 $IGZIP $file1 &> /dev/null
164 fail_check $? "don't have write permissions"
165 chmod -R 700 $TEST_DIR
166 clear_dir
167
168 # Read permissions test
169 cp $TEST_FILE $file1
170 chmod 000 $file1
171 $IGZIP $file1 &> /dev/null
172 fail_check $? "don't have read permissions"
173 clear_dir
174
175 # File overwrite test -f
176 ret=0
177 cp $TEST_FILE $file1 && touch $file1$ds || ret=1
178 yes | $IGZIP $file1 &> /dev/null && ret=1
179 $IGZIP -f $file1 &> /dev/null && cp $file1$ds $file1 || ret=1
180 yes | $IGZIP -d $file1 &> /dev/null && ret=1
181 $IGZIP -df $file1$ds &> /dev/null && $DIFF $TEST_FILE $file1 || ret=1
182 pass_check $ret "Existing file overwrite only with force"
183 clear_dir
184
185 # Quiet suppresses interactivity
186 ret=0
187 cp $TEST_FILE $file1 && touch $file1$ds || ret=1
188 $IGZIP -q $file1 &> /dev/null && ret=1
189 $IGZIP -dq $file1 &> /dev/null && ret=1
190 pass_check $ret "Quiet will not overwrite"
191 clear_dir
192
193 # Input file and output file cannot be the same
194 ret=0
195 cp $TEST_FILE $file1 && $IGZIP $file1 -o $file1 &> /dev/null && ret=1
196 $DIFF $TEST_FILE $file1 &> /dev/null || ret=1
197 pass_check $ret "No in place compression"
198 clear_dir
199
200 # Input file and output file cannot be the same
201 ret=0
202 cp $TEST_FILE $file1 && $IGZIP $file1 -o $file1$ds &> /dev/null || ret=1
203 $IGZIP -do $file1 $file1 &> /dev/null && ret=1
204 $DIFF $TEST_FILE $file1 &> /dev/null || ret=1
205 pass_check $ret "No in place decompression"
206 clear_dir
207
208 ret=0
209 $IGZIP -n $TEST_FILE -o $file1$ds && $IGZIP -Nd $file1$ds && $DIFF $file1 $TEST_FILE || ret=1
210 pass_check $ret "Decompress name with no-name info"
211 clear_dir
212
213 ret=0
214 cp -p $TEST_FILE $file1 && sleep 1 &&\
215 $IGZIP -N $file1 -o $file1$ds && $IGZIP -Nfqd $file1$ds || ret=1
216 TIME_ORIG=$(stat --printf=\("%Y\n"\) $TEST_FILE)
217 TIME_NEW=$(stat --printf=\("%Y\n"\) $file1)
218 if [ "$TIME_ORIG" != "$TIME_NEW" ] ; then
219 ret=1
220 fi
221 pass_check $ret "Decompress with name info"
222 clear_dir
223
224 ret=0
225 cp -p $TEST_FILE $file1 && touch $file2\\
226 $IGZIP $file1 -o $file1$ds || ret=1
227 $IGZIP -t $file1$ds || ret=1
228 $IGZIP -t $file2 &> /dev/null && ret=1
229 cp $file1$ds $file2 && $IGZIP -t $file1$ds || ret=1
230 truncate -s -1 $file1$ds
231 $IGZIP -t $file1$ds &> /dev/null && ret=1
232 pass_check $ret "Test test"
233 clear_dir
234
235 # Large stream test with threading if enabled
236 ret=0
237 (for i in `seq 100`; do cat $TEST_FILE ; done) | $IGZIP -c -T 4 | $IGZIP -t || ret=1
238 pass_check $ret "Large stream test"
239
240
241 # Large stream tests with decompression and threading if enabled
242 if command -V md5sum >/dev/null 2>&1 && command -V dd >/dev/null 2>&1; then
243 ret=0
244 dd if=<(for i in `seq 1000`; do cat $TEST_FILE; done) iflag=fullblock bs=1M count=201 2> out.stder | tee >(md5sum > out.sum1) \
245 | $IGZIP -c -T 4 | $IGZIP -d | md5sum > out.sum2 \
246 && $DIFF out.sum1 out.sum2 || ret=1
247 pass_check $ret "Large stream compresss test"
248 clear_dir
249
250 if test -e /dev/urandom; then
251 ret=0
252 dd if=/dev/urandom iflag=fullblock bs=1M count=200 2> out.stder | tee >(md5sum > out.sum3) \
253 | $IGZIP -c -T 2 | $IGZIP -d | md5sum > out.sum4 \
254 && $DIFF out.sum3 out.sum4 || ret=1
255 pass_check $ret "Large stream random data test"
256 clear_dir
257 fi
258 fi
259
260 echo "Passed all cli checks"
261 cleanup 0