5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are
9 # * Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
12 # * Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
16 # * Neither the name of Red Hat nor the names of its contributors may be
17 # used to endorse or promote products derived from this software without
18 # specific prior written permission.
20 # THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
21 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23 # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
24 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
27 # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30 # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 plugin
=.libs
/test-stdio-plugin.
$SOEXT
39 requires
test -f $plugin
41 sock1
=$
(mktemp
-u /tmp
/nbdkit-test-sock.XXXXXX
)
42 sock2
=$
(mktemp
-u /tmp
/nbdkit-test-sock.XXXXXX
)
43 files
="test-stdio.in test-stdio.out test-stdio.err
44 test-stdio.pid1 test-stdio.pid2 $sock1 $sock2"
46 cleanup_fn
rm -f $files
48 # Using a seekable file lets us prove that if the plugin consumes less
49 # than the full input, the next process sees the rest
50 cat >test-stdio.
in <<EOF
55 # .dump_plugin using stdout is normal; using stdin is odd, but viable
56 { nbdkit
--dump-plugin $plugin; printf 'rest='; cat
57 } < test-stdio.
in > test-stdio.out
58 grep "input=string1" test-stdio.out
59 grep "rest=string2" test-stdio.out
62 nbdkit
-U - -v $plugin one
=1 --run 'printf cmd=; cat' \
63 < test-stdio.
in > test-stdio.out
65 grep "one=string1" test-stdio.out
66 grep "cmd=string2" test-stdio.out
68 # Test with -f; we have to repeat body of start_nbdkit ourselves
69 echo "string" | nbdkit
-P test-stdio.pid1
-v --filter=exitlast \
70 -f -U $sock1 $plugin two
=2 |
tee test-stdio.out
& pid
=$
!
72 if test -s test-stdio.pid1
; then
77 if ! test -s test-stdio.pid1
; then
78 echo "$0: PID file $pidfile was not created"
81 nbdsh
-u "nbd+unix:///?socket=$sock1" -c 'buf = h.pread(512, 0)'
83 grep "two=string" test-stdio.out
86 echo "string" | start_nbdkit
-P test-stdio.pid2
--filter=exitlast \
87 -U $sock2 $plugin three
=3 |
tee test-stdio.out
88 nbdsh
-u "nbd+unix:///?socket=$sock2" -c 'buf = h.pread(512, 0)'
89 grep "three=string" test-stdio.out
91 # Test with -s; here, the plugin produces no output.
93 h.connect_command(["nbdkit", "-v", "-s", "'$plugin'", "four=4"])