Eric Blake
2019-Sep-12 16:14 UTC
[Libguestfs] [libnbd PATCH] nbdsh: Add test of handling globals in -c
Test that we can script the read of a specific pattern from nbdkit. Also, test that we can concatenate global functions through consecutive -c. This test fails if commit d6cbd130 is reverted. --- sh/Makefile.am | 5 ++++- sh/test-dump.sh | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100755 sh/test-dump.sh diff --git a/sh/Makefile.am b/sh/Makefile.am index 2eab987..50cd395 100644 --- a/sh/Makefile.am +++ b/sh/Makefile.am @@ -21,6 +21,7 @@ EXTRA_DIST = \ nbdsh.pod \ examples/LICENSE-FOR-EXAMPLES \ examples/hexdump.sh \ + test-dump.sh \ test-help.sh \ test-version.sh \ $(NULL) @@ -51,7 +52,9 @@ TESTS = \ if HAVE_NBDKIT -TESTS ++TESTS += \ + test-dump.sh \ + $(NULL) endif HAVE_NBDKIT diff --git a/sh/test-dump.sh b/sh/test-dump.sh new file mode 100755 index 0000000..2d4e261 --- /dev/null +++ b/sh/test-dump.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash +# nbd client library in userspace +# Copyright (C) 2019 Red Hat Inc. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +# Test interaction with nbdkit, and for correct global handling over -c. +nbdkit --exit-with-parent --version || exit 77 + +sock=`mktemp -u /tmp/nbdsh.XXXXXX` +pidfile=test-dump.pid +trap 'status=$?; rm -f $sock $pidfile; exit $status' INT QUIT TERM EXIT ERR +nbdkit -v -P $pidfile --exit-with-parent -U $sock pattern size=1m & + +# Wait for the pidfile to appear. +for i in {1..60}; do + if test -f "$pidfile"; then + break + fi + sleep 1 +done +if ! test -f "$pidfile"; then + echo "$0: nbdkit PID file $pidfile was not created" + exit 1 +fi + +nbdsh --connect "nbd+unix://?socket=$sock" \ + -c ' +def size(): + return h.get_size() +' \ + -c 'assert 1024*1024 == size()' \ + -c 'assert h.pread(8, 8) == b"\x00\x00\x00\x00\x00\x00\x00\x08"' -- 2.21.0
Richard W.M. Jones
2019-Sep-12 17:51 UTC
Re: [Libguestfs] [libnbd PATCH] nbdsh: Add test of handling globals in -c
On Thu, Sep 12, 2019 at 11:14:59AM -0500, Eric Blake wrote:> Test that we can script the read of a specific pattern from > nbdkit. Also, test that we can concatenate global functions through > consecutive -c. This test fails if commit d6cbd130 is reverted. > --- > sh/Makefile.am | 5 ++++- > sh/test-dump.sh | 45 +++++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 49 insertions(+), 1 deletion(-) > create mode 100755 sh/test-dump.sh > > diff --git a/sh/Makefile.am b/sh/Makefile.am > index 2eab987..50cd395 100644 > --- a/sh/Makefile.am > +++ b/sh/Makefile.am > @@ -21,6 +21,7 @@ EXTRA_DIST = \ > nbdsh.pod \ > examples/LICENSE-FOR-EXAMPLES \ > examples/hexdump.sh \ > + test-dump.sh \ > test-help.sh \ > test-version.sh \ > $(NULL) > @@ -51,7 +52,9 @@ TESTS = \ > > if HAVE_NBDKIT > > -TESTS +> +TESTS += \ > + test-dump.sh \ > + $(NULL) > > endif HAVE_NBDKIT > > diff --git a/sh/test-dump.sh b/sh/test-dump.sh > new file mode 100755 > index 0000000..2d4e261 > --- /dev/null > +++ b/sh/test-dump.sh > @@ -0,0 +1,45 @@ > +#!/usr/bin/env bash > +# nbd client library in userspace > +# Copyright (C) 2019 Red Hat Inc. > +# > +# This library is free software; you can redistribute it and/or > +# modify it under the terms of the GNU Lesser General Public > +# License as published by the Free Software Foundation; either > +# version 2 of the License, or (at your option) any later version. > +# > +# This library is distributed in the hope that it will be useful, > +# but WITHOUT ANY WARRANTY; without even the implied warranty of > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > +# Lesser General Public License for more details. > +# > +# You should have received a copy of the GNU Lesser General Public > +# License along with this library; if not, write to the Free Software > +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA > + > +# Test interaction with nbdkit, and for correct global handling over -c. > +nbdkit --exit-with-parent --version || exit 77 > + > +sock=`mktemp -u /tmp/nbdsh.XXXXXX` > +pidfile=test-dump.pid > +trap 'status=$?; rm -f $sock $pidfile; exit $status' INT QUIT TERM EXIT ERR > +nbdkit -v -P $pidfile --exit-with-parent -U $sock pattern size=1m & > + > +# Wait for the pidfile to appear. > +for i in {1..60}; do > + if test -f "$pidfile"; then > + break > + fi > + sleep 1 > +done > +if ! test -f "$pidfile"; then > + echo "$0: nbdkit PID file $pidfile was not created" > + exit 1 > +fi > + > +nbdsh --connect "nbd+unix://?socket=$sock" \ > + -c ' > +def size(): > + return h.get_size() > +' \ > + -c 'assert 1024*1024 == size()' \ > + -c 'assert h.pread(8, 8) == b"\x00\x00\x00\x00\x00\x00\x00\x08"' > -- > 2.21.0Seems reasonable, ACK. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-builder quickly builds VMs from scratch http://libguestfs.org/virt-builder.1.html
Seemingly Similar Threads
- [libnbd PATCH] nbdsh: Start adding unit tests
- [libnbd PATCH] nbdsh: Add -b option to simplify h.block_status
- [libnbd PATCH] nbdsh: Hide nbd.Error from abrt-python3-handler
- [libnbd PATCH] nbdsh: Support -u as synonym for --connect
- Problems with replication in the Samba 4