[PATCH v2 3/3] tests: Add test program for APIs which changes domain conf on the fly

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The test driver free()s the test domain conf each time when
the connection is closed, so it's not able to test the APIs
which change the domain conf on the fly with virsh.

This patch is to add a new test program domapitest.c, which
tests the APIs by directly invoking the C APIs. Currently there
is only one test in it for setNumaParameters testing, but similiar
APIs testing can be added there.
---
 tests/Makefile.am  |    7 ++-
 tests/domapitest.c |  151 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 157 insertions(+), 1 deletions(-)
 create mode 100644 tests/domapitest.c

diff --git a/tests/Makefile.am b/tests/Makefile.am
index e3bd6d1..3ddc43b 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -91,7 +91,7 @@ test_programs = virshtest sockettest \
 	virhashtest virnetmessagetest virnetsockettest \
 	utiltest virnettlscontexttest shunloadtest \
 	virtimetest viruritest virkeyfiletest \
-	virauthconfigtest
+	virauthconfigtest domapitest
 
 if WITH_DRIVER_MODULES
 test_programs += virdrivermoduletest
@@ -452,6 +452,11 @@ commandhelper_CFLAGS = -Dabs_builddir="\"`pwd`\"" $(AM_CFLAGS)
 commandhelper_LDADD = $(LDADDS)
 commandhelper_LDFLAGS = -static
 
+domapitest_SOURCES = \
+	domapitest.c \
+	testutils.c testutils.h
+domapitest_LDADD = $(LDADDS)
+
 if WITH_LIBVIRTD
 libvirtdconftest_SOURCES = \
 	libvirtdconftest.c testutils.h testutils.c \
diff --git a/tests/domapitest.c b/tests/domapitest.c
new file mode 100644
index 0000000..c093eb9
--- /dev/null
+++ b/tests/domapitest.c
@@ -0,0 +1,151 @@
+/*
+ * domapitest.c: Test the APIs which changes domain conf
+ *
+ * Copyright (C) 2010-2012 Red Hat, Inc.
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
+ *
+ * Author: Osier Yang <jyang@xxxxxxxxxx>
+ */
+
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "internal.h"
+#include "xml.h"
+#include "util.h"
+#include "testutils.h"
+#include "memory.h"
+#include "virtypedparam.h"
+#include "virterror_internal.h"
+
+#define VIR_FROM_THIS VIR_FROM_TEST
+
+static const char *domname = "test";
+static const char *uri = "test:///default";
+
+static int
+testSetNumaParameters(const void *data) {
+    virDomainPtr dom = (virDomainPtr) data;
+    int nparams = 2;
+    virTypedParameterPtr params = NULL;
+    int flags = 0;
+    char *actual = NULL;
+    int ret = -1;
+    const char *exp = "\
+<domain type='test' id='1'>\n\
+  <name>test</name>\n\
+  <uuid>6695eb01-f6a4-8304-79aa-97f2502e193f</uuid>\n\
+  <memory unit='KiB'>8388608</memory>\n\
+  <currentMemory unit='KiB'>2097152</currentMemory>\n\
+  <vcpu placement='static'>2</vcpu>\n\
+  <numatune>\n\
+    <memory mode='strict' nodeset='10'/>\n\
+  </numatune>\n\
+  <os>\n\
+    <type arch='i686'>hvm</type>\n\
+    <boot dev='hd'/>\n\
+  </os>\n\
+  <clock offset='utc'/>\n\
+  <on_poweroff>destroy</on_poweroff>\n\
+  <on_reboot>restart</on_reboot>\n\
+  <on_crash>destroy</on_crash>\n\
+  <devices>\n\
+  </devices>\n\
+</domain>\n";
+
+    if (VIR_ALLOC_N(params, nparams) < 0){
+        virReportOOMError();
+        return -1;
+    }
+
+    params[0].type = VIR_TYPED_PARAM_INT;
+    if (!virStrcpy(params[0].field,
+                   VIR_DOMAIN_NUMA_MODE,
+                   sizeof(params[0].field))) {
+        virReportOOMError();
+        goto fail;
+    }
+    params[0].value.i = VIR_DOMAIN_NUMATUNE_MEM_STRICT;
+
+    params[1].type = VIR_TYPED_PARAM_STRING;
+    if (!virStrcpy(params[1].field,
+                   VIR_DOMAIN_NUMA_NODESET,
+                   sizeof(params[1].field))) {
+        virReportOOMError();
+        goto fail;
+    }
+    params[1].value.s = strdup("10");
+
+    if (virDomainSetNumaParameters(dom, params, nparams, flags) != 0) {
+        fprintf(stderr, "virDomainSetNumaParameters failed\n");
+        goto fail;
+    }
+
+    if (!(actual = virDomainGetXMLDesc(dom, flags))) {
+        fprintf(stderr, "virDomainGetXMLDesc failed\n");
+        goto fail;
+    }
+
+    if (STRNEQ(exp, actual)) {
+        virtTestDifference(stderr, exp, actual);
+        goto fail;
+    }
+
+    ret = 0;
+
+fail:
+    virTypedParameterArrayClear(params, nparams);
+    VIR_FREE(actual);
+    return ret;
+}
+
+static int
+mymain(void)
+{
+    virConnectPtr conn;
+    virDomainPtr dom;
+    int ret = -1;
+
+    conn = virConnectOpen(uri);
+    if (conn == NULL) {
+        fprintf(stderr, "virConnectOpen failed\n");
+        return EXIT_FAILURE;
+    }
+
+    dom = virDomainLookupByName(conn, domname);
+    if (dom == NULL) {
+        fprintf(stderr, "virDomainLookupByName failed\n");
+        goto fail;
+    }
+
+    if (virtTestRun("setNumaParameters",
+                    1, testSetNumaParameters, dom) != 0)
+        goto fail;
+
+    ret = 0;
+
+fail:
+    /* testClose frees the domain object */
+    if(conn)
+        virConnectClose(conn);
+    return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
+}
+
+VIRT_TEST_MAIN(mymain)
-- 
1.7.7.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]