virshtest: Replace list and nodeinfo tests by equivalent VIR_TEST_SCRIPT variant

Add the basic list and info commands into a script and run it via
VIR_TEST_RUN_SCRIPT to simplify the code and save up on 'virsh'
instances exec'd for the test.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2024-03-20 17:34:45 +01:00
parent e8e79e38e5
commit 4b8581b8ef
5 changed files with 35 additions and 76 deletions

View File

@ -159,66 +159,6 @@ static char *custom_uri;
"--connect", \
custom_uri
static int testCompareListDefault(const void *data)
{
const char *const argv[] = { VIRSH_DEFAULT, "list", NULL };
const char *exp = "\
Id Name State\n\
----------------------\n\
1 test running\n\
\n";
return testCompareOutputLit((const char *) data, exp, NULL, argv);
}
static int testCompareListCustom(const void *data)
{
const char *const argv[] = { VIRSH_CUSTOM, "list", NULL };
const char *exp = "\
Id Name State\n\
----------------------\n\
1 fv0 running\n\
2 fc4 running\n\
3 fc5 running\n\
\n";
return testCompareOutputLit((const char *) data, exp, NULL, argv);
}
static int testCompareNodeinfoDefault(const void *data)
{
const char *const argv[] = { VIRSH_DEFAULT, "nodeinfo", NULL };
const char *exp = "\
CPU model: i686\n\
CPU(s): 16\n\
CPU frequency: 1400 MHz\n\
CPU socket(s): 2\n\
Core(s) per socket: 2\n\
Thread(s) per core: 2\n\
NUMA cell(s): 2\n\
Memory size: 3145728 KiB\n\
\n";
return testCompareOutputLit((const char *) data, exp, NULL, argv);
}
static int testCompareNodeinfoCustom(const void *data)
{
const char *const argv[] = {
VIRSH_CUSTOM,
"nodeinfo",
NULL
};
const char *exp = "\
CPU model: i986\n\
CPU(s): 50\n\
CPU frequency: 6000 MHz\n\
CPU socket(s): 4\n\
Core(s) per socket: 4\n\
Thread(s) per core: 2\n\
NUMA cell(s): 4\n\
Memory size: 8192000 KiB\n\
\n";
return testCompareOutputLit((const char *) data, exp, NULL, argv);
}
static int testCompareDominfoByID(const void *data)
{
const char *const argv[] = { VIRSH_CUSTOM, "dominfo", "2", NULL };
@ -464,22 +404,6 @@ mymain(void)
custom_uri = g_strdup_printf("test://%s/../examples/xml/test/testnode.xml",
abs_srcdir);
if (virTestRun("virsh list (default)",
testCompareListDefault, NULL) != 0)
ret = -1;
if (virTestRun("virsh list (custom)",
testCompareListCustom, NULL) != 0)
ret = -1;
if (virTestRun("virsh nodeinfo (default)",
testCompareNodeinfoDefault, NULL) != 0)
ret = -1;
if (virTestRun("virsh nodeinfo (custom)",
testCompareNodeinfoCustom, NULL) != 0)
ret = -1;
if (virTestRun("virsh dominfo (by id)",
testCompareDominfoByID, NULL) != 0)
ret = -1;
@ -580,6 +504,9 @@ mymain(void)
ret = -1; \
} while (0);
DO_TEST_SCRIPT("info-default", NULL, VIRSH_DEFAULT);
DO_TEST_SCRIPT("info-custom", NULL, VIRSH_CUSTOM);
# define DO_TEST_FULL(testname_, filter, ...) \
do { \
const char *testname = testname_; \

View File

@ -0,0 +1,2 @@
list
nodeinfo

View File

@ -0,0 +1,15 @@
Id Name State
----------------------
1 fv0 running
2 fc4 running
3 fc5 running
CPU model: i986
CPU(s): 50
CPU frequency: 6000 MHz
CPU socket(s): 4
Core(s) per socket: 4
Thread(s) per core: 2
NUMA cell(s): 4
Memory size: 8192000 KiB

View File

@ -0,0 +1,2 @@
list
nodeinfo

View File

@ -0,0 +1,13 @@
Id Name State
----------------------
1 test running
CPU model: i686
CPU(s): 16
CPU frequency: 1400 MHz
CPU socket(s): 2
Core(s) per socket: 2
Thread(s) per core: 2
NUMA cell(s): 2
Memory size: 3145728 KiB