os/kernelhwsrv/halservices/hal/tsrc/t_newhal.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/halservices/hal/tsrc/t_newhal.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,366 @@
     1.4 +// Copyright (c) 1998-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 the License "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 +// hal\tsrc\t_newhal.cpp
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#define __E32TEST_EXTENSION__
    1.22 +
    1.23 +#include <e32test.h>
    1.24 +#include <hal.h>
    1.25 +
    1.26 +RTest test(_L("T_NEWHAL"));
    1.27 +
    1.28 +const TText* AttributeNames[]=
    1.29 +	{
    1.30 +	_S("EManufacturer"),
    1.31 +	_S("EManufacturerHardwareRev"),
    1.32 +	_S("EManufacturerSoftwareRev"),
    1.33 +	_S("EManufacturerSoftwareBuild"),
    1.34 +	_S("EModel"),
    1.35 +	_S("EMachineUid"),
    1.36 +	_S("EDeviceFamily"),
    1.37 +	_S("EDeviceFamilyRev"),
    1.38 +	_S("ECPU"),
    1.39 +	_S("ECPUArch"),
    1.40 +	_S("ECPUABI"),
    1.41 +	_S("ECPUSpeed"),
    1.42 +	_S("ESystemStartupReason"),
    1.43 +	_S("ESystemException"),
    1.44 +	_S("ESystemTickPeriod"),		
    1.45 +	_S("EMemoryRAM"),
    1.46 +	_S("EMemoryRAMFree"),
    1.47 +	_S("EMemoryROM"),
    1.48 +	_S("EMemoryPageSize"),	
    1.49 +	_S("EPowerGood"),
    1.50 +	_S("EPowerBatteryStatus"),	
    1.51 +	_S("EPowerBackup"),
    1.52 +	_S("EPowerBackupStatus"),	
    1.53 +	_S("EPowerExternal"),
    1.54 +	_S("EKeyboard"),
    1.55 +	_S("EKeyboardDeviceKeys"),	
    1.56 +	_S("EKeyboardAppKeys"),
    1.57 +	_S("EKeyboardClick"),
    1.58 +	_S("EKeyboardClickState"),	
    1.59 +	_S("EKeyboardClickVolume"),
    1.60 +	_S("EKeyboardClickVolumeMax"),
    1.61 +	_S("EDisplayXPixels"),
    1.62 +	_S("EDisplayYPixels"),
    1.63 +	_S("EDisplayXTwips"),
    1.64 +	_S("EDisplayYTwips"),
    1.65 +	_S("EDisplayColors"),
    1.66 +	_S("EDisplayState"),
    1.67 +	_S("EDisplayContrast"),
    1.68 +	_S("EDisplayContrastMax"),
    1.69 +	_S("EBacklight"),
    1.70 +	_S("EBacklightState"),
    1.71 +	_S("EPen"),
    1.72 +	_S("EPenX"),
    1.73 +	_S("EPenY"),
    1.74 +	_S("EPenDisplayOn"),
    1.75 +	_S("EPenClick"),
    1.76 +	_S("EPenClickState"),
    1.77 +	_S("EPenClickVolume"),
    1.78 +	_S("EPenClickVolumeMax"),
    1.79 +	_S("EMouse"),
    1.80 +	_S("EMouseX"),
    1.81 +	_S("EMouseY"),			
    1.82 +	_S("EMouseState"),
    1.83 +	_S("EMouseSpeed"),
    1.84 +	_S("EMouseAcceleration"),
    1.85 +	_S("EMouseButtons"),
    1.86 +	_S("EMouseButtonState"),
    1.87 +	_S("ECaseState"),
    1.88 +	_S("ECaseSwitch"),
    1.89 +	_S("ECaseSwitchDisplayOn"),
    1.90 +	_S("ECaseSwitchDisplayOff"),
    1.91 +	_S("ELEDs"),
    1.92 +	_S("ELEDmask"),
    1.93 +	_S("EIntegratedPhone"),
    1.94 +	_S("EDisplayBrightness"),
    1.95 +	_S("EDisplayBrightnessMax"),
    1.96 +	_S("EKeyboardBacklightState"),
    1.97 +	_S("EAccessoryPower"),
    1.98 +	_S("ELanguageIndex"),
    1.99 +	_S("EKeyboardIndex"),
   1.100 +	_S("EMaxRAMDriveSize"),
   1.101 +	_S("EKeyboardState"),
   1.102 +	_S("ESystemDrive"),
   1.103 +	_S("EPenState"),
   1.104 +	_S("EDisplayIsMono"),
   1.105 +	_S("EDisplayIsPalettized"),
   1.106 +	_S("EDisplayBitsPerPixel"),
   1.107 +	_S("EDisplayNumModes"),
   1.108 +	_S("EDisplayMemoryAddress"),
   1.109 +	_S("EDisplayOffsetToFirstPixel"),
   1.110 +	_S("EDisplayOffsetBetweenLines"),
   1.111 +	_S("EDisplayPaletteEntry"),
   1.112 +	_S("EDisplayIsPixelOrderRGB"),
   1.113 +	_S("EDisplayIsPixelOrderLandscape"),
   1.114 +	_S("EDisplayMode"),
   1.115 +	_S("ESwitches"),
   1.116 +	_S("EDebugPort"),
   1.117 +	_S("ELocaleLoaded"),
   1.118 +	_S("EClipboardDrive"),
   1.119 +	_S("ECustomRestart"),
   1.120 +	_S("ECustomRestartReason"),
   1.121 +	_S("EDisplayNumberOfScreens"),
   1.122 +	_S("ENanoTickPeriod"),
   1.123 +	_S("EFastCounterFrequency"),
   1.124 +	_S("EFastCounterCountsUp"),
   1.125 +	_S("EPointer3D"),
   1.126 +	_S("EPointer3DMaxProximity"),
   1.127 +	_S("EPointer3DThetaSupported"),
   1.128 +	_S("EPointer3DPhiSupported"),
   1.129 +	_S("EPointer3DRotationSupported"),
   1.130 +	_S("EPointer3DPressureSupported"),
   1.131 +	_S("EHardwareFloatingPoint"),
   1.132 +	_S("ETimeNonSecureOffset"),
   1.133 +	_S("EPersistStartupModeKernel"),
   1.134 +	_S("EMaximumCustomRestartReasons"),
   1.135 +	_S("EMaximumRestartStartupModes"),
   1.136 +	_S("ECustomResourceDrive"),
   1.137 +	_S("EPointer3DProximityStep"),
   1.138 +	_S("EPointerMaxPointers"),
   1.139 +	_S("EPointerNumberOfPointers"),
   1.140 +	_S("EPointer3DMaxPressure"),
   1.141 +	_S("EPointer3DPressureStep"),
   1.142 +	_S("EPointer3DEnterHighPressureThreshold"),
   1.143 +	_S("EPointer3DExitHighPressureThreshold"),
   1.144 +	_S("EPointer3DEnterCloseProximityThreshold"),
   1.145 +	_S("EPointer3DExitCloseProximityThreshold"),
   1.146 +	_S("EDisplayMemoryHandle"),
   1.147 +	_S("ESerialNumber"),
   1.148 +	_S("ECpuProfilingDefaultInterruptBase"),
   1.149 +	_S("ENumCpus"),
   1.150 +
   1.151 +	};
   1.152 +
   1.153 +TInt MatchAbbrev(const TDesC& anInput, const TText** aList, TInt aListLen)
   1.154 +	{
   1.155 +	TInt first_match=KErrNotFound;
   1.156 +	TInt nmatches=0;
   1.157 +	TInt i;
   1.158 +	for (i=0; i<aListLen; i++)
   1.159 +		{
   1.160 +		TPtrC list_entry(aList[i]);
   1.161 +		TInt r=list_entry.FindF(anInput);
   1.162 +		if (r>=0)
   1.163 +			{
   1.164 +			// substring matches
   1.165 +			if (r==0 && list_entry.Length()==anInput.Length())
   1.166 +				{
   1.167 +				// exact match
   1.168 +				return i;
   1.169 +				}
   1.170 +			if (first_match<0)
   1.171 +				first_match=i;
   1.172 +			++nmatches;
   1.173 +			}
   1.174 +		}
   1.175 +	if (nmatches>1)
   1.176 +		return KErrGeneral;	// ambiguous
   1.177 +	return first_match;		// either KErrNotFound or match index
   1.178 +	}
   1.179 +
   1.180 +TInt MatchAttribute(const TDesC& anInput)
   1.181 +	{
   1.182 +	return MatchAbbrev(anInput, AttributeNames, sizeof(AttributeNames)/sizeof(TText*));
   1.183 +	}
   1.184 +
   1.185 +void TestGet()
   1.186 +	{
   1.187 +	TInt i;
   1.188 +	TInt n=0;
   1.189 +
   1.190 +	for (i=0; i<HAL::ENumHalAttributes; i++)
   1.191 +		{
   1.192 +		TPtrC att_name(AttributeNames[i]);
   1.193 +		TInt val=-1;
   1.194 +		TInt r=HAL::Get((HAL::TAttribute)i,val);
   1.195 +		test.Printf(_L("%S: return %d, value %d(0x%08x)\n"),&att_name,r,val,val);
   1.196 +		if (++n==16)
   1.197 +			{
   1.198 +			n=0;
   1.199 +			test.Printf(_L("\nPress a key to continue...\n"));
   1.200 +			test.Getch();
   1.201 +			}
   1.202 +		}
   1.203 +	}
   1.204 +
   1.205 +
   1.206 +void TestGetAll()
   1.207 +	{
   1.208 +	User::Allocator().Check();
   1.209 +	HAL::SEntry* pE=NULL;
   1.210 +	TInt nEntries=0;
   1.211 +	TInt r=HAL::GetAll(nEntries, pE);
   1.212 +	test(r==KErrNone);
   1.213 +	test.Printf(_L("%d attributes defined\n"),nEntries);
   1.214 +	test(nEntries==HAL::ENumHalAttributes);
   1.215 +	TInt i;
   1.216 +	for (i=0; i<nEntries; ++i)
   1.217 +		{
   1.218 +		TPtrC att_name(AttributeNames[i]);
   1.219 +		TInt f=pE[i].iProperties;
   1.220 +		TInt v=pE[i].iValue;
   1.221 +		TInt v2=-1;
   1.222 +		TInt r=HAL::Get((HAL::TAttribute)i,v2);
   1.223 +		if (f & HAL::EEntryValid)
   1.224 +			{
   1.225 +			test(r==KErrNone);
   1.226 +			if (f & HAL::EEntryDynamic)
   1.227 +				{
   1.228 +				test.Printf(_L("Attribute %S dynamic "),&att_name);
   1.229 +				if (v2!=v)
   1.230 +					{
   1.231 +					test.Printf(_L("Values %d(%08x), %d(%08x)"),v,v,v2,v2);
   1.232 +					}
   1.233 +				test.Printf(_L("\n"));
   1.234 +				}
   1.235 +			else
   1.236 +				{
   1.237 +				test(v==v2);	// constant attribute
   1.238 +				}
   1.239 +			}
   1.240 +		else
   1.241 +			{
   1.242 +			test.Printf(_L("Attribute %S not supported on this platform or requires parameter\n"),&att_name,r);
   1.243 +			test(r==KErrNotSupported || r==KErrArgument);
   1.244 +			}
   1.245 +		}
   1.246 +	User::Free(pE);
   1.247 +	User::Allocator().Check();
   1.248 +	}
   1.249 +
   1.250 +void InputLine(const TDesC& aPrompt, TDes& aLine)
   1.251 +	{
   1.252 +	test.Printf(_L("%S"),&aPrompt);
   1.253 +	aLine.SetLength(0);
   1.254 +	FOREVER
   1.255 +		{
   1.256 +		TKeyCode k=test.Getch();
   1.257 +		switch (k)
   1.258 +			{
   1.259 +			case EKeyEnter:
   1.260 +				test.Printf(_L("\n"));
   1.261 +				return;
   1.262 +			case EKeyEscape:
   1.263 +				aLine.SetLength(0);
   1.264 +				test.Printf(_L("\n%S"),&aPrompt);
   1.265 +				break;
   1.266 +			case EKeyBackspace:
   1.267 +			case EKeyDelete:
   1.268 +				if (aLine.Length()>0)
   1.269 +					{
   1.270 +					aLine.SetLength(aLine.Length()-1);
   1.271 +					test.Printf(_L("\x8"));
   1.272 +					}
   1.273 +				break;
   1.274 +			default:
   1.275 +				{
   1.276 +				TChar ch((TUint)k);
   1.277 +				TBuf<1> b;
   1.278 +				b.Append(ch);
   1.279 +				aLine.Append(ch);
   1.280 +				test.Printf(_L("%S"),&b);
   1.281 +				break;
   1.282 +				}
   1.283 +			}
   1.284 +		}
   1.285 +	}
   1.286 +
   1.287 +void TestSet()
   1.288 +	{
   1.289 +	TBuf<256> line;
   1.290 +	FOREVER
   1.291 +		{
   1.292 +		TInt attrib=KErrNotFound;
   1.293 +		while (attrib<0)
   1.294 +			{
   1.295 +			InputLine(_L("Attribute: "),line);
   1.296 +			if (line.Length()==0)
   1.297 +				return;
   1.298 +			attrib=MatchAttribute(line);
   1.299 +			if (attrib==KErrNotFound)
   1.300 +				test.Printf(_L("Unrecognised attribute\n"));
   1.301 +			else if (attrib==KErrGeneral)
   1.302 +				test.Printf(_L("Ambiguous attribute\n"));
   1.303 +			}
   1.304 +		TPtrC attrib_name(AttributeNames[attrib]);
   1.305 +		test.Printf(_L("Attribute %d (%S) selected\n"),attrib,&attrib_name);
   1.306 +		TInt value=0;
   1.307 +		TInt r=KErrGeneral;
   1.308 +		TBool set=ETrue;
   1.309 +		while(r!=KErrNone)
   1.310 +			{
   1.311 +			InputLine(_L("Value: "),line);
   1.312 +			line.Trim();
   1.313 +			TLex lex(line);
   1.314 +			if (line.MatchF(_L("r"))>=0)
   1.315 +				{
   1.316 +				set=EFalse;
   1.317 +				r=KErrNone;
   1.318 +				}
   1.319 +			else if (line.MatchF(_L("0x"))>=0)
   1.320 +				{
   1.321 +				lex.Inc(2);
   1.322 +				r=lex.Val((TUint&)value,EHex);
   1.323 +				}
   1.324 +			else
   1.325 +				{
   1.326 +				r=lex.Val(value);
   1.327 +				}
   1.328 +			}
   1.329 +		if (set)
   1.330 +			{
   1.331 +			r=HAL::Set((HAL::TAttribute)attrib,value);
   1.332 +			test.Printf(_L("Set returns %d\n"),r);
   1.333 +			}
   1.334 +		TInt v2;
   1.335 +		r=HAL::Get((HAL::TAttribute)attrib,v2);
   1.336 +		test.Printf(_L("Get returns %d, value %d(%08x)\n"),r,v2,v2);
   1.337 +		}
   1.338 +	}
   1.339 +
   1.340 +GLDEF_C TInt E32Main()
   1.341 +	{
   1.342 +	test.Title();
   1.343 +	__UHEAP_MARK;
   1.344 +	__UHEAP_SETFAIL(RHeap::EDeterministic,1);
   1.345 +	TInt machine_id;
   1.346 +	TInt r=HAL::Get(HAL::EMachineUid,machine_id);
   1.347 +	__UHEAP_RESET;
   1.348 +	test(r==KErrNone);
   1.349 +	test.Printf(_L("Machine ID %08x\n"),machine_id);
   1.350 +
   1.351 +	test.Start(_L("Check AttributeNames[] is up-to-date"));
   1.352 +	test_Equal(HAL::ENumHalAttributes, sizeof(AttributeNames)/sizeof(TText*));
   1.353 +
   1.354 +	test.Next(_L("Test Get"));
   1.355 +	TestGet();
   1.356 +
   1.357 +	test.Next(_L("Test GetAll"));
   1.358 +	TestGetAll();
   1.359 +
   1.360 +	test.Next(_L("Test Set"));
   1.361 +	TestSet();
   1.362 +
   1.363 +	test.End();
   1.364 +
   1.365 +	__UHEAP_MARKEND;	// problem if HAL uses TLS
   1.366 +
   1.367 +	return KErrNone;
   1.368 +	}
   1.369 +