1 2 #ifndef __WRAPPER_INT_H_ 3 #define __WRAPPER_INT_H_ 4 5 #include "lsmtest_tdb.h" 6 #include "sqlite3.h" 7 #include "lsm.h" 8 9 #include <assert.h> 10 #include <stdarg.h> 11 #include <stdlib.h> 12 #include <string.h> 13 #include <stdio.h> 14 #ifndef _WIN32 15 # include <unistd.h> 16 #endif 17 #include <sys/types.h> 18 #include <sys/stat.h> 19 #include <fcntl.h> 20 #include <ctype.h> 21 #include <stdlib.h> 22 #include <errno.h> 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 28 #ifdef _WIN32 29 # include "windows.h" 30 # define gettimeofday win32GetTimeOfDay 31 # define F_OK (0) 32 # define sleep(sec) Sleep(1000 * (sec)) 33 # define usleep(usec) Sleep(((usec) + 999) / 1000) 34 # ifdef _MSC_VER 35 # include <io.h> 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) 41 # else 42 # error Unsupported C compiler for Windows. 43 # endif 44 int win32GetTimeOfDay(struct timeval *, void *); 45 #endif 46 47 #ifndef _LSM_INT_H 48 typedef unsigned int u32; 49 typedef unsigned char u8; 50 typedef long long int i64; 51 typedef unsigned long long int u64; 52 #endif 53 54 55 #define ArraySize(x) ((int)(sizeof(x) / sizeof((x)[0]))) 56 57 #define MIN(x,y) ((x)<(y) ? (x) : (y)) 58 #define MAX(x,y) ((x)>(y) ? (x) : (y)) 59 60 #define unused_parameter(x) (void)(x) 61 62 #define TESTDB_DEFAULT_PAGE_SIZE 4096 63 #define TESTDB_DEFAULT_CACHE_SIZE 2048 64 65 #ifndef _O_BINARY 66 # define _O_BINARY (0) 67 #endif 68 69 /* 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. 72 */ 73 typedef struct DatabaseMethods DatabaseMethods; 74 struct TestDb { 75 DatabaseMethods const *pMethods; /* Database methods */ 76 const char *zLibrary; /* Library name for tdb_open() */ 77 }; 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) 86 ); 87 int (*xBegin)(TestDb *, int); 88 int (*xCommit)(TestDb *, int); 89 int (*xRollback)(TestDb *, int); 90 }; 91 92 /* 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. 96 */ 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) 105 ); 106 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) 114 ); 115 116 /* 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. 121 */ 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_zip_open(const char*, const char*, int bClear, TestDb **ppDb); 125 int test_lsm_small_open(const char*, const char*, int bClear, TestDb **ppDb); 126 int test_lsm_mt2(const char*, const char *zFile, int bClear, TestDb **ppDb); 127 int test_lsm_mt3(const char*, const char *zFile, int bClear, TestDb **ppDb); 128 129 int tdb_lsm_configure(lsm_db *, const char *); 130 131 /* Functions in lsmtest_tdb4.c */ 132 int test_bt_open(const char*, const char *zFile, int bClear, TestDb **ppDb); 133 int test_fbt_open(const char*, const char *zFile, int bClear, TestDb **ppDb); 134 int test_fbts_open(const char*, const char *zFile, int bClear, TestDb **ppDb); 135 136 137 /* Functions in testutil.c. */ 138 int testPrngInit(void); 139 u32 testPrngValue(u32 iVal); 140 void testPrngArray(u32 iVal, u32 *aOut, int nOut); 141 void testPrngString(u32 iVal, char *aOut, int nOut); 142 143 void testErrorInit(int argc, char **); 144 void testPrintError(const char *zFormat, ...); 145 void testPrintUsage(const char *zArgs); 146 void testPrintFUsage(const char *zFormat, ...); 147 void testTimeInit(void); 148 int testTimeGet(void); 149 150 /* Functions in testmem.c. */ 151 void testMallocInstall(lsm_env *pEnv); 152 void testMallocUninstall(lsm_env *pEnv); 153 void testMallocCheck(lsm_env *pEnv, int *, int *, FILE *); 154 void testMallocOom(lsm_env *pEnv, int, int, void(*)(void*), void *); 155 void testMallocOomEnable(lsm_env *pEnv, int); 156 157 /* lsmtest.c */ 158 TestDb *testOpen(const char *zSystem, int, int *pRc); 159 void testReopen(TestDb **ppDb, int *pRc); 160 void testClose(TestDb **ppDb); 161 162 void testFetch(TestDb *, void *, int, void *, int, int *); 163 void testWrite(TestDb *, void *, int, void *, int, int *); 164 void testDelete(TestDb *, void *, int, int *); 165 void testDeleteRange(TestDb *, void *, int, void *, int, int *); 166 void testWriteStr(TestDb *, const char *, const char *zVal, int *pRc); 167 void testFetchStr(TestDb *, const char *, const char *, int *pRc); 168 169 void testBegin(TestDb *pDb, int iTrans, int *pRc); 170 void testCommit(TestDb *pDb, int iTrans, int *pRc); 171 172 void test_failed(void); 173 174 char *testMallocPrintf(const char *zFormat, ...); 175 char *testMallocVPrintf(const char *zFormat, va_list ap); 176 int testGlobMatch(const char *zPattern, const char *zStr); 177 178 void testScanCompare(TestDb *, TestDb *, int, void *, int, void *, int, int *); 179 void testFetchCompare(TestDb *, TestDb *, void *, int, int *); 180 181 void *testMalloc(int); 182 void *testMallocCopy(void *pCopy, int nByte); 183 void *testRealloc(void *, int); 184 void testFree(void *); 185 186 /* lsmtest_bt.c */ 187 int do_bt(int nArg, char **azArg); 188 189 /* testio.c */ 190 int testVfsConfigureDb(TestDb *pDb); 191 192 /* testfunc.c */ 193 int do_show(int nArg, char **azArg); 194 int do_work(int nArg, char **azArg); 195 196 /* testio.c */ 197 int do_io(int nArg, char **azArg); 198 199 /* lsmtest2.c */ 200 void do_crash_test(const char *zPattern, int *pRc); 201 int do_rollback_test(int nArg, char **azArg); 202 203 /* test3.c */ 204 void test_rollback(const char *zSystem, const char *zPattern, int *pRc); 205 206 /* test4.c */ 207 void test_mc(const char *zSystem, const char *zPattern, int *pRc); 208 209 /* test5.c */ 210 void test_mt(const char *zSystem, const char *zPattern, int *pRc); 211 212 /* lsmtest6.c */ 213 void test_oom(const char *zPattern, int *pRc); 214 void testDeleteLsmdb(const char *zFile); 215 216 void testSaveDb(const char *zFile, const char *zAuxExt); 217 void testRestoreDb(const char *zFile, const char *zAuxExt); 218 void testCopyLsmdb(const char *zFrom, const char *zTo); 219 220 /* lsmtest7.c */ 221 void test_api(const char *zPattern, int *pRc); 222 223 /* lsmtest8.c */ 224 void do_writer_crash_test(const char *zPattern, int *pRc); 225 226 /************************************************************************* 227 ** Interface to functionality in test_datasource.c. 228 */ 229 typedef struct Datasource Datasource; 230 typedef struct DatasourceDefn DatasourceDefn; 231 232 struct DatasourceDefn { 233 int eType; /* A TEST_DATASOURCE_* value */ 234 int nMinKey; /* Minimum key size */ 235 int nMaxKey; /* Maximum key size */ 236 int nMinVal; /* Minimum value size */ 237 int nMaxVal; /* Maximum value size */ 238 }; 239 240 #define TEST_DATASOURCE_RANDOM 1 241 #define TEST_DATASOURCE_SEQUENCE 2 242 243 char *testDatasourceName(const DatasourceDefn *); 244 Datasource *testDatasourceNew(const DatasourceDefn *); 245 void testDatasourceFree(Datasource *); 246 void testDatasourceEntry(Datasource *, int, void **, int *, void **, int *); 247 /* End of test_datasource.c interface. 248 *************************************************************************/ 249 void testDatasourceFetch( 250 TestDb *pDb, /* Database handle */ 251 Datasource *pData, 252 int iKey, 253 int *pRc /* IN/OUT: Error code */ 254 ); 255 256 void testWriteDatasource(TestDb *, Datasource *, int, int *); 257 void testWriteDatasourceRange(TestDb *, Datasource *, int, int, int *); 258 void testDeleteDatasource(TestDb *, Datasource *, int, int *); 259 void testDeleteDatasourceRange(TestDb *, Datasource *, int, int, int *); 260 261 262 /* test1.c */ 263 void test_data_1(const char *, const char *, int *pRc); 264 void test_data_2(const char *, const char *, int *pRc); 265 void test_data_3(const char *, const char *, int *pRc); 266 void testDbContents(TestDb *, Datasource *, int, int, int, int, int, int *); 267 void testCaseProgress(int, int, int, int *); 268 int testCaseNDot(void); 269 270 void testCompareDb(Datasource *, int, int, TestDb *, TestDb *, int *); 271 int testControlDb(TestDb **ppDb); 272 273 typedef struct CksumDb CksumDb; 274 CksumDb *testCksumArrayNew(Datasource *, int, int, int); 275 char *testCksumArrayGet(CksumDb *, int); 276 void testCksumArrayFree(CksumDb *); 277 void testCaseStart(int *pRc, char *zFmt, ...); 278 void testCaseFinish(int rc); 279 void testCaseSkip(void); 280 int testCaseBegin(int *, const char *, const char *, ...); 281 282 #define TEST_CKSUM_BYTES 29 283 int testCksumDatabase(TestDb *pDb, char *zOut); 284 int testCountDatabase(TestDb *pDb); 285 void testCompareInt(int, int, int *); 286 void testCompareStr(const char *z1, const char *z2, int *pRc); 287 288 /* lsmtest9.c */ 289 void test_data_4(const char *, const char *, int *pRc); 290 291 292 /* 293 ** Similar to the Tcl_GetIndexFromObjStruct() Tcl library function. 294 */ 295 #define testArgSelect(w,x,y,z) testArgSelectX(w,x,sizeof(w[0]),y,z) 296 int testArgSelectX(void *, const char *, int, const char *, int *); 297 298 #ifdef __cplusplus 299 } /* End of the 'extern "C"' block */ 300 #endif 301 302 #endif 303