os/ossrv/genericservices/systemagent/test/rtest/t_initialisehal/t_initialisehal.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericservices/systemagent/test/rtest/t_initialisehal/t_initialisehal.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,513 @@
1.4 +// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// For testing initialise HAL :
1.18 +//
1.19 +//
1.20 +
1.21 +/**
1.22 + @file
1.23 + @internalComponent
1.24 + @test
1.25 +*/
1.26 +
1.27 +#include <e32base.h>
1.28 +#include <hal.h>
1.29 +#include <f32file.h>
1.30 +#include <bautils.h>
1.31 +#include <e32test.h>
1.32 +
1.33 +_LIT(KHALSettingsExeName, "HALSettings.exe");
1.34 +_LIT(KInitialiseLocaleExeName, "InitialiseLocale.exe");
1.35 +
1.36 +// Symbian VendorID as specified in
1.37 +// "Platform security engineering guide" Section 2.1.3.2
1.38 +const TVendorId KSymbianVendorId(0x70000001);
1.39 +
1.40 +#define TEST(arg) ::Check((arg), __LINE__)
1.41 +#define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
1.42 +
1.43 +//Number of sample used
1.44 +TInt noSample = 25;
1.45 +LOCAL_D RTest TheTest (_L ("T_InitialiseHAL"));
1.46 +
1.47 +LOCAL_C void Check(TInt aValue, TInt aLine)
1.48 + {
1.49 + if(!aValue)
1.50 + {
1.51 + TheTest(EFalse, aLine);
1.52 + }
1.53 + }
1.54 +
1.55 +LOCAL_C void Check(TInt aValue, TInt aExpected, TInt aLine)
1.56 + {
1.57 + if(aValue != aExpected)
1.58 + {
1.59 + RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
1.60 + TheTest(EFalse, aLine);
1.61 + }
1.62 + }
1.63 +
1.64 +/**
1.65 + * This function will start HALSettings.exe with invalid argument and wait for finish
1.66 + * It is used for base line performance overhead
1.67 + */
1.68 +TInt StartEmptyExeL()
1.69 + {
1.70 + RProcess process;
1.71 + //With command line length more than 10 HALSettings.exe returns
1.72 + //immediately with error KErrArgument, Used to baseline
1.73 + //performance overhead to run an empty exe
1.74 + TEST2(process.Create(KHALSettingsExeName,_L("Length is more than ten")),KErrNone);
1.75 + TRequestStatus status;
1.76 + process.Logon(status);
1.77 + process.Resume();
1.78 + User::WaitForRequest(status);
1.79 + TInt exitReason = process.ExitReason();
1.80 + process.Close();
1.81 + return exitReason;
1.82 + }
1.83 +
1.84 +/**
1.85 + * Initialise HAL settings from HAL.DAT
1.86 + * This test will start the HALSettings.exe and wait to finish
1.87 + */
1.88 +TInt TestInitialiseHALWaitL()
1.89 + {
1.90 + RProcess process;
1.91 + TEST2(process.Create(KHALSettingsExeName, _L("INITIALISE")),KErrNone);
1.92 + TRequestStatus status;
1.93 + process.Logon(status);
1.94 + process.Resume();
1.95 + User::WaitForRequest(status);
1.96 + TInt exitReason = process.ExitReason();
1.97 + process.Close();
1.98 + return exitReason;
1.99 + }
1.100 +
1.101 +/**
1.102 + * Persist HAL settings to HAL.DAT
1.103 + * It will create a new HAL.DAT
1.104 + */
1.105 +TInt TestPersistHALWaitL()
1.106 + {
1.107 + RProcess process;
1.108 + TEST2(process.Create(KHALSettingsExeName, _L("PERSIST")),KErrNone);
1.109 + TRequestStatus status;
1.110 + process.Logon(status);
1.111 + process.Resume();
1.112 + User::WaitForRequest(status);
1.113 + TInt exitReason = process.ExitReason();
1.114 + process.Close();
1.115 + return exitReason;
1.116 + }
1.117 +
1.118 +//Tests
1.119 +//===================================================================
1.120 +/**
1.121 +@SYMTestCaseID SYSLIB-HALSETTINGS-CT-1712
1.122 +@SYMTestCaseDesc Initialise HAL settings With wrong commandline
1.123 +@SYMTestPriority Medium
1.124 +@SYMTestActions Start HALSettings.exe and returns KErrArgument
1.125 +@SYMTestExpectedResults Tests must not fail
1.126 +@SYMDEF DEF083235: Prop: HAL Attributes (eg screen calibration) lost if the battery is pulled out
1.127 +*/
1.128 +void TestInitialiseHALWrongParameterL()
1.129 + {
1.130 + TheTest.Next (_L (" @SYMTestCaseID:SYSLIB-HALSETTINGS-CT-1712 Try to Initialise With wrong commandline "));
1.131 + RProcess process;
1.132 + TEST2(process.Create(KHALSettingsExeName, _L("ABCD")),KErrNone);
1.133 + TRequestStatus status;
1.134 + process.Logon(status);
1.135 + process.Resume();
1.136 + User::WaitForRequest(status);
1.137 + TInt exitReason = process.ExitReason();
1.138 + process.Close();
1.139 + TEST2(exitReason, KErrArgument);
1.140 + }
1.141 +
1.142 +/**
1.143 +@SYMTestCaseID SYSLIB-HALSETTINGS-CT-1713
1.144 +@SYMTestCaseDesc Missing HAL.DAT File
1.145 +@SYMTestPriority Medium
1.146 +@SYMTestActions This function first delete hal.dat and then try to initialise HAL
1.147 +@SYMTestExpectedResults Tests must not fail
1.148 +@SYMDEF DEF083235: Prop: HAL Attributes (eg screen calibration) lost if the battery is pulled out
1.149 +*/
1.150 +void TestHALFileMissingL()
1.151 + {
1.152 + TheTest.Next (_L (" @SYMTestCaseID:SYSLIB-HALSETTINGS-CT-1713 HAL.DAT file missing "));
1.153 + _LIT(KFileName,"c:\\private\\102825B1\\hal.dat");
1.154 + RFs fs;
1.155 + fs.Connect();
1.156 + TInt err = BaflUtils::DeleteFile(fs,KFileName);
1.157 + if(err == KErrNone || err == KErrNotFound )
1.158 + {
1.159 + TEST2(TestInitialiseHALWaitL(),KErrNotFound);
1.160 + }
1.161 + fs.Close();
1.162 + }
1.163 +
1.164 +/**
1.165 +@SYMTestCaseID SYSLIB-HALSETTINGS-CT-1724
1.166 +@SYMTestCaseDesc No Access HAL.DAT File
1.167 +@SYMTestPriority Medium
1.168 +@SYMTestActions This function first open hal.dat and then try to initialise HAL
1.169 +@SYMTestExpectedResults Tests must not fail
1.170 +@SYMDEF DEF083235: Prop: HAL Attributes (eg screen calibration) lost if the battery is pulled out
1.171 +*/
1.172 +void TestHALFileNoAccessL()
1.173 + {
1.174 + TheTest.Next (_L (" @SYMTestCaseID:SYSLIB-HALSETTINGS-CT-1724 HAL.DAT No Access "));
1.175 + //To create hal.dat
1.176 + TEST2(TestPersistHALWaitL(),KErrNone);
1.177 + _LIT(KFileName,"c:\\private\\102825B1\\hal.dat");
1.178 + RFs fs;
1.179 + fs.Connect();
1.180 + RFile file;
1.181 + TInt err = file.Open(fs,KFileName,EFileShareExclusive);
1.182 + if(err == KErrNone )
1.183 + {
1.184 + TEST2(TestInitialiseHALWaitL(),KErrInUse);
1.185 + }
1.186 + file.Close();
1.187 + fs.Close();
1.188 + }
1.189 +
1.190 +/**
1.191 +@SYMTestCaseID SYSLIB-HALSETTINGS-CT-1714
1.192 +@SYMTestCaseDesc HAL.DAT File is Empty
1.193 +@SYMTestPriority Medium
1.194 +@SYMTestActions This function first create an empty hal.dat and then try to initialise HAL
1.195 +@SYMTestExpectedResults Tests must not fail
1.196 +@SYMDEF DEF083235: Prop: HAL Attributes (eg screen calibration) lost if the battery is pulled out
1.197 +*/
1.198 +void TestHALFileEmptyL()
1.199 + {
1.200 + TheTest.Next (_L (" @SYMTestCaseID:SYSLIB-HALSETTINGS-CT-1714 HAL.DAT file Empty "));
1.201 + _LIT(KFileName,"c:\\private\\102825B1\\hal.dat");
1.202 + RFs fs;
1.203 + fs.Connect();
1.204 + RFile file;
1.205 + TInt err = file.Replace(fs,KFileName,EFileRead);
1.206 + file.Close();
1.207 +
1.208 + if(err == KErrNone )
1.209 + {
1.210 + TEST2(TestInitialiseHALWaitL(), KErrCorrupt);
1.211 + }
1.212 + fs.Close();
1.213 + }
1.214 +
1.215 +/**
1.216 +@SYMTestCaseID SYSLIB-HALSETTINGS-CT-1715
1.217 +@SYMTestCaseDesc Wrong Header
1.218 +@SYMTestPriority Medium
1.219 +@SYMTestActions This function first corrupt hal.dat by adding wrong header and then
1.220 + try to initialise HAL
1.221 +@SYMTestExpectedResults Tests must not fail
1.222 +@SYMDEF DEF083235: Prop: HAL Attributes (eg screen calibration) lost if the battery is pulled out
1.223 +*/
1.224 +void TestHALFileWrongHeaderL()
1.225 + {
1.226 + TheTest.Next (_L (" @SYMTestCaseID:SYSLIB-HALSETTINGS-CT-1715 HAL.DAT wrong header "));
1.227 + _LIT(KFileName,"c:\\private\\102825B1\\hal.dat");
1.228 + RFs fs;
1.229 + fs.Connect();
1.230 + RFile file;
1.231 + TInt err = file.Replace(fs,KFileName,EFileRead| EFileWrite);
1.232 +
1.233 + //write data in multiples of 8 otherwise it will not pass the check (size&7) == 0
1.234 + file.Write(_L8("abcdefghijklmnop"));
1.235 +
1.236 + file.Close();
1.237 + fs.Close();
1.238 +
1.239 + if(err == KErrNone )
1.240 + {
1.241 + TEST2(TestInitialiseHALWaitL(), KErrCorrupt);
1.242 + }
1.243 + }
1.244 +
1.245 +//Performance Tests
1.246 +//======================================================================================
1.247 +/**
1.248 +@SYMTestCaseID SYSLIB-HALSETTINGS-CT-1718
1.249 +@SYMTestCaseDesc Performance Test Initialise with file
1.250 +@SYMTestPriority Medium
1.251 +@SYMTestActions Initialise HAL settings with HAL.DAT present
1.252 +@SYMTestExpectedResults Tests must not fail
1.253 +@SYMDEF DEF083235: Prop: HAL Attributes (eg screen calibration) lost if the battery is pulled out
1.254 +*/
1.255 +void TestPerformanceInitialiseWithFileL()
1.256 + {
1.257 + TheTest.Next (_L (" @SYMTestCaseID:SYSLIB-HALSETTINGS-CT-1718 Performance Test for initialise hal.dat present "));
1.258 +
1.259 + _LIT(KFileName,"c:\\private\\102825B1\\hal.dat");
1.260 + RFs fs;
1.261 + fs.Connect();
1.262 + //to create hal.dat if it is not there
1.263 + TEST2(TestPersistHALWaitL(),KErrNone);
1.264 + TEST(BaflUtils::FileExists(fs,KFileName));
1.265 + TInt fastTimerFreq;
1.266 + HAL::Get(HALData::EFastCounterFrequency, fastTimerFreq);
1.267 + TReal ticksPerMicroSec = 1.0E-6 * fastTimerFreq;
1.268 + TUint prevTime;
1.269 + TUint timeDiff;
1.270 +
1.271 + prevTime = User::FastCounter();
1.272 + TInt noSuccessfulSamples=0;
1.273 + for(;noSuccessfulSamples < noSample; ++noSuccessfulSamples)
1.274 + {
1.275 + if(TestInitialiseHALWaitL() != KErrNone)
1.276 + {
1.277 + break; //Stop performing the tests, calculate average with no of successful Samples.
1.278 + }
1.279 + //else continue;
1.280 + }
1.281 + TEST(noSuccessfulSamples >0);
1.282 + timeDiff = User::FastCounter() - prevTime;
1.283 + TReal64 fsSessionMicroSecs = timeDiff / (noSuccessfulSamples * ticksPerMicroSec);
1.284 + TheTest.Printf(_L("Time to Initialise HAL (with file) = %10.2lf microseconds\n"), fsSessionMicroSecs);
1.285 + fs.Close();
1.286 + }
1.287 +/**
1.288 +@SYMTestCaseID SYSLIB-HALSETTINGS-CT-1719
1.289 +@SYMTestCaseDesc Performance Test Initialise with no file
1.290 +@SYMTestPriority Medium
1.291 +@SYMTestActions Initialise HAL settings with no HAL.DAT present
1.292 +@SYMTestExpectedResults Tests must not fail
1.293 +@SYMDEF DEF083235: Prop: HAL Attributes (eg screen calibration) lost if the battery is pulled out
1.294 +*/
1.295 +void TestPerformanceInitialiseNoFileL()
1.296 + {
1.297 + TheTest.Next (_L (" @SYMTestCaseID:SYSLIB-HALSETTINGS-CT-1719 Performance Test for initialise with out hal.dat "));
1.298 +
1.299 + _LIT(KFileName,"c:\\private\\102825B1\\hal.dat");
1.300 + RFs fs;
1.301 + fs.Connect();
1.302 +
1.303 + //Delete the File if it exists
1.304 + if(BaflUtils::FileExists(fs,KFileName))
1.305 + {
1.306 + TEST2(BaflUtils::DeleteFile(fs,KFileName),KErrNone);
1.307 + }
1.308 + TInt fastTimerFreq;
1.309 + HAL::Get(HALData::EFastCounterFrequency, fastTimerFreq);
1.310 + TReal ticksPerMicroSec = 1.0E-6 * fastTimerFreq;
1.311 + TUint prevTime;
1.312 + TUint timeDiff;
1.313 + prevTime = User::FastCounter();
1.314 + TInt noSuccessfulSamples=0;
1.315 + for(;noSuccessfulSamples < noSample; ++noSuccessfulSamples)
1.316 + {
1.317 + if ( TestInitialiseHALWaitL() !=KErrNotFound)
1.318 + {
1.319 + break;
1.320 + }
1.321 + //else continue;
1.322 + }
1.323 + TEST(noSuccessfulSamples >0);
1.324 + timeDiff = User::FastCounter() - prevTime;
1.325 + TReal64 fsSessionMicroSecs = timeDiff / (noSuccessfulSamples * ticksPerMicroSec);
1.326 + TheTest.Printf(_L("Time to Initialise HAL (no file) = %10.2lf microseconds\n"), fsSessionMicroSecs);
1.327 + fs.Close();
1.328 + }
1.329 +
1.330 +/**
1.331 +@SYMTestCaseID SYSLIB-HALSETTINGS-CT-1720
1.332 +@SYMTestCaseDesc Performance Test Base Line
1.333 +@SYMTestPriority Medium
1.334 +@SYMTestActions Measure the performance to run empty exe
1.335 +@SYMTestExpectedResults Tests must not fail
1.336 +@SYMDEF DEF083235: Prop: HAL Attributes (eg screen calibration) lost if the battery is pulled out
1.337 +*/
1.338 +void PerformanceBaseLineL()
1.339 + {
1.340 + TheTest.Next (_L (" @SYMTestCaseID:SYSLIB-HALSETTINGS-CT-1720 Performance Test of empty EXE "));
1.341 +
1.342 + TInt fastTimerFreq;
1.343 + HAL::Get(HALData::EFastCounterFrequency, fastTimerFreq);
1.344 + TReal ticksPerMicroSec = 1.0E-6 * fastTimerFreq;
1.345 + TUint prevTime;
1.346 + TUint timeDiff;
1.347 +
1.348 + prevTime = User::FastCounter();
1.349 + TInt noSuccessfulSamples=0;
1.350 + for(;noSuccessfulSamples<noSample; ++noSuccessfulSamples)
1.351 + {
1.352 + if (StartEmptyExeL() != KErrArgument)
1.353 + {
1.354 + break;
1.355 + }
1.356 + //else continue;
1.357 + }
1.358 + TEST(noSuccessfulSamples >0);
1.359 + timeDiff = User::FastCounter() - prevTime;
1.360 + TReal64 fsSessionMicroSecs = timeDiff / (noSuccessfulSamples * ticksPerMicroSec);
1.361 + TheTest.Printf(_L("Time to run Empty EXE = %10.2lf microseconds\n"), fsSessionMicroSecs);
1.362 + }
1.363 +
1.364 +
1.365 +
1.366 +/**
1.367 +@SYMTestCaseID SYSLIB-SYSAGENT2-UT-3385
1.368 +@SYMTestCaseDesc Checking the HAL.DAT filesize is not too big
1.369 +@SYMTestPriority Medium
1.370 +@SYMTestActions Initialise HAL settings with HAL.DAT padded past the reasonable threshold
1.371 +@SYMTestExpectedResults Call to initialise HAL settings should return with KErrCorrupt
1.372 +@SYMDEF PDEF101743: A small possibility for halsettings.exe to go infinite loop while initializing
1.373 +*/
1.374 +
1.375 +void TestHALDataSizeMismatchL()
1.376 + {
1.377 + TheTest.Next (_L (" @SYMTestCaseID:SYSLIB-SYSAGENT2-UT-3385 HAL.DAT size mismatch "));
1.378 + TInt err = BaflUtils::PersistHAL();
1.379 + _LIT(KFileName,"c:\\private\\102825B1\\hal.dat");
1.380 + RFs fs;
1.381 + if (err == KErrNone)
1.382 + {
1.383 + fs.Connect();
1.384 + RFile file;
1.385 + TInt pos = 0;
1.386 + err = file.Open(fs,KFileName,EFileRead | EFileWrite);
1.387 + // Want to add junk onto the end of the file, preserving the valid header
1.388 + err = file.Seek(ESeekEnd, pos);
1.389 +
1.390 + //write data in multiples of 8 otherwise it will not pass the check (size&7) == 0
1.391 + for (TInt i = 0; i < 400; i++)
1.392 + {
1.393 + file.Write(_L8("junkjunkjunkjunk"));
1.394 + }
1.395 + file.Close();
1.396 + }
1.397 +
1.398 + if(err == KErrNone)
1.399 + {
1.400 + TInt result = TestInitialiseHALWaitL();
1.401 + TEST2(result, KErrCorrupt);
1.402 + }
1.403 + err = fs.Delete(KFileName);
1.404 + fs.Close();
1.405 + }
1.406 +
1.407 +/**
1.408 +@SYMTestCaseID SYSLIB-SYSAGENT2-UT-4001
1.409 +@SYMTestCaseDesc system clock change is persisted to hal.dat
1.410 +@SYMTestPriority Medium
1.411 +@SYMTestActions 1. delete the hal file.
1.412 + 2. change system time
1.413 + 3. pause a few seconds and check if the hal file get created.
1.414 +@SYMTestExpectedResults At step 1 hal.dat is deleted (or KErrNotFound).
1.415 + At step 3 hal.dat is created.
1.416 +@SYMDEF DEF115375
1.417 +*/
1.418 +void TestTimeChangesDEF115375()
1.419 + {
1.420 + TTime time;
1.421 + RProcess process;
1.422 +
1.423 + TheTest.Next (_L ("TestTimeChangesDEF115375"));
1.424 + _LIT(KFileName,"c:\\private\\102825B1\\hal.dat");
1.425 +
1.426 + TEST2(process.Create(KInitialiseLocaleExeName, KNullDesC),KErrNone);
1.427 +
1.428 + TRequestStatus stat;
1.429 + process.Rendezvous(stat);
1.430 + process.Resume(); // Start the process going
1.431 + //wait for the locale initialisation to complete first before testing
1.432 + User::WaitForRequest(stat);
1.433 + TEST2((stat.Int()==KErrNone)||(stat.Int()==KErrAlreadyExists),ETrue);
1.434 +
1.435 + RFs fs;
1.436 + fs.Connect();
1.437 +
1.438 + //Delete the File if it exists
1.439 + if(BaflUtils::FileExists(fs,KFileName))
1.440 + {
1.441 + TEST2(BaflUtils::DeleteFile(fs,KFileName),KErrNone);
1.442 + }
1.443 +
1.444 + time.UniversalTime();
1.445 + time+=TTimeIntervalMinutes(30);
1.446 + TInt r=User::SetUTCTime(time);
1.447 + TEST2(r, KErrNone);
1.448 +
1.449 + User::After(1000000);
1.450 + TEST(BaflUtils::FileExists(fs,KFileName));
1.451 + fs.Close();
1.452 +
1.453 + process.Close();
1.454 + User::After(1000000);
1.455 + }
1.456 +
1.457 +/**
1.458 +@SYMTestCaseID SYSLIB-SYSAGENT2-UT-4002
1.459 +@SYMTestCaseDesc Check that the VendorID is set to 0x70000001 (Symbian's VendorID)
1.460 +@SYMTestPriority Medium
1.461 +@SYMTestActions 1. Create a process for HALSettings.exe
1.462 + 2. Compare the processes VID against the expected VID (0x70000001)
1.463 +@SYMTestExpectedResults The VIDs should be identical and so the test will pass.
1.464 +@SYMDEF INC121402
1.465 +*/
1.466 +void TestVendorIdINC121402()
1.467 + {
1.468 + TheTest.Next (_L ("TestVendorIDINC121402"));
1.469 +
1.470 + RProcess process;
1.471 + TEST2(process.Create(KHALSettingsExeName, _L("INITIALISE")), KErrNone);
1.472 +
1.473 + // Test that the VendorID of HALSettings.exe is set to the Symbian VendorID
1.474 + TEST2(KSymbianVendorId.iId, process.VendorId().iId);
1.475 +
1.476 + process.Close();
1.477 + }
1.478 +
1.479 +LOCAL_C void RunTestsL()
1.480 + {
1.481 +
1.482 + //To create hal.dat
1.483 + TEST2(TestPersistHALWaitL(),KErrNone);
1.484 + //Initialise HAL
1.485 + TEST2(TestInitialiseHALWaitL(),KErrNone);
1.486 + TestHALFileWrongHeaderL();
1.487 + TestHALFileEmptyL();
1.488 + TestHALFileMissingL();
1.489 + TestInitialiseHALWrongParameterL();
1.490 + TestHALFileNoAccessL();
1.491 + TestTimeChangesDEF115375();
1.492 + TestVendorIdINC121402();
1.493 + //Performance Test
1.494 + PerformanceBaseLineL();
1.495 + TestPerformanceInitialiseWithFileL();
1.496 + TestPerformanceInitialiseNoFileL();
1.497 + TestHALDataSizeMismatchL();
1.498 + }
1.499 +
1.500 +GLDEF_C TInt E32Main()
1.501 + {
1.502 + __UHEAP_MARK;
1.503 + TheTest.Title ();
1.504 + TheTest.Start (_L ("HAL Initialise test"));
1.505 + CTrapCleanup* tc = CTrapCleanup::New();
1.506 +
1.507 + TRAPD(err, ::RunTestsL());
1.508 +
1.509 + delete tc;
1.510 +
1.511 + TheTest.End ();
1.512 + TheTest.Close ();
1.513 +
1.514 + __UHEAP_MARKEND;
1.515 + return err;
1.516 + }