Fix the ".lint fkey-indexes" shell command so that it works with WITHOUT ROWID
[sqlite.git] / ext / lsm1 / lsm-test / lsmtest9.c
blob144cae720309b66256de4c6420b5f2f65da5a510
2 #include "lsmtest.h"
4 #define DATA_SEQUENTIAL TEST_DATASOURCE_SEQUENCE
5 #define DATA_RANDOM TEST_DATASOURCE_RANDOM
7 typedef struct Datatest4 Datatest4;
9 /*
10 ** Test overview:
12 ** 1. Insert (Datatest4.nRec) records into a database.
14 ** 2. Repeat (Datatest4.nRepeat) times:
16 ** 2a. Delete 2/3 of the records in the database.
18 ** 2b. Run lsm_work(nMerge=1).
20 ** 2c. Insert as many records as were deleted in 2a.
22 ** 2d. Check database content is as expected.
24 ** 2e. If (Datatest4.bReopen) is true, close and reopen the database.
26 struct Datatest4 {
27 /* Datasource definition */
28 DatasourceDefn defn;
30 int nRec;
31 int nRepeat;
32 int bReopen;
35 static void doDataTest4(
36 const char *zSystem, /* Database system to test */
37 Datatest4 *p, /* Structure containing test parameters */
38 int *pRc /* OUT: Error code */
40 lsm_db *db = 0;
41 TestDb *pDb;
42 TestDb *pControl;
43 Datasource *pData;
44 int i;
45 int rc = 0;
46 int iDot = 0;
47 int bMultiThreaded = 0; /* True for MT LSM database */
49 int nRecOn3 = (p->nRec / 3);
50 int iData = 0;
52 /* Start the test case, open a database and allocate the datasource. */
53 rc = testControlDb(&pControl);
54 pDb = testOpen(zSystem, 1, &rc);
55 pData = testDatasourceNew(&p->defn);
56 if( rc==0 ){
57 db = tdb_lsm(pDb);
58 bMultiThreaded = tdb_lsm_multithread(pDb);
61 testWriteDatasourceRange(pControl, pData, iData, nRecOn3*3, &rc);
62 testWriteDatasourceRange(pDb, pData, iData, nRecOn3*3, &rc);
64 for(i=0; rc==0 && i<p->nRepeat; i++){
66 testDeleteDatasourceRange(pControl, pData, iData, nRecOn3*2, &rc);
67 testDeleteDatasourceRange(pDb, pData, iData, nRecOn3*2, &rc);
69 if( db ){
70 int nDone;
71 #if 0
72 fprintf(stderr, "lsm_work() start...\n"); fflush(stderr);
73 #endif
74 do {
75 nDone = 0;
76 rc = lsm_work(db, 1, (1<<30), &nDone);
77 }while( rc==0 && nDone>0 );
78 if( bMultiThreaded && rc==LSM_BUSY ) rc = LSM_OK;
79 #if 0
80 fprintf(stderr, "lsm_work() done...\n"); fflush(stderr);
81 #endif
84 if( i+1<p->nRepeat ){
85 iData += (nRecOn3*2);
86 testWriteDatasourceRange(pControl, pData, iData+nRecOn3, nRecOn3*2, &rc);
87 testWriteDatasourceRange(pDb, pData, iData+nRecOn3, nRecOn3*2, &rc);
89 testCompareDb(pData, nRecOn3*3, iData, pControl, pDb, &rc);
91 /* If Datatest4.bReopen is true, close and reopen the database */
92 if( p->bReopen ){
93 testReopen(&pDb, &rc);
94 if( rc==0 ) db = tdb_lsm(pDb);
98 /* Update the progress dots... */
99 testCaseProgress(i, p->nRepeat, testCaseNDot(), &iDot);
102 testClose(&pDb);
103 testClose(&pControl);
104 testDatasourceFree(pData);
105 testCaseFinish(rc);
106 *pRc = rc;
109 static char *getName4(const char *zSystem, Datatest4 *pTest){
110 char *zRet;
111 char *zData;
112 zData = testDatasourceName(&pTest->defn);
113 zRet = testMallocPrintf("data4.%s.%s.%d.%d.%d",
114 zSystem, zData, pTest->nRec, pTest->nRepeat, pTest->bReopen
116 testFree(zData);
117 return zRet;
120 void test_data_4(
121 const char *zSystem, /* Database system name */
122 const char *zPattern, /* Run test cases that match this pattern */
123 int *pRc /* IN/OUT: Error code */
125 Datatest4 aTest[] = {
126 /* defn, nRec, nRepeat, bReopen */
127 { {DATA_RANDOM, 20,25, 500,600}, 10000, 10, 0 },
128 { {DATA_RANDOM, 20,25, 500,600}, 10000, 10, 1 },
131 int i;
133 for(i=0; *pRc==LSM_OK && i<ArraySize(aTest); i++){
134 char *zName = getName4(zSystem, &aTest[i]);
135 if( testCaseBegin(pRc, zPattern, "%s", zName) ){
136 doDataTest4(zSystem, &aTest[i], pRc);
138 testFree(zName);