persistentstorage/dbms/tdbms/t_dbstress.cpp
branchRCL_3
changeset 6 5ffdb8f2067f
parent 0 08ec8eefde2f
child 23 26645d81f48d
equal deleted inserted replaced
2:6862383cf555 6:5ffdb8f2067f
    18 //#define __DUMP_STATE
    18 //#define __DUMP_STATE
    19 #if defined(__WINS__)
    19 #if defined(__WINS__)
    20 //#define _INSTALL_FILE_SYSTEM
    20 //#define _INSTALL_FILE_SYSTEM
    21 #endif
    21 #endif
    22 
    22 
    23 GLDEF_D RTest test(_L("t_dbstress: Stress testing DBMS"));
    23 GLDEF_D RTest TheTest(_L("t_dbstress: Stress testing DBMS"));
    24 
    24 
    25 GLDEF_D TPtrC KTestDir=_S("\\DBMS-TST\\");
    25 GLDEF_D TPtrC KTestDir=_S("\\DBMS-TST\\");
    26 GLDEF_D TPtrC KLogFile=_L("T_STRESS.LOG");
    26 GLDEF_D TPtrC KLogFile=_L("T_STRESS.LOG");
    27 GLDEF_D TPtrC KTestDatabase=_S("T_STRESS.DB");
    27 GLDEF_D TPtrC KTestDatabase=_S("T_STRESS.DB");
    28 GLDEF_D TInt NewCount,OldCount;
    28 GLDEF_D TInt NewCount,OldCount;
    59 	}
    59 	}
    60 
    60 
    61 void Timer::Print()
    61 void Timer::Print()
    62 	{
    62 	{
    63 	TInt64 milli=Stop();
    63 	TInt64 milli=Stop();
    64 	test.Printf(_L("  %u milliseconds\n"), I64LOW(milli) );
    64 	TheTest.Printf(_L("  %u milliseconds\n"), I64LOW(milli) );
    65 	}
    65 	}
    66 
    66 
    67 class Set
    67 class Set
    68 	{
    68 	{
    69 public:
    69 public:
   126 GLDEF_C TInt Random(TInt aRange)
   126 GLDEF_C TInt Random(TInt aRange)
   127 	{
   127 	{
   128 	return (Math::Random()>>11)%aRange;
   128 	return (Math::Random()>>11)%aRange;
   129 	}
   129 	}
   130 
   130 
   131 #undef test
   131 ///////////////////////////////////////////////////////////////////////////////////////
   132 LOCAL_C void Test(TInt aValue,TInt anExpected,TInt aLine)
   132 ///////////////////////////////////////////////////////////////////////////////////////
   133 	{
   133 
   134 	if (aValue==anExpected)
   134 TPtrC FileName(const TText* aFile)
   135 		return;
   135     {
   136 	test.Printf(_L("** Expected %d, was %d\n"),anExpected,aValue);
   136     TPtrC p(aFile);
   137 	test(EFalse,aLine);
   137     TInt ix=p.LocateReverse('\\');
   138 	}
   138     if (ix<0)
   139 #define test1(aTest) test(aTest,__LINE__)
   139         ix=p.LocateReverse('/');
   140 #define test2(aValue,anExpected) Test(aValue,anExpected,__LINE__)
   140     if (ix>=0)
       
   141         p.Set(p.Mid(1+ix));
       
   142     return p;
       
   143     }
       
   144 
       
   145 //Test macros and functions
       
   146 void Check1(TInt aValue, const TText* aFile, TInt aLine)
       
   147     {
       
   148     if(!aValue)
       
   149         {
       
   150         TPtrC fname(FileName(aFile));
       
   151         TheTest.Printf(_L("*** Expression evaluated to false. %S-%d\r\n"), &fname, aLine);
       
   152         TheTest(EFalse, aLine);
       
   153         }
       
   154     }
       
   155 void Check2(TInt aValue, TInt aExpected, const TText* aFile, TInt aLine)
       
   156     {
       
   157     if(aValue != aExpected)
       
   158         {
       
   159         TPtrC fname(FileName(aFile));
       
   160         TheTest.Printf(_L("*** Expected %d, got %d. %S-%d\r\n"), aExpected, aValue, &fname, aLine);
       
   161         TheTest(EFalse, aLine);
       
   162         }
       
   163     }
       
   164 
       
   165 ///////////////////////////////////////////////////////////////////////////////////////
   141 
   166 
   142 LOCAL_C void CreateIndexL(RDbDatabase& aDatabase,const TDesC& aTable,const TDesC& aColumn,TBool aUnique)
   167 LOCAL_C void CreateIndexL(RDbDatabase& aDatabase,const TDesC& aTable,const TDesC& aColumn,TBool aUnique)
   143 	{
   168 	{
   144 	CDbKey* key=CDbKey::NewLC();
   169 	CDbKey* key=CDbKey::NewLC();
   145 	key->AddL(aColumn);
   170 	key->AddL(aColumn);
   146 	if (aUnique)
   171 	if (aUnique)
   147 		key->MakeUnique();
   172 		key->MakeUnique();
   148 	test2(aDatabase.CreateIndex(aColumn,aTable,*key),KErrNone);
   173 	TEST2(aDatabase.CreateIndex(aColumn,aTable,*key),KErrNone);
   149 	CleanupStack::PopAndDestroy();
   174 	CleanupStack::PopAndDestroy();
   150 	}
   175 	}
   151 
   176 
   152 //
   177 //
   153 // Create the database
   178 // Create the database
   158 	store->SetTypeL(KPermanentFileStoreLayoutUid);
   183 	store->SetTypeL(KPermanentFileStoreLayoutUid);
   159 	store->SetRootL(TheDatabase.CreateL(store));
   184 	store->SetRootL(TheDatabase.CreateL(store));
   160 //	create the tables
   185 //	create the tables
   161 	TheDatabase.Begin();
   186 	TheDatabase.Begin();
   162 	CDbColSet* set=Set::CreateL(AccountsDef);
   187 	CDbColSet* set=Set::CreateL(AccountsDef);
   163 	test2(TheDatabase.CreateTable(KAccounts,*set),KErrNone);
   188 	TEST2(TheDatabase.CreateTable(KAccounts,*set),KErrNone);
   164 	delete set;
   189 	delete set;
   165 	CreateIndexL(TheDatabase,KAccounts,KAccountsID,ETrue);
   190 	CreateIndexL(TheDatabase,KAccounts,KAccountsID,ETrue);
   166 	CreateIndexL(TheDatabase,KAccounts,KAccountsBalance,EFalse);
   191 	CreateIndexL(TheDatabase,KAccounts,KAccountsBalance,EFalse);
   167 	set=Set::CreateL(TransactionsDef);
   192 	set=Set::CreateL(TransactionsDef);
   168 	test2(TheDatabase.CreateTable(KTransactions,*set),KErrNone);
   193 	TEST2(TheDatabase.CreateTable(KTransactions,*set),KErrNone);
   169 	delete set;
   194 	delete set;
   170 	CreateIndexL(TheDatabase,KTransactions,KTransactionDate,EFalse);
   195 	CreateIndexL(TheDatabase,KTransactions,KTransactionDate,EFalse);
   171 	test2(TheDatabase.Commit(),KErrNone);
   196 	TEST2(TheDatabase.Commit(),KErrNone);
   172 	OldCount=NewCount=0;
   197 	OldCount=NewCount=0;
   173 // prepare Accs table
   198 // prepare Accs table
   174 	TheDatabase.Begin();
   199 	TheDatabase.Begin();
   175 	test2(Accs.Prepare(TheDatabase,_L("select * from accounts"),Accs.EInsertOnly),KErrNone);
   200 	TEST2(Accs.Prepare(TheDatabase,_L("select * from accounts"),Accs.EInsertOnly),KErrNone);
   176 	Accs.InsertL();
   201 	Accs.InsertL();
   177 	Accs.SetColL(1,TInt32(ECash));
   202 	Accs.SetColL(1,TInt32(ECash));
   178 	Accs.SetColL(2,KInitialCash);
   203 	Accs.SetColL(2,KInitialCash);
   179 	Accs.SetColL(3,KInitialCash);
   204 	Accs.SetColL(3,KInitialCash);
   180 	Accs.PutL();
   205 	Accs.PutL();
   186 		Accs.SetColL(2,KInitialBalance);
   211 		Accs.SetColL(2,KInitialBalance);
   187 		Accs.SetColL(3,KInitialBalance);
   212 		Accs.SetColL(3,KInitialBalance);
   188 		Accs.PutL();
   213 		Accs.PutL();
   189 		TotalMonies+=KInitialBalance;
   214 		TotalMonies+=KInitialBalance;
   190 		}
   215 		}
   191 	test2(TheDatabase.Commit(),KErrNone);
   216 	TEST2(TheDatabase.Commit(),KErrNone);
   192 	Accs.Close();
   217 	Accs.Close();
   193 	TheDatabase.Close();
   218 	TheDatabase.Close();
   194 	CleanupStack::PopAndDestroy();	// store
   219 	CleanupStack::PopAndDestroy();	// store
   195 	}
   220 	}
   196 
   221 
   205 	CleanupClosePushL(match);
   230 	CleanupClosePushL(match);
   206 	for (TInt id=ECash;id<=EPenny;++id)
   231 	for (TInt id=ECash;id<=EPenny;++id)
   207 		{
   232 		{
   208 		Buf.Format(_L("id=%d"),id);
   233 		Buf.Format(_L("id=%d"),id);
   209 		Accs.FirstL();
   234 		Accs.FirstL();
   210 		test1(Accs.FindL(Accs.EForwards,Buf)>=0);
   235 		TEST(Accs.FindL(Accs.EForwards,Buf)>=0);
   211 		Accs.GetL();
   236 		Accs.GetL();
   212 		TInt balance=Accs.ColInt(2);
   237 		TInt balance=Accs.ColInt(2);
   213 		Buf.Format(_L("\nStatement for account %d: Previous balance %d\n"),id,balance);
   238 		Buf.Format(_L("\nStatement for account %d: Previous balance %d\n"),id,balance);
   214 		User::LeaveIfError(file.Write(Buf));
   239 		User::LeaveIfError(file.Write(Buf));
   215 		Buf.Format(_L("from_id=%d or to_id=%d"),id,id);
   240 		Buf.Format(_L("from_id=%d or to_id=%d"),id,id);
   233 		User::LeaveIfError(file.Write(Buf));
   258 		User::LeaveIfError(file.Write(Buf));
   234 		Buf.Format(_L("Account balance %d\n"),Accs.ColInt(3));
   259 		Buf.Format(_L("Account balance %d\n"),Accs.ColInt(3));
   235 		User::LeaveIfError(file.Write(Buf));
   260 		User::LeaveIfError(file.Write(Buf));
   236 		}
   261 		}
   237 	CleanupStack::PopAndDestroy(2);
   262 	CleanupStack::PopAndDestroy(2);
   238 	test1(0);
   263 	TEST(0);
   239 	}
   264 	}
   240 #endif
   265 #endif
   241 
   266 
   242 //
   267 //
   243 // Check that the database structure is fully intact
   268 // Check that the database structure is fully intact
   244 //
   269 //
   245 LOCAL_C void VerifyDatabaseL(CPersistentStore& aStore)
   270 LOCAL_C void VerifyDatabaseL(CPersistentStore& aStore)
   246 	{
   271 	{
   247 	TheDatabase.OpenL(&aStore,aStore.Root());
   272 	TheDatabase.OpenL(&aStore,aStore.Root());
   248 // check any indexes
   273 // check any indexes
   249 	test2(TheTable.Open(TheDatabase,KAccounts,TheTable.EReadOnly),KErrNone);
   274 	TEST2(TheTable.Open(TheDatabase,KAccounts,TheTable.EReadOnly),KErrNone);
   250 	test2(TheTable.CountL(),KAccountIDs);
   275 	TEST2(TheTable.CountL(),KAccountIDs);
   251 	TInt r=TheTable.SetIndex(KAccountsID);
   276 	TInt r=TheTable.SetIndex(KAccountsID);
   252 	if (r!=KErrCorrupt)
   277 	if (r!=KErrCorrupt)
   253 		{
   278 		{
   254 		test2(r,KErrNone);
   279 		TEST2(r,KErrNone);
   255 		test2(TheTable.CountL(),KAccountIDs);
   280 		TEST2(TheTable.CountL(),KAccountIDs);
   256 		for (TInt id=ECash;id<=EPenny;++id)
   281 		for (TInt id=ECash;id<=EPenny;++id)
   257 			{
   282 			{
   258 			test1(TheTable.NextL());
   283 			TEST(TheTable.NextL());
   259 			TheTable.GetL();
   284 			TheTable.GetL();
   260 			test2(TheTable.ColInt(1),id);
   285 			TEST2(TheTable.ColInt(1),id);
   261 			}
   286 			}
   262 		test1(!TheTable.NextL());
   287 		TEST(!TheTable.NextL());
   263 		}
   288 		}
   264 	r=TheTable.SetIndex(KAccountsBalance);
   289 	r=TheTable.SetIndex(KAccountsBalance);
   265 	if (r!=KErrCorrupt)
   290 	if (r!=KErrCorrupt)
   266 		{
   291 		{
   267 		test2(r,KErrNone);
   292 		TEST2(r,KErrNone);
   268 		test2(TheTable.CountL(),KAccountIDs);
   293 		TEST2(TheTable.CountL(),KAccountIDs);
   269 		test1(TheTable.FirstL());
   294 		TEST(TheTable.FirstL());
   270 		TheTable.GetL();
   295 		TheTable.GetL();
   271 		TInt last=TheTable.ColInt(2);
   296 		TInt last=TheTable.ColInt(2);
   272 		for (TInt ii=1;ii<KAccountIDs;++ii)
   297 		for (TInt ii=1;ii<KAccountIDs;++ii)
   273 			{
   298 			{
   274 			test1(TheTable.NextL());
   299 			TEST(TheTable.NextL());
   275 			TheTable.GetL();
   300 			TheTable.GetL();
   276 			TInt bal=TheTable.ColInt(2);
   301 			TInt bal=TheTable.ColInt(2);
   277 			test1(bal>=last);
   302 			TEST(bal>=last);
   278 			last=bal;
   303 			last=bal;
   279 			}
   304 			}
   280 		test1(!TheTable.NextL());
   305 		TEST(!TheTable.NextL());
   281 		}
   306 		}
   282 	TheTable.Close();
   307 	TheTable.Close();
   283 	test2(TheTable.Open(TheDatabase,KTransactions,TheTable.EReadOnly),KErrNone);
   308 	TEST2(TheTable.Open(TheDatabase,KTransactions,TheTable.EReadOnly),KErrNone);
   284 	TInt count=TheTable.CountL();
   309 	TInt count=TheTable.CountL();
   285 	r=TheTable.SetIndex(KTransactionDate);
   310 	r=TheTable.SetIndex(KTransactionDate);
   286 	if (r!=KErrCorrupt)
   311 	if (r!=KErrCorrupt)
   287 		{
   312 		{
   288 		test2(r,KErrNone);
   313 		TEST2(r,KErrNone);
   289 		test2(TheTable.CountL(),count);
   314 		TEST2(TheTable.CountL(),count);
   290 		if (count)
   315 		if (count)
   291 			{
   316 			{
   292 			test1(TheTable.FirstL());
   317 			TEST(TheTable.FirstL());
   293 			TheTable.GetL();
   318 			TheTable.GetL();
   294 			TInt last=TheTable.ColInt(1);
   319 			TInt last=TheTable.ColInt(1);
   295 			while (--count!=0)
   320 			while (--count!=0)
   296 				{
   321 				{
   297 				test1(TheTable.NextL());
   322 				TEST(TheTable.NextL());
   298 				TheTable.GetL();
   323 				TheTable.GetL();
   299 				TInt date=TheTable.ColInt(1);
   324 				TInt date=TheTable.ColInt(1);
   300 				test1(date>last);
   325 				TEST(date>last);
   301 				last=date;
   326 				last=date;
   302 				}
   327 				}
   303 			test1(!TheTable.NextL());
   328 			TEST(!TheTable.NextL());
   304 			}
   329 			}
   305 		else
   330 		else
   306 			test1(!TheTable.FirstL());
   331 			TEST(!TheTable.FirstL());
   307 		}
   332 		}
   308 	TheTable.Close();
   333 	TheTable.Close();
   309 // verify database integrity
   334 // verify database integrity
   310 	TInt balance[KAccountIDs];
   335 	TInt balance[KAccountIDs];
   311 	test2(Accs.Prepare(TheDatabase,_L("select id,statement_balance,balance from accounts"),Accs.EReadOnly),KErrNone);
   336 	TEST2(Accs.Prepare(TheDatabase,_L("select id,statement_balance,balance from accounts"),Accs.EReadOnly),KErrNone);
   312 	test2(Accs.CountL(),KAccountIDs);
   337 	TEST2(Accs.CountL(),KAccountIDs);
   313 	while (Accs.NextL())
   338 	while (Accs.NextL())
   314 		{
   339 		{
   315 		Accs.GetL();
   340 		Accs.GetL();
   316 		TInt id=Accs.ColInt(1);
   341 		TInt id=Accs.ColInt(1);
   317 		balance[id]=Accs.ColInt(2);
   342 		balance[id]=Accs.ColInt(2);
   318 		}
   343 		}
   319 	test2(Trans.Prepare(TheDatabase,_L("select t_date,from_id,to_id,amount from Transactions"),Trans.EReadOnly),KErrNone);
   344 	TEST2(Trans.Prepare(TheDatabase,_L("select t_date,from_id,to_id,amount from Transactions"),Trans.EReadOnly),KErrNone);
   320 	TInt transact=0;
   345 	TInt transact=0;
   321 	while (Trans.NextL())
   346 	while (Trans.NextL())
   322 		{
   347 		{
   323 		++transact;
   348 		++transact;
   324 		Trans.GetL();
   349 		Trans.GetL();
   326 		TInt to=Trans.ColInt(3);
   351 		TInt to=Trans.ColInt(3);
   327 		TInt amount=Trans.ColInt(4);
   352 		TInt amount=Trans.ColInt(4);
   328 		balance[from]-=amount;
   353 		balance[from]-=amount;
   329 		balance[to]+=amount;
   354 		balance[to]+=amount;
   330 		}
   355 		}
   331 	test2(transact,Trans.CountL());
   356 	TEST2(transact,Trans.CountL());
   332 	if (NewCount!=-1 && transact!=NewCount)
   357 	if (NewCount!=-1 && transact!=NewCount)
   333 		{
   358 		{
   334 		test2(transact,OldCount);
   359 		TEST2(transact,OldCount);
   335 		++ShotDuringCommit;
   360 		++ShotDuringCommit;
   336 		}
   361 		}
   337 	OldCount=NewCount=transact;
   362 	OldCount=NewCount=transact;
   338 	TInt total=0;
   363 	TInt total=0;
   339 	for (Accs.BeginningL();Accs.NextL();)
   364 	for (Accs.BeginningL();Accs.NextL();)
   342 		TInt id=Accs.ColInt(1);
   367 		TInt id=Accs.ColInt(1);
   343 #ifdef __DUMP_STATE
   368 #ifdef __DUMP_STATE
   344 		if (balance[id]!=Accs.ColInt(3))
   369 		if (balance[id]!=Accs.ColInt(3))
   345 			DumpStateL();
   370 			DumpStateL();
   346 #else
   371 #else
   347 		test(balance[id]==Accs.ColInt(3));
   372 		TEST(balance[id]==Accs.ColInt(3));
   348 #endif
   373 #endif
   349 		total+=balance[id];
   374 		total+=balance[id];
   350 		}
   375 		}
   351 	test2(total,TotalMonies);
   376 	TEST2(total,TotalMonies);
   352 	Trans.Close();
   377 	Trans.Close();
   353 	Accs.Close();
   378 	Accs.Close();
   354 	TheDatabase.Close();
   379 	TheDatabase.Close();
   355 	}
   380 	}
   356 
   381 
   374 LOCAL_C void CompactL(CStreamStore& aStore)
   399 LOCAL_C void CompactL(CStreamStore& aStore)
   375 	{
   400 	{
   376 	TInt t=aStore.ReclaimL();
   401 	TInt t=aStore.ReclaimL();
   377 	Stopwatch.Start();
   402 	Stopwatch.Start();
   378 	t-=aStore.CompactL();
   403 	t-=aStore.CompactL();
   379 	test.Printf(_L("  compacted %d byte(s) in"),t);
   404 	TheTest.Printf(_L("  compacted %d byte(s) in"),t);
   380 	Stopwatch.Print();
   405 	Stopwatch.Print();
   381 	aStore.CommitL();
   406 	aStore.CommitL();
   382 	}
   407 	}
   383 
   408 
   384 LOCAL_C TInt Compact(CStreamStore& aStore)
   409 LOCAL_C TInt Compact(CStreamStore& aStore)
   406 LOCAL_C void RunTestL(TInt aTestExecutionTime = 0)
   431 LOCAL_C void RunTestL(TInt aTestExecutionTime = 0)
   407 	{
   432 	{
   408 	__ASSERT_ALWAYS(aTestExecutionTime >= 0, User::Invariant());
   433 	__ASSERT_ALWAYS(aTestExecutionTime >= 0, User::Invariant());
   409 
   434 
   410 	RThread().SetPriority(EPriorityMore);
   435 	RThread().SetPriority(EPriorityMore);
   411 	test.Start(_L("Create the database"));
   436 	TheTest.Start(_L("Create the database"));
   412 	CreateDatabaseL();
   437 	CreateDatabaseL();
   413 
   438 
   414 	TTimeIntervalMinutes timeInterval(aTestExecutionTime);
   439 	TTimeIntervalMinutes timeInterval(aTestExecutionTime);
   415 
   440 
   416 	TTime timeCurrent;
   441 	TTime timeCurrent;
   418 	TTime timeEnd(timeCurrent);
   443 	TTime timeEnd(timeCurrent);
   419 	timeEnd += timeInterval;
   444 	timeEnd += timeInterval;
   420 
   445 
   421 	for (TBool condition=ETrue; condition; condition = aTestExecutionTime > 0 ? (timeCurrent < timeEnd) : ETrue)
   446 	for (TBool condition=ETrue; condition; condition = aTestExecutionTime > 0 ? (timeCurrent < timeEnd) : ETrue)
   422 		{
   447 		{
   423 		test.Next(_L("Main loop"));
   448 		TheTest.Next(_L("Main loop"));
   424 		test.Start(_L("Kick off the thread"));
   449 		TheTest.Start(_L("Kick off the thread"));
   425 		test2 (StartThread(TheThread,TheStatus),KErrNone);
   450 		TEST2 (StartThread(TheThread,TheStatus),KErrNone);
   426 		// random delay
   451 		// random delay
   427 		for (;;)
   452 		for (;;)
   428 			{
   453 			{
   429 			User::After(95000);
   454 			User::After(95000);
   430 			if (TheStatus!=KRequestPending)
   455 			if (TheStatus!=KRequestPending)
   431 				break;
   456 				break;
   432 			if (Random(1000)<30)
   457 			if (Random(1000)<30)
   433 				break;
   458 				break;
   434 			}
   459 			}
   435 		test.Next(_L("End the thread"));
   460 		TheTest.Next(_L("End the thread"));
   436 		TInt exit=EndThread();
   461 		TInt exit=EndThread();
   437 		if (exit!=1)
   462 		if (exit!=1)
   438 			test.Printf(_L("  thread failed with error %d\n"),exit);
   463 		    TheTest.Printf(_L("  thread failed with error %d\n"),exit);
   439 //
   464 //
   440 		++Shot;
   465 		++Shot;
   441 		CFileStore* store=NULL;
   466 		CFileStore* store=NULL;
   442 		for (TInt ii=0;;++ii)
   467 		for (TInt ii=0;;++ii)
   443 			{
   468 			{
   444 			test.Printf(_L("Opening %d\r"),ii);
   469 			TheTest.Printf(_L("Opening %d\r"),ii);
   445 			TRAPD(r,store=CFileStore::OpenL(TheFs,KTestDatabase,EFileRead|EFileWrite));
   470 			TRAPD(r,store=CFileStore::OpenL(TheFs,KTestDatabase,EFileRead|EFileWrite));
   446 			if (r==KErrNone)
   471 			if (r==KErrNone)
   447 				break;
   472 				break;
   448 			test (r==KErrInUse);
   473 			TEST2(r, KErrInUse);
   449 			User::After(100000);
   474 			User::After(100000);
   450 			}
   475 			}
   451 		test.Next(_L("Verify & Recover"));
   476 		TheTest.Next(_L("Verify & Recover"));
   452 		test2 (Verify(*store),KErrNone);
   477 		TEST2 (Verify(*store),KErrNone);
   453 		TInt64 tps(TransId);
   478 		TInt64 tps(TransId);
   454 		tps*=1000u;
   479 		tps*=1000u;
   455 		tps/=RunningTime;
   480 		tps/=RunningTime;
   456 		test.Printf(_L("    Iteration %d, TPS %d, during commit %d%%\n"),Shot,I64LOW(tps),(100*ShotDuringCommit)/Shot);
   481 		TheTest.Printf(_L("    Iteration %d, TPS %d, during commit %d%%\n"),Shot,I64LOW(tps),(100*ShotDuringCommit)/Shot);
   457 		TInt r=Recover(*store);
   482 		TInt r=Recover(*store);
   458 		if (r==KErrNoMemory || r==KErrDiskFull)
   483 		if (r==KErrNoMemory || r==KErrDiskFull)
   459 			{	// need to compact before completing recovery
   484 			{	// need to compact before completing recovery
   460 			test.Next(_L("No space, compacting"));
   485 			TheTest.Next(_L("No space, compacting"));
   461 			test2 (Compact(*store),KErrNone);
   486 			TEST2 (Compact(*store),KErrNone);
   462 			test.Next(_L("Verify & Recover again"));
   487 			TheTest.Next(_L("Verify & Recover again"));
   463 			test2 (Verify(*store),KErrNone);
   488 			TEST2 (Verify(*store),KErrNone);
   464 			r=Recover(*store);
   489 			r=Recover(*store);
   465 			}
   490 			}
   466 		test2 (r,KErrNone);
   491 		TEST2 (r,KErrNone);
   467 		test.Next(_L("Verify & Compact"));
   492 		TheTest.Next(_L("Verify & Compact"));
   468 //		test2 (Verify(*store),KErrNone);
   493 //		TEST2 (Verify(*store),KErrNone);
   469 		test2 (Compact(*store),KErrNone);
   494 		TEST2 (Compact(*store),KErrNone);
   470 		test.Next(_L("Verify"));
   495 		TheTest.Next(_L("Verify"));
   471 		test2 (Verify(*store),KErrNone);
   496 		TEST2 (Verify(*store),KErrNone);
   472 //
   497 //
   473 		delete store;
   498 		delete store;
   474 		test.End();
   499 		TheTest.End();
   475 
   500 
   476 		timeCurrent.UniversalTime();
   501 		timeCurrent.UniversalTime();
   477 		}
   502 		}
   478 		test.End();
   503 	TheTest.End();
   479 	}
   504 	}
   480 
   505 
   481 /**
   506 /**
   482 @SYMTestCaseID          SYSLIB-DBMS-CT-0636
   507 @SYMTestCaseID          SYSLIB-DBMS-CT-0636
   483 @SYMTestCaseDesc        DBMS stess testing.
   508 @SYMTestCaseDesc        DBMS stess testing.
   486 @SYMTestExpectedResults Test must not fail
   511 @SYMTestExpectedResults Test must not fail
   487 @SYMREQ                 REQ0000
   512 @SYMREQ                 REQ0000
   488 */
   513 */
   489 static void RunVerify()
   514 static void RunVerify()
   490 	{
   515 	{
   491 	test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0636 Open store "));
   516 	TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0636 Open store "));
   492 	CFileStore* store=NULL;
   517 	CFileStore* store=NULL;
   493 	TRAPD(r,store=CFileStore::OpenL(TheFs,KTestDatabase,EFileRead|EFileWrite));
   518 	TRAPD(r,store=CFileStore::OpenL(TheFs,KTestDatabase,EFileRead|EFileWrite));
   494 	test2 (r,KErrNone);
   519 	TEST2 (r,KErrNone);
   495 	test.Next(_L("Verify"));
   520 	TheTest.Next(_L("Verify"));
   496 	NewCount=-1;
   521 	NewCount=-1;
   497 	TotalMonies=KInitialCash + (EPenny-EJohn+1)*KInitialBalance;
   522 	TotalMonies=KInitialCash + (EPenny-EJohn+1)*KInitialBalance;
   498 	test2 (Verify(*store),KErrNone);
   523 	TEST2 (Verify(*store),KErrNone);
   499 	test.Next(_L("Recover"));
   524 	TheTest.Next(_L("Recover"));
   500 	test2 (Recover(*store),KErrNone);
   525 	TEST2 (Recover(*store),KErrNone);
   501 	test.Next(_L("Verify"));
   526 	TheTest.Next(_L("Verify"));
   502 	test2 (Verify(*store),KErrNone);
   527 	TEST2 (Verify(*store),KErrNone);
   503 	delete store;
   528 	delete store;
   504 	test.End();
   529 	TheTest.End();
   505 	}
   530 	}
   506 
   531 
   507 //
   532 //
   508 // Prepare the test directory.
   533 // Prepare the test directory.
   509 //
   534 //
   510 LOCAL_C void setupTestDirectory()
   535 LOCAL_C void setupTestDirectory()
   511     {
   536     {
   512 	TInt r=TheFs.Connect();
   537 	TInt r=TheFs.Connect();
   513 	test2(r,KErrNone);
   538 	TEST2(r,KErrNone);
   514 //
   539 //
   515 	r=TheFs.MkDir(KTestDir);
   540 	r=TheFs.MkDir(KTestDir);
   516 	test1(r==KErrNone || r==KErrAlreadyExists);
   541 	TEST(r==KErrNone || r==KErrAlreadyExists);
   517 	r=TheFs.SetSessionPath(KTestDir);
   542 	r=TheFs.SetSessionPath(KTestDir);
   518 	test2(r,KErrNone);
   543 	TEST2(r,KErrNone);
   519 	}
   544 	}
   520 
   545 
       
   546 //
       
   547 // Initialise the cleanup stack.
       
   548 //
   521 LOCAL_C CTrapCleanup* setupCleanup()
   549 LOCAL_C CTrapCleanup* setupCleanup()
   522 //
       
   523 // Initialise the cleanup stack.
       
   524 //
       
   525     {
   550     {
   526 	CTrapCleanup* cleanup=CTrapCleanup::New();
   551 	CTrapCleanup* cleanup=CTrapCleanup::New();
   527 	test1(cleanup!=NULL);
   552 	TEST(cleanup!=NULL);
   528 	TRAPD(r,\
   553 	TRAPD(r,\
   529 		{\
   554 		{\
   530 		for (TInt i=KTestCleanupStack;i>0;i--)\
   555 		for (TInt i=KTestCleanupStack;i>0;i--)\
   531 			CleanupStack::PushL((TAny*)0);\
   556 			CleanupStack::PushL((TAny*)0);\
   532 		CleanupStack::Pop(KTestCleanupStack);\
   557 		CleanupStack::Pop(KTestCleanupStack);\
   533 		});
   558 		});
   534 	test2(r,KErrNone);
   559 	TEST2(r,KErrNone);
   535 	return cleanup;
   560 	return cleanup;
   536 	}
   561 	}
   537 
   562 
   538 //
   563 //
   539 // entry point
   564 // entry point
   546 //	<positive number>  - a stress test will be run for <positive number> minutes;
   571 //	<positive number>  - a stress test will be run for <positive number> minutes;
   547 // If the test is run without arguments, the test execution time will be 10 minutes
   572 // If the test is run without arguments, the test execution time will be 10 minutes
   548 // (KDefaultTestExecutionTime constant bellow).
   573 // (KDefaultTestExecutionTime constant bellow).
   549 GLDEF_C TInt E32Main()
   574 GLDEF_C TInt E32Main()
   550     {
   575     {
   551 	test.Title();
   576     TheTest.Title();
   552 	setupTestDirectory();
   577 	setupTestDirectory();
   553 	CTrapCleanup* cleanup=setupCleanup();
   578 	CTrapCleanup* cleanup=setupCleanup();
   554 	__UHEAP_MARK;
   579 	__UHEAP_MARK;
   555 //
   580 //
   556 	TBuf<100> cmd;
   581 	TBuf<100> cmd;
   588 	err2 = TheFs.Delete(KLogFile);
   613 	err2 = TheFs.Delete(KLogFile);
   589 	if(err2 != KErrNone)
   614 	if(err2 != KErrNone)
   590 		{
   615 		{
   591 		RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err2, &KLogFile);
   616 		RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err2, &KLogFile);
   592 		}
   617 		}
   593 	test2(err, KErrNone);
   618 	TEST2(err, KErrNone);
   594 //
   619 //
   595 	__UHEAP_MARKEND;
   620 	__UHEAP_MARKEND;
   596 	delete cleanup;
   621 	delete cleanup;
   597 	TheFs.Close();
   622 	TheFs.Close();
   598 	test.Close();
   623 	TheTest.Close();
   599 	return 0;
   624 	return 0;
   600     }
   625     }