sl@0: // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // For testing initialise HAL : sl@0: // sl@0: // sl@0: sl@0: /** sl@0: @file sl@0: @internalComponent sl@0: @test sl@0: */ sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: _LIT(KHALSettingsExeName, "HALSettings.exe"); sl@0: _LIT(KInitialiseLocaleExeName, "InitialiseLocale.exe"); sl@0: sl@0: // Symbian VendorID as specified in sl@0: // "Platform security engineering guide" Section 2.1.3.2 sl@0: const TVendorId KSymbianVendorId(0x70000001); sl@0: sl@0: #define TEST(arg) ::Check((arg), __LINE__) sl@0: #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__) sl@0: sl@0: //Number of sample used sl@0: TInt noSample = 25; sl@0: LOCAL_D RTest TheTest (_L ("T_InitialiseHAL")); sl@0: sl@0: LOCAL_C void Check(TInt aValue, TInt aLine) sl@0: { sl@0: if(!aValue) sl@0: { sl@0: TheTest(EFalse, aLine); sl@0: } sl@0: } sl@0: sl@0: LOCAL_C void Check(TInt aValue, TInt aExpected, TInt aLine) sl@0: { sl@0: if(aValue != aExpected) sl@0: { sl@0: RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue); sl@0: TheTest(EFalse, aLine); sl@0: } sl@0: } sl@0: sl@0: /** sl@0: * This function will start HALSettings.exe with invalid argument and wait for finish sl@0: * It is used for base line performance overhead sl@0: */ sl@0: TInt StartEmptyExeL() sl@0: { sl@0: RProcess process; sl@0: //With command line length more than 10 HALSettings.exe returns sl@0: //immediately with error KErrArgument, Used to baseline sl@0: //performance overhead to run an empty exe sl@0: TEST2(process.Create(KHALSettingsExeName,_L("Length is more than ten")),KErrNone); sl@0: TRequestStatus status; sl@0: process.Logon(status); sl@0: process.Resume(); sl@0: User::WaitForRequest(status); sl@0: TInt exitReason = process.ExitReason(); sl@0: process.Close(); sl@0: return exitReason; sl@0: } sl@0: sl@0: /** sl@0: * Initialise HAL settings from HAL.DAT sl@0: * This test will start the HALSettings.exe and wait to finish sl@0: */ sl@0: TInt TestInitialiseHALWaitL() sl@0: { sl@0: RProcess process; sl@0: TEST2(process.Create(KHALSettingsExeName, _L("INITIALISE")),KErrNone); sl@0: TRequestStatus status; sl@0: process.Logon(status); sl@0: process.Resume(); sl@0: User::WaitForRequest(status); sl@0: TInt exitReason = process.ExitReason(); sl@0: process.Close(); sl@0: return exitReason; sl@0: } sl@0: sl@0: /** sl@0: * Persist HAL settings to HAL.DAT sl@0: * It will create a new HAL.DAT sl@0: */ sl@0: TInt TestPersistHALWaitL() sl@0: { sl@0: RProcess process; sl@0: TEST2(process.Create(KHALSettingsExeName, _L("PERSIST")),KErrNone); sl@0: TRequestStatus status; sl@0: process.Logon(status); sl@0: process.Resume(); sl@0: User::WaitForRequest(status); sl@0: TInt exitReason = process.ExitReason(); sl@0: process.Close(); sl@0: return exitReason; sl@0: } sl@0: sl@0: //Tests sl@0: //=================================================================== sl@0: /** sl@0: @SYMTestCaseID SYSLIB-HALSETTINGS-CT-1712 sl@0: @SYMTestCaseDesc Initialise HAL settings With wrong commandline sl@0: @SYMTestPriority Medium sl@0: @SYMTestActions Start HALSettings.exe and returns KErrArgument sl@0: @SYMTestExpectedResults Tests must not fail sl@0: @SYMDEF DEF083235: Prop: HAL Attributes (eg screen calibration) lost if the battery is pulled out sl@0: */ sl@0: void TestInitialiseHALWrongParameterL() sl@0: { sl@0: TheTest.Next (_L (" @SYMTestCaseID:SYSLIB-HALSETTINGS-CT-1712 Try to Initialise With wrong commandline ")); sl@0: RProcess process; sl@0: TEST2(process.Create(KHALSettingsExeName, _L("ABCD")),KErrNone); sl@0: TRequestStatus status; sl@0: process.Logon(status); sl@0: process.Resume(); sl@0: User::WaitForRequest(status); sl@0: TInt exitReason = process.ExitReason(); sl@0: process.Close(); sl@0: TEST2(exitReason, KErrArgument); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-HALSETTINGS-CT-1713 sl@0: @SYMTestCaseDesc Missing HAL.DAT File sl@0: @SYMTestPriority Medium sl@0: @SYMTestActions This function first delete hal.dat and then try to initialise HAL sl@0: @SYMTestExpectedResults Tests must not fail sl@0: @SYMDEF DEF083235: Prop: HAL Attributes (eg screen calibration) lost if the battery is pulled out sl@0: */ sl@0: void TestHALFileMissingL() sl@0: { sl@0: TheTest.Next (_L (" @SYMTestCaseID:SYSLIB-HALSETTINGS-CT-1713 HAL.DAT file missing ")); sl@0: _LIT(KFileName,"c:\\private\\102825B1\\hal.dat"); sl@0: RFs fs; sl@0: fs.Connect(); sl@0: TInt err = BaflUtils::DeleteFile(fs,KFileName); sl@0: if(err == KErrNone || err == KErrNotFound ) sl@0: { sl@0: TEST2(TestInitialiseHALWaitL(),KErrNotFound); sl@0: } sl@0: fs.Close(); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-HALSETTINGS-CT-1724 sl@0: @SYMTestCaseDesc No Access HAL.DAT File sl@0: @SYMTestPriority Medium sl@0: @SYMTestActions This function first open hal.dat and then try to initialise HAL sl@0: @SYMTestExpectedResults Tests must not fail sl@0: @SYMDEF DEF083235: Prop: HAL Attributes (eg screen calibration) lost if the battery is pulled out sl@0: */ sl@0: void TestHALFileNoAccessL() sl@0: { sl@0: TheTest.Next (_L (" @SYMTestCaseID:SYSLIB-HALSETTINGS-CT-1724 HAL.DAT No Access ")); sl@0: //To create hal.dat sl@0: TEST2(TestPersistHALWaitL(),KErrNone); sl@0: _LIT(KFileName,"c:\\private\\102825B1\\hal.dat"); sl@0: RFs fs; sl@0: fs.Connect(); sl@0: RFile file; sl@0: TInt err = file.Open(fs,KFileName,EFileShareExclusive); sl@0: if(err == KErrNone ) sl@0: { sl@0: TEST2(TestInitialiseHALWaitL(),KErrInUse); sl@0: } sl@0: file.Close(); sl@0: fs.Close(); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-HALSETTINGS-CT-1714 sl@0: @SYMTestCaseDesc HAL.DAT File is Empty sl@0: @SYMTestPriority Medium sl@0: @SYMTestActions This function first create an empty hal.dat and then try to initialise HAL sl@0: @SYMTestExpectedResults Tests must not fail sl@0: @SYMDEF DEF083235: Prop: HAL Attributes (eg screen calibration) lost if the battery is pulled out sl@0: */ sl@0: void TestHALFileEmptyL() sl@0: { sl@0: TheTest.Next (_L (" @SYMTestCaseID:SYSLIB-HALSETTINGS-CT-1714 HAL.DAT file Empty ")); sl@0: _LIT(KFileName,"c:\\private\\102825B1\\hal.dat"); sl@0: RFs fs; sl@0: fs.Connect(); sl@0: RFile file; sl@0: TInt err = file.Replace(fs,KFileName,EFileRead); sl@0: file.Close(); sl@0: sl@0: if(err == KErrNone ) sl@0: { sl@0: TEST2(TestInitialiseHALWaitL(), KErrCorrupt); sl@0: } sl@0: fs.Close(); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-HALSETTINGS-CT-1715 sl@0: @SYMTestCaseDesc Wrong Header sl@0: @SYMTestPriority Medium sl@0: @SYMTestActions This function first corrupt hal.dat by adding wrong header and then sl@0: try to initialise HAL sl@0: @SYMTestExpectedResults Tests must not fail sl@0: @SYMDEF DEF083235: Prop: HAL Attributes (eg screen calibration) lost if the battery is pulled out sl@0: */ sl@0: void TestHALFileWrongHeaderL() sl@0: { sl@0: TheTest.Next (_L (" @SYMTestCaseID:SYSLIB-HALSETTINGS-CT-1715 HAL.DAT wrong header ")); sl@0: _LIT(KFileName,"c:\\private\\102825B1\\hal.dat"); sl@0: RFs fs; sl@0: fs.Connect(); sl@0: RFile file; sl@0: TInt err = file.Replace(fs,KFileName,EFileRead| EFileWrite); sl@0: sl@0: //write data in multiples of 8 otherwise it will not pass the check (size&7) == 0 sl@0: file.Write(_L8("abcdefghijklmnop")); sl@0: sl@0: file.Close(); sl@0: fs.Close(); sl@0: sl@0: if(err == KErrNone ) sl@0: { sl@0: TEST2(TestInitialiseHALWaitL(), KErrCorrupt); sl@0: } sl@0: } sl@0: sl@0: //Performance Tests sl@0: //====================================================================================== sl@0: /** sl@0: @SYMTestCaseID SYSLIB-HALSETTINGS-CT-1718 sl@0: @SYMTestCaseDesc Performance Test Initialise with file sl@0: @SYMTestPriority Medium sl@0: @SYMTestActions Initialise HAL settings with HAL.DAT present sl@0: @SYMTestExpectedResults Tests must not fail sl@0: @SYMDEF DEF083235: Prop: HAL Attributes (eg screen calibration) lost if the battery is pulled out sl@0: */ sl@0: void TestPerformanceInitialiseWithFileL() sl@0: { sl@0: TheTest.Next (_L (" @SYMTestCaseID:SYSLIB-HALSETTINGS-CT-1718 Performance Test for initialise hal.dat present ")); sl@0: sl@0: _LIT(KFileName,"c:\\private\\102825B1\\hal.dat"); sl@0: RFs fs; sl@0: fs.Connect(); sl@0: //to create hal.dat if it is not there sl@0: TEST2(TestPersistHALWaitL(),KErrNone); sl@0: TEST(BaflUtils::FileExists(fs,KFileName)); sl@0: TInt fastTimerFreq; sl@0: HAL::Get(HALData::EFastCounterFrequency, fastTimerFreq); sl@0: TReal ticksPerMicroSec = 1.0E-6 * fastTimerFreq; sl@0: TUint prevTime; sl@0: TUint timeDiff; sl@0: sl@0: prevTime = User::FastCounter(); sl@0: TInt noSuccessfulSamples=0; sl@0: for(;noSuccessfulSamples < noSample; ++noSuccessfulSamples) sl@0: { sl@0: if(TestInitialiseHALWaitL() != KErrNone) sl@0: { sl@0: break; //Stop performing the tests, calculate average with no of successful Samples. sl@0: } sl@0: //else continue; sl@0: } sl@0: TEST(noSuccessfulSamples >0); sl@0: timeDiff = User::FastCounter() - prevTime; sl@0: TReal64 fsSessionMicroSecs = timeDiff / (noSuccessfulSamples * ticksPerMicroSec); sl@0: TheTest.Printf(_L("Time to Initialise HAL (with file) = %10.2lf microseconds\n"), fsSessionMicroSecs); sl@0: fs.Close(); sl@0: } sl@0: /** sl@0: @SYMTestCaseID SYSLIB-HALSETTINGS-CT-1719 sl@0: @SYMTestCaseDesc Performance Test Initialise with no file sl@0: @SYMTestPriority Medium sl@0: @SYMTestActions Initialise HAL settings with no HAL.DAT present sl@0: @SYMTestExpectedResults Tests must not fail sl@0: @SYMDEF DEF083235: Prop: HAL Attributes (eg screen calibration) lost if the battery is pulled out sl@0: */ sl@0: void TestPerformanceInitialiseNoFileL() sl@0: { sl@0: TheTest.Next (_L (" @SYMTestCaseID:SYSLIB-HALSETTINGS-CT-1719 Performance Test for initialise with out hal.dat ")); sl@0: sl@0: _LIT(KFileName,"c:\\private\\102825B1\\hal.dat"); sl@0: RFs fs; sl@0: fs.Connect(); sl@0: sl@0: //Delete the File if it exists sl@0: if(BaflUtils::FileExists(fs,KFileName)) sl@0: { sl@0: TEST2(BaflUtils::DeleteFile(fs,KFileName),KErrNone); sl@0: } sl@0: TInt fastTimerFreq; sl@0: HAL::Get(HALData::EFastCounterFrequency, fastTimerFreq); sl@0: TReal ticksPerMicroSec = 1.0E-6 * fastTimerFreq; sl@0: TUint prevTime; sl@0: TUint timeDiff; sl@0: prevTime = User::FastCounter(); sl@0: TInt noSuccessfulSamples=0; sl@0: for(;noSuccessfulSamples < noSample; ++noSuccessfulSamples) sl@0: { sl@0: if ( TestInitialiseHALWaitL() !=KErrNotFound) sl@0: { sl@0: break; sl@0: } sl@0: //else continue; sl@0: } sl@0: TEST(noSuccessfulSamples >0); sl@0: timeDiff = User::FastCounter() - prevTime; sl@0: TReal64 fsSessionMicroSecs = timeDiff / (noSuccessfulSamples * ticksPerMicroSec); sl@0: TheTest.Printf(_L("Time to Initialise HAL (no file) = %10.2lf microseconds\n"), fsSessionMicroSecs); sl@0: fs.Close(); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-HALSETTINGS-CT-1720 sl@0: @SYMTestCaseDesc Performance Test Base Line sl@0: @SYMTestPriority Medium sl@0: @SYMTestActions Measure the performance to run empty exe sl@0: @SYMTestExpectedResults Tests must not fail sl@0: @SYMDEF DEF083235: Prop: HAL Attributes (eg screen calibration) lost if the battery is pulled out sl@0: */ sl@0: void PerformanceBaseLineL() sl@0: { sl@0: TheTest.Next (_L (" @SYMTestCaseID:SYSLIB-HALSETTINGS-CT-1720 Performance Test of empty EXE ")); sl@0: sl@0: TInt fastTimerFreq; sl@0: HAL::Get(HALData::EFastCounterFrequency, fastTimerFreq); sl@0: TReal ticksPerMicroSec = 1.0E-6 * fastTimerFreq; sl@0: TUint prevTime; sl@0: TUint timeDiff; sl@0: sl@0: prevTime = User::FastCounter(); sl@0: TInt noSuccessfulSamples=0; sl@0: for(;noSuccessfulSamples0); sl@0: timeDiff = User::FastCounter() - prevTime; sl@0: TReal64 fsSessionMicroSecs = timeDiff / (noSuccessfulSamples * ticksPerMicroSec); sl@0: TheTest.Printf(_L("Time to run Empty EXE = %10.2lf microseconds\n"), fsSessionMicroSecs); sl@0: } sl@0: sl@0: sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SYSAGENT2-UT-3385 sl@0: @SYMTestCaseDesc Checking the HAL.DAT filesize is not too big sl@0: @SYMTestPriority Medium sl@0: @SYMTestActions Initialise HAL settings with HAL.DAT padded past the reasonable threshold sl@0: @SYMTestExpectedResults Call to initialise HAL settings should return with KErrCorrupt sl@0: @SYMDEF PDEF101743: A small possibility for halsettings.exe to go infinite loop while initializing sl@0: */ sl@0: sl@0: void TestHALDataSizeMismatchL() sl@0: { sl@0: TheTest.Next (_L (" @SYMTestCaseID:SYSLIB-SYSAGENT2-UT-3385 HAL.DAT size mismatch ")); sl@0: TInt err = BaflUtils::PersistHAL(); sl@0: _LIT(KFileName,"c:\\private\\102825B1\\hal.dat"); sl@0: RFs fs; sl@0: if (err == KErrNone) sl@0: { sl@0: fs.Connect(); sl@0: RFile file; sl@0: TInt pos = 0; sl@0: err = file.Open(fs,KFileName,EFileRead | EFileWrite); sl@0: // Want to add junk onto the end of the file, preserving the valid header sl@0: err = file.Seek(ESeekEnd, pos); sl@0: sl@0: //write data in multiples of 8 otherwise it will not pass the check (size&7) == 0 sl@0: for (TInt i = 0; i < 400; i++) sl@0: { sl@0: file.Write(_L8("junkjunkjunkjunk")); sl@0: } sl@0: file.Close(); sl@0: } sl@0: sl@0: if(err == KErrNone) sl@0: { sl@0: TInt result = TestInitialiseHALWaitL(); sl@0: TEST2(result, KErrCorrupt); sl@0: } sl@0: err = fs.Delete(KFileName); sl@0: fs.Close(); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SYSAGENT2-UT-4001 sl@0: @SYMTestCaseDesc system clock change is persisted to hal.dat sl@0: @SYMTestPriority Medium sl@0: @SYMTestActions 1. delete the hal file. sl@0: 2. change system time sl@0: 3. pause a few seconds and check if the hal file get created. sl@0: @SYMTestExpectedResults At step 1 hal.dat is deleted (or KErrNotFound). sl@0: At step 3 hal.dat is created. sl@0: @SYMDEF DEF115375 sl@0: */ sl@0: void TestTimeChangesDEF115375() sl@0: { sl@0: TTime time; sl@0: RProcess process; sl@0: sl@0: TheTest.Next (_L ("TestTimeChangesDEF115375")); sl@0: _LIT(KFileName,"c:\\private\\102825B1\\hal.dat"); sl@0: sl@0: TEST2(process.Create(KInitialiseLocaleExeName, KNullDesC),KErrNone); sl@0: sl@0: TRequestStatus stat; sl@0: process.Rendezvous(stat); sl@0: process.Resume(); // Start the process going sl@0: //wait for the locale initialisation to complete first before testing sl@0: User::WaitForRequest(stat); sl@0: TEST2((stat.Int()==KErrNone)||(stat.Int()==KErrAlreadyExists),ETrue); sl@0: sl@0: RFs fs; sl@0: fs.Connect(); sl@0: sl@0: //Delete the File if it exists sl@0: if(BaflUtils::FileExists(fs,KFileName)) sl@0: { sl@0: TEST2(BaflUtils::DeleteFile(fs,KFileName),KErrNone); sl@0: } sl@0: sl@0: time.UniversalTime(); sl@0: time+=TTimeIntervalMinutes(30); sl@0: TInt r=User::SetUTCTime(time); sl@0: TEST2(r, KErrNone); sl@0: sl@0: User::After(1000000); sl@0: TEST(BaflUtils::FileExists(fs,KFileName)); sl@0: fs.Close(); sl@0: sl@0: process.Close(); sl@0: User::After(1000000); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SYSAGENT2-UT-4002 sl@0: @SYMTestCaseDesc Check that the VendorID is set to 0x70000001 (Symbian's VendorID) sl@0: @SYMTestPriority Medium sl@0: @SYMTestActions 1. Create a process for HALSettings.exe sl@0: 2. Compare the processes VID against the expected VID (0x70000001) sl@0: @SYMTestExpectedResults The VIDs should be identical and so the test will pass. sl@0: @SYMDEF INC121402 sl@0: */ sl@0: void TestVendorIdINC121402() sl@0: { sl@0: TheTest.Next (_L ("TestVendorIDINC121402")); sl@0: sl@0: RProcess process; sl@0: TEST2(process.Create(KHALSettingsExeName, _L("INITIALISE")), KErrNone); sl@0: sl@0: // Test that the VendorID of HALSettings.exe is set to the Symbian VendorID sl@0: TEST2(KSymbianVendorId.iId, process.VendorId().iId); sl@0: sl@0: process.Close(); sl@0: } sl@0: sl@0: LOCAL_C void RunTestsL() sl@0: { sl@0: sl@0: //To create hal.dat sl@0: TEST2(TestPersistHALWaitL(),KErrNone); sl@0: //Initialise HAL sl@0: TEST2(TestInitialiseHALWaitL(),KErrNone); sl@0: TestHALFileWrongHeaderL(); sl@0: TestHALFileEmptyL(); sl@0: TestHALFileMissingL(); sl@0: TestInitialiseHALWrongParameterL(); sl@0: TestHALFileNoAccessL(); sl@0: TestTimeChangesDEF115375(); sl@0: TestVendorIdINC121402(); sl@0: //Performance Test sl@0: PerformanceBaseLineL(); sl@0: TestPerformanceInitialiseWithFileL(); sl@0: TestPerformanceInitialiseNoFileL(); sl@0: TestHALDataSizeMismatchL(); sl@0: } sl@0: sl@0: GLDEF_C TInt E32Main() sl@0: { sl@0: __UHEAP_MARK; sl@0: TheTest.Title (); sl@0: TheTest.Start (_L ("HAL Initialise test")); sl@0: CTrapCleanup* tc = CTrapCleanup::New(); sl@0: sl@0: TRAPD(err, ::RunTestsL()); sl@0: sl@0: delete tc; sl@0: sl@0: TheTest.End (); sl@0: TheTest.Close (); sl@0: sl@0: __UHEAP_MARKEND; sl@0: return err; sl@0: }