Statistics
| Branch: | Tag: | Revision:

root / test / py / import-export_unittest.bash @ 7352d33b

History | View | Annotate | Download (11.3 kB)

1 2d76b580 Michael Hanselmann
#!/bin/bash
2 2d76b580 Michael Hanselmann
#
3 2d76b580 Michael Hanselmann
4 90066780 Iustin Pop
# Copyright (C) 2010, 2012 Google Inc.
5 2d76b580 Michael Hanselmann
#
6 2d76b580 Michael Hanselmann
# This program is free software; you can redistribute it and/or modify
7 2d76b580 Michael Hanselmann
# it under the terms of the GNU General Public License as published by
8 2d76b580 Michael Hanselmann
# the Free Software Foundation; either version 2 of the License, or
9 2d76b580 Michael Hanselmann
# (at your option) any later version.
10 2d76b580 Michael Hanselmann
#
11 2d76b580 Michael Hanselmann
# This program is distributed in the hope that it will be useful, but
12 2d76b580 Michael Hanselmann
# WITHOUT ANY WARRANTY; without even the implied warranty of
13 2d76b580 Michael Hanselmann
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 2d76b580 Michael Hanselmann
# General Public License for more details.
15 2d76b580 Michael Hanselmann
#
16 2d76b580 Michael Hanselmann
# You should have received a copy of the GNU General Public License
17 2d76b580 Michael Hanselmann
# along with this program; if not, write to the Free Software
18 2d76b580 Michael Hanselmann
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 2d76b580 Michael Hanselmann
# 02110-1301, USA.
20 2d76b580 Michael Hanselmann
21 2d76b580 Michael Hanselmann
set -e
22 2d76b580 Michael Hanselmann
set -o pipefail
23 2d76b580 Michael Hanselmann
24 2d76b580 Michael Hanselmann
export PYTHON=${PYTHON:=python}
25 2d76b580 Michael Hanselmann
26 9d198e6f Michael Hanselmann
impexpd="$PYTHON daemons/import-export -d"
27 2d76b580 Michael Hanselmann
28 2d76b580 Michael Hanselmann
err() {
29 2d76b580 Michael Hanselmann
  echo "$@"
30 2d76b580 Michael Hanselmann
  echo 'Aborting'
31 9d198e6f Michael Hanselmann
  show_output
32 2d76b580 Michael Hanselmann
  exit 1
33 2d76b580 Michael Hanselmann
}
34 2d76b580 Michael Hanselmann
35 9d198e6f Michael Hanselmann
show_output() {
36 d6547a1c Michael Hanselmann
  if [[ -s "$gencert_output" ]]; then
37 d6547a1c Michael Hanselmann
    echo
38 d6547a1c Michael Hanselmann
    echo 'Generating certificates:'
39 d6547a1c Michael Hanselmann
    cat $gencert_output
40 d6547a1c Michael Hanselmann
  fi
41 9d198e6f Michael Hanselmann
  if [[ -s "$dst_output" ]]; then
42 9d198e6f Michael Hanselmann
    echo
43 9d198e6f Michael Hanselmann
    echo 'Import output:'
44 9d198e6f Michael Hanselmann
    cat $dst_output
45 9d198e6f Michael Hanselmann
  fi
46 9d198e6f Michael Hanselmann
  if [[ -s "$src_output" ]]; then
47 9d198e6f Michael Hanselmann
    echo
48 9d198e6f Michael Hanselmann
    echo 'Export output:'
49 9d198e6f Michael Hanselmann
    cat $src_output
50 9d198e6f Michael Hanselmann
  fi
51 9d198e6f Michael Hanselmann
}
52 9d198e6f Michael Hanselmann
53 2d76b580 Michael Hanselmann
checkpids() {
54 2d76b580 Michael Hanselmann
  local result=0
55 2d76b580 Michael Hanselmann
56 2d76b580 Michael Hanselmann
  # Unlike combining the "wait" commands using || or &&, this ensures we
57 2d76b580 Michael Hanselmann
  # actually wait for all PIDs.
58 2d76b580 Michael Hanselmann
  for pid in "$@"; do
59 2d76b580 Michael Hanselmann
    if ! wait $pid; then
60 2d76b580 Michael Hanselmann
      result=1
61 2d76b580 Michael Hanselmann
    fi
62 2d76b580 Michael Hanselmann
  done
63 2d76b580 Michael Hanselmann
64 2d76b580 Michael Hanselmann
  return $result
65 2d76b580 Michael Hanselmann
}
66 2d76b580 Michael Hanselmann
67 2d76b580 Michael Hanselmann
get_testpath() {
68 2d76b580 Michael Hanselmann
  echo "${TOP_SRCDIR:-.}/test"
69 2d76b580 Michael Hanselmann
}
70 2d76b580 Michael Hanselmann
71 2d76b580 Michael Hanselmann
get_testfile() {
72 2d76b580 Michael Hanselmann
  echo "$(get_testpath)/data/$1"
73 2d76b580 Michael Hanselmann
}
74 2d76b580 Michael Hanselmann
75 53dbf14c Michael Hanselmann
upto() {
76 53dbf14c Michael Hanselmann
  echo "$(date '+%F %T'):" "$@" '...'
77 53dbf14c Michael Hanselmann
}
78 53dbf14c Michael Hanselmann
79 2d76b580 Michael Hanselmann
statusdir=$(mktemp -d)
80 2d76b580 Michael Hanselmann
trap "rm -rf $statusdir" EXIT
81 2d76b580 Michael Hanselmann
82 d6547a1c Michael Hanselmann
gencert_output=$statusdir/gencert.output
83 d6547a1c Michael Hanselmann
84 2d76b580 Michael Hanselmann
src_statusfile=$statusdir/src.status
85 9d198e6f Michael Hanselmann
src_output=$statusdir/src.output
86 2d76b580 Michael Hanselmann
src_x509=$statusdir/src.pem
87 2d76b580 Michael Hanselmann
88 2d76b580 Michael Hanselmann
dst_statusfile=$statusdir/dst.status
89 9d198e6f Michael Hanselmann
dst_output=$statusdir/dst.output
90 2d76b580 Michael Hanselmann
dst_x509=$statusdir/dst.pem
91 2d76b580 Michael Hanselmann
92 2d76b580 Michael Hanselmann
other_x509=$statusdir/other.pem
93 2d76b580 Michael Hanselmann
94 2d76b580 Michael Hanselmann
testdata=$statusdir/data1
95 41a2e7d7 Michael Hanselmann
largetestdata=$statusdir/data2
96 2d76b580 Michael Hanselmann
97 53dbf14c Michael Hanselmann
upto 'Command line parameter tests'
98 53dbf14c Michael Hanselmann
99 2d76b580 Michael Hanselmann
$impexpd >/dev/null 2>&1 &&
100 2d76b580 Michael Hanselmann
  err "daemon-util succeeded without parameters"
101 2d76b580 Michael Hanselmann
102 2d76b580 Michael Hanselmann
$impexpd foo bar baz moo boo >/dev/null 2>&1 &&
103 2d76b580 Michael Hanselmann
  err "daemon-util succeeded with wrong parameters"
104 2d76b580 Michael Hanselmann
105 2d76b580 Michael Hanselmann
$impexpd $src_statusfile >/dev/null 2>&1 &&
106 2d76b580 Michael Hanselmann
  err "daemon-util succeeded with insufficient parameters"
107 2d76b580 Michael Hanselmann
108 2d76b580 Michael Hanselmann
$impexpd $src_statusfile invalidmode >/dev/null 2>&1 &&
109 2d76b580 Michael Hanselmann
  err "daemon-util succeeded with invalid mode"
110 2d76b580 Michael Hanselmann
111 acd65a16 Michael Hanselmann
for mode in import export; do
112 acd65a16 Michael Hanselmann
  $impexpd $src_statusfile $mode --compression=rot13 >/dev/null 2>&1 &&
113 acd65a16 Michael Hanselmann
    err "daemon-util succeeded with invalid compression"
114 acd65a16 Michael Hanselmann
115 acd65a16 Michael Hanselmann
  for host in '' '  ' ' s p a c e' ... , foo.example.net... \
116 acd65a16 Michael Hanselmann
              'some"evil"name' 'x\ny\tmoo'; do
117 acd65a16 Michael Hanselmann
    $impexpd $src_statusfile $mode --host="$host" >/dev/null 2>&1 &&
118 acd65a16 Michael Hanselmann
      err "daemon-util succeeded with invalid host '$host'"
119 acd65a16 Michael Hanselmann
  done
120 acd65a16 Michael Hanselmann
121 acd65a16 Michael Hanselmann
  for port in '' ' ' -1234 'some ` port " here'; do
122 acd65a16 Michael Hanselmann
    $impexpd $src_statusfile $mode --port="$port" >/dev/null 2>&1 &&
123 acd65a16 Michael Hanselmann
      err "daemon-util succeeded with invalid port '$port'"
124 acd65a16 Michael Hanselmann
  done
125 1d3dfa29 Michael Hanselmann
126 1d3dfa29 Michael Hanselmann
  for magic in '' ' ' 'this`is' 'invalid!magic' 'he"re'; do
127 1d3dfa29 Michael Hanselmann
    $impexpd $src_statusfile $mode --magic="$magic" >/dev/null 2>&1 &&
128 1d3dfa29 Michael Hanselmann
      err "daemon-util succeeded with invalid magic '$magic'"
129 1d3dfa29 Michael Hanselmann
  done
130 acd65a16 Michael Hanselmann
done
131 7e3c1da6 Michael Hanselmann
132 4dd97aa1 Michael Hanselmann
upto 'Generate test data'
133 2d76b580 Michael Hanselmann
cat $(get_testfile proc_drbd8.txt) $(get_testfile cert1.pem) > $testdata
134 2d76b580 Michael Hanselmann
135 41a2e7d7 Michael Hanselmann
# Generate about 7.5 MB of test data
136 41a2e7d7 Michael Hanselmann
{ tmp="$(<$testdata)"
137 41a2e7d7 Michael Hanselmann
  for (( i=0; i < 100; ++i )); do
138 41a2e7d7 Michael Hanselmann
    echo "$tmp $tmp $tmp $tmp $tmp $tmp"
139 41a2e7d7 Michael Hanselmann
  done
140 41a2e7d7 Michael Hanselmann
  dd if=/dev/zero bs=1024 count=4096 2>/dev/null
141 41a2e7d7 Michael Hanselmann
  for (( i=0; i < 100; ++i )); do
142 41a2e7d7 Michael Hanselmann
    echo "$tmp $tmp $tmp $tmp $tmp $tmp"
143 41a2e7d7 Michael Hanselmann
  done
144 41a2e7d7 Michael Hanselmann
} > $largetestdata
145 41a2e7d7 Michael Hanselmann
146 2d76b580 Michael Hanselmann
impexpd_helper() {
147 90066780 Iustin Pop
  $PYTHON $(get_testpath)/py/import-export_unittest-helper "$@"
148 2d76b580 Michael Hanselmann
}
149 2d76b580 Michael Hanselmann
150 ca9ec5aa Michael Hanselmann
start_test() {
151 ca9ec5aa Michael Hanselmann
  upto "$@"
152 2d76b580 Michael Hanselmann
153 ca9ec5aa Michael Hanselmann
  rm -f $src_statusfile $dst_output $dst_statusfile $dst_output
154 ca9ec5aa Michael Hanselmann
  rm -f $gencert_output
155 53dbf14c Michael Hanselmann
156 ca9ec5aa Michael Hanselmann
  imppid=
157 ca9ec5aa Michael Hanselmann
  exppid=
158 2d76b580 Michael Hanselmann
159 ca9ec5aa Michael Hanselmann
  cmd_prefix=
160 ca9ec5aa Michael Hanselmann
  cmd_suffix=
161 ca9ec5aa Michael Hanselmann
  connect_timeout=30
162 ca9ec5aa Michael Hanselmann
  connect_retries=1
163 ca9ec5aa Michael Hanselmann
  compress=gzip
164 1d3dfa29 Michael Hanselmann
  magic=
165 2d76b580 Michael Hanselmann
}
166 2d76b580 Michael Hanselmann
167 ca9ec5aa Michael Hanselmann
wait_import_ready() {
168 2d76b580 Michael Hanselmann
  # Wait for listening port
169 ca9ec5aa Michael Hanselmann
  impexpd_helper $dst_statusfile listen-port
170 2d76b580 Michael Hanselmann
}
171 2d76b580 Michael Hanselmann
172 ca9ec5aa Michael Hanselmann
do_export() {
173 2d76b580 Michael Hanselmann
  local port=$1
174 2d76b580 Michael Hanselmann
175 2d76b580 Michael Hanselmann
  $impexpd $src_statusfile export --bind=127.0.0.1 \
176 2d76b580 Michael Hanselmann
    --host=127.0.0.1 --port=$port \
177 2d76b580 Michael Hanselmann
    --key=$src_x509 --cert=$src_x509 --ca=$dst_x509 \
178 9d198e6f Michael Hanselmann
    --cmd-prefix="$cmd_prefix" --cmd-suffix="$cmd_suffix" \
179 9d198e6f Michael Hanselmann
    --connect-timeout=$connect_timeout \
180 7e3c1da6 Michael Hanselmann
    --connect-retries=$connect_retries \
181 1d3dfa29 Michael Hanselmann
    --compress=$compress ${magic:+--magic="$magic"}
182 2d76b580 Michael Hanselmann
}
183 2d76b580 Michael Hanselmann
184 2d76b580 Michael Hanselmann
do_import() {
185 2d76b580 Michael Hanselmann
  $impexpd $dst_statusfile import --bind=127.0.0.1 \
186 2d76b580 Michael Hanselmann
    --host=127.0.0.1 \
187 2d76b580 Michael Hanselmann
    --key=$dst_x509 --cert=$dst_x509 --ca=$src_x509 \
188 9d198e6f Michael Hanselmann
    --cmd-prefix="$cmd_prefix" --cmd-suffix="$cmd_suffix" \
189 9d198e6f Michael Hanselmann
    --connect-timeout=$connect_timeout \
190 7e3c1da6 Michael Hanselmann
    --connect-retries=$connect_retries \
191 1d3dfa29 Michael Hanselmann
    --compress=$compress ${magic:+--magic="$magic"}
192 2d76b580 Michael Hanselmann
}
193 2d76b580 Michael Hanselmann
194 9d198e6f Michael Hanselmann
upto 'Generate X509 certificates and keys'
195 d6547a1c Michael Hanselmann
impexpd_helper $src_x509 gencert 2>$gencert_output & srccertpid=$!
196 d6547a1c Michael Hanselmann
impexpd_helper $dst_x509 gencert 2>$gencert_output & dstcertpid=$!
197 d6547a1c Michael Hanselmann
impexpd_helper $other_x509 gencert 2>$gencert_output & othercertpid=$!
198 d6547a1c Michael Hanselmann
checkpids $srccertpid $dstcertpid $othercertpid || \
199 d6547a1c Michael Hanselmann
  err 'Failed to generate certificates'
200 2d76b580 Michael Hanselmann
201 ca9ec5aa Michael Hanselmann
start_test 'Normal case'
202 9d198e6f Michael Hanselmann
do_import > $statusdir/recv1 2>$dst_output & imppid=$!
203 ca9ec5aa Michael Hanselmann
if port=$(wait_import_ready 2>$src_output); then
204 ca9ec5aa Michael Hanselmann
  do_export $port < $testdata >>$src_output 2>&1 & exppid=$!
205 ca9ec5aa Michael Hanselmann
fi
206 2d76b580 Michael Hanselmann
checkpids $exppid $imppid || err 'An error occurred'
207 2d76b580 Michael Hanselmann
cmp $testdata $statusdir/recv1 || err 'Received data does not match input'
208 2d76b580 Michael Hanselmann
209 ca9ec5aa Michael Hanselmann
start_test 'Export using wrong CA'
210 9d198e6f Michael Hanselmann
# Setting lower timeout to not wait for too long
211 9d198e6f Michael Hanselmann
connect_timeout=1 do_import &>$dst_output & imppid=$!
212 ca9ec5aa Michael Hanselmann
if port=$(wait_import_ready 2>$src_output); then
213 ca9ec5aa Michael Hanselmann
  : | dst_x509=$other_x509 do_export $port >>$src_output 2>&1 & exppid=$!
214 ca9ec5aa Michael Hanselmann
fi
215 2d76b580 Michael Hanselmann
checkpids $exppid $imppid && err 'Export did not fail when using wrong CA'
216 2d76b580 Michael Hanselmann
217 ca9ec5aa Michael Hanselmann
start_test 'Import using wrong CA'
218 9d198e6f Michael Hanselmann
# Setting lower timeout to not wait for too long
219 9d198e6f Michael Hanselmann
src_x509=$other_x509 connect_timeout=1 do_import &>$dst_output & imppid=$!
220 ca9ec5aa Michael Hanselmann
if port=$(wait_import_ready 2>$src_output); then
221 ca9ec5aa Michael Hanselmann
  : | do_export $port >>$src_output 2>&1 & exppid=$!
222 ca9ec5aa Michael Hanselmann
fi
223 2d76b580 Michael Hanselmann
checkpids $exppid $imppid && err 'Import did not fail when using wrong CA'
224 2d76b580 Michael Hanselmann
225 ca9ec5aa Michael Hanselmann
start_test 'Suffix command on import'
226 9d198e6f Michael Hanselmann
cmd_suffix="| cksum > $statusdir/recv2" do_import &>$dst_output & imppid=$!
227 ca9ec5aa Michael Hanselmann
if port=$(wait_import_ready 2>$src_output); then
228 ca9ec5aa Michael Hanselmann
  do_export $port < $testdata >>$src_output 2>&1 & exppid=$!
229 ca9ec5aa Michael Hanselmann
fi
230 2d76b580 Michael Hanselmann
checkpids $exppid $imppid || err 'Testing additional commands failed'
231 2d76b580 Michael Hanselmann
cmp $statusdir/recv2 <(cksum < $testdata) || \
232 2d76b580 Michael Hanselmann
  err 'Checksum of received data does not match'
233 2d76b580 Michael Hanselmann
234 ca9ec5aa Michael Hanselmann
start_test 'Prefix command on export'
235 9d198e6f Michael Hanselmann
do_import > $statusdir/recv3 2>$dst_output & imppid=$!
236 ca9ec5aa Michael Hanselmann
if port=$(wait_import_ready 2>$src_output); then
237 ca9ec5aa Michael Hanselmann
  cmd_prefix='cksum |' do_export $port <$testdata >>$src_output 2>&1 & exppid=$!
238 ca9ec5aa Michael Hanselmann
fi
239 2d76b580 Michael Hanselmann
checkpids $exppid $imppid || err 'Testing additional commands failed'
240 2d76b580 Michael Hanselmann
cmp $statusdir/recv3 <(cksum < $testdata) || \
241 2d76b580 Michael Hanselmann
  err 'Received checksum does not match'
242 2d76b580 Michael Hanselmann
243 ca9ec5aa Michael Hanselmann
start_test 'Failing prefix command on export'
244 ca9ec5aa Michael Hanselmann
: | cmd_prefix='exit 1;' do_export 0 &>$src_output & exppid=$!
245 2d76b580 Michael Hanselmann
checkpids $exppid && err 'Prefix command on export did not fail when it should'
246 2d76b580 Michael Hanselmann
247 ca9ec5aa Michael Hanselmann
start_test 'Failing suffix command on export'
248 ca9ec5aa Michael Hanselmann
do_import >&$dst_output & imppid=$!
249 ca9ec5aa Michael Hanselmann
if port=$(wait_import_ready 2>$src_output); then
250 ca9ec5aa Michael Hanselmann
  : | cmd_suffix='| exit 1' do_export $port >>$src_output 2>&1 & exppid=$!
251 ca9ec5aa Michael Hanselmann
fi
252 2d76b580 Michael Hanselmann
checkpids $imppid $exppid && \
253 2d76b580 Michael Hanselmann
  err 'Suffix command on export did not fail when it should'
254 2d76b580 Michael Hanselmann
255 ca9ec5aa Michael Hanselmann
start_test 'Failing prefix command on import'
256 9d198e6f Michael Hanselmann
cmd_prefix='exit 1;' do_import &>$dst_output & imppid=$!
257 2d76b580 Michael Hanselmann
checkpids $imppid && err 'Prefix command on import did not fail when it should'
258 2d76b580 Michael Hanselmann
259 ca9ec5aa Michael Hanselmann
start_test 'Failing suffix command on import'
260 9d198e6f Michael Hanselmann
cmd_suffix='| exit 1' do_import &>$dst_output & imppid=$!
261 ca9ec5aa Michael Hanselmann
if port=$(wait_import_ready 2>$src_output); then
262 ca9ec5aa Michael Hanselmann
  : | do_export $port >>$src_output 2>&1 & exppid=$!
263 ca9ec5aa Michael Hanselmann
fi
264 2d76b580 Michael Hanselmann
checkpids $imppid $exppid && \
265 2d76b580 Michael Hanselmann
  err 'Suffix command on import did not fail when it should'
266 2d76b580 Michael Hanselmann
267 ca9ec5aa Michael Hanselmann
start_test 'Listen timeout A'
268 9d198e6f Michael Hanselmann
# Setting lower timeout to not wait too long (there won't be anything trying to
269 9d198e6f Michael Hanselmann
# connect)
270 9d198e6f Michael Hanselmann
connect_timeout=1 do_import &>$dst_output & imppid=$!
271 9d198e6f Michael Hanselmann
checkpids $imppid && \
272 9d198e6f Michael Hanselmann
  err 'Listening with timeout did not fail when it should'
273 9d198e6f Michael Hanselmann
274 ca9ec5aa Michael Hanselmann
start_test 'Listen timeout B'
275 9d198e6f Michael Hanselmann
do_import &>$dst_output & imppid=$!
276 ca9ec5aa Michael Hanselmann
if port=$(wait_import_ready 2>$src_output); then
277 ca9ec5aa Michael Hanselmann
  { sleep 1; : | do_export $port; } >>$src_output 2>&1 & exppid=$!
278 ca9ec5aa Michael Hanselmann
fi
279 9d198e6f Michael Hanselmann
checkpids $exppid $imppid || \
280 9d198e6f Michael Hanselmann
  err 'Listening with timeout failed when it should not'
281 9d198e6f Michael Hanselmann
282 ca9ec5aa Michael Hanselmann
start_test 'Connect timeout'
283 4dd97aa1 Michael Hanselmann
# Setting lower timeout as nothing will be listening on port 0
284 ca9ec5aa Michael Hanselmann
: | connect_timeout=1 do_export 0 &>$src_output & exppid=$!
285 4dd97aa1 Michael Hanselmann
checkpids $exppid && err 'Connection did not time out when it should'
286 4dd97aa1 Michael Hanselmann
287 ca9ec5aa Michael Hanselmann
start_test 'No compression'
288 7e3c1da6 Michael Hanselmann
compress=none do_import > $statusdir/recv-nocompr 2>$dst_output & imppid=$!
289 ca9ec5aa Michael Hanselmann
if port=$(wait_import_ready 2>$src_output); then
290 ca9ec5aa Michael Hanselmann
  compress=none do_export $port < $testdata >>$src_output 2>&1 & exppid=$!
291 ca9ec5aa Michael Hanselmann
fi
292 7e3c1da6 Michael Hanselmann
checkpids $exppid $imppid || err 'An error occurred'
293 7e3c1da6 Michael Hanselmann
cmp $testdata $statusdir/recv-nocompr || \
294 7e3c1da6 Michael Hanselmann
  err 'Received data does not match input'
295 7e3c1da6 Michael Hanselmann
296 ca9ec5aa Michael Hanselmann
start_test 'Compression mismatch A'
297 7e3c1da6 Michael Hanselmann
compress=none do_import > $statusdir/recv-miscompr 2>$dst_output & imppid=$!
298 ca9ec5aa Michael Hanselmann
if port=$(wait_import_ready 2>$src_output); then
299 ca9ec5aa Michael Hanselmann
  compress=gzip do_export $port < $testdata >>$src_output 2>&1 & exppid=$!
300 ca9ec5aa Michael Hanselmann
fi
301 7e3c1da6 Michael Hanselmann
checkpids $exppid $imppid || err 'An error occurred'
302 7e3c1da6 Michael Hanselmann
cmp -s $testdata $statusdir/recv-miscompr && \
303 7e3c1da6 Michael Hanselmann
  err 'Received data matches input when it should not'
304 7e3c1da6 Michael Hanselmann
305 ca9ec5aa Michael Hanselmann
start_test 'Compression mismatch B'
306 7e3c1da6 Michael Hanselmann
compress=gzip do_import > $statusdir/recv-miscompr2 2>$dst_output & imppid=$!
307 ca9ec5aa Michael Hanselmann
if port=$(wait_import_ready 2>$src_output); then
308 ca9ec5aa Michael Hanselmann
  compress=none do_export $port < $testdata >>$src_output 2>&1 & exppid=$!
309 ca9ec5aa Michael Hanselmann
fi
310 7e3c1da6 Michael Hanselmann
checkpids $exppid $imppid && err 'Did not fail when it should'
311 7e3c1da6 Michael Hanselmann
cmp -s $testdata $statusdir/recv-miscompr2 && \
312 7e3c1da6 Michael Hanselmann
  err 'Received data matches input when it should not'
313 7e3c1da6 Michael Hanselmann
314 1d3dfa29 Michael Hanselmann
start_test 'Magic without compression'
315 1d3dfa29 Michael Hanselmann
compress=none magic=MagicValue13582 \
316 1d3dfa29 Michael Hanselmann
do_import > $statusdir/recv-magic1 2>$dst_output & imppid=$!
317 1d3dfa29 Michael Hanselmann
if port=$(wait_import_ready 2>$src_output); then
318 1d3dfa29 Michael Hanselmann
  compress=none magic=MagicValue13582 \
319 1d3dfa29 Michael Hanselmann
  do_export $port < $testdata >>$src_output 2>&1 & exppid=$!
320 1d3dfa29 Michael Hanselmann
fi
321 1d3dfa29 Michael Hanselmann
checkpids $exppid $imppid || err 'An error occurred'
322 1d3dfa29 Michael Hanselmann
cmp $testdata $statusdir/recv-magic1 || err 'Received data does not match input'
323 1d3dfa29 Michael Hanselmann
324 1d3dfa29 Michael Hanselmann
start_test 'Magic with compression'
325 1d3dfa29 Michael Hanselmann
compress=gzip magic=yzD1FBH7Iw \
326 1d3dfa29 Michael Hanselmann
do_import > $statusdir/recv-magic2 2>$dst_output & imppid=$!
327 1d3dfa29 Michael Hanselmann
if port=$(wait_import_ready 2>$src_output); then
328 1d3dfa29 Michael Hanselmann
  compress=gzip magic=yzD1FBH7Iw \
329 1d3dfa29 Michael Hanselmann
  do_export $port < $testdata >>$src_output 2>&1 & exppid=$!
330 1d3dfa29 Michael Hanselmann
fi
331 1d3dfa29 Michael Hanselmann
checkpids $exppid $imppid || err 'An error occurred'
332 1d3dfa29 Michael Hanselmann
cmp $testdata $statusdir/recv-magic2 || err 'Received data does not match input'
333 1d3dfa29 Michael Hanselmann
334 1d3dfa29 Michael Hanselmann
start_test 'Magic mismatch A (same length)'
335 1d3dfa29 Michael Hanselmann
magic=h0tmIKXK do_import > $statusdir/recv-magic3 2>$dst_output & imppid=$!
336 1d3dfa29 Michael Hanselmann
if port=$(wait_import_ready 2>$src_output); then
337 1d3dfa29 Michael Hanselmann
  magic=bo6m9uAw do_export $port < $testdata >>$src_output 2>&1 & exppid=$!
338 1d3dfa29 Michael Hanselmann
fi
339 1d3dfa29 Michael Hanselmann
checkpids $exppid $imppid && err 'Did not fail when it should'
340 1d3dfa29 Michael Hanselmann
341 1d3dfa29 Michael Hanselmann
start_test 'Magic mismatch B'
342 1d3dfa29 Michael Hanselmann
magic=AUxVEWXVr5GK do_import > $statusdir/recv-magic4 2>$dst_output & imppid=$!
343 1d3dfa29 Michael Hanselmann
if port=$(wait_import_ready 2>$src_output); then
344 1d3dfa29 Michael Hanselmann
  magic=74RiP9KP do_export $port < $testdata >>$src_output 2>&1 & exppid=$!
345 1d3dfa29 Michael Hanselmann
fi
346 1d3dfa29 Michael Hanselmann
checkpids $exppid $imppid && err 'Did not fail when it should'
347 1d3dfa29 Michael Hanselmann
348 ca9ec5aa Michael Hanselmann
start_test 'Large transfer'
349 41a2e7d7 Michael Hanselmann
do_import > $statusdir/recv-large 2>$dst_output & imppid=$!
350 ca9ec5aa Michael Hanselmann
if port=$(wait_import_ready 2>$src_output); then
351 ca9ec5aa Michael Hanselmann
  do_export $port < $largetestdata >>$src_output 2>&1 & exppid=$!
352 ca9ec5aa Michael Hanselmann
fi
353 41a2e7d7 Michael Hanselmann
checkpids $exppid $imppid || err 'An error occurred'
354 41a2e7d7 Michael Hanselmann
cmp $largetestdata $statusdir/recv-large || \
355 41a2e7d7 Michael Hanselmann
  err 'Received data does not match input'
356 41a2e7d7 Michael Hanselmann
357 2d76b580 Michael Hanselmann
exit 0