|
1 /* |
|
2 * Copyright (c) 2006 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: Implementation of DevTokenServerDebug |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifdef _DEBUG |
|
21 |
|
22 #include <f32file.h> |
|
23 #include "DevTokenServerDebug.h" |
|
24 |
|
25 _LIT(KHeapErrorFile, "C:\\devtokenserver_heap_error"); |
|
26 |
|
27 TInt DevTokenServerDebug::iCounter = 0; |
|
28 TInt DevTokenServerDebug::iStartCount = 0; |
|
29 TInt DevTokenServerDebug::iPauseCount = 0; |
|
30 TInt DevTokenServerDebug::iInitialAllocCount = 0; |
|
31 |
|
32 // ======== MEMBER FUNCTIONS ======== |
|
33 |
|
34 // --------------------------------------------------------------------------- |
|
35 // DevTokenServerDebug::StartOOMTest() |
|
36 // --------------------------------------------------------------------------- |
|
37 // |
|
38 void DevTokenServerDebug::StartOOMTest() |
|
39 { |
|
40 iStartCount = User::CountAllocCells(); |
|
41 iCounter = 0; |
|
42 } |
|
43 |
|
44 |
|
45 // --------------------------------------------------------------------------- |
|
46 // DevTokenServerDebug::IncHeapFailPoint() |
|
47 // --------------------------------------------------------------------------- |
|
48 // |
|
49 void DevTokenServerDebug::IncHeapFailPoint() |
|
50 { |
|
51 __UHEAP_FAILNEXT(iCounter); |
|
52 ++iCounter; |
|
53 } |
|
54 |
|
55 |
|
56 // --------------------------------------------------------------------------- |
|
57 // DevTokenServerDebug::ResetHeapFail() |
|
58 // --------------------------------------------------------------------------- |
|
59 // |
|
60 void DevTokenServerDebug::ResetHeapFail() |
|
61 { |
|
62 __UHEAP_RESET; |
|
63 } |
|
64 |
|
65 |
|
66 // --------------------------------------------------------------------------- |
|
67 // DevTokenServerDebug::PauseOOMTest() |
|
68 // --------------------------------------------------------------------------- |
|
69 // |
|
70 void DevTokenServerDebug::PauseOOMTest() |
|
71 { |
|
72 ASSERT(iPauseCount == 0); // Don't nest |
|
73 if (iCounter) |
|
74 { |
|
75 __UHEAP_RESET; |
|
76 iPauseCount = User::CountAllocCells(); |
|
77 } |
|
78 } |
|
79 |
|
80 |
|
81 // --------------------------------------------------------------------------- |
|
82 // DevTokenServerDebug::ResumeOOMTest() |
|
83 // --------------------------------------------------------------------------- |
|
84 // |
|
85 void DevTokenServerDebug::ResumeOOMTest() |
|
86 { |
|
87 if (iCounter) |
|
88 { |
|
89 ASSERT(iPauseCount > 0); |
|
90 __UHEAP_FAILNEXT(iCounter - (iPauseCount - iStartCount)); |
|
91 iPauseCount = 0; |
|
92 } |
|
93 } |
|
94 |
|
95 |
|
96 // --------------------------------------------------------------------------- |
|
97 // DevTokenServerDebug::HeapCheckStart() |
|
98 // --------------------------------------------------------------------------- |
|
99 // |
|
100 void DevTokenServerDebug::HeapCheckStart() |
|
101 { |
|
102 iInitialAllocCount = User::CountAllocCells(); |
|
103 } |
|
104 |
|
105 |
|
106 // --------------------------------------------------------------------------- |
|
107 // DevTokenServerDebug::HeapCheckEnd() |
|
108 // --------------------------------------------------------------------------- |
|
109 // |
|
110 void DevTokenServerDebug::HeapCheckEnd() |
|
111 { |
|
112 TInt finalAllocCount = User::CountAllocCells(); |
|
113 TRAP_IGNORE(HeapErrorL(finalAllocCount != iInitialAllocCount)); |
|
114 // ignore errors |
|
115 } |
|
116 |
|
117 |
|
118 // --------------------------------------------------------------------------- |
|
119 // DevTokenServerDebug::HeapErrorL() |
|
120 // Write or delete a file to signify to the test code that there's a memory leak |
|
121 // in the server. This is unfortunately the best way of doing it since we can't |
|
122 // trap a panic when the server's shutting down. |
|
123 // --------------------------------------------------------------------------- |
|
124 // |
|
125 void DevTokenServerDebug::HeapErrorL(TBool aError) |
|
126 { |
|
127 RFs fs; |
|
128 User::LeaveIfError(fs.Connect()); |
|
129 |
|
130 if (aError) |
|
131 { |
|
132 RFile file; |
|
133 TInt err = file.Create(fs, KHeapErrorFile, EFileWrite | EFileShareExclusive); |
|
134 if (err != KErrNone || err != KErrAlreadyExists) |
|
135 { |
|
136 User::Leave(err); |
|
137 } |
|
138 file.Close(); |
|
139 } |
|
140 else |
|
141 { |
|
142 TInt err = fs.Delete(KHeapErrorFile); |
|
143 if (err != KErrNone && err != KErrNotFound) |
|
144 { |
|
145 User::Leave(err); |
|
146 } |
|
147 } |
|
148 } |
|
149 |
|
150 #endif |
|
151 |
|
152 //EOF |
|
153 |