os/kernelhwsrv/kerneltest/e32test/property/t_framework.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#include <e32test.h>
sl@0
    17
#include "t_framework.h"
sl@0
    18
sl@0
    19
RTest test(RProcess().FileName());
sl@0
    20
sl@0
    21
CTestProgram::CTestProgram(const TDesC& aName) : iName(aName) 
sl@0
    22
	{
sl@0
    23
	iThreadId = RThread().Id();
sl@0
    24
	}
sl@0
    25
sl@0
    26
void CTestProgram::Panic()
sl@0
    27
	{
sl@0
    28
	TPtrC8 fd((TUint8*)iFile);
sl@0
    29
	TPtrC8 cd((TUint8*)iCond);
sl@0
    30
sl@0
    31
	HBufC* fhb = HBufC::NewMax(fd.Length());
sl@0
    32
	test(fhb != 0);
sl@0
    33
	HBufC* chb = HBufC::NewMax(cd.Length());
sl@0
    34
	test(chb != 0);
sl@0
    35
sl@0
    36
	fhb->Des().Copy(fd);
sl@0
    37
	chb->Des().Copy(cd);
sl@0
    38
sl@0
    39
	test.Panic(iError, _L("Test '%S' Fails;\nCond: '%S'; File: '%S'; Line %d;\n"), &iName, chb, fhb, iLine);
sl@0
    40
	}
sl@0
    41
sl@0
    42
void CTestProgram::Panic(TInt aError, char* aCond, char* aFile, TInt aLine)
sl@0
    43
	{
sl@0
    44
	iError = aError;
sl@0
    45
	iCond = aCond;
sl@0
    46
	iFile = aFile;
sl@0
    47
	iLine = aLine;
sl@0
    48
	if (iThreadId != RThread().Id())
sl@0
    49
		{
sl@0
    50
		RThread thr;
sl@0
    51
		thr.Panic(_L("FAIL"), aError);
sl@0
    52
		}
sl@0
    53
	Panic();
sl@0
    54
	}
sl@0
    55
sl@0
    56
void CTestProgram::Launch(TUint aCount)
sl@0
    57
	{
sl@0
    58
	// Remember the number of open handles. Just for a sanity check ....
sl@0
    59
	TInt start_thc, start_phc;
sl@0
    60
	RThread().HandleCount(start_phc, start_thc);
sl@0
    61
	TF_ERROR(RThread().RequestCount(), RThread().RequestCount() == 0);
sl@0
    62
sl@0
    63
	test.Next(iName);
sl@0
    64
	Run(aCount);
sl@0
    65
sl@0
    66
	// Sanity check for open handles
sl@0
    67
	TInt end_thc, end_phc;
sl@0
    68
	RThread().HandleCount(end_phc, end_thc);
sl@0
    69
	TF_ERROR(end_thc - start_thc, start_thc == end_thc);
sl@0
    70
	TF_ERROR(end_phc - start_phc, start_phc == end_phc);
sl@0
    71
		// and also for pending requests ...
sl@0
    72
	TF_ERROR(RThread().RequestCount(), RThread().RequestCount() == 0);
sl@0
    73
	}
sl@0
    74
sl@0
    75
void CTestProgram::LaunchGroup(CTestProgram** aGroup, TUint aCount)
sl@0
    76
	{
sl@0
    77
	for (CTestProgram** progP = aGroup; *progP; ++progP)
sl@0
    78
		{
sl@0
    79
		CTestProgram* prog = *progP;
sl@0
    80
		prog->Launch(aCount);
sl@0
    81
		}
sl@0
    82
	}
sl@0
    83
sl@0
    84
TInt CTestProgram::ThreadEntry(TAny* a)
sl@0
    85
	{
sl@0
    86
	CTestProgram* prog = (CTestProgram*) a;
sl@0
    87
	prog->Run(prog->iCount);
sl@0
    88
	return KErrNone;
sl@0
    89
	}
sl@0
    90
sl@0
    91
void CTestProgram::Spawn(TUint aCount)
sl@0
    92
	{
sl@0
    93
	test.Next(iName); 
sl@0
    94
	iCount = aCount;
sl@0
    95
	iStatus = KRequestPending;
sl@0
    96
	RThread thr;
sl@0
    97
	TInt r = thr.Create(KNullDesC, ThreadEntry, 0x2000, NULL, this);
sl@0
    98
	TF_ERROR(r, r == KErrNone);
sl@0
    99
	thr.NotifyDestruction(iDestroyStatus);
sl@0
   100
	thr.Logon(iStatus);
sl@0
   101
	thr.Resume();
sl@0
   102
	thr.Close();
sl@0
   103
	}
sl@0
   104
sl@0
   105
void CTestProgram::Wait()
sl@0
   106
	{
sl@0
   107
	User::WaitForRequest(iStatus);
sl@0
   108
	if (iStatus.Int() != KErrNone)
sl@0
   109
		{
sl@0
   110
		Panic();
sl@0
   111
		}
sl@0
   112
	User::WaitForRequest(iDestroyStatus);
sl@0
   113
	if (iDestroyStatus.Int() != KErrNone)
sl@0
   114
		{
sl@0
   115
		Panic();
sl@0
   116
		}
sl@0
   117
	}
sl@0
   118
sl@0
   119
void CTestProgram::SpawnGroup(CTestProgram** aGroup, TUint aCount)
sl@0
   120
	{
sl@0
   121
	test.Start(_L("=== Start Parallel Testing ==="));
sl@0
   122
	CTestProgram** progP;
sl@0
   123
	for (progP = aGroup; *progP; ++progP)
sl@0
   124
		{
sl@0
   125
		CTestProgram* prog = *progP;
sl@0
   126
		prog->Spawn(aCount);
sl@0
   127
		}
sl@0
   128
	for (progP = aGroup; *progP; ++progP)
sl@0
   129
		{
sl@0
   130
		CTestProgram* prog = *progP;
sl@0
   131
		prog->Wait();
sl@0
   132
		}
sl@0
   133
	test.Next(_L("=== End Parallel Testing ==="));
sl@0
   134
	test.End();
sl@0
   135
	}
sl@0
   136
sl@0
   137
void CTestProgram::Exec(const TDesC& aFile, TAny* args, TInt size)
sl@0
   138
	{
sl@0
   139
	//
sl@0
   140
	// Create the child process and pass args as a UNICODE command line.
sl@0
   141
	// (we suppose that the args size is multiple of sizeof(TUint16))
sl@0
   142
	//
sl@0
   143
	RProcess proc;
sl@0
   144
	TInt r = proc.Create(aFile, TPtrC((TUint16*) args, size/sizeof(TUint16)));
sl@0
   145
	TF_ERROR(r, r == KErrNone);
sl@0
   146
	TRequestStatus status;
sl@0
   147
	proc.Logon(status);
sl@0
   148
	proc.Resume();
sl@0
   149
	User::WaitForRequest(status);
sl@0
   150
	TF_ERROR(status.Int(), status.Int() == KErrNone);
sl@0
   151
	proc.Close();
sl@0
   152
	}
sl@0
   153
sl@0
   154
void CTestProgram::Start()
sl@0
   155
	{
sl@0
   156
	test.Title();
sl@0
   157
	test.Start(_L("GO!"));
sl@0
   158
	}
sl@0
   159
sl@0
   160
void CTestProgram::End()
sl@0
   161
	{
sl@0
   162
	test.End();
sl@0
   163
	}