]> www.infradead.org Git - mtd-utils.git/commitdiff
fs-tests: integck: improve re-mounting test coverage
authorArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Thu, 24 Mar 2011 13:43:35 +0000 (15:43 +0200)
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Thu, 24 Mar 2011 17:25:12 +0000 (19:25 +0200)
The integck tests re-mounts the file-system from time to time
and checks the integrity afterwords. And it re-mounts always
the same-way: unmount and then mount R/W back. However, it is
better to do it differently some times, e.g.:

* re-mount R/O then re-mount R/W
* unmount then mount R/W
* both of the above
* unmount, mount R/O, then re-mount R/W
* etc.

This will give better test coverage. This patch does exactly
that by improving the 'tests_remount()' function.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
tests/fs-tests/lib/tests.c

index 587eda80d3c2dc7522a87fd1812b592e2cb0b4e2..00b94f92ac165f7fbdb805d6c7ba89804cbb0b3b 100644 (file)
@@ -1049,26 +1049,39 @@ out_mem:
        return 1;
 }
 
-/* Un-mount and re-mount test file system */
+/*
+ * Re-mount test file system. Randomly choose how to do this: re-mount R/O then
+ * re-mount R/W, or unmount, then mount R/W, or unmount then mount R/O then
+ * re-mount R/W, etc. This should improve test coverage.
+ */
 void tests_remount(void)
 {
+       int err;
        struct mntent mount_info;
-       char *source;
-       char *target;
-       char *filesystemtype;
-       unsigned long mountflags;
-       char *data;
+       char *source, *target, *filesystemtype, *data;
        char cwd[4096];
+       unsigned long mountflags, flags;
+       unsigned int rorw1, um, um_ro, um_rorw, rorw2;
 
        CHECK(tests_get_mount_info(&mount_info));
 
        if (strcmp(mount_info.mnt_dir,"/") == 0)
                return;
 
+       /* Save current working directory */
        CHECK(getcwd(cwd, 4096) != NULL);
+       /* Temporarily change working directory to '/' */
        CHECK(chdir("/") != -1);
 
-       CHECK(umount(tests_file_system_mount_dir) != -1);
+       /* Choose what to do */
+       rorw1 = tests_random_no(2);
+       um = tests_random_no(2);
+       um_ro = tests_random_no(2);
+       um_rorw = tests_random_no(2);
+       rorw2 = tests_random_no(2);
+
+       if (rorw1 + um + rorw2 == 0)
+               um = 1;
 
        source = mount_info.mnt_fsname;
        target = tests_file_system_mount_dir;
@@ -1076,7 +1089,62 @@ void tests_remount(void)
        data = mount_info.mnt_opts;
        process_mount_options(&data, &mountflags);
 
-       CHECK(mount(source, target, filesystemtype, mountflags, data) != -1);
+       if (rorw1) {
+               /* Re-mount R/O and then re-mount R/W */
+               flags = mountflags | MS_RDONLY | MS_REMOUNT;
+               err = mount(source, target, filesystemtype, flags, data);
+               CHECK(err != -1);
+
+               flags = mountflags | MS_REMOUNT;
+               flags &= ~((unsigned long)MS_RDONLY);
+               err = mount(source, target, filesystemtype, flags, data);
+               CHECK(err != -1);
+       }
+
+       if (um) {
+               /* Unmount and mount */
+               if (um_ro) {
+                       /* But re-mount R/O before unmounting */
+                       flags = mountflags | MS_RDONLY | MS_REMOUNT;
+                       err = mount(source, target, filesystemtype,
+                                   flags, data);
+                       CHECK(err != -1);
+               }
+
+               CHECK(umount(target) != -1);
+
+               if (!um_rorw) {
+                       /* Mount R/W straight away */
+                       err = mount(source, target, filesystemtype,
+                                   mountflags, data);
+                       CHECK(err != -1);
+               } else {
+                       /* Mount R/O and then re-mount R/W */
+                       err = mount(source, target, filesystemtype,
+                                   mountflags | MS_RDONLY, data);
+                       CHECK(err != -1);
+
+                       flags = mountflags | MS_REMOUNT;
+                       flags &= ~((unsigned long)MS_RDONLY);
+                       err = mount(source, target, filesystemtype,
+                                   flags, data);
+                       CHECK(err != -1);
+               }
+       }
+
+       if (rorw2) {
+               /* Re-mount R/O and then re-mount R/W */
+               flags = mountflags | MS_RDONLY | MS_REMOUNT;
+               err = mount(source, target, filesystemtype, flags, data);
+               CHECK(err != -1);
+
+               flags = mountflags | MS_REMOUNT;
+               flags &= ~((unsigned long)MS_RDONLY);
+               err = mount(source, target, filesystemtype, flags, data);
+               CHECK(err != -1);
+       }
+
+       /* Restore the previous working directory */
        CHECK(chdir(cwd) != -1);
 }