[PATCH 5/5] tests: Test detach-device and detach-device-alias for test driver
Luke Yue
lukedyue at gmail.com
Tue Aug 17 13:01:32 UTC 2021
On Tue, 2021-08-17 at 14:22 +0200, Martin Kletzander wrote:
> On Mon, Aug 16, 2021 at 07:19:49PM +0800, Luke Yue wrote:
> > Signed-off-by: Luke Yue <lukedyue at gmail.com>
> > ---
> > tests/virshtest.c | 24 ++++++++++++++++++++++++
> > 1 file changed, 24 insertions(+)
> >
> > diff --git a/tests/virshtest.c b/tests/virshtest.c
> > index 53db2aa19a..273596d636 100644
> > --- a/tests/virshtest.c
> > +++ b/tests/virshtest.c
> > @@ -291,6 +291,22 @@ static int
> > testCompareDomControlInfoByName(const void *data G_GNUC_UNUSED)
> > return testCompareOutputLit(exp, NULL, argv);
> > }
> >
> > +static int testCompareDetachDevice(const void *data G_GNUC_UNUSED)
> > +{
> > + const char *const argv[] = { VIRSH_CUSTOM, "detach-device",
> > "fc5",
> > +
> > "../examples/xml/test/testdevif.xml", NULL };
> > + const char *exp = "Device detached successfully\n\n";
> > + return testCompareOutputLit(exp, NULL, argv);
> > +}
> > +
> > +static int testCompareDetachDeviceAlias(const void *data
> > G_GNUC_UNUSED)
> > +{
> > + const char *const argv[] = { VIRSH_CUSTOM, "detach-device-
> > alias", "fc5",
> > + "ua-testCD", NULL };
> > + const char *exp = "Device detach request sent
> > successfully\n\n";
> > + return testCompareOutputLit(exp, NULL, argv);
> > +}
> > +
>
> Not many XMLs from the previous patch are used here. There could
> also
> be some negative tests (failing on a device that does not exist for
> example).
>
> But if you de-duplicate the code then you can also go the other route
> and test the generic functions without running 'virsh -c test:///...'
> for every piece of functionality.
>
No problem, will reimplement and and more tests in v2.
> > struct testInfo {
> > const char *const *argv;
> > const char *result;
> > @@ -383,6 +399,14 @@ mymain(void)
> > testCompareDomControlInfoByName, NULL) != 0)
> > ret = -1;
> >
> > + if (virTestRun("virsh detach-device",
> > + testCompareDetachDevice, NULL) != 0)
> > + ret = -1;
> > +
> > + if (virTestRun("virsh detach-device-alias",
> > + testCompareDetachDeviceAlias, NULL) != 0)
> > + ret = -1;
> > +
> > /* It's a bit awkward listing result before argument, but
> > that's a
> > * limitation of C99 vararg macros. */
> > # define DO_TEST(i, result, ...) \
> > --
> > 2.32.0
> >
More information about the libvir-list
mailing list