
On Sat, Feb 08, 2014 at 12:21:40PM +0530, Pradipta Kr. Banerjee wrote:
This test creates a Fake NUMA topology with non-sequential cell ids to check if libvirt properly handles the same
Signed-off-by: Shivaprasad G Bhat <sbhat@linux.vnet.ibm.com> Signed-off-by: Pradipta Kr. Banerjee <bpradip@in.ibm.com> --- tests/Makefile.am | 5 ++ tests/vircapstest.c | 129 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 134 insertions(+)
diff --git a/tests/Makefile.am b/tests/Makefile.am index eb96f38..bb50ac5 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -144,6 +144,7 @@ test_programs = virshtest sockettest \ virstoragetest \ virnetdevbandwidthtest \ virkmodtest \ + vircapstest \ $(NULL)
nit-pick: inconsistent indentation
diff --git a/tests/vircapstest.c b/tests/vircapstest.c new file mode 100644 index 0000000..dab8f3b --- /dev/null +++ b/tests/vircapstest.c +static virCapsPtr +buildNUMATopology(int seq) +{ + virCapsPtr caps; + virCapsHostNUMACellCPUPtr cell_cpus; + int core_id, cell_id; + int id; + + 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 + core_id; + cell_cpus[core_id].socket_id = cell_id + seq; + 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++;
Indentation off by 4
+ + if (virCapabilitiesAddHostNUMACell(caps, cell_id + seq, + MAX_CPUS_IN_CELL, + MAX_MEM_IN_CELL, + cell_cpus) < 0) + goto error; + + cell_cpus = NULL; + } + + return caps; + +error: + virObjectUnref(caps); + return NULL; + +} + + +static int +test_virCapabilitiesGetCpusForNodemask(const void *data ATTRIBUTE_UNUSED) +{ + const char *nodestr = "3,4,5,6"; + virBitmapPtr nodemask = NULL; + virBitmapPtr cpumap = NULL; + virCapsPtr caps; + int mask_size = 8; + int ret = -1; + + //Build a NUMA topology with cell_id (NUMA node id + //being 3(0 + 3),4(1 + 3), 5 and 6
We prefer /* */ over // for comments
+ if (!(caps = buildNUMATopology(3))) + goto error; + + if (virBitmapParse(nodestr, 0, &nodemask, mask_size) < 0) + goto error; + + if (!(cpumap = virCapabilitiesGetCpusForNodemask(caps, nodemask))) + goto error; + + ret = 0; + +error: + virBitmapFree(nodemask); + virBitmapFree(cpumap); + return ret; + +} + + +static int
ACK, I'll fix style nitpicks when pushing. Thanks for taking the time to write the test case. Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|