summaryrefslogtreecommitdiffstats
path: root/tests/libcg_ba.cpp
diff options
context:
space:
mode:
authorBalbir Singh <balbir@linux.vnet.ibm.com>2008-05-24 11:08:57 +0000
committerBalbir Singh <balbir@linux.vnet.ibm.com>2008-05-24 11:08:57 +0000
commit6b0384f40a1eb8ff70b27b6dfed3553883c9141f (patch)
tree95d650f507446f69071f3d0cd728392468027d5c /tests/libcg_ba.cpp
parentc74b7e334e27928cbfeee489adcc7c25d2efb369 (diff)
downloadlibcg-6b0384f40a1eb8ff70b27b6dfed3553883c9141f.tar.gz
libcg-6b0384f40a1eb8ff70b27b6dfed3553883c9141f.tar.xz
libcg-6b0384f40a1eb8ff70b27b6dfed3553883c9141f.zip
Add v0.1b tag
git-svn-id: https://libcg.svn.sourceforge.net/svnroot/libcg/tags/v0.1b@49 4f4bb910-9a46-0410-90c8-c897d4f1cd53
Diffstat (limited to 'tests/libcg_ba.cpp')
-rw-r--r--tests/libcg_ba.cpp56
1 files changed, 21 insertions, 35 deletions
diff --git a/tests/libcg_ba.cpp b/tests/libcg_ba.cpp
index 967b1ff..f06ba9b 100644
--- a/tests/libcg_ba.cpp
+++ b/tests/libcg_ba.cpp
@@ -11,14 +11,14 @@
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
- * Basic acceptance test for libcg - Written one late night by Balbir Singh
+ * Basic acceptance test for libcgroup - Written one late night by Balbir Singh
*/
using namespace std;
#include <string>
#include <stdexcept>
#include <iostream>
-#include <libcg.h>
+#include <libcgroup.h>
#include <sys/types.h>
#include <pwd.h>
#include <errno.h>
@@ -42,7 +42,7 @@ cg::cg(void)
{
int ret;
- ret = cg_init();
+ ret = cgroup_init();
if (ret)
throw logic_error("Control Group Initialization failed..."
"Please check that cgroups are mounted and\n"
@@ -55,13 +55,13 @@ struct cgroup *cg::makenode(const string &name, const string &task_uid,
{
uid_t tuid, cuid;
gid_t tgid, cgid;
+ char *cgroup_name;
struct cgroup *ccg;
+ struct cgroup_controller *cpu, *memory, *cpuacct;
struct passwd *passwd;
struct group *grp;
int ret;
- ccg = (struct cgroup *)malloc(sizeof(*ccg));
-
passwd = getpwnam(task_uid.c_str());
if (!passwd)
return NULL;
@@ -84,38 +84,23 @@ struct cgroup *cg::makenode(const string &name, const string &task_uid,
dbg("tuid %d, tgid %d, cuid %d, cgid %d\n", tuid, tgid, cuid, cgid);
- strcpy(ccg->name, name.c_str());
- ccg->controller[0] = (struct controller *)
- calloc(1, sizeof(struct controller));
- strcpy(ccg->controller[0]->name,"cpu");
-
- ccg->controller[0]->values[0] = (struct control_value *)
- calloc(1, sizeof(struct control_value));
- strcpy(ccg->controller[0]->values[0]->name,"cpu.shares");
- strcpy(ccg->controller[0]->values[0]->value, "100");
-
- ccg->controller[1] = (struct controller *)
- calloc(1, sizeof(struct controller));
- strcpy(ccg->controller[1]->name, "memory");
- ccg->controller[1]->values[0] = (struct control_value *)
- calloc(1, sizeof(struct control_value));
- strcpy(ccg->controller[1]->values[0]->name,"memory.limit_in_bytes");
- strcpy(ccg->controller[1]->values[0]->value, "102400");
-
- strcpy(ccg->controller[2]->name, "cpuacct");
- ccg->controller[2]->values[0] = (struct control_value *)
- calloc(1, sizeof(struct control_value));
- strcpy(ccg->controller[2]->values[0]->name,"cpuacct.usage");
- strcpy(ccg->controller[2]->values[0]->value, "0");
- ccg->tasks_uid = tuid;
- ccg->tasks_gid = tgid;
- ccg->control_uid = cuid;
- ccg->control_gid = cgid;
-
- ret = cg_create_cgroup(ccg, 1);
+ cgroup_name = (char *) malloc(name.length());
+ memset(cgroup_name, '\0', name.length());
+ strncpy(cgroup_name, name.c_str(), name.length());
+
+ ccg = cgroup_new_cgroup(cgroup_name, tuid, tgid, cuid, cgid);
+ cpu = cgroup_add_controller(ccg, "cpu");
+ cgroup_add_value_uint64(cpu, "cpu.shares", 2048);
+ memory = cgroup_add_controller(ccg, "memory");
+ cgroup_add_value_uint64(memory, "memory.limit_in_bytes", 102400);
+ cpuacct = cgroup_add_controller(ccg, "cpuacct");
+ cgroup_add_value_uint64(cpuacct, "cpuacct.usage", 0);
+
+
+ ret = cgroup_create_cgroup(ccg, 1);
if (ret) {
cout << "cg create group failed " << errno << endl;
- ret = cg_delete_cgroup(ccg, 1);
+ ret = cgroup_delete_cgroup(ccg, 1);
if (ret)
cout << "cg delete group failed " << errno << endl;
}
@@ -132,6 +117,7 @@ int main(int argc, char *argv[])
struct cgroup *ccg;
ccg = app->makenode("database", "root", "root", "balbir",
"balbir");
+ cgroup_free(&ccg);
delete app;
} catch (exception &e) {
cout << e.what() << endl;