Update contrib.
1 // Copyright (c) 2002-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 the License "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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\secure\t_shal.cpp
16 // Test the security aspects of the HAL class.
20 // - For a variety of capability sets, get and set HAL hardware attributes
21 // and check that the results are as expected.
22 // - Set and restore the XYInputCalibration.
23 // - Add an event using UserSvr::AddEvent() and verify the resulting capability
25 // Platforms/Drives/Compatibility:
27 // Assumptions/Requirement/Pre-requisites:
28 // Failures and causes:
29 // Base Port information:
33 #define __INCLUDE_CAPABILITY_NAMES__
40 LOCAL_D RTest test(_L("T_SHAL"));
42 TCapabilitySet Capabilities;
44 TInt PolicingVerified = 0;
46 LOCAL_C TBool Check(TInt aResult,TCapability aCap)
50 case KErrNotSupported:
51 RDebug::Print(_L(" Not Supported"));
54 RDebug::Print(_L(" No Error"));
56 case KErrPermissionDenied:
57 RDebug::Print(_L(" Permission Denied"));
60 RDebug::Print(_L(" Error %d"),aResult);
64 if(Capabilities.HasCapability(aCap))
65 return aResult==KErrNone;
66 else if(PlatSec::IsCapabilityEnforced(aCap))
67 return aResult==KErrPermissionDenied;
69 return aResult==KErrNone;
72 LOCAL_C void GetSetCheck(const char* aText,HALData::TAttribute aAttribute,TCapability aCap)
74 TBuf8<256> text=(const TUint8*)"HAL::Set(";
75 text.Append((const TUint8*)aText,User::StringLength((const TUint8*)aText));
77 test.Next(text.Expand());
79 HAL::Get(aAttribute,x);
80 TInt r = HAL::Set(aAttribute,x);
84 #define SET_CHECK(a,c) GetSetCheck(#a,a,c);
86 LOCAL_C TInt DoTests()
92 // ECapabilityReadDeviceData
96 test.Start(_L("UserHal::MachineInfo()"));
97 TMachineInfoV2Buf info;
98 r = UserHal::MachineInfo(info);
99 test(Check(r,ECapabilityReadDeviceData));
103 // ECapabilityWriteDeviceData
106 SET_CHECK(HAL::EKeyboardClickState,ECapabilityWriteDeviceData);
107 SET_CHECK(HAL::EKeyboardClickVolume,ECapabilityWriteDeviceData);
108 SET_CHECK(HAL::EPenClickState,ECapabilityWriteDeviceData);
109 SET_CHECK(HAL::EPenClickVolume,ECapabilityWriteDeviceData);
110 SET_CHECK(HAL::ELanguageIndex,ECapabilityWriteDeviceData);
111 SET_CHECK(HAL::EKeyboardIndex,ECapabilityWriteDeviceData);
112 SET_CHECK(HAL::ESystemDrive,ECapabilityWriteDeviceData);
113 SET_CHECK(HAL::ECaseSwitchDisplayOn,ECapabilityWriteDeviceData);
114 SET_CHECK(HAL::ECaseSwitchDisplayOff,ECapabilityWriteDeviceData);
115 SET_CHECK(HAL::EDisplayContrast,ECapabilityWriteDeviceData);
116 SET_CHECK(HAL::EDisplayBrightness,ECapabilityWriteDeviceData);
117 SET_CHECK(HAL::EBacklightState,ECapabilityWriteDeviceData);
118 SET_CHECK(HAL::EPenDisplayOn,ECapabilityWriteDeviceData);
119 SET_CHECK(HAL::ELocaleLoaded,ECapabilityWriteDeviceData);
120 SET_CHECK(HAL::ECustomResourceDrive,ECapabilityWriteDeviceData);
122 test.Next(_L("UserHal::CalibrationPoints()"));
123 TDigitizerCalibration xy;
124 UserHal::CalibrationPoints(xy);
125 r = UserHal::SetXYInputCalibration(xy);
126 test(Check(r,ECapabilityWriteDeviceData));
128 test.Next(_L("UserHal::RestoreXYInputCalibration()"));
129 UserHal::SaveXYInputCalibration();
130 r = UserHal::RestoreXYInputCalibration(ESaved);
131 test(Check(r,ECapabilityWriteDeviceData));
134 // ECapabilityMultimediaDD
137 SET_CHECK(HAL::EMouseState,ECapabilityMultimediaDD);
138 SET_CHECK(HAL::EMouseSpeed,ECapabilityMultimediaDD);
139 SET_CHECK(HAL::EMouseAcceleration,ECapabilityMultimediaDD);
140 // SET_CHECK(HAL::EDisplayMode,ECapabilityMultimediaDD);
141 // SET_CHECK(HAL::EDisplayPaletteEntry,ECapabilityMultimediaDD);
144 // ECapabilityPowerMgmt
147 SET_CHECK(HAL::EKeyboardBacklightState,ECapabilityPowerMgmt);
148 SET_CHECK(HAL::EAccessoryPower,ECapabilityPowerMgmt);
149 SET_CHECK(HAL::EDisplayState,ECapabilityPowerMgmt);
150 SET_CHECK(HAL::EKeyboardState,ECapabilityPowerMgmt);
151 SET_CHECK(HAL::EPenState,ECapabilityPowerMgmt);
153 test.Next(_L("UserHal::SwitchOff()"));
159 wakeup+=TTimeIntervalSeconds(4);
160 timer.At(done,wakeup);
161 r = UserHal::SwitchOff(); // May not actually turn off due to imminent RTimer.At()
162 test(Check(r,ECapabilityPowerMgmt));
163 User::WaitForRequest(done);
166 // ECapabilitySwEvent
169 test.Next(_L("UserSvr::AddEvent()"));
171 r = UserSvr::AddEvent(event);
172 test(Check(r,ECapabilitySwEvent));
182 enum TTestProcessFunctions
187 #include "testprocess.h"
191 GLDEF_C TInt E32Main()
193 Capabilities = TSecurityInfo(RProcess()).iCaps;
197 if(User::CommandLineLength())
200 __ASSERT_COMPILE(ECapability_Limit<64);
201 message.AppendFormat(_L("Tests with capabilities %08x%08x"),((TUint32*)&Capabilities)[1],((TUint32*)&Capabilities)[0]);
203 TInt result = DoTests();
204 // Don't test.End() so we don't get lots of 'Success's in logs
209 test.Start(_L("Start"));
211 for(c=0; c<1+ECapability_Limit; c++)
217 caps.SetAllSupported();
218 if(!caps.HasCapability((TCapability)c))
220 caps.RemoveCapability((TCapability)c);
221 TBuf8<128> capNameBuf;
222 capNameBuf.Copy((const TUint8*)CapabilityNames[c]);
223 TPtr capName(capNameBuf.Expand());
224 message.AppendFormat(_L("Tests with all capabilities except %S"),&capName);
226 p.Create(*(TUint32*)&caps,ETestProcessDoTests);
229 User::WaitForRequest(s);
230 test(p.ExitType()==EExitKill);
231 TInt result=s.Int()^0x55555555;
236 // Show results requiring manual inspection
237 _LIT(KSeperatorText,"----------------------------------------------------------------------------\n");
238 test.Printf(_L("\n"));
239 test.Printf(_L("RESULTS\n"));
240 test.Printf(KSeperatorText);
242 for(c=0; c<ECapability_Limit; c++)
243 if(!PlatSec::IsCapabilityEnforced((TCapability)c))
247 test.Printf(_L("* Did NOT verify security checking\n"));
249 test.Printf(_L("* Verified security checking\n"));
250 test.Printf(KSeperatorText);
252 // Wait for a while, or for a key press
253 test.Printf(_L("Waiting a short while for key press...\n"));
254 TRequestStatus keyStat;
255 test.Console()->Read(keyStat);
257 test(timer.CreateLocal()==KErrNone);
258 TRequestStatus timerStat;
259 timer.After(timerStat,20*1000000);
260 User::WaitForRequest(timerStat,keyStat);
262 if(keyStat!=KRequestPending)
263 key = test.Console()->KeyCode();
265 test.Console()->ReadCancel();
266 User::WaitForAnyRequest();