nodedevmdevctltest: Use internal linewrapping and variable command path stripping

Remove `nodedevCompareToFile` which was stripping the path to mdevctl
since it's no longer needed if we use the new features of
virCommandSetDryRun.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
Peter Krempa 2021-04-09 09:21:28 +02:00
parent 2dcbdc7f4b
commit d146b193e2
11 changed files with 44 additions and 32 deletions

View File

@ -1,2 +1,5 @@
$MDEVCTL_BINARY$ define -p 0000:00:02.0 --jsonfile /dev/stdin \ mdevctl \
define \
-p 0000:00:02.0 \
--jsonfile /dev/stdin \
--uuid=d069d019-36ea-4111-8f0a-8c9a70e21366 --uuid=d069d019-36ea-4111-8f0a-8c9a70e21366

View File

@ -1,2 +1,5 @@
$MDEVCTL_BINARY$ start -p 0000:00:02.0 --jsonfile /dev/stdin \ mdevctl \
start \
-p 0000:00:02.0 \
--jsonfile /dev/stdin \
--uuid=d069d019-36ea-4111-8f0a-8c9a70e21366 --uuid=d069d019-36ea-4111-8f0a-8c9a70e21366

View File

@ -1 +1,4 @@
$MDEVCTL_BINARY$ define -p 0000:00:02.0 --jsonfile /dev/stdin mdevctl \
define \
-p 0000:00:02.0 \
--jsonfile /dev/stdin

View File

@ -1 +1,4 @@
$MDEVCTL_BINARY$ start -p 0000:00:02.0 --jsonfile /dev/stdin mdevctl \
start \
-p 0000:00:02.0 \
--jsonfile /dev/stdin

View File

@ -1 +1,4 @@
$MDEVCTL_BINARY$ define -p 0000:00:02.0 --jsonfile /dev/stdin mdevctl \
define \
-p 0000:00:02.0 \
--jsonfile /dev/stdin

View File

@ -1 +1,4 @@
$MDEVCTL_BINARY$ start -p 0000:00:02.0 --jsonfile /dev/stdin mdevctl \
start \
-p 0000:00:02.0 \
--jsonfile /dev/stdin

View File

@ -1 +1,3 @@
$MDEVCTL_BINARY$ start -u 8a05ad83-3472-497d-8631-8142f31460e8 mdevctl \
start \
-u 8a05ad83-3472-497d-8631-8142f31460e8

View File

@ -1 +1,4 @@
$MDEVCTL_BINARY$ list --dumpjson --defined mdevctl \
list \
--dumpjson \
--defined

View File

@ -1 +1,3 @@
$MDEVCTL_BINARY$ stop -u e2451f73-c95b-4124-b900-e008af37c576 mdevctl \
stop \
-u e2451f73-c95b-4124-b900-e008af37c576

View File

@ -1 +1,3 @@
$MDEVCTL_BINARY$ undefine -u d76a6b78-45ed-4149-a325-005f9abc5281 mdevctl \
undefine \
-u d76a6b78-45ed-4149-a325-005f9abc5281

View File

@ -40,21 +40,6 @@ testCommandDryRunCallback(const char *const*args G_GNUC_UNUSED,
*stdinbuf = g_strdup(input); *stdinbuf = g_strdup(input);
} }
/* We don't want the result of the test to depend on the path to the mdevctl
* binary on the developer's machine, so replace the path to mdevctl with a
* placeholder string before comparing to the expected output */
static int
nodedevCompareToFile(const char *actual,
const char *filename)
{
g_autofree char *replacedCmdline = NULL;
replacedCmdline = virStringReplace(actual, MDEVCTL, "$MDEVCTL_BINARY$");
return virTestCompareToFile(replacedCmdline, filename);
}
typedef virCommand* (*MdevctlCmdFunc)(virNodeDeviceDef *, char **, char **); typedef virCommand* (*MdevctlCmdFunc)(virNodeDeviceDef *, char **, char **);
@ -87,14 +72,14 @@ testMdevctlStartOrDefine(const char *virt_type,
if (!cmd) if (!cmd)
goto cleanup; goto cleanup;
virCommandSetDryRun(dryRunToken, &buf, false, false, testCommandDryRunCallback, &stdinbuf); virCommandSetDryRun(dryRunToken, &buf, true, true, testCommandDryRunCallback, &stdinbuf);
if (virCommandRun(cmd, NULL) < 0) if (virCommandRun(cmd, NULL) < 0)
goto cleanup; goto cleanup;
if (!(actualCmdline = virBufferCurrentContent(&buf))) if (!(actualCmdline = virBufferCurrentContent(&buf)))
goto cleanup; goto cleanup;
if (nodedevCompareToFile(actualCmdline, cmdfile) < 0) if (virTestCompareToFileFull(actualCmdline, cmdfile, false) < 0)
goto cleanup; goto cleanup;
if (virTestCompareToFile(stdinbuf, jsonfile) < 0) if (virTestCompareToFile(stdinbuf, jsonfile) < 0)
@ -159,14 +144,14 @@ testMdevctlUuidCommand(const char *uuid, GetStopUndefineCmdFunc func, const char
if (!cmd) if (!cmd)
goto cleanup; goto cleanup;
virCommandSetDryRun(dryRunToken, &buf, false, false, NULL, NULL); virCommandSetDryRun(dryRunToken, &buf, true, true, NULL, NULL);
if (virCommandRun(cmd, NULL) < 0) if (virCommandRun(cmd, NULL) < 0)
goto cleanup; goto cleanup;
if (!(actualCmdline = virBufferCurrentContent(&buf))) if (!(actualCmdline = virBufferCurrentContent(&buf)))
goto cleanup; goto cleanup;
if (nodedevCompareToFile(actualCmdline, outfile) < 0) if (virTestCompareToFileFull(actualCmdline, outfile, false) < 0)
goto cleanup; goto cleanup;
ret = 0; ret = 0;
@ -221,14 +206,14 @@ testMdevctlListDefined(const void *data G_GNUC_UNUSED)
if (!cmd) if (!cmd)
goto cleanup; goto cleanup;
virCommandSetDryRun(dryRunToken, &buf, false, false, NULL, NULL); virCommandSetDryRun(dryRunToken, &buf, true, true, NULL, NULL);
if (virCommandRun(cmd, NULL) < 0) if (virCommandRun(cmd, NULL) < 0)
goto cleanup; goto cleanup;
if (!(actualCmdline = virBufferCurrentContent(&buf))) if (!(actualCmdline = virBufferCurrentContent(&buf)))
goto cleanup; goto cleanup;
if (nodedevCompareToFile(actualCmdline, cmdlinefile) < 0) if (virTestCompareToFileFull(actualCmdline, cmdlinefile, false) < 0)
goto cleanup; goto cleanup;
ret = 0; ret = 0;
@ -270,7 +255,7 @@ testMdevctlParse(const void *data)
virBufferAddStr(&xmloutbuf, devxml); virBufferAddStr(&xmloutbuf, devxml);
} }
if (nodedevCompareToFile(virBufferCurrentContent(&xmloutbuf), xmloutfile) < 0) if (virTestCompareToFileFull(virBufferCurrentContent(&xmloutbuf), xmloutfile, false) < 0)
goto cleanup; goto cleanup;
ret = 0; ret = 0;