diff -r 36bfc973b146 -r 329ab0095843 kerneltest/e32test/dmav2/test_thread.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/kerneltest/e32test/dmav2/test_thread.cpp Mon Jan 18 21:31:10 2010 +0200 @@ -0,0 +1,216 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* Implementation of test_thread.h +* +*/ +#include "test_thread.h" + +TInt TTestRemote::iCount=0; + +TInt TTestRemote::RunFunctor(TAny* aFunctor) + { + TFunctor& functor = *(TFunctor*)aFunctor; + functor(); + return KErrNone; + } + +TTestThread::TTestThread(const TDesC& aName, TThreadFunction aFn, TAny* aData, TBool aAutoResume) + { + Init(aName, aFn, aData, aAutoResume); + } + +TTestThread::TTestThread(const TDesC& aName, TFunctor& aFunctor, TBool aAutoResume) + { + Init(aName, RunFunctor, &aFunctor, aAutoResume); + } + +TTestThread::~TTestThread() + { + //RTest::CloseHandleAndWaitForDestruction(iThread); + iThread.Close(); + } + +void TTestThread::Resume() + { + iThread.Resume(); + } + +TInt TTestThread::WaitForExitL() + { + User::WaitForRequest(iLogonStatus); + const TInt exitType = iThread.ExitType(); + const TInt exitReason = iThread.ExitReason(); + + __ASSERT_ALWAYS(exitType != EExitPending, User::Panic(_L("TTestThread"),0)); + + if(exitType != EExitKill) + User::Leave(exitReason); + + return exitReason; + } + +void TTestThread::Rendezvous(TRequestStatus& aStatus) + { + iThread.Rendezvous(aStatus); + } + +void TTestThread::Init(const TDesC& aName, TThreadFunction aFn, TAny* aData, TBool aAutoResume) + { + TKName name(aName); + name.AppendFormat(_L("-%d"), iCount++); + TInt r=iThread.Create(name, aFn, KDefaultStackSize, KHeapSize, KHeapSize, aData); + if(r!=KErrNone) + { + RDebug::Printf("RThread::Create failed, code=%d", r); + User::Panic(KPanicCat, EThreadCreateFailed); + } + + iThread.Logon(iLogonStatus); + __ASSERT_ALWAYS(iLogonStatus == KRequestPending, User::Panic(_L("TTestThread"),0)); + + if(aAutoResume) + iThread.Resume(); + } + + +CTest::~CTest() + { + iName.Close(); + } + +void CTest::operator()() + { + for(TInt i=0; i testArray; + RPointerArray threadArray; + + for(TInt i=0; iWaitForExitL()); + if(leaveCode != KErrNone) + { + test.Printf(_L("Thread %d: Panic code:%d\n"), j, leaveCode); + test_KErrNone(leaveCode); + } + + if(r!=KErrNone) + { + test.Printf(_L("Thread Number %d\n"), j); + test_KErrNone(r); + } + + threadArray.Remove(0); + delete thread; + } + threadArray.Close(); + + testArray.ResetAndDestroy(); + testArray.Close(); + } + +/** +Runs each CTest in aTests in its own thread +Returns once all threads have terminated +*/ +void MultipleTestRun(const RPointerArray& aTests) + { + RTest test(_L("CTest::MultipleTestRun")); + RPointerArray threads; + + const TInt count = aTests.Count(); + + TInt i; + for(i=0; iResume(); + } + + + for(i=0; iWaitForExitL(); + test_KErrNone(r); + } + + threads.ResetAndDestroy(); + test.Close(); + }