Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/bouyer-quota2]: src/tests/fs/ffs Add some quota+snapshot tests.



details:   https://anonhg.NetBSD.org/src/rev/968903b42322
branches:  bouyer-quota2
changeset: 761171:968903b42322
user:      bouyer <bouyer%NetBSD.org@localhost>
date:      Sat Feb 12 21:49:08 2011 +0000

description:
Add some quota+snapshot tests.

diffstat:

 tests/fs/ffs/h_quota2_tests.c |  93 ++++++++++++++++++++++++++++++++++++++----
 tests/fs/ffs/t_miscquota.sh   |  59 ++++++++++++++++++++++++++-
 2 files changed, 141 insertions(+), 11 deletions(-)

diffs (265 lines):

diff -r 8476aa6635ff -r 968903b42322 tests/fs/ffs/h_quota2_tests.c
--- a/tests/fs/ffs/h_quota2_tests.c     Sat Feb 12 21:48:41 2011 +0000
+++ b/tests/fs/ffs/h_quota2_tests.c     Sat Feb 12 21:49:08 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: h_quota2_tests.c,v 1.1.2.3 2011/02/07 16:22:50 bouyer Exp $    */
+/*     $NetBSD: h_quota2_tests.c,v 1.1.2.4 2011/02/12 21:49:08 bouyer Exp $    */
 
 /*
  * rump server for advanced quota tests
@@ -17,6 +17,7 @@
 #include <unistd.h>
 
 #include <ufs/ufs/ufsmount.h>
+#include <dev/fssvar.h>
 
 #include <rump/rump.h>
 #include <rump/rump_syscalls.h>
@@ -28,7 +29,7 @@
 #define TEST_NONROOT_ID 1
 
 static int
-quota_test0(void)
+quota_test0(const char *testopts)
 {
        static char buf[512];
        int fd;
@@ -60,7 +61,7 @@
 }
 
 static int
-quota_test1(void)
+quota_test1(const char *testopts)
 {
        static char buf[512];
        int fd;
@@ -107,7 +108,7 @@
 }
 
 static int
-quota_test2(void)
+quota_test2(const char *testopts)
 {
        static char buf[512];
        int fd;
@@ -143,7 +144,7 @@
 }
 
 static int
-quota_test3(void)
+quota_test3(const char *testopts)
 {
        static char buf[512];
        int fd;
@@ -189,8 +190,71 @@
        return error;
 }
 
+static int
+quota_test4(const char *testopts)
+{
+       static char buf[512];
+       int fd, fssfd;
+       struct fss_set fss;
+       unsigned int i;
+       int unl=0;
+       int unconf=0;
+
+       /*
+        * take an internal snapshot of the filesystem, and create a new
+        * file with some data
+        */
+
+       for (i =0; testopts && i < strlen(testopts); i++) {
+               switch(testopts[i]) {
+               case 'L':
+                       unl++;
+                       break;
+               case 'C':
+                       unconf++;
+                       break;
+               default:
+                       errx(1, "test4: unknown option %c", testopts[i]);
+               }
+       }
+
+       /* first create the snapshot */
+
+        fd = rump_sys_open(FSTEST_MNTNAME "/le_snap", O_CREAT | O_RDWR, 0777);
+        if (fd == -1)
+               err(1, "create " FSTEST_MNTNAME "/le_snap");
+        rump_sys_close(fd);
+        fssfd = rump_sys_open("/dev/rfss0", O_RDWR);
+        if (fssfd == -1)
+               err(1, "cannot open fss");
+       memset(&fss, 0, sizeof(fss));
+       fss.fss_mount = __UNCONST("/mnt");
+       fss.fss_bstore = __UNCONST(FSTEST_MNTNAME "/le_snap");
+       fss.fss_csize = 0;
+       if (rump_sys_ioctl(fssfd, FSSIOCSET, &fss) == -1)
+               err(1, "create snapshot");
+       if (unl)
+               rump_sys_unlink(FSTEST_MNTNAME "/le_snap");
+
+       /* now create some extra files */
+
+       for (i = 0; i < 4; i++) {
+               sprintf(buf, "file%d", i);
+               fd = rump_sys_open(buf, O_EXCL| O_CREAT | O_RDWR, 0644);
+               if (fd < 0)
+                       err(1, "create %s", buf);
+               sprintf(buf, "test file no %d", i);
+               rump_sys_write(fd, buf, strlen(buf));
+               rump_sys_close(fd);
+       }
+       if (unconf)
+               if (rump_sys_ioctl(fssfd, FSSIOCCLR, NULL) == -1)
+                       err(1, "unconfigure snapshot");
+       return 0;
+}
+
 struct quota_test {
-       int (*func)(void);
+       int (*func)(const char *);
        const char *desc;
 };
 
@@ -199,13 +263,19 @@
        { quota_test1, "write beyond the soft limit after grace time"},
        { quota_test2, "create file up to hard limit"},
        { quota_test3, "create file beyond the soft limit after grace time"},
+       { quota_test4, "take a snapshot and add some data"},
 };
 
 static void
 usage(void)
 {
+       unsigned int test;
        fprintf(stderr, "usage: %s [-b] [-l] test# diskimage bindurl\n",
            getprogname());
+       fprintf(stderr, "available tests:\n");
+       for (test = 0; test < sizeof(quota_tests) / sizeof(quota_tests[0]);
+           test++)
+               fprintf(stderr, "\t%d: %s\n", test, quota_tests[test].desc);
        exit(1);
 }
 
@@ -236,10 +306,11 @@
        struct ufs_args uargs;
        const char *filename;
        const char *serverurl;
+       const char *topts = NULL;
        int log = 0;
        int ch;
 
-       while ((ch = getopt(argc, argv, "bl")) != -1) {
+       while ((ch = getopt(argc, argv, "blo:")) != -1) {
                switch(ch) {
                case 'b':
                        background = 1;
@@ -247,6 +318,9 @@
                case 'l':
                        log = 1;
                        break;
+               case 'o':
+                       topts = optarg;
+                       break;
                default:
                        usage();
                }
@@ -265,8 +339,7 @@
                usage();
        }
        if (test > sizeof(quota_tests) / sizeof(quota_tests[0])) {
-               fprintf(stderr, "test number %lu too big\n", test);
-               exit(1);
+               usage();
        }
 
        if (background) {
@@ -291,7 +364,7 @@
                err(1, "cd %s", FSTEST_MNTNAME);
        rump_sys_chown(".", 0, 0);
        rump_sys_chmod(".", 0777);
-       error = quota_tests[test].func();
+       error = quota_tests[test].func(topts);
        if (error) {
                fprintf(stderr, " test %lu: %s returned %d: %s\n",
                    test, quota_tests[test].desc, error, strerror(error));
diff -r 8476aa6635ff -r 968903b42322 tests/fs/ffs/t_miscquota.sh
--- a/tests/fs/ffs/t_miscquota.sh       Sat Feb 12 21:48:41 2011 +0000
+++ b/tests/fs/ffs/t_miscquota.sh       Sat Feb 12 21:49:08 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: t_miscquota.sh,v 1.1.2.2 2011/02/11 17:28:29 bouyer Exp $ 
+# $NetBSD: t_miscquota.sh,v 1.1.2.3 2011/02/12 21:49:08 bouyer Exp $ 
 #
 #  Copyright (c) 2011 Manuel Bouyer
 #  All rights reserved.
@@ -28,6 +28,23 @@
 test_case_root walk_list_user quota_walk_list \
     "walk user quota list over several disk blocks" -b le 1 user
 
+test_case_root psnapshot_user quota_snap \
+    "create a persistent shapshot of quota-enabled fs, and do some writes" \
+    -b le 1 user
+
+test_case_root npsnapshot_user quota_snap \
+    "create a non-persistent shapshot of quota-enabled fs, and do some writes" \
+    -boL le 1 user
+
+test_case_root psnapshot_unconf_user quota_snap \
+    "create a persistent shapshot of quota-enabled fs, and do some writes and unconf" \
+    -boC le 1 user
+
+test_case_root npsnapshot_unconf_user quota_snap \
+    "create a non-persistent shapshot of quota-enabled fs, and do some writes and unconf" \
+    -boLC le 1 user
+
+
 quota_walk_list()
 {
        create_with_quotas_server $*
@@ -61,3 +78,43 @@
            $(atf_get_srcdir)/rump_repquota -x -${expect} /mnt
        rump_shutdown
 }
+
+quota_snap()
+{
+       local flag=$1; shift
+       create_with_quotas $*
+       local q=$3
+       local expect
+
+       case ${q} in
+       user)
+               expect=u
+               fail=g
+               ;;
+       group)
+               expect=g
+               fail=u
+               ;;
+       *)
+               atf_fail "wrong quota type"
+               ;;
+       esac
+
+       #start our server which takes a snapshot
+       atf_check -s exit:0 -o ignore \
+           $(atf_get_srcdir)/h_quota2_tests ${flag} 4 ${IMG} ${RUMP_SERVER}
+       # create a few users
+       local i=1;
+       while [ $i -lt 11 ]; do
+               atf_check -s exit:0 \
+                  $(atf_get_srcdir)/rump_edquota -${expect} \
+                  -s10k/20 -h40M/50k -t 2W/3D $i
+               i=$((i + 1))
+       done
+       # we should have 5 files (root + 4 regular files)
+       atf_check -s exit:0 \
+           -o 'match:-        -  7days         5       -       -  7days' \
+           $(atf_get_srcdir)/rump_repquota -av
+       #shutdown and check filesystem
+       rump_shutdown
+}



Home | Main Index | Thread Index | Old Index