---
tests/Makefile.am | 5 +++
tests/vircgrouptest.c | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 108 insertions(+)
create mode 100644 tests/vircgrouptest.c
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 61b0a0c..b2ccdc1 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -99,6 +99,7 @@ test_programs = virshtest sockettest \
virlockspacetest \
virstringtest \
sysinfotest \
+ vircgrouptest \
$(NULL)
if WITH_GNUTLS
@@ -640,6 +641,10 @@ utiltest_SOURCES = \
utiltest.c testutils.h testutils.c
utiltest_LDADD = $(LDADDS)
+vircgrouptest_SOURCES = \
+ vircgrouptest.c testutils.h testutils.c
+vircgrouptest_LDADD = $(LDADDS)
+
if WITH_DRIVER_MODULES
virdrivermoduletest_SOURCES = \
virdrivermoduletest.c testutils.h testutils.c
diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c
new file mode 100644
index 0000000..8d0387b
--- /dev/null
+++ b/tests/vircgrouptest.c
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2012 Fujitsu.
+ *
+ * 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/>.
+ *
+ */
+
+#include <config.h>
+
+#include "testutils.h"
+
+#include "vircgroup.h"
+
+static int test_cgroup(const void *data ATTRIBUTE_UNUSED)
+{
+ virCgroupItemPtr cpuset;
+
+ cpuset = virCgroupItemNew(VIR_CGROUP_CONTROLLER_CPUSET,
+ "test_cgroup",
+ virCgroupGetAppRoot(VIR_CGROUP_CONTROLLER_CPUSET, false));
+ if (!cpuset)
+ return -1;
+
+ if (virCgroupSetCpusetCpus(cpuset, "1") < 0) {
+ virCgroupItemFree(cpuset);
+ return -1;
+ }
+
+ virCgroupItemFree(cpuset);
+
+ return 0;
+}
+
+static int test_child_cgroup(const void *data ATTRIBUTE_UNUSED)
+{
+ int ret = -1;
+ virCgroupItemPtr item = NULL, item1 = NULL, item2 = NULL;
+ char *cpus;
+
+ item = virCgroupItemNew(VIR_CGROUP_CONTROLLER_CPUSET,
+ "test_child_cgroup",
+ virCgroupGetAppRoot(VIR_CGROUP_CONTROLLER_CPUSET, false));
+ if (!item)
+ goto out;
+
+ item1 = virCgroupItemNew(VIR_CGROUP_CONTROLLER_CPUSET, "child1", item);
+ item2 = virCgroupItemNew(VIR_CGROUP_CONTROLLER_CPUSET, "child2", item1);
+
+ if (virCgroupGetCpusetCpus(item2, &cpus) < 0)
+ goto out;
+
+ VIR_FREE(cpus);
+
+ if (virCgroupSetCpusetCpus(item2, "0") < 0)
+ goto out;
+
+ if (virCgroupGetCpusetCpus(item2, &cpus) < 0)
+ goto out;
+
+ VIR_FREE(cpus);
+
+ ret = 0;
+out:
+ if (item)
+ virCgroupItemFree(item);
+ if (item1)
+ virCgroupItemFree(item1);
+ if (item2)
+ virCgroupItemFree(item2);
+ return ret;
+}
+
+static int
+mymain(void)
+{
+ int ret = 0;
+
+ if (virCgroupInit() < 0)
+ return -1;
+
+ if (virtTestRun("test_cgroup", 1, test_cgroup, NULL) < 0)
+ ret = -1;
+ if (virtTestRun("test_child_cgroup", 1, test_child_cgroup, NULL) < 0)
+ ret = -1;
+
+ virCgroupUninit();
+
+ return ret;
+}
+
+VIRT_TEST_MAIN(mymain)
--
1.8.0.1.240.ge8a1f5a