|
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 "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 // Overload of the CTransition test that provides |
|
15 // Heap and Handle leak testing upon a test method. |
|
16 // |
|
17 // |
|
18 |
|
19 #include <ecom/test_bed/datalogger.h> |
|
20 #include "LeakTestTransition.h" |
|
21 |
|
22 EXPORT_C CLeakTestTransition::CLeakTestTransition(const TDesC& aTransitionId, |
|
23 CUnitTestContext& aUTContext, |
|
24 TTransitionValidator& aValidator) |
|
25 : CTransition(aTransitionId, aUTContext, aValidator), |
|
26 iFailStep(KMemoryLeakTestFailInit), |
|
27 iBreakStep(KMemoryLeakTestBreakNone) |
|
28 { |
|
29 // Do nothing here |
|
30 } |
|
31 |
|
32 // Define the overloaded RunL behaviour here |
|
33 EXPORT_C void CLeakTestTransition::RunL() |
|
34 { |
|
35 // Setup leak check and call the base RunL |
|
36 iThread.HandleCount(iStartProcessHandleCount, iStartThreadHandleCount); |
|
37 __UHEAP_SETFAIL(RHeap::EDeterministic,iFailStep); |
|
38 __UHEAP_MARK; |
|
39 if(iBreakStep == iFailStep) |
|
40 { |
|
41 // Drop into the debugger because an unexpected leave occured |
|
42 // on the last run of the RunL. (This is therefore a repeat run...) |
|
43 __DEBUGGER(); |
|
44 iBreakStep = KMemoryLeakTestBreakNone; |
|
45 } |
|
46 |
|
47 if(iStatus == KErrNoMemory) |
|
48 { |
|
49 // Special case of Async Process signalling |
|
50 // a failure during the notification |
|
51 _LIT(KAsyncProblem, "CLeakTestTransition::RunL() async completion with error %d."); |
|
52 iUTContext.DataLogger().LogInformationWithParameters(KAsyncProblem, iStatus.Int()); |
|
53 User::Leave(iStatus.Int()); |
|
54 } |
|
55 |
|
56 CTransition::RunL(); |
|
57 if(iTransitionFinished) |
|
58 { |
|
59 // Successful completion. |
|
60 if(iStatus == KErrNone) |
|
61 { |
|
62 _LIT(KTransitionRunSuccess, "CLeakTestTransition::TransitMethodL() successful completion on iteration %d."); |
|
63 iUTContext.DataLogger().LogInformationWithParameters(KTransitionRunSuccess, iFailStep); |
|
64 } |
|
65 else if(iStatus == KRequestPending) |
|
66 { |
|
67 //This transition was to set up an asynchronous request |
|
68 _LIT(KTransitionRunAsync, "CLeakTestTransition::TransitMethodL() successful called async method on iteration %d."); |
|
69 iUTContext.DataLogger().LogInformationWithParameters(KTransitionRunAsync, iFailStep); |
|
70 } |
|
71 else |
|
72 { |
|
73 _LIT(KTransitionRunError, "CLeakTestTransition::TransitMethodL() error %d completion on iteration %d."); |
|
74 iUTContext.DataLogger().LogInformationWithParameters(KTransitionRunError, iStatus.Int(), iFailStep); |
|
75 } |
|
76 } |
|
77 else |
|
78 { |
|
79 __DEBUGGER(); // An impossible case ???? |
|
80 } |
|
81 } |
|
82 |
|
83 EXPORT_C TInt CLeakTestTransition::RunError(TInt aErrorCode) |
|
84 { |
|
85 if(aErrorCode != KErrNoMemory) |
|
86 { |
|
87 iLeaveError = aErrorCode; |
|
88 // Check if the leave is associated with a repeat request |
|
89 // I.e. it was an execution path test from a stub. |
|
90 if(iLeaveError == KTestBedRepeatTest && iRepeatThis) |
|
91 { |
|
92 _LIT(KTransitionRunRepeat, "CLeakTestTransition::TransitMethodL() leaving on iteration %d for repeat test."); |
|
93 iUTContext.DataLogger().LogInformationWithParameters(KTransitionRunRepeat, iFailStep); |
|
94 User::RequestComplete(iUnitTestStatus, KTestBedRepeatTest); |
|
95 } |
|
96 else |
|
97 { |
|
98 iBreakStep = iFailStep; // Unexpected so |
|
99 // Record the leave and signal completed with a leave code |
|
100 _LIT(KTransitionRunError, "CLeakTestTransition::TransitMethodL() leaving error %d on iteration %d."); |
|
101 iUTContext.DataLogger().LogInformationWithParameters(KTransitionRunError, |
|
102 aErrorCode, |
|
103 iFailStep); |
|
104 User::RequestComplete(iUnitTestStatus, KTestBedTestLeft); |
|
105 } |
|
106 } |
|
107 else |
|
108 { |
|
109 ++iFailStep; // Caused by this test harness |
|
110 // Safety check in case we are testing a function which always leaves with KErrNoMemory |
|
111 if(iFailStep > KProbablyInfinitelyLooping) |
|
112 User::RequestComplete(iUnitTestStatus, KTestBedLeakTestLoopDetected); |
|
113 else |
|
114 { |
|
115 // Re-Schedule |
|
116 // Only Reset if its not a stub repeat |
|
117 // request via a leave |
|
118 if(aErrorCode != KTestBedRepeatTest) |
|
119 iTransitionInfo.iIteration = 0; |
|
120 SetActive(); |
|
121 TRequestStatus* status = &iStatus; |
|
122 User::RequestComplete(status, KErrNone); |
|
123 } |
|
124 } |
|
125 // Check leak cleanup |
|
126 iThread.HandleCount(iEndProcessHandleCount, iEndThreadHandleCount); |
|
127 if(iStartThreadHandleCount != iEndThreadHandleCount) |
|
128 { |
|
129 __DEBUGGER(); // Oops leaked some handles |
|
130 } |
|
131 __UHEAP_MARKEND; |
|
132 __UHEAP_SETFAIL(RHeap::ENone, KMemoryLeakTestFailInit); // No more fails |
|
133 return KErrNone; |
|
134 } |
|
135 |
|
136 EXPORT_C void CLeakTestTransition::PostTransitionCleanup() |
|
137 { |
|
138 __UHEAP_SETFAIL(RHeap::ENone, KMemoryLeakTestFailInit); // No more fails |
|
139 } |