[Libguestfs] [libnbd PATCH 2/2] ocaml: Fix test 505

Eric Blake eblake at redhat.com
Wed Aug 14 18:54:34 UTC 2019


The logic in this test was wrong (blindly copied from a similar test
in python), but masked by other problems until recently.  The fourth
test claims to fail during only chunk, but passed '42' as the
user_data for callback which requires that !err be 0; if chunk had
actually failed, !err should be non-zero.

We're overloading a single user_data int to try and control two
orthogonal things (what to expect in err, and whether to fail); let's
instead make the callback user_data a tuple.

Fixes: ce0f2126
---
 .../test_505_aio_pread_structured_callback.ml      | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/ocaml/tests/test_505_aio_pread_structured_callback.ml b/ocaml/tests/test_505_aio_pread_structured_callback.ml
index 075ec85..433dc27 100644
--- a/ocaml/tests/test_505_aio_pread_structured_callback.ml
+++ b/ocaml/tests/test_505_aio_pread_structured_callback.ml
@@ -45,12 +45,12 @@ let chunk user_data buf2 offset s err =
   0

 let callback user_data err =
-  if user_data <= 43 then
+  if fst user_data = 42 then
     assert (!err = 0)
   else
     assert (!err = 100);
   err := 101;
-  assert (user_data = 42);
+  assert (snd user_data = 42);
   0

 let () =
@@ -61,7 +61,7 @@ let () =
   (* First try: succeed in both callbacks *)
   let buf = NBD.Buffer.alloc 512 in
   let cookie = NBD.aio_pread_structured nbd buf 0_L (chunk 42)
-                 ~completion:(callback 42) in
+                 ~completion:(callback (42, 42)) in
   while not (NBD.aio_command_completed nbd cookie) do
     ignore (NBD.poll nbd (-1))
   done;
@@ -73,7 +73,7 @@ let () =
   (* Second try: fail only during callback *)
   let buf = NBD.Buffer.alloc 512 in
   let cookie = NBD.aio_pread_structured nbd buf 0_L (chunk 42)
-                 ~completion:(callback 43) in
+                 ~completion:(callback (42, 43)) in
   try
     while not (NBD.aio_command_completed nbd cookie) do
       ignore (NBD.poll nbd (-1))
@@ -86,8 +86,8 @@ let () =

   (* Third try: fail during both *)
   let buf = NBD.Buffer.alloc 512 in
-  let cookie = NBD.aio_pread_structured nbd buf 0_L (chunk 43)
-                 ~completion:(callback 44) in
+  let cookie = NBD.aio_pread_structured nbd buf 0_L (chunk 44)
+                 ~completion:(callback (43, 43)) in
   try
     while not (NBD.aio_command_completed nbd cookie) do
       ignore (NBD.poll nbd (-1))
@@ -101,7 +101,7 @@ let () =
   (* Fourth try: fail only during chunk *)
   let buf = NBD.Buffer.alloc 512 in
   let cookie = NBD.aio_pread_structured nbd buf 0_L (chunk 43)
-                 ~completion:(callback 42) in
+                 ~completion:(callback (43, 42)) in
   try
     while not (NBD.aio_command_completed nbd cookie) do
       ignore (NBD.poll nbd (-1))
-- 
2.20.1




More information about the Libguestfs mailing list