persistentstorage/sql/TEST/t_sqlcmdlineutil.cpp
changeset 25 63532cdadd44
parent 22 a7ba600cb39d
equal deleted inserted replaced
22:a7ba600cb39d 25:63532cdadd44
    19 	{
    19 	{
    20 	User::CommandLine(aCmdLine);
    20 	User::CommandLine(aCmdLine);
    21 	aCmdLine.TrimAll();
    21 	aCmdLine.TrimAll();
    22 	if(aCmdLine.Length() == 0)
    22 	if(aCmdLine.Length() == 0)
    23 		{
    23 		{
    24 		aTest.Printf(_L("Usage: %S [ [/enc=<16/8>] /drv=<drive letter>:] [/page=<512/1024/2048/4096/8192/16384/32768>] ] [/cache=<number>]\r\n"), &aTestName);
    24 		aTest.Printf(_L("Usage: %S [ [/enc=<16/8>] /drv=<drive letter>:] [/page=<512/1024/2048/4096/8192/16384/32768>] ] [/cache=<number>] [/hlimit=<Kb>]\r\n"), &aTestName);
    25 		return;
    25 		return;
    26 		}
    26 		}
    27 	aCmdLine.Append(TChar('/'));
    27 	aCmdLine.Append(TChar('/'));
    28 	}
    28 	}
    29 
    29 
   137 			if(err == KErrNone && (cacheSize > 0 && cacheSize < 1000000000))
   137 			if(err == KErrNone && (cacheSize > 0 && cacheSize < 1000000000))
   138 				{
   138 				{
   139 				aCmdLineParams.iCacheSize = cacheSize;
   139 				aCmdLineParams.iCacheSize = cacheSize;
   140 				}
   140 				}
   141 			}
   141 			}
       
   142 		else if(aPrmNames[i].CompareF(_L("hlimit")) == 0)
       
   143 			{
       
   144 			TLex lex(aPrmValues[i]);
       
   145 			TInt softHeapLimit = 0;
       
   146 			TInt err = lex.Val(softHeapLimit);
       
   147 			if(err == KErrNone && (softHeapLimit >= 0 && softHeapLimit < 1000000000))
       
   148 				{
       
   149 				aCmdLineParams.iSoftHeapLimitKb = softHeapLimit;
       
   150 				}
       
   151 			}
   142 		}
   152 		}
   143 	}
   153 	}
   144 
   154 
   145 static void PrepareSqlConfigString(RTest& aTest, const TCmdLineParams& aCmdLineParams, TDes8& aConfigStr)
   155 static void PrepareSqlConfigString(RTest& aTest, const TCmdLineParams& aCmdLineParams, TDes8& aConfigStr)
   146 	{
   156 	{
   166 	TBuf8<20> cacheSizeBuf;
   176 	TBuf8<20> cacheSizeBuf;
   167 	cacheSizeBuf.Format(_L8("cache_size=%d;"), aCmdLineParams.iCacheSize);
   177 	cacheSizeBuf.Format(_L8("cache_size=%d;"), aCmdLineParams.iCacheSize);
   168 	aConfigStr.Append(cacheSizeBuf);
   178 	aConfigStr.Append(cacheSizeBuf);
   169 	
   179 	
   170 	aTest.Printf(_L("--PRM--Database drive: %S\r\n"), &aCmdLineParams.iDriveName);
   180 	aTest.Printf(_L("--PRM--Database drive: %S\r\n"), &aCmdLineParams.iDriveName);
   171 	}
   181 
       
   182 	if(aCmdLineParams.iSoftHeapLimitKb > 0)
       
   183 		{
       
   184 		aTest.Printf(_L("--PRM--Soft heap limit: %d Kb\r\n"), aCmdLineParams.iSoftHeapLimitKb);
       
   185 		}
       
   186 	else
       
   187 		{
       
   188 		aTest.Printf(_L("--PRM--Soft heap limit: default\r\n"));
       
   189 		}
       
   190 	}
       
   191 
       
   192 #ifdef SQL_SOFT_HEAP_LIMIT_TEST	
       
   193 
       
   194 static TInt KillProcess(const TDesC& aProcessName)
       
   195 	{
       
   196 	TFullName name;
       
   197 	TBuf<64> pattern(aProcessName);
       
   198 	TInt length = pattern.Length();
       
   199 	pattern += _L("*");
       
   200 	TFindProcess procFinder(pattern);
       
   201 
       
   202 	while (procFinder.Next(name) == KErrNone)
       
   203 		{
       
   204 		if (name.Length() > length)
       
   205 			{//If found name is a string containing aProcessName string.
       
   206 			TChar c(name[length]);
       
   207 			if (c.IsAlphaDigit() ||
       
   208 				c == TChar('_') ||
       
   209 				c == TChar('-'))
       
   210 				{
       
   211 				// If the found name is other valid application name
       
   212 				// starting with aProcessName string.
       
   213 				continue;
       
   214 				}
       
   215 			}
       
   216 		RProcess proc;
       
   217 		if (proc.Open(name) == KErrNone)
       
   218 			{
       
   219 			proc.Kill(0);
       
   220 			}
       
   221 		proc.Close();
       
   222 		}
       
   223 	return KErrNone;
       
   224 	}
       
   225 
       
   226 _LIT(KSqlSrvName, "sqlsrv.exe");
       
   227 _LIT(KSqlSrvConfigFile, "c:\\test\\t_sqlserver.cfg");
       
   228 
       
   229 static void ReplaceConfigFile(const TDesC16& aConfig)
       
   230 	{
       
   231 	RFs fs;
       
   232 	TInt err = fs.Connect();
       
   233 	__ASSERT_ALWAYS(err == KErrNone, User::Invariant());
       
   234 	
       
   235 	(void)KillProcess(KSqlSrvName);
       
   236 	
       
   237 	(void)fs.MkDirAll(KSqlSrvConfigFile);
       
   238 	(void)fs.Delete(KSqlSrvConfigFile);
       
   239 	
       
   240 	RFile file;
       
   241 	err = file.Create(fs, KSqlSrvConfigFile, EFileRead | EFileWrite);
       
   242 	__ASSERT_ALWAYS(err == KErrNone, User::Invariant());
       
   243 	
       
   244 	TPtrC8 p((const TUint8*)aConfig.Ptr(), aConfig.Length() * sizeof(TUint16));
       
   245 	err = file.Write(p);
       
   246 	file.Close();
       
   247 	__ASSERT_ALWAYS(err == KErrNone, User::Invariant());
       
   248 	
       
   249 	fs.Close();
       
   250 	}
       
   251 
       
   252 static void DeleteConfigFile()
       
   253 	{
       
   254 	RFs fs;
       
   255 	TInt err = fs.Connect();
       
   256 	__ASSERT_ALWAYS(err == KErrNone, User::Invariant());
       
   257 	
       
   258 	(void)KillProcess(KSqlSrvName);
       
   259 	
       
   260 	(void)fs.MkDirAll(KSqlSrvConfigFile);
       
   261 	(void)fs.Delete(KSqlSrvConfigFile);
       
   262 	
       
   263 	fs.Close();
       
   264 	}
       
   265 
       
   266 #endif //SQL_SOFT_HEAP_LIMIT_TEST	
   172 
   267 
   173 void GetCmdLineParamsAndSqlConfigString(RTest& aTest, const TDesC& aTestName, TCmdLineParams& aCmdLineParams, TDes8& aConfigStr)
   268 void GetCmdLineParamsAndSqlConfigString(RTest& aTest, const TDesC& aTestName, TCmdLineParams& aCmdLineParams, TDes8& aConfigStr)
   174 	{
   269 	{
   175 	TBuf<200> cmdLine;
   270 	TBuf<200> cmdLine;
   176 	GetCmdLine(aTest, aTestName, cmdLine);
   271 	GetCmdLine(aTest, aTestName, cmdLine);
   188 	TParse parse;
   283 	TParse parse;
   189 	parse.Set(aDriveName, &aDeafultDbName, 0);
   284 	parse.Set(aDriveName, &aDeafultDbName, 0);
   190 	const TDesC& dbFilePath = parse.FullName();
   285 	const TDesC& dbFilePath = parse.FullName();
   191 	aDbName.Copy(dbFilePath);
   286 	aDbName.Copy(dbFilePath);
   192 	}
   287 	}
       
   288 
       
   289 void SetSoftHeapLimit(TInt aSoftHeapLimit)
       
   290 	{
       
   291 	if(aSoftHeapLimit > 0)
       
   292 		{
       
   293 #ifdef SQL_SOFT_HEAP_LIMIT_TEST	
       
   294 		TBuf<50> configBuf;
       
   295 		configBuf.Format(_L("soft_heap_limit_kb=%d"), aSoftHeapLimit);
       
   296 		ReplaceConfigFile(configBuf);
       
   297 #else
       
   298 		RDebug::Print(_L("The soft heap limit cannot be set if \"SQL_SOFT_HEAP_LIMIT_TEST\" macro is not defined!\r\n"));
       
   299 #endif
       
   300 		}
       
   301 	else if(aSoftHeapLimit < 0)
       
   302 		{
       
   303 		RDebug::Print(_L("Soft heap limit of %d Kb cannot be set!\r\n"), aSoftHeapLimit);
       
   304 		}
       
   305 	}
       
   306 
       
   307 void ResetSoftHeapLimit()
       
   308 	{
       
   309 #ifdef SQL_SOFT_HEAP_LIMIT_TEST	
       
   310 	DeleteConfigFile();
       
   311 #endif
       
   312 	}
       
   313