2 #ifndef __WRAPPER_INT_H_
3 #define __WRAPPER_INT_H_
5 #include "lsmtest_tdb.h"
17 #include <sys/types.h>
30 # define gettimeofday win32GetTimeOfDay
32 # define sleep(sec) Sleep(1000 * (sec))
33 # define usleep(usec) Sleep(((usec) + 999) / 1000)
36 # define snprintf _snprintf
37 # define fsync(fd) FlushFileBuffers((HANDLE)_get_osfhandle((fd)))
38 # define fdatasync(fd) FlushFileBuffers((HANDLE)_get_osfhandle((fd)))
39 # define __va_copy(dst,src) ((dst) = (src))
40 # define ftruncate(fd,sz) ((_chsize_s((fd), (sz))==0) ? 0 : -1)
42 # error Unsupported C compiler for Windows.
44 int win32GetTimeOfDay(struct timeval
*, void *);
48 typedef unsigned int u32
;
49 typedef unsigned char u8
;
50 typedef long long int i64
;
51 typedef unsigned long long int u64
;
55 #define ArraySize(x) ((int)(sizeof(x) / sizeof((x)[0])))
57 #define MIN(x,y) ((x)<(y) ? (x) : (y))
58 #define MAX(x,y) ((x)>(y) ? (x) : (y))
60 #define unused_parameter(x) (void)(x)
62 #define TESTDB_DEFAULT_PAGE_SIZE 4096
63 #define TESTDB_DEFAULT_CACHE_SIZE 2048
66 # define _O_BINARY (0)
70 ** Ideally, these should be in wrapper.c. But they are here instead so that
71 ** they can be used by the C++ database wrappers in wrapper2.cc.
73 typedef struct DatabaseMethods DatabaseMethods
;
75 DatabaseMethods
const *pMethods
; /* Database methods */
76 const char *zLibrary
; /* Library name for tdb_open() */
78 struct DatabaseMethods
{
79 int (*xClose
)(TestDb
*);
80 int (*xWrite
)(TestDb
*, void *, int , void *, int);
81 int (*xDelete
)(TestDb
*, void *, int);
82 int (*xDeleteRange
)(TestDb
*, void *, int, void *, int);
83 int (*xFetch
)(TestDb
*, void *, int, void **, int *);
84 int (*xScan
)(TestDb
*, void *, int, void *, int, void *, int,
85 void (*)(void *, void *, int , void *, int)
87 int (*xBegin
)(TestDb
*, int);
88 int (*xCommit
)(TestDb
*, int);
89 int (*xRollback
)(TestDb
*, int);
93 ** Functions in wrapper2.cc (a C++ source file). wrapper2.cc contains the
94 ** wrapper for Kyoto Cabinet. Kyoto cabinet has a C API, but
95 ** the primary interface is the C++ API.
97 int test_kc_open(const char*, const char *zFilename
, int bClear
, TestDb
**ppDb
);
98 int test_kc_close(TestDb
*);
99 int test_kc_write(TestDb
*, void *, int , void *, int);
100 int test_kc_delete(TestDb
*, void *, int);
101 int test_kc_delete_range(TestDb
*, void *, int, void *, int);
102 int test_kc_fetch(TestDb
*, void *, int, void **, int *);
103 int test_kc_scan(TestDb
*, void *, int, void *, int, void *, int,
104 void (*)(void *, void *, int , void *, int)
107 int test_mdb_open(const char*, const char *zFile
, int bClear
, TestDb
**ppDb
);
108 int test_mdb_close(TestDb
*);
109 int test_mdb_write(TestDb
*, void *, int , void *, int);
110 int test_mdb_delete(TestDb
*, void *, int);
111 int test_mdb_fetch(TestDb
*, void *, int, void **, int *);
112 int test_mdb_scan(TestDb
*, void *, int, void *, int, void *, int,
113 void (*)(void *, void *, int , void *, int)
117 ** Functions in wrapper3.c. This file contains the tdb wrapper for lsm.
118 ** The wrapper for lsm is a bit more involved than the others, as it
119 ** includes code for a couple of different lsm configurations, and for
120 ** various types of fault injection and robustness testing.
122 int test_lsm_open(const char*, const char *zFile
, int bClear
, TestDb
**ppDb
);
123 int test_lsm_lomem_open(const char*, const char*, int bClear
, TestDb
**ppDb
);
124 int test_lsm_lomem2_open(const char*, const char*, int bClear
, TestDb
**ppDb
);
125 int test_lsm_zip_open(const char*, const char*, int bClear
, TestDb
**ppDb
);
126 int test_lsm_small_open(const char*, const char*, int bClear
, TestDb
**ppDb
);
127 int test_lsm_mt2(const char*, const char *zFile
, int bClear
, TestDb
**ppDb
);
128 int test_lsm_mt3(const char*, const char *zFile
, int bClear
, TestDb
**ppDb
);
130 int tdb_lsm_configure(lsm_db
*, const char *);
132 /* Functions in lsmtest_tdb4.c */
133 int test_bt_open(const char*, const char *zFile
, int bClear
, TestDb
**ppDb
);
134 int test_fbt_open(const char*, const char *zFile
, int bClear
, TestDb
**ppDb
);
135 int test_fbts_open(const char*, const char *zFile
, int bClear
, TestDb
**ppDb
);
138 /* Functions in testutil.c. */
139 int testPrngInit(void);
140 u32
testPrngValue(u32 iVal
);
141 void testPrngArray(u32 iVal
, u32
*aOut
, int nOut
);
142 void testPrngString(u32 iVal
, char *aOut
, int nOut
);
144 void testErrorInit(int argc
, char **);
145 void testPrintError(const char *zFormat
, ...);
146 void testPrintUsage(const char *zArgs
);
147 void testPrintFUsage(const char *zFormat
, ...);
148 void testTimeInit(void);
149 int testTimeGet(void);
151 /* Functions in testmem.c. */
152 void testMallocInstall(lsm_env
*pEnv
);
153 void testMallocUninstall(lsm_env
*pEnv
);
154 void testMallocCheck(lsm_env
*pEnv
, int *, int *, FILE *);
155 void testMallocOom(lsm_env
*pEnv
, int, int, void(*)(void*), void *);
156 void testMallocOomEnable(lsm_env
*pEnv
, int);
159 TestDb
*testOpen(const char *zSystem
, int, int *pRc
);
160 void testReopen(TestDb
**ppDb
, int *pRc
);
161 void testClose(TestDb
**ppDb
);
163 void testFetch(TestDb
*, void *, int, void *, int, int *);
164 void testWrite(TestDb
*, void *, int, void *, int, int *);
165 void testDelete(TestDb
*, void *, int, int *);
166 void testDeleteRange(TestDb
*, void *, int, void *, int, int *);
167 void testWriteStr(TestDb
*, const char *, const char *zVal
, int *pRc
);
168 void testFetchStr(TestDb
*, const char *, const char *, int *pRc
);
170 void testBegin(TestDb
*pDb
, int iTrans
, int *pRc
);
171 void testCommit(TestDb
*pDb
, int iTrans
, int *pRc
);
173 void test_failed(void);
175 char *testMallocPrintf(const char *zFormat
, ...);
176 char *testMallocVPrintf(const char *zFormat
, va_list ap
);
177 int testGlobMatch(const char *zPattern
, const char *zStr
);
179 void testScanCompare(TestDb
*, TestDb
*, int, void *, int, void *, int, int *);
180 void testFetchCompare(TestDb
*, TestDb
*, void *, int, int *);
182 void *testMalloc(int);
183 void *testMallocCopy(void *pCopy
, int nByte
);
184 void *testRealloc(void *, int);
185 void testFree(void *);
188 int do_bt(int nArg
, char **azArg
);
191 int testVfsConfigureDb(TestDb
*pDb
);
194 int do_show(int nArg
, char **azArg
);
195 int do_work(int nArg
, char **azArg
);
198 int do_io(int nArg
, char **azArg
);
201 void do_crash_test(const char *zPattern
, int *pRc
);
202 int do_rollback_test(int nArg
, char **azArg
);
205 void test_rollback(const char *zSystem
, const char *zPattern
, int *pRc
);
208 void test_mc(const char *zSystem
, const char *zPattern
, int *pRc
);
211 void test_mt(const char *zSystem
, const char *zPattern
, int *pRc
);
214 void test_oom(const char *zPattern
, int *pRc
);
215 void testDeleteLsmdb(const char *zFile
);
217 void testSaveDb(const char *zFile
, const char *zAuxExt
);
218 void testRestoreDb(const char *zFile
, const char *zAuxExt
);
219 void testCopyLsmdb(const char *zFrom
, const char *zTo
);
222 void test_api(const char *zPattern
, int *pRc
);
225 void do_writer_crash_test(const char *zPattern
, int *pRc
);
227 /*************************************************************************
228 ** Interface to functionality in test_datasource.c.
230 typedef struct Datasource Datasource
;
231 typedef struct DatasourceDefn DatasourceDefn
;
233 struct DatasourceDefn
{
234 int eType
; /* A TEST_DATASOURCE_* value */
235 int nMinKey
; /* Minimum key size */
236 int nMaxKey
; /* Maximum key size */
237 int nMinVal
; /* Minimum value size */
238 int nMaxVal
; /* Maximum value size */
241 #define TEST_DATASOURCE_RANDOM 1
242 #define TEST_DATASOURCE_SEQUENCE 2
244 char *testDatasourceName(const DatasourceDefn
*);
245 Datasource
*testDatasourceNew(const DatasourceDefn
*);
246 void testDatasourceFree(Datasource
*);
247 void testDatasourceEntry(Datasource
*, int, void **, int *, void **, int *);
248 /* End of test_datasource.c interface.
249 *************************************************************************/
250 void testDatasourceFetch(
251 TestDb
*pDb
, /* Database handle */
254 int *pRc
/* IN/OUT: Error code */
257 void testWriteDatasource(TestDb
*, Datasource
*, int, int *);
258 void testWriteDatasourceRange(TestDb
*, Datasource
*, int, int, int *);
259 void testDeleteDatasource(TestDb
*, Datasource
*, int, int *);
260 void testDeleteDatasourceRange(TestDb
*, Datasource
*, int, int, int *);
264 void test_data_1(const char *, const char *, int *pRc
);
265 void test_data_2(const char *, const char *, int *pRc
);
266 void test_data_3(const char *, const char *, int *pRc
);
267 void testDbContents(TestDb
*, Datasource
*, int, int, int, int, int, int *);
268 void testCaseProgress(int, int, int, int *);
269 int testCaseNDot(void);
271 void testCompareDb(Datasource
*, int, int, TestDb
*, TestDb
*, int *);
272 int testControlDb(TestDb
**ppDb
);
274 typedef struct CksumDb CksumDb
;
275 CksumDb
*testCksumArrayNew(Datasource
*, int, int, int);
276 char *testCksumArrayGet(CksumDb
*, int);
277 void testCksumArrayFree(CksumDb
*);
278 void testCaseStart(int *pRc
, char *zFmt
, ...);
279 void testCaseFinish(int rc
);
280 void testCaseSkip(void);
281 int testCaseBegin(int *, const char *, const char *, ...);
283 #define TEST_CKSUM_BYTES 29
284 int testCksumDatabase(TestDb
*pDb
, char *zOut
);
285 int testCountDatabase(TestDb
*pDb
);
286 void testCompareInt(int, int, int *);
287 void testCompareStr(const char *z1
, const char *z2
, int *pRc
);
290 void test_data_4(const char *, const char *, int *pRc
);
294 ** Similar to the Tcl_GetIndexFromObjStruct() Tcl library function.
296 #define testArgSelect(w,x,y,z) testArgSelectX(w,x,sizeof(w[0]),y,z)
297 int testArgSelectX(void *, const char *, int, const char *, int *);
300 } /* End of the 'extern "C"' block */