Signed-off-by: Luyao Huang <lhuang(a)redhat.com>
---
cases/test_connection.conf | 4 ++
repos/virconn/connection_allocPages.py | 88 ++++++++++++++++++++++++++++++++++
2 files changed, 92 insertions(+)
create mode 100644 repos/virconn/connection_allocPages.py
diff --git a/cases/test_connection.conf b/cases/test_connection.conf
index 336b1ad..600ec32 100644
--- a/cases/test_connection.conf
+++ b/cases/test_connection.conf
@@ -77,3 +77,7 @@ virconn:connection_getMemoryParameters
virconn:connection_getMemoryStats
conn
qemu:///system
+
+virconn:connection_allocPages
+ conn
+ qemu:///system
diff --git a/repos/virconn/connection_allocPages.py
b/repos/virconn/connection_allocPages.py
new file mode 100644
index 0000000..9ddd474
--- /dev/null
+++ b/repos/virconn/connection_allocPages.py
@@ -0,0 +1,88 @@
+#!/usr/bin/env python
+
+import libvirt
+from libvirt import libvirtError
+import lxml
+import lxml.etree
+
+required_params = ()
+optional_params = {'conn': ''}
+
+HOST_HUGEPAGE =
'/sys/devices/system/node/node%d/hugepages/hugepages-%dkB/nr_hugepages'
+
+def get_host_pagesize(conn):
+ ret = []
+ tree = lxml.etree.fromstring(conn.getCapabilities())
+
+ set = tree.xpath("/capabilities/host/cpu/pages")
+ for n in set:
+ ret.append(int(n.attrib['size']))
+
+ return ret
+
+def get_host_pagecount(pagesize):
+ try:
+ return int(open(HOST_HUGEPAGE % (0, pagesize)).read())
+ except IOError:
+ return -1
+
+def connection_allocPages(params):
+ """
+ test API for allocPages in class virConnect
+ """
+ logger = params['logger']
+ fail=0
+
+ try:
+ conn=libvirt.open(params['conn'])
+ logger.info("get connection to libvirtd")
+ list1 = get_host_pagesize(conn)
+
+ except libvirtError, e:
+ logger.error("API error message: %s" % e.message)
+ return 1
+
+ for i in list1:
+ logger.info("test hugepage size %d" % i)
+
+ if get_host_pagecount(i) == -1:
+ logger.info("Skip system page size %d" % i)
+ continue
+
+ """ test flag VIR_NODE_ALLOC_PAGES_SET """
+ try:
+ cur_count = get_host_pagecount(i)
+ conn.allocPages({i : cur_count + 1}, 0, 1, libvirt.VIR_NODE_ALLOC_PAGES_SET)
+ if get_host_pagecount(i) != cur_count + 1:
+ logger.info("libvirt set a wrong page count to %dKiB hugepage"
% i)
+ fail = 1
+ except libvirtError, e:
+ if "Allocated only" in e.message:
+ tmp_count = int(e.message.replace(" ", "")[-1:])
+
+ if tmp_count != get_host_pagecount(i):
+ logger.info("libvirt output %dKiB hugepage count is not
right" % i)
+ fail = 1
+ else:
+ logger.error("API error message: %s" % e.message)
+ return 1
+
+ """ test flag VIR_NODE_ALLOC_PAGES_ADD """
+ try:
+ cur_count = get_host_pagecount(i)
+ conn.allocPages({i : 1}, 0, 1, libvirt.VIR_NODE_ALLOC_PAGES_ADD)
+ if get_host_pagecount(i) != cur_count + 1:
+ logger.info("libvirt set a wrong page count to %dKiB hugepage"
% i)
+ fail = 1
+ except libvirtError, e:
+ if "Allocated only" in e.message:
+ tmp_count = int(e.message.replace(" ", "")[-1:])
+
+ if tmp_count != get_host_pagecount(i):
+ logger.info("libvirt output %dKiB hugepage count is not
right" % i)
+ fail = 1
+ else:
+ logger.error("API error message: %s" % e.message)
+ return 1
+
+ return fail
--
1.8.3.1