1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/device/d_ldd.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,347 @@
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 +// e32test\device\d_ldd.cpp
1.18 +// LDD for testing LDD static data
1.19 +//
1.20 +//
1.21 +
1.22 +#include <kernel/kernel.h>
1.23 +#include "d_ldd.h"
1.24 +#include "d_ldd2.h"
1.25 +
1.26 +const TInt KMajorVersionNumber=0;
1.27 +const TInt KMinorVersionNumber=1;
1.28 +const TInt KBuildVersionNumber=1;
1.29 +
1.30 +TInt AFunction()
1.31 + {
1.32 + return KErrNone;
1.33 + }
1.34 +
1.35 +TInt data=0x100;
1.36 +TAny* dataptr=(TAny*)&AFunction;
1.37 +TInt TheBss;
1.38 +
1.39 +class TGlobal
1.40 + {
1.41 +public:
1.42 + TGlobal();
1.43 + ~TGlobal();
1.44 + void Update(TUint32 a);
1.45 + TInt Verify();
1.46 +public:
1.47 + TUint32 iInt;
1.48 + TAny* iPtr;
1.49 + };
1.50 +
1.51 +TGlobal Global;
1.52 +
1.53 +TGlobal::TGlobal()
1.54 + {
1.55 + __KTRACE_OPT(KDEVICE,Kern::Printf("TGlobal::TGlobal()"));
1.56 + iPtr = Kern::Alloc(65536);
1.57 + Update(487);
1.58 + }
1.59 +
1.60 +TGlobal::~TGlobal()
1.61 + {
1.62 + __KTRACE_OPT(KDEVICE,Kern::Printf("TGlobal::~TGlobal()"));
1.63 + Kern::Free(iPtr);
1.64 + }
1.65 +
1.66 +void TGlobal::Update(TUint32 a)
1.67 + {
1.68 + iInt = a;
1.69 + if (iPtr)
1.70 + {
1.71 + TUint32* p = (TUint32*)iPtr;
1.72 + TUint32* pE = p + 65536/4;
1.73 + while (p<pE)
1.74 + {
1.75 + a = (a*69069u)+41;
1.76 + *p++ = a;
1.77 + }
1.78 + }
1.79 + }
1.80 +
1.81 +TInt TGlobal::Verify()
1.82 + {
1.83 + TUint32 x = iInt;
1.84 + if (iPtr)
1.85 + {
1.86 + TUint32* p = (TUint32*)iPtr;
1.87 + TUint32* pE = p + 65536/4;
1.88 + while (p<pE)
1.89 + {
1.90 + x = (x*69069u)+41;
1.91 + if (*p++ != x)
1.92 + return KErrGeneral;
1.93 + }
1.94 + return KErrNone;
1.95 + }
1.96 + return KErrNoMemory;
1.97 + }
1.98 +
1.99 +class DTest;
1.100 +
1.101 +class DTestFactory : public DLogicalDevice
1.102 +//
1.103 +// Test LDD factory
1.104 +//
1.105 + {
1.106 +public:
1.107 + DTestFactory();
1.108 + virtual TInt Install(); //overriding pure virtual
1.109 + virtual void GetCaps(TDes8& aDes) const; //overriding pure virtual
1.110 + virtual TInt Create(DLogicalChannelBase*& aChannel); //overriding pure virtual
1.111 + };
1.112 +
1.113 +class DTest : public DLogicalChannelBase
1.114 +//
1.115 +// Test logical channel
1.116 +//
1.117 + {
1.118 +public:
1.119 + virtual ~DTest();
1.120 +protected:
1.121 + virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
1.122 + virtual TInt Request(TInt aFunction, TAny* a1, TAny* a2);
1.123 + };
1.124 +
1.125 +class DKInstallTestFactory : public DLogicalDevice
1.126 +//
1.127 +// Extra test device which will be installed from kernel side using
1.128 +// Kern::InstallLogicalDevice
1.129 +//
1.130 + {
1.131 +public:
1.132 + DKInstallTestFactory();
1.133 + virtual TInt Install();
1.134 + virtual void GetCaps(TDes8& aDes) const;
1.135 + virtual TInt Create(DLogicalChannelBase*& aChannel);
1.136 + };
1.137 +
1.138 +class DKInstallTest : public DLogicalChannelBase
1.139 +//
1.140 +// Extra test logical channel
1.141 +//
1.142 + {
1.143 +public:
1.144 + virtual ~DKInstallTest();
1.145 +protected:
1.146 + virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
1.147 + virtual TInt Request(TInt aFunction, TAny* a1, TAny* a2);
1.148 + };
1.149 +
1.150 +DECLARE_STANDARD_LDD()
1.151 + {
1.152 + return Global.iPtr ? new DTestFactory : NULL;
1.153 + }
1.154 +
1.155 +DTestFactory::DTestFactory()
1.156 +//
1.157 +// Constructor
1.158 +//
1.159 + {
1.160 + iVersion=TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);
1.161 + //iParseMask=0;//No units, no info, no PDD
1.162 + //iUnitsMask=0;//Only one thing
1.163 + }
1.164 +
1.165 +TInt DTestFactory::Create(DLogicalChannelBase*& aChannel)
1.166 +//
1.167 +// Create a new DTest on this logical device
1.168 +//
1.169 + {
1.170 + aChannel=new DTest;
1.171 + return aChannel?KErrNone:KErrNoMemory;
1.172 + }
1.173 +
1.174 +TInt DTestFactory::Install()
1.175 +//
1.176 +// Install the LDD - overriding pure virtual
1.177 +//
1.178 + {
1.179 + return SetName(&KLddName);
1.180 + }
1.181 +
1.182 +void DTestFactory::GetCaps(TDes8& aDes) const
1.183 +//
1.184 +// Get capabilities - overriding pure virtual
1.185 +//
1.186 + {
1.187 + TCapsTestV01 b;
1.188 + b.iVersion=TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);
1.189 + Kern::InfoCopy(aDes,(TUint8*)&b,sizeof(b));
1.190 + }
1.191 +
1.192 +TInt DTest::DoCreate(TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& aVer)
1.193 +//
1.194 +// Create channel
1.195 +//
1.196 + {
1.197 +
1.198 + if (!Kern::QueryVersionSupported(TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber),aVer))
1.199 + return KErrNotSupported;
1.200 + return KErrNone;
1.201 + }
1.202 +
1.203 +DTest::~DTest()
1.204 +//
1.205 +// Destructor
1.206 +//
1.207 + {
1.208 + }
1.209 +
1.210 +TInt DTest::Request(TInt aFunction, TAny* a1, TAny* a2)
1.211 + {
1.212 + (void)a1;
1.213 + (void)a2;
1.214 + TInt r=KErrNone;
1.215 + switch (aFunction)
1.216 + {
1.217 + case RLddTest::EControlTest1:
1.218 + r=(TInt)dataptr;
1.219 + break;
1.220 + case RLddTest::EControlTest2:
1.221 + r=data++;
1.222 + break;
1.223 + case RLddTest::EControlTest3:
1.224 + r=data--;
1.225 + break;
1.226 + case RLddTest::EControlTest4:
1.227 + r=data;
1.228 + break;
1.229 + case RLddTest::EControlTest5:
1.230 + r=TheBss;
1.231 + break;
1.232 + case RLddTest::EControlTest6:
1.233 + TheBss=(TInt)a1;
1.234 + break;
1.235 + case RLddTest::EControlTest7:
1.236 + r = (TInt)Global.iInt;
1.237 + break;
1.238 + case RLddTest::EControlTest8:
1.239 + Global.Update((TUint32)a1);
1.240 + break;
1.241 + case RLddTest::EControlTest9:
1.242 + r = Global.Verify();
1.243 + break;
1.244 + case RLddTest::EControlLinkedTest1:
1.245 + r=LinkedTest1();
1.246 + break;
1.247 + case RLddTest::EControlLinkedTest2:
1.248 + r=LinkedTest2();
1.249 + break;
1.250 + case RLddTest::EControlLinkedTest3:
1.251 + r=LinkedTest3();
1.252 + break;
1.253 + case RLddTest::EControlLinkedTest4:
1.254 + r=LinkedTest4();
1.255 + break;
1.256 + case RLddTest::EControlLinkedTest5:
1.257 + r=LinkedTest5();
1.258 + break;
1.259 + case RLddTest::EControlLinkedTest6:
1.260 + r=LinkedTest6((TInt)a1);
1.261 + break;
1.262 + case RLddTest::EControlLinkedTest7:
1.263 + r = LinkedTest7();
1.264 + break;
1.265 + case RLddTest::EControlLinkedTest8:
1.266 + LinkedTest8((TUint32)a1);
1.267 + break;
1.268 + case RLddTest::EControlLinkedTest9:
1.269 + r = LinkedTest9();
1.270 + break;
1.271 + case RLddTest::EControlTestKInstall:
1.272 + {
1.273 + r = KErrNoMemory;
1.274 + NKern::ThreadEnterCS();
1.275 + DLogicalDevice* device = new DKInstallTestFactory;
1.276 + if (device!=NULL)
1.277 + r = Kern::InstallLogicalDevice(device);
1.278 + NKern::ThreadLeaveCS();
1.279 + }
1.280 + break;
1.281 + default:
1.282 + r=KErrNotSupported;
1.283 + break;
1.284 + }
1.285 + return r;
1.286 + }
1.287 +
1.288 +DKInstallTestFactory::DKInstallTestFactory()
1.289 +//
1.290 +// Constructor
1.291 +//
1.292 + {
1.293 + iVersion=TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);
1.294 + //iParseMask=0;//No units, no info, no PDD
1.295 + //iUnitsMask=0;//Only one thing
1.296 + }
1.297 +
1.298 +TInt DKInstallTestFactory::Create(DLogicalChannelBase*& aChannel)
1.299 +//
1.300 +// Create a new DKInstallTest on this logical device
1.301 +//
1.302 + {
1.303 + aChannel=new DKInstallTest;
1.304 + return aChannel?KErrNone:KErrNoMemory;
1.305 + }
1.306 +
1.307 +TInt DKInstallTestFactory::Install()
1.308 +//
1.309 +// Install the LDD - overriding pure virtual
1.310 +//
1.311 + {
1.312 + return SetName(&KKInstallLddName);
1.313 + }
1.314 +
1.315 +void DKInstallTestFactory::GetCaps(TDes8& aDes) const
1.316 +//
1.317 +// Get capabilities - overriding pure virtual
1.318 +//
1.319 + {
1.320 + TCapsTestV01 b;
1.321 + b.iVersion=TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);
1.322 + Kern::InfoCopy(aDes,(TUint8*)&b,sizeof(b));
1.323 + }
1.324 +
1.325 +TInt DKInstallTest::DoCreate(TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& aVer)
1.326 +//
1.327 +// Create channel
1.328 +//
1.329 + {
1.330 +
1.331 + if (!Kern::QueryVersionSupported(TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber),aVer))
1.332 + return KErrNotSupported;
1.333 + return KErrNone;
1.334 + }
1.335 +
1.336 +DKInstallTest::~DKInstallTest()
1.337 +//
1.338 +// Destructor
1.339 +//
1.340 + {
1.341 + }
1.342 +
1.343 +TInt DKInstallTest::Request(TInt aFunction, TAny* a1, TAny* a2)
1.344 + {
1.345 + (void)aFunction;
1.346 + (void)a1;
1.347 + (void)a2;
1.348 + return KErrNotSupported;
1.349 + }
1.350 +