Fix the ".lint fkey-indexes" shell command so that it works with WITHOUT ROWID
[sqlite.git] / ext / lsm1 / lsm-test / lsmtest.h
blob249bc999e0e9a4a243477093da60b7cd9d2a16be
2 #ifndef __WRAPPER_INT_H_
3 #define __WRAPPER_INT_H_
5 #include "lsmtest_tdb.h"
6 #include "sqlite3.h"
7 #include "lsm.h"
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>
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
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
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
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
65 #ifndef _O_BINARY
66 # define _O_BINARY (0)
67 #endif
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;
74 struct TestDb {
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);
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.
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_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);
129 int tdb_lsm_configure(lsm_db *, const char *);
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);
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);
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);
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);
157 /* lsmtest.c */
158 TestDb *testOpen(const char *zSystem, int, int *pRc);
159 void testReopen(TestDb **ppDb, int *pRc);
160 void testClose(TestDb **ppDb);
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);
169 void testBegin(TestDb *pDb, int iTrans, int *pRc);
170 void testCommit(TestDb *pDb, int iTrans, int *pRc);
172 void test_failed(void);
174 char *testMallocPrintf(const char *zFormat, ...);
175 char *testMallocVPrintf(const char *zFormat, va_list ap);
176 int testGlobMatch(const char *zPattern, const char *zStr);
178 void testScanCompare(TestDb *, TestDb *, int, void *, int, void *, int, int *);
179 void testFetchCompare(TestDb *, TestDb *, void *, int, int *);
181 void *testMalloc(int);
182 void *testMallocCopy(void *pCopy, int nByte);
183 void *testRealloc(void *, int);
184 void testFree(void *);
186 /* lsmtest_bt.c */
187 int do_bt(int nArg, char **azArg);
189 /* testio.c */
190 int testVfsConfigureDb(TestDb *pDb);
192 /* testfunc.c */
193 int do_show(int nArg, char **azArg);
194 int do_work(int nArg, char **azArg);
196 /* testio.c */
197 int do_io(int nArg, char **azArg);
199 /* lsmtest2.c */
200 void do_crash_test(const char *zPattern, int *pRc);
201 int do_rollback_test(int nArg, char **azArg);
203 /* test3.c */
204 void test_rollback(const char *zSystem, const char *zPattern, int *pRc);
206 /* test4.c */
207 void test_mc(const char *zSystem, const char *zPattern, int *pRc);
209 /* test5.c */
210 void test_mt(const char *zSystem, const char *zPattern, int *pRc);
212 /* lsmtest6.c */
213 void test_oom(const char *zPattern, int *pRc);
214 void testDeleteLsmdb(const char *zFile);
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);
220 /* lsmtest7.c */
221 void test_api(const char *zPattern, int *pRc);
223 /* lsmtest8.c */
224 void do_writer_crash_test(const char *zPattern, int *pRc);
226 /*************************************************************************
227 ** Interface to functionality in test_datasource.c.
229 typedef struct Datasource Datasource;
230 typedef struct DatasourceDefn DatasourceDefn;
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 */
240 #define TEST_DATASOURCE_RANDOM 1
241 #define TEST_DATASOURCE_SEQUENCE 2
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 */
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 *);
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);
270 void testCompareDb(Datasource *, int, int, TestDb *, TestDb *, int *);
271 int testControlDb(TestDb **ppDb);
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 *, ...);
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);
288 /* lsmtest9.c */
289 void test_data_4(const char *, const char *, int *pRc);
293 ** Similar to the Tcl_GetIndexFromObjStruct() Tcl library function.
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 *);
298 #ifdef __cplusplus
299 } /* End of the 'extern "C"' block */
300 #endif
302 #endif