[PATCH] commandtest: Fix test28 error detection

Michal Privoznik posted 1 patch 4 years, 1 month ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/0c838d4dec96fb5f26a98590ba6f3f571b937586.1585054475.git.mprivozn@redhat.com
tests/commandtest.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
[PATCH] commandtest: Fix test28 error detection
Posted by Michal Privoznik 4 years, 1 month ago
As a part of c799d150d5e9dae I've introduced a test case that
tests whether passing error object between processes works. The
test spawns a child which reports a system error, parent process
then reads the error and compares with expected output. Problem
with this approach is that error message contains stringified
errno which is not portable. FreeBSD has generally different
messages than Linux. Therefore, use g_strerror() to do the errno
to string translation for us.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 tests/commandtest.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/tests/commandtest.c b/tests/commandtest.c
index f4a2c67c05..d5092b7dd0 100644
--- a/tests/commandtest.c
+++ b/tests/commandtest.c
@@ -1272,6 +1272,7 @@ test28(const void *unused G_GNUC_UNUSED)
     /* Not strictly a virCommand test, but this is the easiest place
      * to test this lower-level interface. */
     virErrorPtr err;
+    g_autofree char *msg = g_strdup_printf("some error message: %s", g_strerror(ENODATA));
 
     if (virProcessRunInFork(test28Callback, NULL) != -1) {
         fprintf(stderr, "virProcessRunInFork did not fail\n");
@@ -1285,10 +1286,10 @@ test28(const void *unused G_GNUC_UNUSED)
 
     if (!(err->code == VIR_ERR_SYSTEM_ERROR &&
           err->domain == 0 &&
-          STREQ(err->message, "some error message: No data available") &&
+          STREQ(err->message, msg) &&
           err->level == VIR_ERR_ERROR &&
           STREQ(err->str1, "%s") &&
-          STREQ(err->str2, "some error message: No data available") &&
+          STREQ(err->str2, msg) &&
           err->int1 == ENODATA &&
           err->int2 == -1)) {
         fprintf(stderr, "Unexpected error object\n");
-- 
2.24.1

Re: [PATCH] commandtest: Fix test28 error detection
Posted by Daniel P. Berrangé 4 years, 1 month ago
On Tue, Mar 24, 2020 at 01:54:35PM +0100, Michal Privoznik wrote:
> As a part of c799d150d5e9dae I've introduced a test case that
> tests whether passing error object between processes works. The
> test spawns a child which reports a system error, parent process
> then reads the error and compares with expected output. Problem
> with this approach is that error message contains stringified
> errno which is not portable. FreeBSD has generally different
> messages than Linux. Therefore, use g_strerror() to do the errno
> to string translation for us.
> 
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
>  tests/commandtest.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|