]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
From: Sudhir Kumar <skumar@linux.vnet.ibm.com>
authorDhaval Giani <dhaval@linux.vnet.ibm.com>
Tue, 1 Jul 2008 14:09:44 +0000 (14:09 +0000)
committerDhaval Giani <dhaval@linux.vnet.ibm.com>
Tue, 1 Jul 2008 14:09:44 +0000 (14:09 +0000)
libcgroup: adds sanity check in libcgroup testcases binary

This patch adds a sanity check on cgroup file system info in testcases.
If cgroup filesystem is not mounted and script sends the info as mounted,
then the binar would have failed. This patch handles that.

Signed-off-by: Sudhir Kumar <skumar@linux.vnet.ibm.com>
Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
git-svn-id: https://libcg.svn.sourceforge.net/svnroot/libcg/trunk@95 4f4bb910-9a46-0410-90c8-c897d4f1cd53

tests/libcgrouptest.h
tests/libcgrouptest01.c

index 1efc4b8bf8fdb70aa1f0ca2587805283021b1bbd..73c4a9bca08090167b24175a4ae4e763e3bc546d 100644 (file)
@@ -20,6 +20,7 @@
 
 #include <errno.h>
 #include <fcntl.h>
+#include <mntent.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -67,6 +68,7 @@ static int set_controller(int controller, char *controller_name,
 static int group_modified(char *path_control_file, int value_type);
 struct cgroup *new_cgroup(char *group, char *controller_name,
                                 char *control_file, int value_type);
+int check_fsmounted();
 
 static inline pid_t cgrouptest_gettid()
 {
index a57c3ab13f2817f02642a951386b704437eaa1c9..2ec63ec108f90e76fcc16755be79078b0d5b3945 100644 (file)
@@ -149,6 +149,13 @@ int main(int argc, char *argv[])
 
        case FS_MOUNTED:
 
+               /* Do a sanity check if cgroup fs is mounted */
+               if (check_fsmounted()) {
+                       printf("Sanity check fails. cgroup fs not mounted\n");
+                       printf("Exiting without running this set of tests\n");
+                       exit(1);
+               }
+
                /*
                 * Test01: call cgroup_attach_task() with null group
                 * without calling cgroup_inti(). We can check other apis too.
@@ -570,3 +577,30 @@ struct cgroup *new_cgroup(char *group, char *controller_name,
        }
        return newcgroup;
 }
+
+int check_fsmounted()
+{
+       struct mntent *entry, *tmp_entry;
+       /* Need a better mechanism to decide memory allocation size here */
+       char entry_buffer[FILENAME_MAX * 4];
+       FILE *proc_file;
+
+       tmp_entry = (struct mntent *) malloc(sizeof(struct mntent *));
+       if (!tmp_entry) {
+               perror("Error: failled to mallloc for mntent\n");
+               return 1;
+       }
+
+       proc_file = fopen("/proc/mounts", "r");
+       if (!proc_file) {
+               printf("Error in opening /proc/mounts.\n");
+               return EIO;
+       }
+       while ((entry = getmntent_r(proc_file, tmp_entry, entry_buffer, FILENAME_MAX*4)) != NULL) {
+               if (!strncmp(entry->mnt_type, "cgroup", strlen("cgroup"))) {
+                       printf("sanity check pass.... %s\n", entry->mnt_type);
+                       return 0;
+               }
+       }
+       return 1;
+}