Home | History | Annotate | Line # | Download | only in common
h_fsmacros.h revision 1.20
      1  1.20  pooka /*	$NetBSD: h_fsmacros.h,v 1.20 2010/08/26 08:19:18 pooka Exp $	*/
      2   1.1  njoly 
      3   1.1  njoly /*-
      4   1.1  njoly  * Copyright (c) 2010 The NetBSD Foundation, Inc.
      5   1.1  njoly  * All rights reserved.
      6   1.1  njoly  *
      7   1.1  njoly  * This code is derived from software contributed to The NetBSD Foundation
      8   1.2  njoly  * by Nicolas Joly.
      9   1.1  njoly  *
     10   1.1  njoly  * Redistribution and use in source and binary forms, with or without
     11   1.1  njoly  * modification, are permitted provided that the following conditions
     12   1.1  njoly  * are met:
     13   1.1  njoly  * 1. Redistributions of source code must retain the above copyright
     14   1.1  njoly  *    notice, this list of conditions and the following disclaimer.
     15   1.1  njoly  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1  njoly  *    notice, this list of conditions and the following disclaimer in the
     17   1.1  njoly  *    documentation and/or other materials provided with the distribution.
     18   1.1  njoly  *
     19   1.1  njoly  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20   1.1  njoly  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21   1.1  njoly  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22   1.1  njoly  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23   1.1  njoly  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24   1.1  njoly  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25   1.1  njoly  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26   1.1  njoly  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27   1.1  njoly  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28   1.1  njoly  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29   1.1  njoly  * POSSIBILITY OF SUCH DAMAGE.
     30   1.1  njoly  */
     31   1.1  njoly 
     32   1.1  njoly #ifndef __H_FSMACROS_H_
     33   1.1  njoly #define __H_FSMACROS_H_
     34   1.1  njoly 
     35   1.5  njoly #include <sys/mount.h>
     36   1.5  njoly 
     37   1.1  njoly #include <atf-c.h>
     38  1.17  pooka #include <puffsdump.h>
     39   1.1  njoly #include <string.h>
     40   1.1  njoly 
     41  1.20  pooka #include <rump/rump.h>
     42  1.20  pooka 
     43  1.20  pooka #include "../../h_macros.h"
     44  1.20  pooka 
     45  1.11  pooka #define FSPROTOS(_fs_)							\
     46  1.17  pooka int _fs_##_fstest_newfs(const atf_tc_t *, void **, const char *,	\
     47  1.17  pooka 			off_t, void *);					\
     48  1.11  pooka int _fs_##_fstest_delfs(const atf_tc_t *, void *);			\
     49  1.11  pooka int _fs_##_fstest_mount(const atf_tc_t *, void *, const char *, int);	\
     50  1.11  pooka int _fs_##_fstest_unmount(const atf_tc_t *, const char *, int);
     51  1.11  pooka 
     52  1.11  pooka FSPROTOS(ext2fs);
     53  1.11  pooka FSPROTOS(ffs);
     54  1.11  pooka FSPROTOS(lfs);
     55  1.11  pooka FSPROTOS(msdosfs);
     56  1.14  pooka FSPROTOS(nfs);
     57  1.11  pooka FSPROTOS(puffs);
     58  1.11  pooka FSPROTOS(sysvbfs);
     59  1.11  pooka FSPROTOS(tmpfs);
     60   1.1  njoly 
     61  1.18  pooka #ifndef FSTEST_IMGNAME
     62  1.12  pooka #define FSTEST_IMGNAME "image.fs"
     63  1.18  pooka #endif
     64  1.18  pooka #ifndef FSTEST_IMGSIZE
     65  1.12  pooka #define FSTEST_IMGSIZE (10000 * 512)
     66  1.18  pooka #endif
     67  1.18  pooka #ifndef FSTEST_MNTNAME
     68  1.12  pooka #define FSTEST_MNTNAME "/mnt"
     69  1.18  pooka #endif
     70   1.1  njoly 
     71  1.15  pooka #define FSTEST_CONSTRUCTOR(_tc_, _fs_, _args_)				\
     72  1.15  pooka do {									\
     73  1.15  pooka 	if (_fs_##_fstest_newfs(_tc_, &_args_,				\
     74  1.17  pooka 	    FSTEST_IMGNAME, FSTEST_IMGSIZE, NULL) != 0)			\
     75  1.19  pooka 		atf_tc_fail_errno("newfs failed");			\
     76  1.17  pooka 	if (_fs_##_fstest_mount(_tc_, _args_, FSTEST_MNTNAME, 0) != 0)	\
     77  1.19  pooka 		atf_tc_fail_errno("mount failed");			\
     78  1.17  pooka } while (/*CONSTCOND*/0);
     79  1.17  pooka 
     80  1.17  pooka #define FSTEST_CONSTRUCTOR_FSPRIV(_tc_, _fs_, _args_, _privargs_)	\
     81  1.17  pooka do {									\
     82  1.17  pooka 	if (_fs_##_fstest_newfs(_tc_, &_args_,				\
     83  1.17  pooka 	    FSTEST_IMGNAME, FSTEST_IMGSIZE, _privargs_) != 0)		\
     84  1.19  pooka 		atf_tc_fail_errno("newfs failed");			\
     85  1.15  pooka 	if (_fs_##_fstest_mount(_tc_, _args_, FSTEST_MNTNAME, 0) != 0)	\
     86  1.19  pooka 		atf_tc_fail_errno("mount failed");			\
     87  1.15  pooka } while (/*CONSTCOND*/0);
     88  1.15  pooka 
     89  1.15  pooka #define FSTEST_DESTRUCTOR(_tc_, _fs_, _args_)				\
     90  1.15  pooka do {									\
     91  1.19  pooka 	if (_fs_##_fstest_unmount(_tc_, FSTEST_MNTNAME, 0) != 0) {	\
     92  1.19  pooka 		rump_pub_vfs_mount_print(FSTEST_MNTNAME, 1);		\
     93  1.19  pooka 		atf_tc_fail_errno("unmount failed");			\
     94  1.19  pooka 	}								\
     95  1.15  pooka 	if (_fs_##_fstest_delfs(_tc_, _args_) != 0)			\
     96  1.19  pooka 		atf_tc_fail_errno("delfs failed");			\
     97  1.15  pooka } while (/*CONSTCOND*/0);
     98  1.15  pooka 
     99   1.1  njoly #define ATF_TC_FSADD(fs,type,func,desc) \
    100  1.13  njoly   ATF_TC_WITH_CLEANUP(fs##_##func); \
    101   1.1  njoly   ATF_TC_HEAD(fs##_##func,tc) \
    102   1.1  njoly   { \
    103   1.1  njoly     atf_tc_set_md_var(tc, "descr", type " test for " desc); \
    104   1.1  njoly     atf_tc_set_md_var(tc, "use.fs", "true"); \
    105   1.6  njoly     atf_tc_set_md_var(tc, "X-fs.type", type); \
    106   1.1  njoly   } \
    107  1.13  njoly   void *fs##func##tmp; \
    108   1.1  njoly   ATF_TC_BODY(fs##_##func,tc) \
    109   1.1  njoly   { \
    110  1.13  njoly     if (!atf_check_fstype(tc, type)) \
    111  1.13  njoly       atf_tc_skip("filesystem not selected"); \
    112  1.15  pooka     FSTEST_CONSTRUCTOR(tc,fs,fs##func##tmp); \
    113  1.12  pooka     func(tc,FSTEST_MNTNAME); \
    114  1.19  pooka     if (fs##_fstest_unmount(tc, FSTEST_MNTNAME, 0) != 0) { \
    115  1.19  pooka       rump_pub_vfs_mount_print(FSTEST_MNTNAME, 1); \
    116  1.19  pooka       atf_tc_fail_errno("unmount failed"); \
    117  1.19  pooka     } \
    118  1.13  njoly   } \
    119  1.13  njoly   ATF_TC_CLEANUP(fs##_##func,tc) \
    120  1.13  njoly   { \
    121  1.13  njoly     if (!atf_check_fstype(tc, type)) \
    122  1.13  njoly       return; \
    123  1.13  njoly     if (fs##_fstest_delfs(tc, fs##func##tmp) != 0) \
    124  1.19  pooka       atf_tc_fail_errno("delfs failed"); \
    125   1.1  njoly   }
    126   1.1  njoly 
    127   1.1  njoly #define ATF_TP_FSADD(fs,func) \
    128   1.1  njoly   ATF_TP_ADD_TC(tp,fs##_##func)
    129   1.1  njoly 
    130   1.1  njoly #define ATF_TC_FSAPPLY(func,desc) \
    131   1.5  njoly   ATF_TC_FSADD(ext2fs,MOUNT_EXT2FS,func,desc) \
    132   1.5  njoly   ATF_TC_FSADD(ffs,MOUNT_FFS,func,desc) \
    133   1.5  njoly   ATF_TC_FSADD(lfs,MOUNT_LFS,func,desc) \
    134   1.5  njoly   ATF_TC_FSADD(msdosfs,MOUNT_MSDOS,func,desc) \
    135  1.14  pooka   ATF_TC_FSADD(nfs,MOUNT_NFS,func,desc) \
    136  1.10  pooka   ATF_TC_FSADD(puffs,MOUNT_PUFFS,func,desc) \
    137   1.5  njoly   ATF_TC_FSADD(sysvbfs,MOUNT_SYSVBFS,func,desc) \
    138   1.5  njoly   ATF_TC_FSADD(tmpfs,MOUNT_TMPFS,func,desc)
    139   1.1  njoly 
    140   1.1  njoly #define ATF_TP_FSAPPLY(func) \
    141   1.1  njoly   ATF_TP_FSADD(ext2fs,func); \
    142   1.1  njoly   ATF_TP_FSADD(ffs,func); \
    143   1.3  pooka   ATF_TP_FSADD(lfs,func); \
    144   1.1  njoly   ATF_TP_FSADD(msdosfs,func); \
    145  1.14  pooka   ATF_TP_FSADD(nfs,func); \
    146  1.10  pooka   ATF_TP_FSADD(puffs,func); \
    147   1.1  njoly   ATF_TP_FSADD(sysvbfs,func); \
    148   1.1  njoly   ATF_TP_FSADD(tmpfs,func);
    149   1.1  njoly 
    150   1.1  njoly #define ATF_FSAPPLY(func,desc) \
    151   1.1  njoly   ATF_TC_FSAPPLY(func,desc); \
    152   1.1  njoly   ATF_TP_ADD_TCS(tp) \
    153   1.1  njoly   { \
    154   1.1  njoly     ATF_TP_FSAPPLY(func); \
    155   1.1  njoly     return atf_no_error(); \
    156   1.1  njoly   }
    157   1.1  njoly 
    158  1.13  njoly static __inline bool
    159   1.1  njoly atf_check_fstype(const atf_tc_t *tc, const char *fs)
    160   1.1  njoly {
    161   1.1  njoly   const char *fstype;
    162   1.1  njoly 
    163   1.1  njoly   if (!atf_tc_has_config_var(tc, "fstype"))
    164  1.13  njoly     return true;
    165   1.1  njoly   fstype = atf_tc_get_config_var(tc, "fstype");
    166   1.1  njoly   if (strcmp(fstype, fs) == 0)
    167  1.13  njoly     return true;
    168  1.13  njoly   return false;
    169   1.1  njoly }
    170   1.1  njoly 
    171   1.8  pooka #define FSTYPE_EXT2FS(tc)\
    172   1.8  pooka     (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_EXT2FS) == 0)
    173   1.8  pooka #define FSTYPE_FFS(tc)\
    174   1.8  pooka     (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_FFS) == 0)
    175   1.8  pooka #define FSTYPE_LFS(tc)\
    176   1.8  pooka     (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_LFS) == 0)
    177   1.8  pooka #define FSTYPE_MSDOS(tc)\
    178   1.8  pooka     (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_MSDOS) == 0)
    179  1.14  pooka #define FSTYPE_NFS(tc)\
    180  1.14  pooka     (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_NFS) == 0)
    181   1.8  pooka #define FSTYPE_PUFFS(tc)\
    182   1.8  pooka     (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_PUFFS) == 0)
    183   1.8  pooka #define FSTYPE_SYSVBFS(tc)\
    184   1.8  pooka     (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_SYSVBFS) == 0)
    185   1.8  pooka #define FSTYPE_TMPFS(tc)\
    186   1.8  pooka     (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_TMPFS) == 0)
    187   1.5  njoly 
    188  1.17  pooka #define FSTEST_ENTER()						\
    189  1.17  pooka     if (rump_sys_chdir(FSTEST_MNTNAME) == -1)			\
    190  1.17  pooka 	atf_tc_fail_errno("failed to cd into test mount")
    191  1.17  pooka #define FSTEST_EXIT()						\
    192  1.17  pooka     if (rump_sys_chdir("/") == -1)				\
    193  1.17  pooka 	atf_tc_fail_errno("failed to cd out of test mount")
    194  1.17  pooka 
    195  1.17  pooka /*
    196  1.17  pooka  * file system args structures
    197  1.17  pooka  */
    198  1.16  pooka 
    199  1.16  pooka struct nfstestargs {
    200  1.16  pooka 	pid_t ta_childpid;
    201  1.16  pooka 	char ta_ethername[MAXPATHLEN];
    202  1.16  pooka };
    203  1.16  pooka 
    204  1.17  pooka struct puffstestargs {
    205  1.17  pooka 	uint8_t			*pta_pargs;
    206  1.17  pooka 	size_t			pta_pargslen;
    207  1.17  pooka 
    208  1.17  pooka 	int			pta_pflags;
    209  1.17  pooka 	pid_t			pta_childpid;
    210  1.17  pooka 
    211  1.17  pooka 	int			pta_rumpfd;
    212  1.17  pooka 	int			pta_servfd;
    213  1.17  pooka 
    214  1.17  pooka 	char			pta_dev[MAXPATHLEN];
    215  1.17  pooka 	char			pta_dir[MAXPATHLEN];
    216  1.17  pooka 
    217  1.17  pooka 	int			pta_mntflags;
    218  1.17  pooka 
    219  1.17  pooka 	int			pta_vfs_toserv_ops[PUFFS_VFS_MAX];
    220  1.17  pooka 	int			pta_vn_toserv_ops[PUFFS_VN_MAX];
    221  1.17  pooka };
    222  1.17  pooka 
    223   1.1  njoly #endif /* __H_FSMACROS_H_ */
    224