[PATCH libnbd] golang: tests: Fix error handling
Like lot of the C examples, the aio copy test ignores read and write errors in the completion callback, which can cause silent data corruption. The failure in the test is not critical, but this is a bad example that may be copied by developers to a real application. The test panics now if completion callback fails, similar to other Go examples. Signed-off-by: Nir Soffer <nsoffer@redhat.com> --- golang/libnbd_590_aio_copy_test.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/golang/libnbd_590_aio_copy_test.go b/golang/libnbd_590_aio_copy_test.go index 570635c9..8be0ad2d 100644 --- a/golang/libnbd_590_aio_copy_test.go +++ b/golang/libnbd_590_aio_copy_test.go @@ -99,33 +99,41 @@ func asynch_copy(t *testing.T, src *Libnbd, dst *Libnbd) { source then do it now. */ if soff < size && src_in_flight < max_reads_in_flight { n := bs if n > size-soff { n = size - soff } buf := MakeAioBuffer(uint(n)) soff_copy := soff var optargs AioPreadOptargs optargs.CompletionCallbackSet = true - optargs.CompletionCallback = func(*int) int { + optargs.CompletionCallback = func(error *int) int { + if *error != 0 { + err := syscall.Errno(*error).Error() + panic(err) + } return read_completed(buf, soff_copy) } src.AioPread(buf, soff, &optargs) soff += n } /* If there are any write commands waiting to be issued, send them now. */ for _, wb := range writes { var optargs AioPwriteOptargs optargs.CompletionCallbackSet = true - optargs.CompletionCallback = func(*int) int { + optargs.CompletionCallback = func(error *int) int { + if *error != 0 { + err := syscall.Errno(*error).Error() + panic(err) + } return write_completed(wb.buf) } dst.AioPwrite(wb.buf, wb.offset, &optargs) } writes = writes[:0] /* Now poll the file descriptors. */ nfd := 1 sfd, err := src.AioGetFd() if err != nil { -- 2.34.1
On Thu, Feb 03, 2022 at 08:07:52PM +0200, Nir Soffer wrote:
Like lot of the C examples, the aio copy test ignores read and write errors in the completion callback, which can cause silent data corruption. The failure in the test is not critical, but this is a bad example that may be copied by developers to a real application.
The test panics now if completion callback fails, similar to other Go examples.
Signed-off-by: Nir Soffer <nsoffer@redhat.com> --- golang/libnbd_590_aio_copy_test.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
ACK. python/t/590-aio-copy.py and ocaml/tests/test_490_aio_copy.ml need the same treatment. I'll post that with my v2 of the CVE fix. (It's nice that we've tried to share the same test numbers across language bindings - it makes it a bit easier where we copy the same coding paradigms across different languages) -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
On Thu, Feb 3, 2022 at 9:24 PM Eric Blake <eblake@redhat.com> wrote:
On Thu, Feb 03, 2022 at 08:07:52PM +0200, Nir Soffer wrote:
Like lot of the C examples, the aio copy test ignores read and write errors in the completion callback, which can cause silent data corruption. The failure in the test is not critical, but this is a bad example that may be copied by developers to a real application.
The test panics now if completion callback fails, similar to other Go examples.
Signed-off-by: Nir Soffer <nsoffer@redhat.com> --- golang/libnbd_590_aio_copy_test.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
ACK.
Thanks, pushed as b80780e980275a879c13d27aff1449f91f883ce6
python/t/590-aio-copy.py and ocaml/tests/test_490_aio_copy.ml need the same treatment. I'll post that with my v2 of the CVE fix.
(It's nice that we've tried to share the same test numbers across language bindings - it makes it a bit easier where we copy the same coding paradigms across different languages)
I wondered why we are using these numbers. I think using same pattern like {lang}/tests/{name}_test.{suffix} would be nicer. Nir
On Thu, Feb 03, 2022 at 09:39:24PM +0200, Nir Soffer wrote:
On Thu, Feb 3, 2022 at 9:24 PM Eric Blake <eblake@redhat.com> wrote:
On Thu, Feb 03, 2022 at 08:07:52PM +0200, Nir Soffer wrote:
Like lot of the C examples, the aio copy test ignores read and write errors in the completion callback, which can cause silent data corruption. The failure in the test is not critical, but this is a bad example that may be copied by developers to a real application.
The test panics now if completion callback fails, similar to other Go examples.
Signed-off-by: Nir Soffer <nsoffer@redhat.com> --- golang/libnbd_590_aio_copy_test.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
ACK.
Thanks, pushed as b80780e980275a879c13d27aff1449f91f883ce6
python/t/590-aio-copy.py and ocaml/tests/test_490_aio_copy.ml need the same treatment. I'll post that with my v2 of the CVE fix.
(It's nice that we've tried to share the same test numbers across language bindings - it makes it a bit easier where we copy the same coding paradigms across different languages)
I wondered why we are using these numbers. I think using same pattern like {lang}/tests/{name}_test.{suffix} would be nicer.
But we want to run them in order, or at least express that there is an ordering to them. 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
On Thu, Feb 3, 2022 at 9:55 PM Richard W.M. Jones <rjones@redhat.com> wrote:
On Thu, Feb 03, 2022 at 09:39:24PM +0200, Nir Soffer wrote:
On Thu, Feb 3, 2022 at 9:24 PM Eric Blake <eblake@redhat.com> wrote:
On Thu, Feb 03, 2022 at 08:07:52PM +0200, Nir Soffer wrote:
Like lot of the C examples, the aio copy test ignores read and write errors in the completion callback, which can cause silent data corruption. The failure in the test is not critical, but this is a bad example that may be copied by developers to a real application.
The test panics now if completion callback fails, similar to other Go examples.
Signed-off-by: Nir Soffer <nsoffer@redhat.com> --- golang/libnbd_590_aio_copy_test.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
ACK.
Thanks, pushed as b80780e980275a879c13d27aff1449f91f883ce6
python/t/590-aio-copy.py and ocaml/tests/test_490_aio_copy.ml need the same treatment. I'll post that with my v2 of the CVE fix.
(It's nice that we've tried to share the same test numbers across language bindings - it makes it a bit easier where we copy the same coding paradigms across different languages)
I wondered why we are using these numbers. I think using same pattern like {lang}/tests/{name}_test.{suffix} would be nicer.
But we want to run them in order, or at least express that there is an ordering to them.
Tests ordering is an anti-pattern. Tests must not depend on each other so you can run any tests in any order. The only reason I can see for ordering tests is easier to use output when you compare failures, you know where to find the names. This can be done by the test runner (e.g sort tests before running them). Nir
On Thu, Feb 03, 2022 at 10:42:09PM +0200, Nir Soffer wrote:
I wondered why we are using these numbers. I think using same pattern like {lang}/tests/{name}_test.{suffix} would be nicer.
But we want to run them in order, or at least express that there is an ordering to them.
Tests ordering is an anti-pattern. Tests must not depend on each other so you can run any tests in any order.
They are independent, you should be able to run any of the tests in isolation (modulo however easy or hard it is to convince that language to run a subset of its testsuite). But our numbering still makes sense: if tests 1xx and 5xx both fail, we are better off debugging the failure in 1xx first, because we've hosed the core interaction with the language bindings, whereas 5xx is more the application usage built on top of what is assumed to be a working core. -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
On Thu, Feb 3, 2022 at 10:52 PM Eric Blake <eblake@redhat.com> wrote:
On Thu, Feb 03, 2022 at 10:42:09PM +0200, Nir Soffer wrote:
I wondered why we are using these numbers. I think using same pattern like {lang}/tests/{name}_test.{suffix} would be nicer.
But we want to run them in order, or at least express that there is an ordering to them.
Tests ordering is an anti-pattern. Tests must not depend on each other so you can run any tests in any order.
They are independent, you should be able to run any of the tests in isolation (modulo however easy or hard it is to convince that language to run a subset of its testsuite). But our numbering still makes sense: if tests 1xx and 5xx both fail, we are better off debugging the failure in 1xx first, because we've hosed the core interaction with the language bindings, whereas 5xx is more the application usage built on top of what is assumed to be a working core.
These semantics can be expressed better with names. For example keep the core tests in core/ directory, application tests in application/, or use file name prefix: libnbd_core_handle_test.go ... libnbd_app_aio_copy_test.go Nir
On Thu, Feb 03, 2022 at 09:39:24PM +0200, Nir Soffer wrote:
On Thu, Feb 3, 2022 at 9:24 PM Eric Blake <eblake@redhat.com> wrote:
On Thu, Feb 03, 2022 at 08:07:52PM +0200, Nir Soffer wrote:
Like lot of the C examples, the aio copy test ignores read and write errors in the completion callback, which can cause silent data corruption. The failure in the test is not critical, but this is a bad example that may be copied by developers to a real application.
The test panics now if completion callback fails, similar to other Go examples.
Signed-off-by: Nir Soffer <nsoffer@redhat.com> --- golang/libnbd_590_aio_copy_test.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
ACK.
Thanks, pushed as b80780e980275a879c13d27aff1449f91f883ce6
python/t/590-aio-copy.py and ocaml/tests/test_490_aio_copy.ml need the
s/490/590/
same treatment. I'll post that with my v2 of the CVE fix.
(It's nice that we've tried to share the same test numbers across language bindings - it makes it a bit easier where we copy the same coding paradigms across different languages)
I wondered why we are using these numbers. I think using same pattern like {lang}/tests/{name}_test.{suffix} would be nicer.
Yeah, except that different languages have their own idioms for how a testsuite should look, such as Go requiring the package name in the unit test file name, or python wanting unit tests under subdirectory t/. The great thing about standards is there's so many to pick from ;) -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
participants (3)
-
Eric Blake -
Nir Soffer -
Richard W.M. Jones