mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 05:35:25 +00:00
vircaps2xmltest: Introduce basic testing
For now only one test is introduced. It's purpose in life is to check we don't break NUMA host distances XML format. Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
9b8d6e1eef
commit
6af0623234
@ -124,6 +124,7 @@ EXTRA_DIST = \
|
||||
storagevolxml2xmlout \
|
||||
sysinfodata \
|
||||
test-lib.sh \
|
||||
vircaps2xmldata \
|
||||
virsh-uriprecedence \
|
||||
virfiledata \
|
||||
virpcitestdata \
|
||||
@ -167,6 +168,7 @@ test_programs = virshtest sockettest \
|
||||
vircapstest \
|
||||
domainconftest \
|
||||
virhostdevtest \
|
||||
vircaps2xmltest \
|
||||
$(NULL)
|
||||
|
||||
if WITH_REMOTE
|
||||
@ -803,6 +805,10 @@ vircapstest_SOURCES = \
|
||||
vircapstest.c testutils.h testutils.c
|
||||
vircapstest_LDADD = $(LDADDS)
|
||||
|
||||
vircaps2xmltest_SOURCES = \
|
||||
vircaps2xmltest.c testutils.h testutils.c
|
||||
vircaps2xmltest_LDADD = $(LDADDS)
|
||||
|
||||
if WITH_LIBVIRTD
|
||||
libvirtdconftest_SOURCES = \
|
||||
libvirtdconftest.c testutils.h testutils.c \
|
||||
|
74
tests/vircaps2xmldata/vircaps-basic-4-4-2G.xml
Normal file
74
tests/vircaps2xmldata/vircaps-basic-4-4-2G.xml
Normal file
@ -0,0 +1,74 @@
|
||||
<capabilities>
|
||||
|
||||
<host>
|
||||
<cpu>
|
||||
<arch>x86_64</arch>
|
||||
</cpu>
|
||||
<power_management/>
|
||||
<topology>
|
||||
<cells num='4'>
|
||||
<cell id='0'>
|
||||
<memory unit='KiB'>2097152</memory>
|
||||
<distances>
|
||||
<sibling id='0' value='10'/>
|
||||
<sibling id='1' value='20'/>
|
||||
<sibling id='2' value='20'/>
|
||||
<sibling id='3' value='20'/>
|
||||
</distances>
|
||||
<cpus num='4'>
|
||||
<cpu id='0' socket_id='0' core_id='0' siblings='0'/>
|
||||
<cpu id='0' socket_id='0' core_id='1' siblings='0'/>
|
||||
<cpu id='0' socket_id='0' core_id='2' siblings='0'/>
|
||||
<cpu id='0' socket_id='0' core_id='3' siblings='0'/>
|
||||
</cpus>
|
||||
</cell>
|
||||
<cell id='1'>
|
||||
<memory unit='KiB'>2097152</memory>
|
||||
<distances>
|
||||
<sibling id='0' value='20'/>
|
||||
<sibling id='1' value='10'/>
|
||||
<sibling id='2' value='20'/>
|
||||
<sibling id='3' value='20'/>
|
||||
</distances>
|
||||
<cpus num='4'>
|
||||
<cpu id='1' socket_id='1' core_id='1' siblings='1'/>
|
||||
<cpu id='1' socket_id='1' core_id='2' siblings='1'/>
|
||||
<cpu id='1' socket_id='1' core_id='3' siblings='1'/>
|
||||
<cpu id='1' socket_id='1' core_id='4' siblings='1'/>
|
||||
</cpus>
|
||||
</cell>
|
||||
<cell id='2'>
|
||||
<memory unit='KiB'>2097152</memory>
|
||||
<distances>
|
||||
<sibling id='0' value='20'/>
|
||||
<sibling id='1' value='20'/>
|
||||
<sibling id='2' value='10'/>
|
||||
<sibling id='3' value='20'/>
|
||||
</distances>
|
||||
<cpus num='4'>
|
||||
<cpu id='2' socket_id='2' core_id='2' siblings='2'/>
|
||||
<cpu id='2' socket_id='2' core_id='3' siblings='2'/>
|
||||
<cpu id='2' socket_id='2' core_id='4' siblings='2'/>
|
||||
<cpu id='2' socket_id='2' core_id='5' siblings='2'/>
|
||||
</cpus>
|
||||
</cell>
|
||||
<cell id='3'>
|
||||
<memory unit='KiB'>2097152</memory>
|
||||
<distances>
|
||||
<sibling id='0' value='20'/>
|
||||
<sibling id='1' value='20'/>
|
||||
<sibling id='2' value='20'/>
|
||||
<sibling id='3' value='10'/>
|
||||
</distances>
|
||||
<cpus num='4'>
|
||||
<cpu id='3' socket_id='3' core_id='3' siblings='3'/>
|
||||
<cpu id='3' socket_id='3' core_id='4' siblings='3'/>
|
||||
<cpu id='3' socket_id='3' core_id='5' siblings='3'/>
|
||||
<cpu id='3' socket_id='3' core_id='6' siblings='3'/>
|
||||
</cpus>
|
||||
</cell>
|
||||
</cells>
|
||||
</topology>
|
||||
</host>
|
||||
|
||||
</capabilities>
|
164
tests/vircaps2xmltest.c
Normal file
164
tests/vircaps2xmltest.c
Normal file
@ -0,0 +1,164 @@
|
||||
/*
|
||||
* Copyright (C) Red Hat, Inc. 2014
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Authors:
|
||||
* Michal Privoznik <mprivozn@redhat.com>
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "testutils.h"
|
||||
#include "capabilities.h"
|
||||
#include "virbitmap.h"
|
||||
|
||||
|
||||
#define VIR_FROM_THIS VIR_FROM_NONE
|
||||
|
||||
static virCapsPtr
|
||||
buildVirCapabilities(int max_cells,
|
||||
int max_cpus_in_cell,
|
||||
int max_mem_in_cell)
|
||||
{
|
||||
virCapsPtr caps;
|
||||
virCapsHostNUMACellCPUPtr cell_cpus = NULL;
|
||||
virCapsHostNUMACellSiblingInfoPtr siblings = NULL;
|
||||
int core_id, cell_id, nsiblings;
|
||||
int id;
|
||||
size_t i;
|
||||
|
||||
if ((caps = virCapabilitiesNew(VIR_ARCH_X86_64, 0, 0)) == NULL)
|
||||
goto error;
|
||||
|
||||
id = 0;
|
||||
for (cell_id = 0; cell_id < max_cells; cell_id++) {
|
||||
if (VIR_ALLOC_N(cell_cpus, max_cpus_in_cell) < 0)
|
||||
goto error;
|
||||
|
||||
for (core_id = 0; core_id < max_cpus_in_cell; core_id++) {
|
||||
cell_cpus[core_id].id = id;
|
||||
cell_cpus[core_id].socket_id = cell_id;
|
||||
cell_cpus[core_id].core_id = id + core_id;
|
||||
if (!(cell_cpus[core_id].siblings =
|
||||
virBitmapNew(max_cpus_in_cell)))
|
||||
goto error;
|
||||
ignore_value(virBitmapSetBit(cell_cpus[core_id].siblings, id));
|
||||
}
|
||||
id++;
|
||||
|
||||
if (VIR_ALLOC_N(siblings, max_cells) < 0)
|
||||
goto error;
|
||||
nsiblings = max_cells;
|
||||
|
||||
for (i = 0; i < nsiblings; i++) {
|
||||
siblings[i].node = i;
|
||||
/* Some magical constants, see virNumaGetDistances()
|
||||
* for their description. */
|
||||
siblings[i].distance = cell_id == i ? 10 : 20;
|
||||
}
|
||||
|
||||
if (virCapabilitiesAddHostNUMACell(caps, cell_id,
|
||||
max_mem_in_cell,
|
||||
max_cpus_in_cell, cell_cpus,
|
||||
nsiblings, siblings) < 0)
|
||||
goto error;
|
||||
|
||||
cell_cpus = NULL;
|
||||
siblings = NULL;
|
||||
}
|
||||
|
||||
return caps;
|
||||
|
||||
error:
|
||||
virCapabilitiesClearHostNUMACellCPUTopology(cell_cpus, max_cpus_in_cell);
|
||||
VIR_FREE(cell_cpus);
|
||||
VIR_FREE(siblings);
|
||||
virObjectUnref(caps);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
struct virCapabilitiesFormatData {
|
||||
const char *filename;
|
||||
int max_cells;
|
||||
int max_cpus_in_cell;
|
||||
int max_mem_in_cell;
|
||||
};
|
||||
|
||||
static int
|
||||
test_virCapabilitiesFormat(const void *opaque)
|
||||
{
|
||||
struct virCapabilitiesFormatData *data = (struct virCapabilitiesFormatData *) opaque;
|
||||
virCapsPtr caps = NULL;
|
||||
char *capsXML = NULL;
|
||||
char *capsFromFile = NULL;
|
||||
char *path = NULL;
|
||||
int ret = -1;
|
||||
|
||||
if (!(caps = buildVirCapabilities(data->max_cells, data->max_cpus_in_cell,
|
||||
data->max_mem_in_cell)))
|
||||
goto cleanup;
|
||||
|
||||
if (!(capsXML = virCapabilitiesFormatXML(caps))) {
|
||||
fprintf(stderr, "Unable to format capabilities XML");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (virAsprintf(&path, "%s/vircaps2xmldata/vircaps-%s.xml",
|
||||
abs_srcdir, data->filename) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (virFileReadAll(path, 8192, &capsFromFile) < 0)
|
||||
goto cleanup;
|
||||
|
||||
|
||||
if (STRNEQ(capsXML, capsFromFile)) {
|
||||
virtTestDifference(stderr, capsFromFile, capsXML);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(path);
|
||||
VIR_FREE(capsFromFile);
|
||||
VIR_FREE(capsXML);
|
||||
virObjectUnref(caps);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
mymain(void)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
#define DO_TEST(filename, max_cells, \
|
||||
max_cpus_in_cell, max_mem_in_cell) \
|
||||
do { \
|
||||
struct virCapabilitiesFormatData data = {filename, max_cells, \
|
||||
max_cpus_in_cell, \
|
||||
max_mem_in_cell}; \
|
||||
if (virtTestRun(filename, test_virCapabilitiesFormat, &data) < 0) \
|
||||
ret = -1; \
|
||||
} while (0)
|
||||
|
||||
DO_TEST("basic-4-4-2G", 4, 4, 2*1024*1024);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
VIRT_TEST_MAIN(mymain)
|
Loading…
Reference in New Issue
Block a user