[libvirt PATCH v2 09/10] nodedev: Add testing for 'mdevctl stop'
Erik Skultety
eskultet at redhat.com
Thu Jun 11 14:25:23 UTC 2020
On Tue, Jun 09, 2020 at 04:43:49PM -0500, Jonathon Jongsma wrote:
> Test that we run 'mdevctl' with the proper arguments when we destroy
> mediated devices with virNodeDeviceDestroy()
>
> Signed-off-by: Jonathon Jongsma <jjongsma at redhat.com>
> ---
> tests/nodedevmdevctldata/mdevctl-stop.argv | 1 +
> tests/nodedevmdevctltest.c | 43 ++++++++++++++++++++++
> 2 files changed, 44 insertions(+)
> create mode 100644 tests/nodedevmdevctldata/mdevctl-stop.argv
>
> diff --git a/tests/nodedevmdevctldata/mdevctl-stop.argv b/tests/nodedevmdevctldata/mdevctl-stop.argv
> new file mode 100644
> index 0000000000..25ee7145ce
> --- /dev/null
> +++ b/tests/nodedevmdevctldata/mdevctl-stop.argv
> @@ -0,0 +1 @@
> +/usr/sbin/mdevctl stop -u e2451f73-c95b-4124-b900-e008af37c576
> diff --git a/tests/nodedevmdevctltest.c b/tests/nodedevmdevctltest.c
> index 32a22246c2..58ebf976e2 100644
> --- a/tests/nodedevmdevctltest.c
> +++ b/tests/nodedevmdevctltest.c
> @@ -98,6 +98,42 @@ testMdevctlStartHelper(const void *data)
> jsonfile);
> }
>
> +static int
> +testMdevctlStopHelper(const void *data)
This is not very symmetric to the StartHelper, maybe we can call this one
MdevctlStop directly?
> +{
> + const char *uuid = data;
> + virBuffer buf = VIR_BUFFER_INITIALIZER;
> + const char *actualCmdline = NULL;
> + int ret = -1;
> + g_autoptr(virCommand) cmd = NULL;
> +
> + g_autofree char *cmdlinefile =
> + g_strdup_printf("%s/nodedevmdevctldata/mdevctl-stop.argv",
> + abs_srcdir);
> +
> + cmd = nodeDeviceGetMdevctlStopCommand(uuid, false);
> +
> + if (!cmd)
> + goto cleanup;
> +
> + virCommandSetDryRun(&buf, NULL, NULL);
> + if (virCommandRun(cmd, NULL) < 0)
> + goto cleanup;
> +
> + if (!(actualCmdline = virBufferCurrentContent(&buf)))
> + goto cleanup;
> +
> + if (virTestCompareToFile(actualCmdline, cmdlinefile) < 0)
> + goto cleanup;
> +
> + ret = 0;
> +
> + cleanup:
> + virBufferFreeAndReset(&buf);
> + virCommandSetDryRun(NULL, NULL, NULL);
> + return ret;
> +}
> +
> static void
> nodedevTestDriverFree(virNodeDeviceDriverStatePtr drv)
> {
> @@ -248,6 +284,13 @@ mymain(void)
> DO_TEST("mdev_fedc4916_1ca8_49ac_b176_871d16c13076");
> DO_TEST("mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9");
>
> + // Test mdevctl stop command, pass an arbitrary uuid
/* ... */
> + if (virTestRun("mdevctl stop", testMdevctlStopHelper,
> + "e2451f73-c95b-4124-b900-e008af37c576") < 0)
Can we remain consistent with the usage of macros and rework DO_TEST_FULL so
that mdevctl stop could be run through the DO_TEST macro?
Erik
More information about the libvir-list
mailing list