genericservices/systemagent/test/rtest/t_persisthal/t_persisthal.cpp
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 // Copyright (c) 2006-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 // For testing Persist HAL :
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalComponent
       
    21  @test
       
    22 */
       
    23 
       
    24 #include <e32base.h>
       
    25 #include <hal.h>
       
    26 #include <bautils.h>
       
    27 #include <e32test.h>
       
    28 
       
    29 #define TEST(arg) ::Check((arg), __LINE__)
       
    30 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
       
    31 
       
    32 LOCAL_D RTest 			TheTest (_L ("T_PersistHAL"));
       
    33 
       
    34 TInt noSample = 25;
       
    35 
       
    36 LOCAL_C  void Check(TInt aValue, TInt aLine)
       
    37 	{
       
    38 	if(!aValue)
       
    39 		{
       
    40 		TheTest(EFalse, aLine);
       
    41 		}
       
    42 	}
       
    43 
       
    44 LOCAL_C void Check(TInt aValue, TInt aExpected, TInt aLine)
       
    45 	{
       
    46 	if(aValue != aExpected)
       
    47 		{
       
    48 		RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
       
    49 		TheTest(EFalse, aLine);
       
    50 		}
       
    51 	}
       
    52 
       
    53 TInt TestPersistHALWaitDirectL()
       
    54 	{
       
    55 	RProcess process;
       
    56 	TEST2(process.Create(_L("HALSettings.exe"), _L("PERSIST")),KErrNone);
       
    57 	TRequestStatus status;
       
    58 	process.Logon(status);
       
    59 	process.Resume();
       
    60 	User::WaitForRequest(status);
       
    61 	TInt exitReason = process.ExitReason();
       
    62 	process.Close();
       
    63 	return exitReason;
       
    64 	}
       
    65 
       
    66 //Tests
       
    67 //====================================================================
       
    68 
       
    69 /**
       
    70 @SYMTestCaseID          SYSLIB-HALSETTINGS-CT-1721
       
    71 @SYMTestCaseDesc        Performance Test Persist HAL
       
    72 @SYMTestPriority        Medium
       
    73 @SYMTestActions         This test trys to persist HAL settings by starting HALSetting.exe
       
    74 						directly
       
    75 @SYMTestExpectedResults Tests must not fail
       
    76 @SYMDEF                 DEF083235: Prop: HAL Attributes (eg screen calibration) lost if the battery is pulled out
       
    77 */
       
    78 void TestPerformancePersistDirectL()
       
    79 	{
       
    80 	TheTest.Next (_L (" @SYMTestCaseID:SYSLIB-HALSETTINGS-CT-1721 Performance Persist test directly calling EXE "));
       
    81 	TInt fastTimerFreq;
       
    82 	HAL::Get(HALData::EFastCounterFrequency, fastTimerFreq);
       
    83 	TReal ticksPerMicroSec = 1.0E-6 * fastTimerFreq;
       
    84 
       
    85 	TUint prevTime;
       
    86 	TUint timeDiff;
       
    87 
       
    88 	prevTime = User::FastCounter();
       
    89 	TInt noSuccessfulSamples=0;
       
    90 	for(; noSuccessfulSamples < noSample; ++noSuccessfulSamples)
       
    91 		{
       
    92 		if(TestPersistHALWaitDirectL() !=KErrNone )
       
    93 			{
       
    94 		  	break;//Stop performing the tests, calculate average with no of successful Samples.
       
    95 		  	}
       
    96 		}
       
    97 	TEST(noSuccessfulSamples >0);
       
    98 	timeDiff = User::FastCounter() - prevTime;
       
    99 	TReal64 fsSessionMicroSecs = timeDiff / (noSuccessfulSamples * ticksPerMicroSec);
       
   100 	TheTest.Printf(_L("Time to Persist HAL directly calling exe = %10.2lf microseconds\n"), fsSessionMicroSecs);
       
   101 	}
       
   102 
       
   103 /**
       
   104 @SYMTestCaseID          SYSLIB-HALSETTINGS-CT-1722
       
   105 @SYMTestCaseDesc        Performance Test Persist HAL through BAFL DLL
       
   106 @SYMTestPriority        Medium
       
   107 @SYMTestActions         This test trys to persist HAL settings by calling BAFL
       
   108 						API
       
   109 @SYMTestExpectedResults Tests must not fail
       
   110 @SYMDEF                 DEF083235: Prop: HAL Attributes (eg screen calibration) lost if the battery is pulled out
       
   111 */
       
   112 void TestPerformancePersistThroughBAFL()
       
   113 	{
       
   114 
       
   115 	TheTest.Next (_L (" @SYMTestCaseID:SYSLIB-HALSETTINGS-CT-1722 Performance Persist test Through BAFL DLL "));
       
   116 	TInt fastTimerFreq;
       
   117 	HAL::Get(HALData::EFastCounterFrequency, fastTimerFreq);
       
   118 	TReal ticksPerMicroSec = 1.0E-6 * fastTimerFreq;
       
   119 
       
   120 	TUint prevTime;
       
   121 	TUint timeDiff;
       
   122 
       
   123 	prevTime = User::FastCounter();
       
   124 	TInt noSuccessfulSamples=0;
       
   125 	for(;noSuccessfulSamples< noSample; ++noSuccessfulSamples)
       
   126 		{
       
   127 		if(BaflUtils::PersistHAL()!=KErrNone)
       
   128 			{
       
   129 			break;//Stop performing the tests, calculate average with no of successful Samples.
       
   130 			}
       
   131 		}
       
   132 	TEST(noSuccessfulSamples >0);
       
   133 	timeDiff = User::FastCounter() - prevTime;
       
   134 	TReal64 fsSessionMicroSecs = timeDiff / (noSuccessfulSamples * ticksPerMicroSec);
       
   135 	TheTest.Printf(_L("Time to Persist HAL through BAFL DLL = %10.2lf microseconds\n"), fsSessionMicroSecs);
       
   136 	}
       
   137 
       
   138 /**
       
   139 @SYMTestCaseID          SYSLIB-HALSETTINGS-CT-1723
       
   140 @SYMTestCaseDesc        Capability Test
       
   141 @SYMTestPriority        Medium
       
   142 @SYMTestActions         This test exe do not have the capability to initialise HAL settings
       
   143 						try to initialise HAL setting by starting HALSetting.exe
       
   144 @SYMTestExpectedResults Tests must not fail
       
   145 @SYMDEF                 DEF083235: Prop: HAL Attributes (eg screen calibration) lost if the battery is pulled out
       
   146 */
       
   147 void CapabilityTest()
       
   148 	{
       
   149 	TheTest.Next (_L (" @SYMTestCaseID:SYSLIB-HALSETTINGS-CT-1723 Capability Test "));
       
   150 	RProcess process;
       
   151 	//To initialise processes should have SID == SID of EStart, This process's SID is '0'
       
   152 	TEST2(process.Create(_L("HALSettings.exe"), _L("INITIALISE")),KErrNone);
       
   153 	TRequestStatus status;
       
   154 	process.Logon(status);
       
   155 	process.Resume();
       
   156 	User::WaitForRequest(status);
       
   157 	TInt exitReason = process.ExitReason();
       
   158 	process.Close();
       
   159 	TEST2(exitReason,KErrPermissionDenied);
       
   160 	}
       
   161 
       
   162 LOCAL_C void RunTestsL()
       
   163 	{
       
   164 	TEST2(TestPersistHALWaitDirectL (),KErrNone);
       
   165 	TEST2(BaflUtils::PersistHAL(),KErrNone);
       
   166 
       
   167 	CapabilityTest();
       
   168 	TestPerformancePersistDirectL ();
       
   169 	TestPerformancePersistThroughBAFL ();
       
   170 	}
       
   171 
       
   172 GLDEF_C TInt E32Main()
       
   173 	{
       
   174 	__UHEAP_MARK;
       
   175 	TheTest.Title ();
       
   176 	TheTest.Start (_L ("HAL Persist test"));
       
   177 	CTrapCleanup* tc = CTrapCleanup::New();
       
   178 
       
   179 	TRAPD(err, ::RunTestsL());
       
   180 
       
   181 	delete tc;
       
   182 	TheTest.End ();
       
   183 	TheTest.Close ();
       
   184 	__UHEAP_MARKEND;
       
   185 	return err;
       
   186 	}