commandtest: Use virTestCompareToFile() in checkoutput()

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>
This commit is contained in:
Michal Privoznik 2022-03-22 13:36:38 +01:00
parent e97b6f4bc5
commit f3b049e878

View File

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