Home | History | Annotate | Line # | Download | only in common
h_fsmacros.h revision 1.2
      1 /*	$NetBSD: h_fsmacros.h,v 1.2 2010/07/05 14:53:03 njoly 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 <atf-c.h>
     36 #include <string.h>
     37 
     38 #include "ext2fs.c"
     39 #include "ffs.c"
     40 #include "msdosfs.c"
     41 #include "sysvbfs.c"
     42 #include "tmpfs.c"
     43 
     44 #define IMGNAME "image.fs"
     45 #define IMGSIZE (10000 * 512)
     46 #define MNTNAME "/mnt"
     47 
     48 #define ATF_TC_FSADD(fs,type,func,desc) \
     49   ATF_TC(fs##_##func); \
     50   ATF_TC_HEAD(fs##_##func,tc) \
     51   { \
     52     atf_tc_set_md_var(tc, "descr", type " test for " desc); \
     53     atf_tc_set_md_var(tc, "use.fs", "true"); \
     54   } \
     55   ATF_TC_BODY(fs##_##func,tc) \
     56   { \
     57     void *tmp; \
     58     atf_check_fstype(tc, type); \
     59     if (fs##_newfs(&tmp, IMGNAME, IMGSIZE) != 0) \
     60       atf_tc_fail("newfs failed"); \
     61     if (fs##_mount(tmp, MNTNAME, 0) != 0) \
     62       atf_tc_fail("mount failed"); \
     63     func(MNTNAME); \
     64     if (fs##_unmount(MNTNAME, 0) != 0) \
     65       atf_tc_fail("unmount failed"); \
     66     if (fs##_delfs(tmp) != 0) \
     67       atf_tc_fail("delfs failed"); \
     68   }
     69 
     70 #define ATF_TP_FSADD(fs,func) \
     71   ATF_TP_ADD_TC(tp,fs##_##func)
     72 
     73 #define ATF_TC_FSAPPLY(func,desc) \
     74   ATF_TC_FSADD(ext2fs,"ext2fs",func,desc) \
     75   ATF_TC_FSADD(ffs,"ffs",func,desc) \
     76   ATF_TC_FSADD(msdosfs,"msdosfs",func,desc) \
     77   ATF_TC_FSADD(sysvbfs,"sysvbfs",func,desc) \
     78   ATF_TC_FSADD(tmpfs,"tmpfs",func,desc)
     79 
     80 #define ATF_TP_FSAPPLY(func) \
     81   ATF_TP_FSADD(ext2fs,func); \
     82   ATF_TP_FSADD(ffs,func); \
     83   ATF_TP_FSADD(msdosfs,func); \
     84   ATF_TP_FSADD(sysvbfs,func); \
     85   ATF_TP_FSADD(tmpfs,func);
     86 
     87 #define ATF_FSAPPLY(func,desc) \
     88   ATF_TC_FSAPPLY(func,desc); \
     89   ATF_TP_ADD_TCS(tp) \
     90   { \
     91     ATF_TP_FSAPPLY(func); \
     92     return atf_no_error(); \
     93   }
     94 
     95 static void
     96 atf_check_fstype(const atf_tc_t *tc, const char *fs)
     97 {
     98   const char *fstype;
     99 
    100   if (!atf_tc_has_config_var(tc, "fstype"))
    101     return;
    102   fstype = atf_tc_get_config_var(tc, "fstype");
    103   if (strcmp(fstype, fs) == 0)
    104     return;
    105   atf_tc_skip("filesystem not selected");
    106 }
    107 
    108 #endif /* __H_FSMACROS_H_ */
    109