Fix a typo inside an assert() statement introduced by the previous commit.
[sqlite.git] / ext / lsm1 / lsm-test / lsmtest.h
blobca60424adde9a60bcfd90acce739db44908c0338
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_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);
158 /* lsmtest.c */
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 *);
187 /* lsmtest_bt.c */
188 int do_bt(int nArg, char **azArg);
190 /* testio.c */
191 int testVfsConfigureDb(TestDb *pDb);
193 /* testfunc.c */
194 int do_show(int nArg, char **azArg);
195 int do_work(int nArg, char **azArg);
197 /* testio.c */
198 int do_io(int nArg, char **azArg);
200 /* lsmtest2.c */
201 void do_crash_test(const char *zPattern, int *pRc);
202 int do_rollback_test(int nArg, char **azArg);
204 /* test3.c */
205 void test_rollback(const char *zSystem, const char *zPattern, int *pRc);
207 /* test4.c */
208 void test_mc(const char *zSystem, const char *zPattern, int *pRc);
210 /* test5.c */
211 void test_mt(const char *zSystem, const char *zPattern, int *pRc);
213 /* lsmtest6.c */
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);
221 /* lsmtest7.c */
222 void test_api(const char *zPattern, int *pRc);
224 /* lsmtest8.c */
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 */
252 Datasource *pData,
253 int iKey,
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 *);
263 /* test1.c */
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);
289 /* lsmtest9.c */
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 *);
299 #ifdef __cplusplus
300 } /* End of the 'extern "C"' block */
301 #endif
303 #endif