1 /* $NetBSD: t_quota2_1.c,v 1.4 2012/03/15 02:02:22 joerg Exp $ */
4 * Basic tests for quota2
9 #include "../common/h_fsmacros.h"
11 #include <sys/types.h>
12 #include <sys/mount.h>
16 #include <ufs/ufs/ufsmount.h>
18 #include <rump/rump.h>
19 #include <rump/rump_syscalls.h>
21 #include "../../h_macros.h"
24 do_quota(const atf_tc_t
*tc
, int n
, const char *newfs_opts
, int log
)
30 struct ufs_args uargs
;
32 snprintf(buf
, sizeof(buf
), "newfs -q user -q group -F -s 4000 -n %d "
33 "%s %s", (n
+ 3), newfs_opts
, FSTEST_IMGNAME
);
34 if (system(buf
) == -1)
35 atf_tc_fail_errno("cannot create file system");
38 if (rump_sys_mkdir(FSTEST_MNTNAME
, 0777) == -1)
39 atf_tc_fail_errno("mount point create");
41 rump_pub_etfs_register("/diskdev", FSTEST_IMGNAME
, RUMP_ETFS_BLK
);
43 uargs
.fspec
= __UNCONST("/diskdev");
44 if (rump_sys_mount(MOUNT_FFS
, FSTEST_MNTNAME
, (log
) ? MNT_LOG
: 0,
45 &uargs
, sizeof(uargs
)) == -1)
46 atf_tc_fail_errno("mount ffs %s", FSTEST_MNTNAME
);
50 RL(rump_sys_chown(".", 0, 0));
51 for (i
= 0 ; i
< n
; i
++) {
52 sprintf(buf
, "file%d", i
);
53 RL(fd
= rump_sys_open(buf
, O_CREAT
| O_RDWR
, 0755));
54 sprintf(buf
, "test file no %d", i
);
55 RL(rump_sys_write(fd
, buf
, strlen(buf
)));
56 RL(rump_sys_fchown(fd
, i
, i
+80000));
60 if (rump_sys_unmount(FSTEST_MNTNAME
, 0) != 0) {
61 rump_pub_vfs_mount_print(FSTEST_MNTNAME
, 1);
62 atf_tc_fail_errno("unmount failed");
64 snprintf(buf
, 1024, "fsck_ffs -fn -F %s", FSTEST_IMGNAME
);
67 atf_tc_fail("fsck returned %d", res
);
70 #define DECL_TEST(nent, newops, name, descr, log) \
71 ATF_TC(quota_##name); \
73 ATF_TC_HEAD(quota_##name, tc) \
75 atf_tc_set_md_var(tc, "descr", \
76 "test quotas with %d users and groups, %s", \
80 ATF_TC_BODY(quota_##name, tc) \
82 do_quota(tc, nent, newops, log); \
85 DECL_TEST(40, "-O1 -B le", 40_O1_le
, "UFS1 little-endian", 0)
86 DECL_TEST(40, "-O1 -B be", 40_O1_be
, "UFS1 big-endian", 0)
88 DECL_TEST(40, "-O2 -B le", 40_O2_le
, "UFS2 little-endian", 0)
89 DECL_TEST(40, "-O2 -B be", 40_O2_be
, "UFS2 big-endian", 0)
91 DECL_TEST(40, "-O1", 40_O1_log
, "UFS1 log", 1)
92 DECL_TEST(40, "-O2", 40_O2_log
, "UFS2 log", 1)
94 DECL_TEST(1000, "-O1 -B le", 1000_O1_le
, "UFS1 little-endian", 0)
95 DECL_TEST(1000, "-O1 -B be", 1000_O1_be
, "UFS1 big-endian", 0)
97 DECL_TEST(1000, "-O2 -B le", 1000_O2_le
, "UFS2 little-endian", 0)
98 DECL_TEST(1000, "-O2 -B be", 1000_O2_be
, "UFS2 big-endian", 0)
103 ATF_TP_ADD_TC(tp
, quota_40_O1_le
);
104 ATF_TP_ADD_TC(tp
, quota_40_O1_be
);
105 ATF_TP_ADD_TC(tp
, quota_40_O2_le
);
106 ATF_TP_ADD_TC(tp
, quota_40_O2_be
);
107 ATF_TP_ADD_TC(tp
, quota_40_O1_log
);
108 ATF_TP_ADD_TC(tp
, quota_40_O2_log
);
109 ATF_TP_ADD_TC(tp
, quota_1000_O1_le
);
110 ATF_TP_ADD_TC(tp
, quota_1000_O1_be
);
111 ATF_TP_ADD_TC(tp
, quota_1000_O2_le
);
112 ATF_TP_ADD_TC(tp
, quota_1000_O2_be
);
113 return atf_no_error();