Boot-to-ramdisk image generation scripts
[minix3.git] / tests / fs / ffs / t_quota2_1.c
blob333f3c71270821b6bd11428c146f2c3c707d48e3
1 /* $NetBSD: t_quota2_1.c,v 1.4 2012/03/15 02:02:22 joerg Exp $ */
3 /*
4 * Basic tests for quota2
5 */
7 #include <atf-c.h>
9 #include "../common/h_fsmacros.h"
11 #include <sys/types.h>
12 #include <sys/mount.h>
14 #include <stdlib.h>
16 #include <ufs/ufs/ufsmount.h>
18 #include <rump/rump.h>
19 #include <rump/rump_syscalls.h>
21 #include "../../h_macros.h"
23 static void
24 do_quota(const atf_tc_t *tc, int n, const char *newfs_opts, int log)
26 int i;
27 char buf[1024];
28 int res;
29 int fd;
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");
37 rump_init();
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);
48 atf_tc_expect_pass();
49 FSTEST_ENTER();
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));
57 rump_sys_close(fd);
59 FSTEST_EXIT();
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);
65 res = system(buf);
66 if (res != 0)
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) \
74 { \
75 atf_tc_set_md_var(tc, "descr", \
76 "test quotas with %d users and groups, %s", \
77 nent, descr); \
78 } \
80 ATF_TC_BODY(quota_##name, tc) \
81 { \
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)
100 ATF_TP_ADD_TCS(tp)
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();