From 6af0623234855b348d9cfb9149d6b260c0c44f06 Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Thu, 5 Jun 2014 13:53:16 +0200 Subject: [PATCH] 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 --- tests/Makefile.am | 6 + .../vircaps2xmldata/vircaps-basic-4-4-2G.xml | 74 ++++++++ tests/vircaps2xmltest.c | 164 ++++++++++++++++++ 3 files changed, 244 insertions(+) create mode 100644 tests/vircaps2xmldata/vircaps-basic-4-4-2G.xml create mode 100644 tests/vircaps2xmltest.c diff --git a/tests/Makefile.am b/tests/Makefile.am index 1fdfd3b0f3..9f4dff34a4 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 \ diff --git a/tests/vircaps2xmldata/vircaps-basic-4-4-2G.xml b/tests/vircaps2xmldata/vircaps-basic-4-4-2G.xml new file mode 100644 index 0000000000..8694f87d1f --- /dev/null +++ b/tests/vircaps2xmldata/vircaps-basic-4-4-2G.xml @@ -0,0 +1,74 @@ + + + + + x86_64 + + + + + + 2097152 + + + + + + + + + + + + + + + 2097152 + + + + + + + + + + + + + + + 2097152 + + + + + + + + + + + + + + + 2097152 + + + + + + + + + + + + + + + + + + diff --git a/tests/vircaps2xmltest.c b/tests/vircaps2xmltest.c new file mode 100644 index 0000000000..fa02534656 --- /dev/null +++ b/tests/vircaps2xmltest.c @@ -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 + * . + * + * Authors: + * Michal Privoznik + */ + +#include +#include + +#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)