Home | History | Annotate | Download | only in dmapi
      1 /*
      2  *   Copyright (c) International Business Machines  Corp., 2004
      3  *
      4  *   This program is free software;  you can redistribute it and/or modify
      5  *   it under the terms of the GNU General Public License as published by
      6  *   the Free Software Foundation; either version 2 of the License, or
      7  *   (at your option) any later version.
      8  *
      9  *   This program is distributed in the hope that it will be useful,
     10  *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
     11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
     12  *   the GNU General Public License for more details.
     13  *
     14  *   You should have received a copy of the GNU General Public License
     15  *   along with this program;  if not, write to the Free Software
     16  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
     17  */
     18 
     19 /*
     20  * FILE NAME	: dm_test.h
     21  *
     22  * PURPOSE	: Define macros and constants common to all DMAPI test cases
     23  */
     24 
     25 #include <stdlib.h>
     26 #if HAVE_SYS_JFSDMAPI_H
     27 #include <sys/jfsdmapi.h>
     28 #endif
     29 #include "dm_vars.h"
     30 
     31 /* The following constants are implementation-independent */
     32 #define ABORT_ERRNO 12
     33 #define DUMMY_STRING "0123456789"
     34 #define DUMMY_STRING2 "9876543210"
     35 #define DUMMY_STRLEN (sizeof(DUMMY_STRING)-1)
     36 #define ATTR_NAME "DMAttr01"
     37 #define ATTR_VALUE "This is a DM attribute's value"
     38 #define ATTR_VALUELEN (sizeof(ATTR_VALUE)-1)
     39 #define DUMMY_TIME 0xCAFEFEED
     40 #define DUMMY_UID 0xDEAD
     41 #define DUMMY_GID 0xBEEF
     42 #define DUMMY_MODE 0xBAD
     43 #define MODE_MASK 0x0FFF
     44 #define CURRENT_DIR "."
     45 #define PARENT_DIR ".."
     46 #define MSG_DATA "This is the message data for a DM user event"
     47 #define MSG_DATALEN sizeof(MSG_DATA)
     48 #define DWALIGN(n) (((n)+(sizeof(int)-1)) & ~(sizeof(int)-1))
     49 
     50 /* The following constants are more than likely implementation-dependent */
     51 #define INVALID_ADDR 0xDEADBEEF
     52 #define FILE_HANDLELEN 24
     53 #define EVENT_DELIVERY_DELAY sleep(1)
     54 #define EVENT_DELIVERY_DELAY_LOOP { \
     55 	do { \
     56 		eventReceived = DM_EVENT_INVALID; \
     57 		EVENT_DELIVERY_DELAY; \
     58 	} while (eventReceived != DM_EVENT_INVALID); \
     59 }
     60 #define TIMESTAMP_DELAY { \
     61 	DMLOG_PRINT(DMLVL_DEBUG, "Sleeping to guarantee timestamp change...\n"); \
     62 	sleep(3); \
     63 }
     64 #define PAGE_SIZE 4096
     65 #define PAGEALIGN(n) (((n)+(PAGE_SIZE-1)) & ~(PAGE_SIZE-1))
     66 #define O_DIRECTORY 0200000
     67 
     68 /* The following constants are implementation-dependent */
     69 #define DMAPI_ATTR_PREFIX "user.dmi."
     70 #define PMR_ATTRNAME "system.dmi.persistent.regions"
     71 #define MAXFILESIZE ((__s64)1 << 52)
     72 #define ROOT_INODE 2
     73 #define BLK_SIZE 4096
     74 #define BLKALIGN(n) (((n)+(BLK_SIZE-1)) & ~(BLK_SIZE-1))
     75 #define UNALIGNED_BLK_OFF 1357 /* Odd number less than BLK_SIZE */
     76 
     77 /* The following constants are file/directory/link names */
     78 #define DUMMY_FILE "dummy.txt"
     79 #define DUMMY_FILE2 "dummy2.txt"
     80 #define DUMMY_LINK "dummy.lnk"
     81 #define DUMMY_SUBDIR "dummy.dir"
     82 #define DUMMY_SUBDIR2 "dummy2.dir"
     83 #define DUMMY_SUBDIR_FILE "dummy.dir/dummy.txt"
     84 #define DUMMY_SUBDIR_LINK "dummy.dir/dummy.lnk"
     85 #define DUMMY_SUBDIR_SUBDIR "dummy.dir/dummy.dir"
     86 #define DUMMY_SUBDIR2_FILE "dummy2.dir/dummy.txt"
     87 #define DUMMY_SUBDIR2_LINK "dummy2.dir/dummy.lnk"
     88 #define DUMMY_SUBDIR2_SUBDIR "dummy2.dir/dummy.dir"
     89 #define DUMMY_TMP "dummy.tmp"
     90 #define DUMMY_FILE_RO_MODE 	(S_IRUSR | S_IRGRP | S_IROTH)
     91 #define DUMMY_FILE_RW_MODE 	(DUMMY_FILE_RO_MODE | S_IWUSR)
     92 #define DUMMY_DIR_RO_MODE 	(DUMMY_FILE_RO_MODE | S_IXUSR | S_IXGRP | S_IXOTH)
     93 #define DUMMY_DIR_RW_MODE	(DUMMY_DIR_RO_MODE | S_IWUSR)
     94 
     95 /* The following constants and macros pertain to DM logging */
     96 #define DMLVL_ERR	1
     97 #define DMLVL_WARN	2
     98 #define DMLVL_DEBUG	3
     99 #define DMLVL_INFO	4
    100 
    101 #define DMSTAT_PASS	1
    102 #define DMSTAT_FAIL	2
    103 #define DMSTAT_SKIP	3
    104 
    105 #define DMLOG_START()	dm_StartLogging()
    106 #define DMLOG_STOP()	dm_StopLogging()
    107 #define DMLOG_PRINT	dm_LogPrintf
    108 #define DMVAR_EXEC(v)	dm_ExecuteVariation(v)
    109 #define DMVAR_PASS()	dm_PassVariation()
    110 #define DMVAR_FAIL()	dm_FailVariation()
    111 #define DMVAR_SKIP()	dm_SkipVariation()
    112 #define DMOPT_PARSE(c,v)	dm_ParseCommandLineOptions(c, v)
    113 #define DMOPT_GET(o)	dm_GetCommandLineOption(o)
    114 #define DM_ERROR	dm_error
    115 #define DM_EXIT()	exit(-1)
    116 #define DMVAR_ENDPASSEXP(n,e,a)	dm_EndVariation_SuccessExpected(n, e, a)
    117 #define DMVAR_ENDFAILEXP(n,e,a,f) dm_EndVariation_FailureExpected(n, e, a, f);
    118 #define DMVAR_CHKPASSEXP(e1,a1,e2,a2) dm_CheckVariation_SuccessExpected(e1, a1, e2, a2)
    119 #define DMVAR_CHKFAILEXP(e1,a1,e,e2,a2) dm_CheckVariation_FailureExpected(e1, a1, e, e2, a2)
    120 #define DMVAR_END(s)	{ if ((s) == DMSTAT_PASS) DMVAR_PASS(); else DMVAR_FAIL(); }
    121 
    122 /* DM logging global functions */
    123 void dm_ParseCommandLineOptions(int argc, char **argv);
    124 char *dm_GetCommandLineOption(char *option);
    125 void dm_StartLogging(void);
    126 void dm_StopLogging(void);
    127 void dm_Error(char *format, ...);
    128 void dm_LogPrintf(u_int level, char *format, ...);
    129 int dm_ExecuteVariation(int var);
    130 void dm_PassVariation(void);
    131 void dm_FailVariation(void);
    132 void dm_SkipVariation(void);
    133 void dm_EndVariation_SuccessExpected(char *funcname, int expectedRC, int actualRC);
    134 void dm_EndVariation_FailureExpected(char *funcname, int expectedRC, int actualRC, int expectedErrno);
    135 #if HAVE_SYS_JFSDMAPI_H
    136 int dm_CheckVariation_SuccessExpected(int expectedRC, int actualRC, dm_eventtype_t expectedEvent, dm_eventtype_t actualEvent);
    137 int dm_CheckVariation_FailureExpected(int expectedRC, int actualRC, int expectedErrno, dm_eventtype_t expectedEvent, dm_eventtype_t actualEvent);
    138 void dm_LogHandle(char *hdl, int len);
    139 
    140 /* Persistent managed regions global data */
    141 
    142 #ifdef MULTIPLE_REGIONS
    143 #define PMR_NUM_REGIONS 5
    144 #else
    145 #define PMR_NUM_REGIONS 1
    146 #endif
    147 extern dm_region_t dm_PMR_regbuf[];
    148 
    149 /* Implementation-dependent data structures */
    150 typedef struct configResult {
    151 	char		*name;
    152 	dm_size_t	result;
    153 } configResult_t;
    154 
    155 typedef struct eventValidity {
    156 	dm_boolean_t bGlobalHandle;
    157 	dm_boolean_t bFSHandle;
    158 	dm_boolean_t bDirHandle;
    159 	dm_boolean_t bFileHandle;
    160 	char *       name;
    161 } eventValidity_t;
    162 
    163 /* Implementation-dependent global function */
    164 int dmimpl_mount(char **mountPt, char **deviceNm);
    165 
    166 /* Implementation-dependent global data */
    167 #define CONFIG_MAX 20
    168 extern configResult_t dmimpl_expectedResults[];
    169 extern eventValidity_t dmimpl_validEvents[];
    170 extern dm_eventset_t dmimpl_eventset;
    171 #endif
    172