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