]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
commandtest: Use virTestCompareToFile() in checkoutput()
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 22 Mar 2022 12:36:38 +0000 (13:36 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 1 Dec 2022 13:22:39 +0000 (14:22 +0100)
In the commandtest there is checkoutput() function which checks
the latest log of commandhelper (containing things like cmd line
arguments, env vars, FDs, CWD, etc.) and compares that against
expected output. Well, the way this function implements that is
effectively by open coding virTestCompareToFile() except for the
nice feature that the virTestCompareToFile() has:
VIR_TEST_OUTPUT_REGENERATE.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
tests/commandtest.c

index 6d45ff196f0be0e3cb9d50211c5bcac800f0bf3b..ffc4b24ef422bfee54f966921d1f4266a10b513e 100644 (file)
@@ -58,29 +58,18 @@ static int checkoutput(const char *testname)
 {
     int ret = -1;
     g_autofree char *expectname = NULL;
-    g_autofree char *expectlog = NULL;
     g_autofree char *actualname = NULL;
     g_autofree char *actuallog = NULL;
 
     expectname = g_strdup_printf("%s/commanddata/%s.log", abs_srcdir, testname);
     actualname = g_strdup_printf("%s/commandhelper.log", abs_builddir);
 
-    if (virFileReadAll(expectname, 1024*64, &expectlog) < 0) {
-        fprintf(stderr, "cannot read %s\n", expectname);
-        goto cleanup;
-    }
-
     if (virFileReadAll(actualname, 1024*64, &actuallog) < 0) {
         fprintf(stderr, "cannot read %s\n", actualname);
         goto cleanup;
     }
 
-    if (STRNEQ(expectlog, actuallog)) {
-        virTestDifference(stderr, expectlog, actuallog);
-        goto cleanup;
-    }
-
-    ret = 0;
+    ret = virTestCompareToFile(actuallog, expectname);
 
  cleanup:
     if (actualname)
@@ -1292,6 +1281,7 @@ mymain(void)
      * since we're about to reset 'environ' */
     ignore_value(virTestGetDebug());
     ignore_value(virTestGetVerbose());
+    ignore_value(virTestGetRegenerate());
 
     /* Make sure to not leak fd's */
     virinitret = virInitialize();