Home | History | Annotate | Line # | Download | only in common
h_fsmacros.h revision 1.12
      1 /*	$NetBSD: h_fsmacros.h,v 1.12 2010/07/19 16:21:22 pooka Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2010 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Nicolas Joly.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #ifndef __H_FSMACROS_H_
     33 #define __H_FSMACROS_H_
     34 
     35 #include <sys/mount.h>
     36 
     37 #include <atf-c.h>
     38 #include <string.h>
     39 
     40 #define FSPROTOS(_fs_)							\
     41 int _fs_##_fstest_newfs(const atf_tc_t *, void **, const char *, off_t);\
     42 int _fs_##_fstest_delfs(const atf_tc_t *, void *);			\
     43 int _fs_##_fstest_mount(const atf_tc_t *, void *, const char *, int);	\
     44 int _fs_##_fstest_unmount(const atf_tc_t *, const char *, int);
     45 
     46 FSPROTOS(ext2fs);
     47 FSPROTOS(ffs);
     48 FSPROTOS(lfs);
     49 FSPROTOS(msdosfs);
     50 FSPROTOS(puffs);
     51 FSPROTOS(sysvbfs);
     52 FSPROTOS(tmpfs);
     53 
     54 #define FSTEST_IMGNAME "image.fs"
     55 #define FSTEST_IMGSIZE (10000 * 512)
     56 #define FSTEST_MNTNAME "/mnt"
     57 
     58 #define ATF_TC_FSADD(fs,type,func,desc) \
     59   ATF_TC(fs##_##func); \
     60   ATF_TC_HEAD(fs##_##func,tc) \
     61   { \
     62     atf_tc_set_md_var(tc, "descr", type " test for " desc); \
     63     atf_tc_set_md_var(tc, "use.fs", "true"); \
     64     atf_tc_set_md_var(tc, "X-fs.type", type); \
     65   } \
     66   ATF_TC_BODY(fs##_##func,tc) \
     67   { \
     68     void *tmp; \
     69     atf_check_fstype(tc, type); \
     70     if (fs##_fstest_newfs(tc, &tmp, FSTEST_IMGNAME, FSTEST_IMGSIZE) != 0) \
     71       atf_tc_fail("newfs failed"); \
     72     if (fs##_fstest_mount(tc, tmp, FSTEST_MNTNAME, 0) != 0) \
     73       atf_tc_fail("mount failed"); \
     74     func(tc,FSTEST_MNTNAME); \
     75     if (fs##_fstest_unmount(tc, FSTEST_MNTNAME, 0) != 0) \
     76       atf_tc_fail("unmount failed"); \
     77     if (fs##_fstest_delfs(tc, tmp) != 0) \
     78       atf_tc_fail("delfs failed"); \
     79   }
     80 
     81 #define ATF_TP_FSADD(fs,func) \
     82   ATF_TP_ADD_TC(tp,fs##_##func)
     83 
     84 #define ATF_TC_FSAPPLY(func,desc) \
     85   ATF_TC_FSADD(ext2fs,MOUNT_EXT2FS,func,desc) \
     86   ATF_TC_FSADD(ffs,MOUNT_FFS,func,desc) \
     87   ATF_TC_FSADD(lfs,MOUNT_LFS,func,desc) \
     88   ATF_TC_FSADD(msdosfs,MOUNT_MSDOS,func,desc) \
     89   ATF_TC_FSADD(puffs,MOUNT_PUFFS,func,desc) \
     90   ATF_TC_FSADD(sysvbfs,MOUNT_SYSVBFS,func,desc) \
     91   ATF_TC_FSADD(tmpfs,MOUNT_TMPFS,func,desc)
     92 
     93 #define ATF_TP_FSAPPLY(func) \
     94   ATF_TP_FSADD(ext2fs,func); \
     95   ATF_TP_FSADD(ffs,func); \
     96   ATF_TP_FSADD(lfs,func); \
     97   ATF_TP_FSADD(msdosfs,func); \
     98   ATF_TP_FSADD(puffs,func); \
     99   ATF_TP_FSADD(sysvbfs,func); \
    100   ATF_TP_FSADD(tmpfs,func);
    101 
    102 #define ATF_FSAPPLY(func,desc) \
    103   ATF_TC_FSAPPLY(func,desc); \
    104   ATF_TP_ADD_TCS(tp) \
    105   { \
    106     ATF_TP_FSAPPLY(func); \
    107     return atf_no_error(); \
    108   }
    109 
    110 static __inline void
    111 atf_check_fstype(const atf_tc_t *tc, const char *fs)
    112 {
    113   const char *fstype;
    114 
    115   if (!atf_tc_has_config_var(tc, "fstype"))
    116     return;
    117   fstype = atf_tc_get_config_var(tc, "fstype");
    118   if (strcmp(fstype, fs) == 0)
    119     return;
    120   atf_tc_skip("filesystem not selected");
    121 }
    122 
    123 #define FSTYPE_EXT2FS(tc)\
    124     (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_EXT2FS) == 0)
    125 #define FSTYPE_FFS(tc)\
    126     (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_FFS) == 0)
    127 #define FSTYPE_LFS(tc)\
    128     (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_LFS) == 0)
    129 #define FSTYPE_MSDOS(tc)\
    130     (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_MSDOS) == 0)
    131 #define FSTYPE_PUFFS(tc)\
    132     (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_PUFFS) == 0)
    133 #define FSTYPE_SYSVBFS(tc)\
    134     (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_SYSVBFS) == 0)
    135 #define FSTYPE_TMPFS(tc)\
    136     (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), MOUNT_TMPFS) == 0)
    137 
    138 #endif /* __H_FSMACROS_H_ */
    139