os/kernelhwsrv/kerneltest/e32test/personality/example/t_expers.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 1997-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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // e32test\personality\example\t_expers.cpp
    15 // 
    16 //
    17 
    18 #include <e32base.h>
    19 #include <e32base_private.h>
    20 #include <e32test.h>
    21 #include "ifcldd.h"
    22 #include "../../misc/prbs.h"
    23 
    24 RTest test(_L("EXAMPLE PERSONALITY"));
    25 
    26 _LIT(KIfcLddName,"expers.ldd");
    27 
    28 class CRxData : public CActive
    29 	{
    30 public:
    31 	CRxData();
    32 	static void New(RRtosIfc aIfc);
    33 	void Start();
    34 	void RunL();
    35 	void DoCancel();
    36 public:
    37 	RRtosIfc iIfc;
    38 	TUint8 iBuf[512];
    39 	};
    40 
    41 void CRxData::New(RRtosIfc aIfc)
    42 	{
    43 	CRxData* p = new CRxData;
    44 	test(p!=NULL);
    45 	p->iIfc = aIfc;
    46 	CActiveScheduler::Add(p);
    47 	p->Start();
    48 	}
    49 
    50 CRxData::CRxData()
    51 	:	CActive(0)
    52 	{
    53 	}
    54 
    55 void CRxData::DoCancel()
    56 	{
    57 	iIfc.Cancel(RRtosIfc::ECancelReceive);
    58 	}
    59 
    60 void CRxData::Start()
    61 	{
    62 	iIfc.Receive(iStatus, *(SRxData*)iBuf);
    63 	SetActive();
    64 	}
    65 
    66 void CRxData::RunL()
    67 	{
    68 	SRxData& rxd = *(SRxData*)iBuf;
    69 	TInt l = rxd.iLength;
    70 	TUint cs = 0;
    71 	TInt i;
    72 	for (i=0; i<l; ++i)
    73 		cs += rxd.iData[i];
    74 	test( (cs & 0xff) == rxd.iChecksum);
    75 	test.Printf(_L("RXD: l=%02x cs=%02x\n"), l, rxd.iChecksum);
    76 	Start();
    77 	}
    78 
    79 class CReport : public CActive
    80 	{
    81 public:
    82 	CReport();
    83 	static void New(RRtosIfc aIfc);
    84 	void Start();
    85 	void RunL();
    86 	void DoCancel();
    87 	void SendData();
    88 public:
    89 	RRtosIfc iIfc;
    90 	TUint iSeed[2];
    91 	SReport iRpt;
    92 	};
    93 
    94 void CReport::New(RRtosIfc aIfc)
    95 	{
    96 	CReport* p = new CReport;
    97 	test(p!=NULL);
    98 	p->iIfc = aIfc;
    99 	CActiveScheduler::Add(p);
   100 	p->Start();
   101 	}
   102 
   103 CReport::CReport()
   104 	:	CActive(0)
   105 	{
   106 	iSeed[0] = 0xb504f333;
   107 	}
   108 
   109 void CReport::DoCancel()
   110 	{
   111 	iIfc.Cancel(RRtosIfc::ECancelReport);
   112 	}
   113 
   114 void CReport::Start()
   115 	{
   116 	iIfc.Report(iStatus, iRpt);
   117 	SetActive();
   118 	}
   119 
   120 void CReport::RunL()
   121 	{
   122 	switch (iRpt.iType)
   123 		{
   124 		case SReport::ESem:
   125 			test.Printf(_L("SEM: C:%10d OK:%10d BAD:%10d\n"), iRpt.iCount, iRpt.iOkCount, iRpt.iBadCount);
   126 			if (iRpt.iOkCount>1000000)
   127 				CActiveScheduler::Stop();
   128 			break;
   129 		case SReport::ERcv:
   130 			test.Printf(_L("RCV: C:%10d OK:%10d BAD:%10d\n"), iRpt.iCount, iRpt.iOkCount, iRpt.iBadCount);
   131 			break;
   132 		case SReport::ETm:
   133 			test.Printf(_L("TM: C:%10d\n"), iRpt.iCount);
   134 #ifndef __EPOC32__
   135 			if (iRpt.iCount > 100000)
   136 				CActiveScheduler::Stop();
   137 #endif
   138 			TUint x = Random(iSeed) & 3;
   139 			if (x==3)
   140 				SendData();
   141 			if (x)
   142 				SendData();
   143 			else
   144 				iIfc.FlushData();
   145 			break;
   146 		}
   147 	Start();
   148 	}
   149 
   150 void CReport::SendData()
   151 	{
   152 	TInt l = (Random(iSeed)&127)+128;
   153 	TUint buf[64];
   154 	TInt i;
   155 	for (i=0; i<64; ++i)
   156 		buf[i] = Random(iSeed);
   157 	TPtrC8 ptr((const TUint8*)buf, l);
   158 	TInt r = iIfc.SendData(ptr);
   159 	test(r==KErrNone);
   160 	}
   161 
   162 
   163 GLDEF_C TInt E32Main()
   164 	{
   165 	test.Title();
   166 	test.Start(_L("Load interface LDD"));
   167 
   168 	TInt r = User::LoadLogicalDevice(KIfcLddName);
   169 	test(r==KErrNone || r==KErrAlreadyExists);
   170 
   171 	test.Next(_L("Open channel"));
   172 	RRtosIfc ifc;
   173 	RThread().SetPriority(EPriorityAbsoluteHigh);
   174 	r = ifc.Open();
   175 	test(r==KErrNone);
   176 
   177 	test.Next(_L("Start personality tests"));
   178 	ifc.Init();
   179 
   180 	TRequestStatus s;
   181 	ifc.WaitInitialTests(s);
   182 	User::WaitForRequest(s);
   183 	test(s==KErrNone);
   184 
   185 	CActiveScheduler* as = new CActiveScheduler;
   186 	test(as!=NULL);
   187 	CActiveScheduler::Install(as);
   188 	CRxData::New(ifc);
   189 	CReport::New(ifc);
   190 
   191 	CActiveScheduler::Start();
   192 
   193 	ifc.Finish();
   194 	ifc.Close();
   195 
   196 	test.End();
   197 	return 0;
   198 	}
   199