testexecmdw/tef/tef/scriptengine/src/testwatcher.cpp
branchRCL_3
changeset 3 9397a16b6eb8
parent 1 6edeef394eb7
equal deleted inserted replaced
1:6edeef394eb7 3:9397a16b6eb8
     1 /*
       
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  
       
    15 * Implementation for Test Watcher object using RUndertaker object
       
    16 * for trapping dead threads during test execution
       
    17 * Collect details of dead threads and pass it on to TEF for logging
       
    18 *
       
    19 */
       
    20 
       
    21 
       
    22 
       
    23 /**
       
    24  @file TestWatcher.cpp
       
    25 */
       
    26 
       
    27 #include "testwatcher.h"
       
    28 
       
    29 TThreadPanicDetails::TThreadPanicDetails(TName aThreadName, 
       
    30 	TInt aReason, TExitCategoryName aCategory, TTime aTime)
       
    31 	: iThreadName(aThreadName), iReason(aReason), iCategory(aCategory), iTime(aTime)
       
    32 	{
       
    33 	}
       
    34 
       
    35 CTestWatcher::CTestWatcher()
       
    36 	{
       
    37 	}
       
    38 
       
    39 TInt ThreadFunc(TAny* anArgument)
       
    40 	{
       
    41 	CSharedData* mySharedData = reinterpret_cast<CSharedData*> (anArgument);
       
    42 	
       
    43 	RUndertaker u;
       
    44 	u.Create();
       
    45 	
       
    46 	TRequestStatus status;
       
    47 	TInt deadThread;
       
    48 	
       
    49 	TBool clientWaiting = ETrue;
       
    50 	
       
    51 	FOREVER
       
    52 		{
       
    53 		status = KRequestPending;
       
    54 		u.Logon(status,deadThread);
       
    55 		// wait for the next thread to die.
       
    56 	
       
    57 		if (clientWaiting)
       
    58 			{
       
    59 			// rendezvous with the client so that they know we're ready.
       
    60 			// This guarantees that we will catch at least the first panic to 
       
    61 			// occur (as long as we aren't closed before kernel tells us.
       
    62 			RThread::Rendezvous(KErrNone);
       
    63 			clientWaiting = EFalse;
       
    64 			}
       
    65 
       
    66 		User::WaitForRequest(status);
       
    67 		// until we get back around to the top we are missing notifications now.
       
    68 		// being high priority helps us, but still...
       
    69 		// deal with this QUICKLY
       
    70 
       
    71 
       
    72 		// get handle to the dead thread (this has already been marked for us in 
       
    73 		// the kernel)
       
    74 		RThread t;
       
    75 		t.SetHandle(deadThread);
       
    76 	
       
    77 		if (t.ExitType() == EExitPanic)
       
    78 			{
       
    79 			// the other ways threads can die are uninteresting
       
    80 			TTime now;
       
    81 			now.UniversalTime();
       
    82 			
       
    83 			TThreadPanicDetails* tpd = new TThreadPanicDetails (t.Name(),
       
    84 				t.ExitReason(),t.ExitCategory(),now);
       
    85 			
       
    86 			mySharedData->iPanicDetails.AppendL(tpd);
       
    87 			}
       
    88 		t.Close();
       
    89 		}
       
    90 	}
       
    91 	
       
    92 	
       
    93 CTestWatcher::~CTestWatcher()
       
    94 	{
       
    95 	iWorker.Close();
       
    96 	for (TInt i = 0; i<iSharedData->iPanicDetails.Count();i++)
       
    97 		{
       
    98 		delete iSharedData->iPanicDetails[i];
       
    99 		}
       
   100 	iSharedData->iPanicDetails.Close();
       
   101 	delete iSharedData;
       
   102 	}
       
   103 
       
   104 CTestWatcher* CTestWatcher::NewL()
       
   105 	{
       
   106 	CTestWatcher* tw = new (ELeave) CTestWatcher();
       
   107 	CleanupStack::PushL(tw);
       
   108 	tw->ConstructL();
       
   109 	CleanupStack::Pop(tw);
       
   110 	return tw;
       
   111 	}
       
   112 	
       
   113 void CTestWatcher::ConstructL() 
       
   114 	{
       
   115 	iSharedData = new CSharedData();
       
   116 	_LIT(KUndertakerWatcher,"UndertakerWatcher");
       
   117 	User::LeaveIfError(iWorker.Create(KUndertakerWatcher(),ThreadFunc,KDefaultStackSize,&User::Heap(),iSharedData,EOwnerProcess));
       
   118 	iWorker.SetPriority(EPriorityAbsoluteForeground);
       
   119 	}
       
   120 
       
   121 void CTestWatcher::StartL()
       
   122 	{
       
   123 	TRequestStatus status = KRequestPending;
       
   124 	iWorker.Rendezvous(status); 
       
   125 	iWorker.Resume();
       
   126 	User::WaitForRequest(status);// wait for it to have initialized the undertaker.
       
   127 	User::LeaveIfError(status.Int());
       
   128 	}
       
   129 	
       
   130 void CTestWatcher::Stop()
       
   131 	{
       
   132 	iWorker.Suspend();
       
   133 	}