persistentstorage/dbms/tdbms/t_dbstress.cpp
changeset 0 08ec8eefde2f
child 6 5ffdb8f2067f
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "t_dbstress.h"
       
    17 
       
    18 //#define __DUMP_STATE
       
    19 #if defined(__WINS__)
       
    20 //#define _INSTALL_FILE_SYSTEM
       
    21 #endif
       
    22 
       
    23 GLDEF_D RTest test(_L("t_dbstress: Stress testing DBMS"));
       
    24 
       
    25 GLDEF_D TPtrC KTestDir=_S("\\DBMS-TST\\");
       
    26 GLDEF_D TPtrC KLogFile=_L("T_STRESS.LOG");
       
    27 GLDEF_D TPtrC KTestDatabase=_S("T_STRESS.DB");
       
    28 GLDEF_D TInt NewCount,OldCount;
       
    29 GLDEF_D TInt TransId;
       
    30 GLDEF_D Timer RunTimer;
       
    31 
       
    32 
       
    33 LOCAL_D RFs TheFs;
       
    34 LOCAL_D RThread TheThread;
       
    35 LOCAL_D TRequestStatus TheStatus;
       
    36 LOCAL_D RDbStoreDatabase TheDatabase;
       
    37 LOCAL_D RDbView Accs;
       
    38 LOCAL_D RDbView Trans;
       
    39 LOCAL_D RDbTable TheTable;
       
    40 LOCAL_D TInt Shot,ShotDuringCommit;
       
    41 LOCAL_D TInt64 RunningTime(1);
       
    42 LOCAL_D Timer Stopwatch;
       
    43 
       
    44 #ifdef __DUMP_STATE
       
    45 const TPtrC KDumpFile=_S("T_STRESS.DMP");
       
    46 #endif
       
    47 const TInt KTestCleanupStack=0x20;
       
    48 
       
    49 void Timer::Start()
       
    50 	{
       
    51 	iTime.UniversalTime();
       
    52 	}
       
    53 
       
    54 TInt64 Timer::Stop()
       
    55 	{
       
    56 	TTime t;
       
    57 	t.UniversalTime();
       
    58 	return ((t.MicroSecondsFrom(iTime).Int64()) + 500)/1000;
       
    59 	}
       
    60 
       
    61 void Timer::Print()
       
    62 	{
       
    63 	TInt64 milli=Stop();
       
    64 	test.Printf(_L("  %u milliseconds\n"), I64LOW(milli) );
       
    65 	}
       
    66 
       
    67 class Set
       
    68 	{
       
    69 public:
       
    70 	struct SColDef
       
    71 		{
       
    72 		const TDesC* iName;
       
    73 		TDbColType iType;
       
    74 		TInt iAttributes;
       
    75 		};
       
    76 public:
       
    77 	static CDbColSet* CreateL(const SColDef* aDef);
       
    78 	};
       
    79 CDbColSet* Set::CreateL(const SColDef* aDef)
       
    80 	{
       
    81 	CDbColSet *set=CDbColSet::NewLC();
       
    82 	for (;aDef->iName!=NULL;++aDef)
       
    83 		{
       
    84 		TDbCol col(*aDef->iName,aDef->iType);
       
    85 		col.iAttributes=aDef->iAttributes;
       
    86 		set->AddL(col);
       
    87 		}
       
    88 	CleanupStack::Pop();
       
    89 	return set;
       
    90 	}
       
    91 
       
    92 // Accounts table
       
    93 const TPtrC KAccounts=_S("ACCOUNTS");
       
    94 const TPtrC KAccountsID=_S("ID");
       
    95 const TPtrC KAccountsBalance=_S("BALANCE");
       
    96 const TPtrC KAccountsStatement=_S("STATEMENT_BALANCE");
       
    97 Set::SColDef const AccountsDef[]=
       
    98 	{
       
    99 	{&KAccountsID,EDbColInt32,TDbCol::ENotNull},
       
   100 	{&KAccountsBalance,EDbColInt32,TDbCol::ENotNull},
       
   101 	{&KAccountsStatement,EDbColInt32,TDbCol::ENotNull},
       
   102 	{0}
       
   103 	};
       
   104 const TInt KInitialCash=100000;
       
   105 const TInt KInitialBalance=1000;
       
   106 
       
   107 // Transaction table
       
   108 const TPtrC KTransactions=_S("TRANSACTIONS");
       
   109 const TPtrC KTransactionDate=_S("T_DATE");
       
   110 const TPtrC KTransactionFrom=_S("FROM_ID");
       
   111 const TPtrC KTransactionTo=_S("TO_ID");
       
   112 const TPtrC KTransactionAmount=_S("AMOUNT");
       
   113 Set::SColDef const TransactionsDef[]=
       
   114 	{
       
   115 //	{&KTransactionDate,EDbColDateTime,TDbCol::ENotNull},
       
   116 	{&KTransactionDate,EDbColInt32,TDbCol::ENotNull},
       
   117 	{&KTransactionFrom,EDbColInt32,TDbCol::ENotNull},
       
   118 	{&KTransactionTo,EDbColInt32,TDbCol::ENotNull},
       
   119 	{&KTransactionAmount,EDbColInt32,TDbCol::ENotNull},
       
   120 	{0}
       
   121 	};
       
   122 
       
   123 LOCAL_D TInt32 TotalMonies;
       
   124 LOCAL_D TBuf<100> Buf;
       
   125 
       
   126 GLDEF_C TInt Random(TInt aRange)
       
   127 	{
       
   128 	return (Math::Random()>>11)%aRange;
       
   129 	}
       
   130 
       
   131 #undef test
       
   132 LOCAL_C void Test(TInt aValue,TInt anExpected,TInt aLine)
       
   133 	{
       
   134 	if (aValue==anExpected)
       
   135 		return;
       
   136 	test.Printf(_L("** Expected %d, was %d\n"),anExpected,aValue);
       
   137 	test(EFalse,aLine);
       
   138 	}
       
   139 #define test1(aTest) test(aTest,__LINE__)
       
   140 #define test2(aValue,anExpected) Test(aValue,anExpected,__LINE__)
       
   141 
       
   142 LOCAL_C void CreateIndexL(RDbDatabase& aDatabase,const TDesC& aTable,const TDesC& aColumn,TBool aUnique)
       
   143 	{
       
   144 	CDbKey* key=CDbKey::NewLC();
       
   145 	key->AddL(aColumn);
       
   146 	if (aUnique)
       
   147 		key->MakeUnique();
       
   148 	test2(aDatabase.CreateIndex(aColumn,aTable,*key),KErrNone);
       
   149 	CleanupStack::PopAndDestroy();
       
   150 	}
       
   151 
       
   152 //
       
   153 // Create the database
       
   154 //
       
   155 LOCAL_C void CreateDatabaseL()
       
   156 	{
       
   157 	CFileStore* store=CPermanentFileStore::ReplaceLC(TheFs,KTestDatabase,EFileRead|EFileWrite);
       
   158 	store->SetTypeL(KPermanentFileStoreLayoutUid);
       
   159 	store->SetRootL(TheDatabase.CreateL(store));
       
   160 //	create the tables
       
   161 	TheDatabase.Begin();
       
   162 	CDbColSet* set=Set::CreateL(AccountsDef);
       
   163 	test2(TheDatabase.CreateTable(KAccounts,*set),KErrNone);
       
   164 	delete set;
       
   165 	CreateIndexL(TheDatabase,KAccounts,KAccountsID,ETrue);
       
   166 	CreateIndexL(TheDatabase,KAccounts,KAccountsBalance,EFalse);
       
   167 	set=Set::CreateL(TransactionsDef);
       
   168 	test2(TheDatabase.CreateTable(KTransactions,*set),KErrNone);
       
   169 	delete set;
       
   170 	CreateIndexL(TheDatabase,KTransactions,KTransactionDate,EFalse);
       
   171 	test2(TheDatabase.Commit(),KErrNone);
       
   172 	OldCount=NewCount=0;
       
   173 // prepare Accs table
       
   174 	TheDatabase.Begin();
       
   175 	test2(Accs.Prepare(TheDatabase,_L("select * from accounts"),Accs.EInsertOnly),KErrNone);
       
   176 	Accs.InsertL();
       
   177 	Accs.SetColL(1,TInt32(ECash));
       
   178 	Accs.SetColL(2,KInitialCash);
       
   179 	Accs.SetColL(3,KInitialCash);
       
   180 	Accs.PutL();
       
   181 	TotalMonies=KInitialCash;
       
   182 	for (TInt ii=EJohn;ii<=EPenny;++ii)
       
   183 		{
       
   184 		Accs.InsertL();
       
   185 		Accs.SetColL(1,ii);
       
   186 		Accs.SetColL(2,KInitialBalance);
       
   187 		Accs.SetColL(3,KInitialBalance);
       
   188 		Accs.PutL();
       
   189 		TotalMonies+=KInitialBalance;
       
   190 		}
       
   191 	test2(TheDatabase.Commit(),KErrNone);
       
   192 	Accs.Close();
       
   193 	TheDatabase.Close();
       
   194 	CleanupStack::PopAndDestroy();	// store
       
   195 	}
       
   196 
       
   197 
       
   198 #ifdef __DUMP_STATE
       
   199 LOCAL_C void DumpStateL()
       
   200 	{
       
   201 	RFile file;
       
   202 	CleanupClosePushL(file);
       
   203 	User::LeaveIfError(file.Replace(TheFs,KLogFile,EFileWrite|EFileStreamText));
       
   204 	RDbRowSet::RConstraint match;
       
   205 	CleanupClosePushL(match);
       
   206 	for (TInt id=ECash;id<=EPenny;++id)
       
   207 		{
       
   208 		Buf.Format(_L("id=%d"),id);
       
   209 		Accs.FirstL();
       
   210 		test1(Accs.FindL(Accs.EForwards,Buf)>=0);
       
   211 		Accs.GetL();
       
   212 		TInt balance=Accs.ColInt(2);
       
   213 		Buf.Format(_L("\nStatement for account %d: Previous balance %d\n"),id,balance);
       
   214 		User::LeaveIfError(file.Write(Buf));
       
   215 		Buf.Format(_L("from_id=%d or to_id=%d"),id,id);
       
   216 		User::LeaveIfError(match.Open(Trans,Buf));
       
   217 		for (Trans.BeginningL();Trans.NextL();)
       
   218 			{
       
   219 			if (Trans.MatchL(match))
       
   220 				{
       
   221 				Trans.GetL();
       
   222 				TInt from=Trans.ColInt(2);
       
   223 				TInt amount=Trans.ColInt(4);
       
   224 				Buf.Format(_L("%04d: %6s %5d\n"),Trans.ColInt(1),from==id?_S("debit"):_S("credit"),amount);
       
   225 				User::LeaveIfError(file.Write(Buf));
       
   226 				if (from==id)
       
   227 					balance-=amount;
       
   228 				else
       
   229 					balance+=amount;
       
   230 				}
       
   231 			}
       
   232 		Buf.Format(_L("Closing balance %d\n"),balance);
       
   233 		User::LeaveIfError(file.Write(Buf));
       
   234 		Buf.Format(_L("Account balance %d\n"),Accs.ColInt(3));
       
   235 		User::LeaveIfError(file.Write(Buf));
       
   236 		}
       
   237 	CleanupStack::PopAndDestroy(2);
       
   238 	test1(0);
       
   239 	}
       
   240 #endif
       
   241 
       
   242 //
       
   243 // Check that the database structure is fully intact
       
   244 //
       
   245 LOCAL_C void VerifyDatabaseL(CPersistentStore& aStore)
       
   246 	{
       
   247 	TheDatabase.OpenL(&aStore,aStore.Root());
       
   248 // check any indexes
       
   249 	test2(TheTable.Open(TheDatabase,KAccounts,TheTable.EReadOnly),KErrNone);
       
   250 	test2(TheTable.CountL(),KAccountIDs);
       
   251 	TInt r=TheTable.SetIndex(KAccountsID);
       
   252 	if (r!=KErrCorrupt)
       
   253 		{
       
   254 		test2(r,KErrNone);
       
   255 		test2(TheTable.CountL(),KAccountIDs);
       
   256 		for (TInt id=ECash;id<=EPenny;++id)
       
   257 			{
       
   258 			test1(TheTable.NextL());
       
   259 			TheTable.GetL();
       
   260 			test2(TheTable.ColInt(1),id);
       
   261 			}
       
   262 		test1(!TheTable.NextL());
       
   263 		}
       
   264 	r=TheTable.SetIndex(KAccountsBalance);
       
   265 	if (r!=KErrCorrupt)
       
   266 		{
       
   267 		test2(r,KErrNone);
       
   268 		test2(TheTable.CountL(),KAccountIDs);
       
   269 		test1(TheTable.FirstL());
       
   270 		TheTable.GetL();
       
   271 		TInt last=TheTable.ColInt(2);
       
   272 		for (TInt ii=1;ii<KAccountIDs;++ii)
       
   273 			{
       
   274 			test1(TheTable.NextL());
       
   275 			TheTable.GetL();
       
   276 			TInt bal=TheTable.ColInt(2);
       
   277 			test1(bal>=last);
       
   278 			last=bal;
       
   279 			}
       
   280 		test1(!TheTable.NextL());
       
   281 		}
       
   282 	TheTable.Close();
       
   283 	test2(TheTable.Open(TheDatabase,KTransactions,TheTable.EReadOnly),KErrNone);
       
   284 	TInt count=TheTable.CountL();
       
   285 	r=TheTable.SetIndex(KTransactionDate);
       
   286 	if (r!=KErrCorrupt)
       
   287 		{
       
   288 		test2(r,KErrNone);
       
   289 		test2(TheTable.CountL(),count);
       
   290 		if (count)
       
   291 			{
       
   292 			test1(TheTable.FirstL());
       
   293 			TheTable.GetL();
       
   294 			TInt last=TheTable.ColInt(1);
       
   295 			while (--count!=0)
       
   296 				{
       
   297 				test1(TheTable.NextL());
       
   298 				TheTable.GetL();
       
   299 				TInt date=TheTable.ColInt(1);
       
   300 				test1(date>last);
       
   301 				last=date;
       
   302 				}
       
   303 			test1(!TheTable.NextL());
       
   304 			}
       
   305 		else
       
   306 			test1(!TheTable.FirstL());
       
   307 		}
       
   308 	TheTable.Close();
       
   309 // verify database integrity
       
   310 	TInt balance[KAccountIDs];
       
   311 	test2(Accs.Prepare(TheDatabase,_L("select id,statement_balance,balance from accounts"),Accs.EReadOnly),KErrNone);
       
   312 	test2(Accs.CountL(),KAccountIDs);
       
   313 	while (Accs.NextL())
       
   314 		{
       
   315 		Accs.GetL();
       
   316 		TInt id=Accs.ColInt(1);
       
   317 		balance[id]=Accs.ColInt(2);
       
   318 		}
       
   319 	test2(Trans.Prepare(TheDatabase,_L("select t_date,from_id,to_id,amount from Transactions"),Trans.EReadOnly),KErrNone);
       
   320 	TInt transact=0;
       
   321 	while (Trans.NextL())
       
   322 		{
       
   323 		++transact;
       
   324 		Trans.GetL();
       
   325 		TInt from=Trans.ColInt(2);
       
   326 		TInt to=Trans.ColInt(3);
       
   327 		TInt amount=Trans.ColInt(4);
       
   328 		balance[from]-=amount;
       
   329 		balance[to]+=amount;
       
   330 		}
       
   331 	test2(transact,Trans.CountL());
       
   332 	if (NewCount!=-1 && transact!=NewCount)
       
   333 		{
       
   334 		test2(transact,OldCount);
       
   335 		++ShotDuringCommit;
       
   336 		}
       
   337 	OldCount=NewCount=transact;
       
   338 	TInt total=0;
       
   339 	for (Accs.BeginningL();Accs.NextL();)
       
   340 		{
       
   341 		Accs.GetL();
       
   342 		TInt id=Accs.ColInt(1);
       
   343 #ifdef __DUMP_STATE
       
   344 		if (balance[id]!=Accs.ColInt(3))
       
   345 			DumpStateL();
       
   346 #else
       
   347 		test(balance[id]==Accs.ColInt(3));
       
   348 #endif
       
   349 		total+=balance[id];
       
   350 		}
       
   351 	test2(total,TotalMonies);
       
   352 	Trans.Close();
       
   353 	Accs.Close();
       
   354 	TheDatabase.Close();
       
   355 	}
       
   356 
       
   357 LOCAL_C TInt Verify(CPersistentStore& aStore)
       
   358 	{
       
   359 	TRAPD(r,VerifyDatabaseL(aStore));
       
   360 	return r;
       
   361 	}
       
   362 
       
   363 LOCAL_C TInt Recover(CPersistentStore& aStore)
       
   364 	{
       
   365 	TRAPD(r,TheDatabase.OpenL(&aStore,aStore.Root()));
       
   366 	if (r==KErrNone)
       
   367 		{
       
   368 		r=TheDatabase.Recover();
       
   369 		TheDatabase.Close();
       
   370 		}
       
   371 	return r;
       
   372 	}
       
   373 
       
   374 LOCAL_C void CompactL(CStreamStore& aStore)
       
   375 	{
       
   376 	TInt t=aStore.ReclaimL();
       
   377 	Stopwatch.Start();
       
   378 	t-=aStore.CompactL();
       
   379 	test.Printf(_L("  compacted %d byte(s) in"),t);
       
   380 	Stopwatch.Print();
       
   381 	aStore.CommitL();
       
   382 	}
       
   383 
       
   384 LOCAL_C TInt Compact(CStreamStore& aStore)
       
   385 	{
       
   386 	TRAPD(r,CompactL(aStore));
       
   387 	return r;
       
   388 	}
       
   389 
       
   390 LOCAL_C TInt EndThread()
       
   391 	{
       
   392 	RunningTime+=RunTimer.Stop();
       
   393 	if (TheStatus==KRequestPending)
       
   394 		TheThread.Kill(1);
       
   395 	User::WaitForRequest(TheStatus);
       
   396 	TInt r;
       
   397 	if (TheThread.ExitType()==EExitKill)
       
   398 		r=TheThread.ExitReason();
       
   399 	else
       
   400 		r=TheStatus.Int();
       
   401 	TheThread.Close();
       
   402 	return r;
       
   403 	}
       
   404 
       
   405 //aTestExecutionTime - desired test execution time in minutes
       
   406 LOCAL_C void RunTestL(TInt aTestExecutionTime = 0)
       
   407 	{
       
   408 	__ASSERT_ALWAYS(aTestExecutionTime >= 0, User::Invariant());
       
   409 
       
   410 	RThread().SetPriority(EPriorityMore);
       
   411 	test.Start(_L("Create the database"));
       
   412 	CreateDatabaseL();
       
   413 
       
   414 	TTimeIntervalMinutes timeInterval(aTestExecutionTime);
       
   415 
       
   416 	TTime timeCurrent;
       
   417 	timeCurrent.UniversalTime();
       
   418 	TTime timeEnd(timeCurrent);
       
   419 	timeEnd += timeInterval;
       
   420 
       
   421 	for (TBool condition=ETrue; condition; condition = aTestExecutionTime > 0 ? (timeCurrent < timeEnd) : ETrue)
       
   422 		{
       
   423 		test.Next(_L("Main loop"));
       
   424 		test.Start(_L("Kick off the thread"));
       
   425 		test2 (StartThread(TheThread,TheStatus),KErrNone);
       
   426 		// random delay
       
   427 		for (;;)
       
   428 			{
       
   429 			User::After(95000);
       
   430 			if (TheStatus!=KRequestPending)
       
   431 				break;
       
   432 			if (Random(1000)<30)
       
   433 				break;
       
   434 			}
       
   435 		test.Next(_L("End the thread"));
       
   436 		TInt exit=EndThread();
       
   437 		if (exit!=1)
       
   438 			test.Printf(_L("  thread failed with error %d\n"),exit);
       
   439 //
       
   440 		++Shot;
       
   441 		CFileStore* store=NULL;
       
   442 		for (TInt ii=0;;++ii)
       
   443 			{
       
   444 			test.Printf(_L("Opening %d\r"),ii);
       
   445 			TRAPD(r,store=CFileStore::OpenL(TheFs,KTestDatabase,EFileRead|EFileWrite));
       
   446 			if (r==KErrNone)
       
   447 				break;
       
   448 			test (r==KErrInUse);
       
   449 			User::After(100000);
       
   450 			}
       
   451 		test.Next(_L("Verify & Recover"));
       
   452 		test2 (Verify(*store),KErrNone);
       
   453 		TInt64 tps(TransId);
       
   454 		tps*=1000u;
       
   455 		tps/=RunningTime;
       
   456 		test.Printf(_L("    Iteration %d, TPS %d, during commit %d%%\n"),Shot,I64LOW(tps),(100*ShotDuringCommit)/Shot);
       
   457 		TInt r=Recover(*store);
       
   458 		if (r==KErrNoMemory || r==KErrDiskFull)
       
   459 			{	// need to compact before completing recovery
       
   460 			test.Next(_L("No space, compacting"));
       
   461 			test2 (Compact(*store),KErrNone);
       
   462 			test.Next(_L("Verify & Recover again"));
       
   463 			test2 (Verify(*store),KErrNone);
       
   464 			r=Recover(*store);
       
   465 			}
       
   466 		test2 (r,KErrNone);
       
   467 		test.Next(_L("Verify & Compact"));
       
   468 //		test2 (Verify(*store),KErrNone);
       
   469 		test2 (Compact(*store),KErrNone);
       
   470 		test.Next(_L("Verify"));
       
   471 		test2 (Verify(*store),KErrNone);
       
   472 //
       
   473 		delete store;
       
   474 		test.End();
       
   475 
       
   476 		timeCurrent.UniversalTime();
       
   477 		}
       
   478 		test.End();
       
   479 	}
       
   480 
       
   481 /**
       
   482 @SYMTestCaseID          SYSLIB-DBMS-CT-0636
       
   483 @SYMTestCaseDesc        DBMS stess testing.
       
   484 @SYMTestPriority        Medium
       
   485 @SYMTestActions         Tests for verifying the database integrity.
       
   486 @SYMTestExpectedResults Test must not fail
       
   487 @SYMREQ                 REQ0000
       
   488 */
       
   489 static void RunVerify()
       
   490 	{
       
   491 	test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0636 Open store "));
       
   492 	CFileStore* store=NULL;
       
   493 	TRAPD(r,store=CFileStore::OpenL(TheFs,KTestDatabase,EFileRead|EFileWrite));
       
   494 	test2 (r,KErrNone);
       
   495 	test.Next(_L("Verify"));
       
   496 	NewCount=-1;
       
   497 	TotalMonies=KInitialCash + (EPenny-EJohn+1)*KInitialBalance;
       
   498 	test2 (Verify(*store),KErrNone);
       
   499 	test.Next(_L("Recover"));
       
   500 	test2 (Recover(*store),KErrNone);
       
   501 	test.Next(_L("Verify"));
       
   502 	test2 (Verify(*store),KErrNone);
       
   503 	delete store;
       
   504 	test.End();
       
   505 	}
       
   506 
       
   507 //
       
   508 // Prepare the test directory.
       
   509 //
       
   510 LOCAL_C void setupTestDirectory()
       
   511     {
       
   512 	TInt r=TheFs.Connect();
       
   513 	test2(r,KErrNone);
       
   514 //
       
   515 	r=TheFs.MkDir(KTestDir);
       
   516 	test1(r==KErrNone || r==KErrAlreadyExists);
       
   517 	r=TheFs.SetSessionPath(KTestDir);
       
   518 	test2(r,KErrNone);
       
   519 	}
       
   520 
       
   521 LOCAL_C CTrapCleanup* setupCleanup()
       
   522 //
       
   523 // Initialise the cleanup stack.
       
   524 //
       
   525     {
       
   526 	CTrapCleanup* cleanup=CTrapCleanup::New();
       
   527 	test1(cleanup!=NULL);
       
   528 	TRAPD(r,\
       
   529 		{\
       
   530 		for (TInt i=KTestCleanupStack;i>0;i--)\
       
   531 			CleanupStack::PushL((TAny*)0);\
       
   532 		CleanupStack::Pop(KTestCleanupStack);\
       
   533 		});
       
   534 	test2(r,KErrNone);
       
   535 	return cleanup;
       
   536 	}
       
   537 
       
   538 //
       
   539 // entry point
       
   540 //
       
   541 // Parameters usage:
       
   542 //	t_stress [-v]|[0]|[<positive number>]
       
   543 // Where:
       
   544 //	-v - a verification test will be run;
       
   545 //	0  - a stress test will be run for indefinite time;
       
   546 //	<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
       
   548 // (KDefaultTestExecutionTime constant bellow).
       
   549 GLDEF_C TInt E32Main()
       
   550     {
       
   551 	test.Title();
       
   552 	setupTestDirectory();
       
   553 	CTrapCleanup* cleanup=setupCleanup();
       
   554 	__UHEAP_MARK;
       
   555 //
       
   556 	TBuf<100> cmd;
       
   557     User::CommandLine(cmd);
       
   558 	TLex lex(cmd);
       
   559 	TInt err = KErrNone;
       
   560 	for(;;)
       
   561 		{
       
   562 		TPtrC arg(lex.NextToken());
       
   563 		if(arg.Length() == 0)
       
   564 			{
       
   565 			const TInt KDefaultTestExecutionTime = 10;//default test execution time - minutes
       
   566 			TRAP(err, RunTestL(KDefaultTestExecutionTime));
       
   567 			break;
       
   568 			}
       
   569 		else if(arg.CompareF(_L("-v")) == 0)
       
   570 			{
       
   571 			RunVerify();
       
   572 			break;
       
   573 			}
       
   574 		else
       
   575 			{
       
   576 			TInt32 testExecutionTime = 0;
       
   577 			lex.Assign(arg);
       
   578 			(void)lex.Val(testExecutionTime);
       
   579 			TRAP(err, RunTestL(testExecutionTime));
       
   580 			break;
       
   581 			}
       
   582 		}
       
   583 	TInt err2 = TheFs.Delete(KTestDatabase);
       
   584 	if(err2 != KErrNone)
       
   585 		{
       
   586 		RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err2, &KTestDatabase);
       
   587 		}
       
   588 	err2 = TheFs.Delete(KLogFile);
       
   589 	if(err2 != KErrNone)
       
   590 		{
       
   591 		RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err2, &KLogFile);
       
   592 		}
       
   593 	test2(err, KErrNone);
       
   594 //
       
   595 	__UHEAP_MARKEND;
       
   596 	delete cleanup;
       
   597 	TheFs.Close();
       
   598 	test.Close();
       
   599 	return 0;
       
   600     }