os/kernelhwsrv/kerneltest/e32test/property/t_framework.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/property/t_framework.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,163 @@
     1.4 +// Copyright (c) 2002-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 +//
    1.18 +
    1.19 +#include <e32test.h>
    1.20 +#include "t_framework.h"
    1.21 +
    1.22 +RTest test(RProcess().FileName());
    1.23 +
    1.24 +CTestProgram::CTestProgram(const TDesC& aName) : iName(aName) 
    1.25 +	{
    1.26 +	iThreadId = RThread().Id();
    1.27 +	}
    1.28 +
    1.29 +void CTestProgram::Panic()
    1.30 +	{
    1.31 +	TPtrC8 fd((TUint8*)iFile);
    1.32 +	TPtrC8 cd((TUint8*)iCond);
    1.33 +
    1.34 +	HBufC* fhb = HBufC::NewMax(fd.Length());
    1.35 +	test(fhb != 0);
    1.36 +	HBufC* chb = HBufC::NewMax(cd.Length());
    1.37 +	test(chb != 0);
    1.38 +
    1.39 +	fhb->Des().Copy(fd);
    1.40 +	chb->Des().Copy(cd);
    1.41 +
    1.42 +	test.Panic(iError, _L("Test '%S' Fails;\nCond: '%S'; File: '%S'; Line %d;\n"), &iName, chb, fhb, iLine);
    1.43 +	}
    1.44 +
    1.45 +void CTestProgram::Panic(TInt aError, char* aCond, char* aFile, TInt aLine)
    1.46 +	{
    1.47 +	iError = aError;
    1.48 +	iCond = aCond;
    1.49 +	iFile = aFile;
    1.50 +	iLine = aLine;
    1.51 +	if (iThreadId != RThread().Id())
    1.52 +		{
    1.53 +		RThread thr;
    1.54 +		thr.Panic(_L("FAIL"), aError);
    1.55 +		}
    1.56 +	Panic();
    1.57 +	}
    1.58 +
    1.59 +void CTestProgram::Launch(TUint aCount)
    1.60 +	{
    1.61 +	// Remember the number of open handles. Just for a sanity check ....
    1.62 +	TInt start_thc, start_phc;
    1.63 +	RThread().HandleCount(start_phc, start_thc);
    1.64 +	TF_ERROR(RThread().RequestCount(), RThread().RequestCount() == 0);
    1.65 +
    1.66 +	test.Next(iName);
    1.67 +	Run(aCount);
    1.68 +
    1.69 +	// Sanity check for open handles
    1.70 +	TInt end_thc, end_phc;
    1.71 +	RThread().HandleCount(end_phc, end_thc);
    1.72 +	TF_ERROR(end_thc - start_thc, start_thc == end_thc);
    1.73 +	TF_ERROR(end_phc - start_phc, start_phc == end_phc);
    1.74 +		// and also for pending requests ...
    1.75 +	TF_ERROR(RThread().RequestCount(), RThread().RequestCount() == 0);
    1.76 +	}
    1.77 +
    1.78 +void CTestProgram::LaunchGroup(CTestProgram** aGroup, TUint aCount)
    1.79 +	{
    1.80 +	for (CTestProgram** progP = aGroup; *progP; ++progP)
    1.81 +		{
    1.82 +		CTestProgram* prog = *progP;
    1.83 +		prog->Launch(aCount);
    1.84 +		}
    1.85 +	}
    1.86 +
    1.87 +TInt CTestProgram::ThreadEntry(TAny* a)
    1.88 +	{
    1.89 +	CTestProgram* prog = (CTestProgram*) a;
    1.90 +	prog->Run(prog->iCount);
    1.91 +	return KErrNone;
    1.92 +	}
    1.93 +
    1.94 +void CTestProgram::Spawn(TUint aCount)
    1.95 +	{
    1.96 +	test.Next(iName); 
    1.97 +	iCount = aCount;
    1.98 +	iStatus = KRequestPending;
    1.99 +	RThread thr;
   1.100 +	TInt r = thr.Create(KNullDesC, ThreadEntry, 0x2000, NULL, this);
   1.101 +	TF_ERROR(r, r == KErrNone);
   1.102 +	thr.NotifyDestruction(iDestroyStatus);
   1.103 +	thr.Logon(iStatus);
   1.104 +	thr.Resume();
   1.105 +	thr.Close();
   1.106 +	}
   1.107 +
   1.108 +void CTestProgram::Wait()
   1.109 +	{
   1.110 +	User::WaitForRequest(iStatus);
   1.111 +	if (iStatus.Int() != KErrNone)
   1.112 +		{
   1.113 +		Panic();
   1.114 +		}
   1.115 +	User::WaitForRequest(iDestroyStatus);
   1.116 +	if (iDestroyStatus.Int() != KErrNone)
   1.117 +		{
   1.118 +		Panic();
   1.119 +		}
   1.120 +	}
   1.121 +
   1.122 +void CTestProgram::SpawnGroup(CTestProgram** aGroup, TUint aCount)
   1.123 +	{
   1.124 +	test.Start(_L("=== Start Parallel Testing ==="));
   1.125 +	CTestProgram** progP;
   1.126 +	for (progP = aGroup; *progP; ++progP)
   1.127 +		{
   1.128 +		CTestProgram* prog = *progP;
   1.129 +		prog->Spawn(aCount);
   1.130 +		}
   1.131 +	for (progP = aGroup; *progP; ++progP)
   1.132 +		{
   1.133 +		CTestProgram* prog = *progP;
   1.134 +		prog->Wait();
   1.135 +		}
   1.136 +	test.Next(_L("=== End Parallel Testing ==="));
   1.137 +	test.End();
   1.138 +	}
   1.139 +
   1.140 +void CTestProgram::Exec(const TDesC& aFile, TAny* args, TInt size)
   1.141 +	{
   1.142 +	//
   1.143 +	// Create the child process and pass args as a UNICODE command line.
   1.144 +	// (we suppose that the args size is multiple of sizeof(TUint16))
   1.145 +	//
   1.146 +	RProcess proc;
   1.147 +	TInt r = proc.Create(aFile, TPtrC((TUint16*) args, size/sizeof(TUint16)));
   1.148 +	TF_ERROR(r, r == KErrNone);
   1.149 +	TRequestStatus status;
   1.150 +	proc.Logon(status);
   1.151 +	proc.Resume();
   1.152 +	User::WaitForRequest(status);
   1.153 +	TF_ERROR(status.Int(), status.Int() == KErrNone);
   1.154 +	proc.Close();
   1.155 +	}
   1.156 +
   1.157 +void CTestProgram::Start()
   1.158 +	{
   1.159 +	test.Title();
   1.160 +	test.Start(_L("GO!"));
   1.161 +	}
   1.162 +
   1.163 +void CTestProgram::End()
   1.164 +	{
   1.165 +	test.End();
   1.166 +	}