persistentstorage/sql/TEST/t_sqlload.cpp
branchGCC_SURGE
changeset 38 c4e342fcf0c8
parent 35 0d6db0a14001
equal deleted inserted replaced
27:ba32e40d9f36 38:c4e342fcf0c8
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    58 //Max allowed alive RSqlStatement objects per thread
    58 //Max allowed alive RSqlStatement objects per thread
    59 const TInt KMaxStatementPerThread = 30;
    59 const TInt KMaxStatementPerThread = 30;
    60 //Binary data length
    60 //Binary data length
    61 const TInt KBinDataLen = 2003;
    61 const TInt KBinDataLen = 2003;
    62 
    62 
       
    63 //StatementMaxNumberTest() time limit in seconds.
       
    64 const TInt KTestTimeLimit = 60;//seconds
       
    65 
    63 ///////////////////////////////////////////////////////////////////////////////////////
    66 ///////////////////////////////////////////////////////////////////////////////////////
    64 
    67 
    65 void DeleteTestFiles()
    68 void DeleteTestFiles()
    66 	{
    69 	{
    67 	RSqlDatabase::Delete(KTestDbName3);
    70 	RSqlDatabase::Delete(KTestDbName3);
    68 	RSqlDatabase::Delete(KTestDbName2);
    71 	RSqlDatabase::Delete(KTestDbName2);
    69 	RSqlDatabase::Delete(KTestDbName1);
    72 	RSqlDatabase::Delete(KTestDbName1);
       
    73 	}
       
    74 
       
    75 void GetHomeTimeAsString(TDes& aStr)
       
    76 	{
       
    77 	TTime time;
       
    78 	time.HomeTime();
       
    79 	TDateTime dt = time.DateTime();
       
    80 	aStr.Format(_L("%02d:%02d:%02d.%06d"), dt.Hour(), dt.Minute(), dt.Second(), dt.MicroSecond());
    70 	}
    81 	}
    71 
    82 
    72 ///////////////////////////////////////////////////////////////////////////////////////
    83 ///////////////////////////////////////////////////////////////////////////////////////
    73 ///////////////////////////////////////////////////////////////////////////////////////
    84 ///////////////////////////////////////////////////////////////////////////////////////
    74 //Test macros and functions
    85 //Test macros and functions
   112 #define TEST2(aValue, aExpected) ::Check2(aValue, aExpected, __LINE__)
   123 #define TEST2(aValue, aExpected) ::Check2(aValue, aExpected, __LINE__)
   113 #define TTEST(arg) ::Check1((arg), __LINE__, ETrue)
   124 #define TTEST(arg) ::Check1((arg), __LINE__, ETrue)
   114 #define TTEST2(aValue, aExpected) ::Check2(aValue, aExpected, __LINE__, ETrue)
   125 #define TTEST2(aValue, aExpected) ::Check2(aValue, aExpected, __LINE__, ETrue)
   115 
   126 
   116 ///////////////////////////////////////////////////////////////////////////////////////
   127 ///////////////////////////////////////////////////////////////////////////////////////
       
   128 
       
   129 //StatementMaxNumberTest() timeouts in WDP builds.
       
   130 //This function is used return the seconds passed from the start of the test case.
       
   131 TTimeIntervalSeconds ExecutionTimeSeconds()
       
   132 	{
       
   133 	struct TStartTime
       
   134 		{
       
   135 		TStartTime()
       
   136 			{
       
   137 			iTime.HomeTime();
       
   138 			}
       
   139 		TTime iTime;
       
   140 		};
       
   141 	
       
   142 	static TStartTime startTime; 
       
   143 	
       
   144 	TTime currTime;
       
   145 	currTime.HomeTime();
       
   146 	
       
   147 	TTimeIntervalSeconds s;
       
   148 	TInt err = currTime.SecondsFrom(startTime.iTime, s);
       
   149 	TEST2(err, KErrNone);
       
   150 	return s;
       
   151 	}
   117 
   152 
   118 void CreateTestDir()
   153 void CreateTestDir()
   119     {
   154     {
   120     RFs fs;
   155     RFs fs;
   121 	TInt err = fs.Connect();
   156 	TInt err = fs.Connect();
   530 	User::After(2000000);
   565 	User::After(2000000);
   531 
   566 
   532 	CloseTestThreads(threads, statuses, KTestThreadCnt);
   567 	CloseTestThreads(threads, statuses, KTestThreadCnt);
   533 	}
   568 	}
   534 
   569 
       
   570 /**
       
   571 @SYMTestCaseID          PDS-SQL-CT-4201
       
   572 @SYMTestCaseDesc        Max number of SQL statements test.
       
   573 @SYMTestPriority        High
       
   574 @SYMTestActions         The test creates a table with couple of records and then
       
   575 						creates as many as possible SQL statements. The expected result is
       
   576 						that either the statement creation process will fail with KErrNoMemory or
       
   577 						the max number of statements to be created is reached (100000).
       
   578 						Then the test deletes 1/2 of the created statements objects and
       
   579 						after that attempts to execute Next() on the rest of them.
       
   580 						Note that the test has a time limit of 500 seconds. Otherwise on some platforms
       
   581 						with WDP feature switched on the test may timeout.
       
   582 @SYMTestExpectedResults Test must not fail
       
   583 @SYMDEF                 DEF145236
       
   584 */  
       
   585 void StatementMaxNumberTest()
       
   586 	{
       
   587 	TBuf<30> time;
       
   588 	GetHomeTimeAsString(time);
       
   589 	TheTest.Printf(_L("=== %S: Create database\r\n"), &time);
       
   590 	
       
   591 	(void)RSqlDatabase::Delete(KTestDbName1);
       
   592 	RSqlDatabase db;
       
   593 	TInt err = db.Create(KTestDbName1);
       
   594 	TEST2(err, KErrNone);
       
   595 	err = db.Exec(_L("CREATE TABLE A(I INTEGER); INSERT INTO A(I) VALUES(1); INSERT INTO A(I) VALUES(2);"));
       
   596 	TEST(err >= 0);
       
   597 
       
   598 	GetHomeTimeAsString(time);
       
   599 	TheTest.Printf(_L("=== %S: Create statements array\r\n"), &time);
       
   600 	
       
   601 	//Reserve memory for the statement objects
       
   602 	const TInt KMaxStmtCount = 100000;
       
   603 	RSqlStatement* stmt = new RSqlStatement[KMaxStmtCount];
       
   604 	TEST(stmt != NULL);
       
   605 
       
   606 	//Create as many statement objects as possible
       
   607 	TInt idx = 0;
       
   608 	err = KErrNone;
       
   609 	for(;idx<KMaxStmtCount;++idx)
       
   610 		{
       
   611 		err = stmt[idx].Prepare(db, _L("SELECT * FROM A WHERE I>=0 AND I<10"));
       
   612 		if(err != KErrNone)
       
   613 			{
       
   614 			break;
       
   615 			}
       
   616 		if((idx % 100) == 0)
       
   617 			{
       
   618 			GetHomeTimeAsString(time);
       
   619 			TTimeIntervalSeconds s = ExecutionTimeSeconds();
       
   620 			TheTest.Printf(_L("=== %S: Create % 5d statements. %d seconds.\r\n"), &time, idx + 1, s.Int());
       
   621 			if(s.Int() > KTestTimeLimit)
       
   622 				{
       
   623 				TheTest.Printf(_L("=== %S: The time limit reached.\r\n"), &time);
       
   624 				++idx;//The idx-th statement is valid, the statement count is idx + 1.
       
   625 				break;
       
   626 				}
       
   627 			}
       
   628 		}
       
   629 	
       
   630 	TInt stmtCnt = idx;
       
   631 	TheTest.Printf(_L("%d created statement objects. Last error: %d.\r\n"), stmtCnt, err);
       
   632 	TEST(err == KErrNone || err == KErrNoMemory);
       
   633 
       
   634 	//Close 1/2 of the statements to free some memory
       
   635 	idx = 0;
       
   636 	for(;idx<(stmtCnt/2);++idx)
       
   637 		{
       
   638 		stmt[idx].Close();
       
   639 		if((idx % 100) == 0)
       
   640 			{
       
   641 			GetHomeTimeAsString(time);
       
   642 			TheTest.Printf(_L("=== %S: % 5d statements closed\r\n"), &time, idx + 1);
       
   643 			}
       
   644 		}
       
   645 	
       
   646 	//Now, there should be enough memory to be able to execute Next() on the rest of the statements
       
   647 	for(TInt j=0;idx<stmtCnt;++idx,++j)
       
   648 		{
       
   649 		err = stmt[idx].Next();
       
   650 		TEST2(err, KSqlAtRow);
       
   651 		err = stmt[idx].Next();
       
   652 		TEST2(err, KSqlAtRow);
       
   653 		err = stmt[idx].Next();
       
   654 		TEST2(err, KSqlAtEnd);
       
   655 		GetHomeTimeAsString(time);
       
   656 		TTimeIntervalSeconds s = ExecutionTimeSeconds();
       
   657 		if((j % 100) == 0)
       
   658 			{
       
   659 			TheTest.Printf(_L("=== %S: % 5d statements processed. %d seconds.\r\n"), &time, j + 1, s.Int());
       
   660 			}
       
   661 		if(s.Int() > KTestTimeLimit)
       
   662 			{
       
   663 			TheTest.Printf(_L("=== %S: The time limit reached.\r\n"), &time);
       
   664 			break;
       
   665 			}
       
   666 		}
       
   667 
       
   668 	//Cleanup
       
   669 	for(idx=0;idx<stmtCnt;++idx)
       
   670 		{
       
   671 		stmt[idx].Close();
       
   672 		if((idx % 100) == 0)
       
   673 			{
       
   674 			GetHomeTimeAsString(time);
       
   675 			TheTest.Printf(_L("=== %S: % 5d statements closed\r\n"), &time, idx + 1);
       
   676 			}
       
   677 		}
       
   678 	delete [] stmt;
       
   679 	db.Close();
       
   680 	(void)RSqlDatabase::Delete(KTestDbName1);
       
   681 	GetHomeTimeAsString(time);
       
   682 	TheTest.Printf(_L("=== %S: Test case end\r\n"), &time);
       
   683 	}
       
   684 
   535 void DoTests()
   685 void DoTests()
   536 	{
   686 	{
   537 	TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1627-0001 SQL server load test "));
   687 	TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1627-0001 SQL server load test "));
   538 	SqlLoadTest();
   688 	SqlLoadTest();
       
   689 	TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-CT-4201 Statement max number test"));
       
   690 	StatementMaxNumberTest();
   539 	}
   691 	}
   540 
   692 
   541 TInt E32Main()
   693 TInt E32Main()
   542 	{
   694 	{
   543 	TheTest.Title();
   695 	TheTest.Title();