|
1 /* |
|
2 * Copyright (c) 2004-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 the License "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 * tokenserverdebug.h |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #ifdef _DEBUG |
|
21 |
|
22 #include "tokenserverdebug.h" |
|
23 #include <f32file.h> |
|
24 |
|
25 TInt TokenServerDebug::iCounter = 0; |
|
26 TInt TokenServerDebug::iStartCount = 0; |
|
27 TInt TokenServerDebug::iPauseCount = 0; |
|
28 TInt TokenServerDebug::iInitialAllocCount = 0; |
|
29 |
|
30 _LIT(KHeapErrorFile, "\\fsserver_heap_error"); |
|
31 |
|
32 void TokenServerDebug::StartOOMTest() |
|
33 { |
|
34 iStartCount = User::CountAllocCells(); |
|
35 iCounter = 0; |
|
36 } |
|
37 |
|
38 void TokenServerDebug::IncHeapFailPoint() |
|
39 { |
|
40 __UHEAP_FAILNEXT(iCounter); |
|
41 ++iCounter; |
|
42 } |
|
43 |
|
44 void TokenServerDebug::ResetHeapFail() |
|
45 { |
|
46 __UHEAP_RESET; |
|
47 } |
|
48 |
|
49 void TokenServerDebug::PauseOOMTest() |
|
50 { |
|
51 ASSERT(iPauseCount == 0); // Don't nest |
|
52 if (iCounter) |
|
53 { |
|
54 __UHEAP_RESET; |
|
55 iPauseCount = User::CountAllocCells(); |
|
56 } |
|
57 } |
|
58 |
|
59 void TokenServerDebug::ResumeOOMTest() |
|
60 { |
|
61 if (iCounter) |
|
62 { |
|
63 ASSERT(iPauseCount > 0); |
|
64 __UHEAP_FAILNEXT(iCounter - (iPauseCount - iStartCount)); |
|
65 iPauseCount = 0; |
|
66 } |
|
67 } |
|
68 |
|
69 void TokenServerDebug::HeapCheckStart() |
|
70 { |
|
71 iInitialAllocCount = User::CountAllocCells(); |
|
72 } |
|
73 |
|
74 void TokenServerDebug::HeapCheckEnd() |
|
75 { |
|
76 TInt finalAllocCount = User::CountAllocCells(); |
|
77 TRAP_IGNORE(HeapErrorL(finalAllocCount != iInitialAllocCount)); |
|
78 // ignore errors |
|
79 } |
|
80 |
|
81 /** |
|
82 * Write or delete a file to signify to the test code that there's a memory leak |
|
83 * in the server. This is unfortunately the best way of doing it since we can't |
|
84 * trap a panic when the server's shutting down. |
|
85 */ |
|
86 void TokenServerDebug::HeapErrorL(TBool aError) |
|
87 { |
|
88 RFs fs; |
|
89 User::LeaveIfError(fs.Connect()); |
|
90 |
|
91 TDriveUnit sysDrive (fs.GetSystemDrive()); |
|
92 TDriveName driveName(sysDrive.Name()); |
|
93 TFileName heapErrFile (driveName); |
|
94 heapErrFile.Append(KHeapErrorFile); |
|
95 |
|
96 if (aError) |
|
97 { |
|
98 RFile file; |
|
99 TInt err = file.Create(fs, heapErrFile, EFileWrite | EFileShareExclusive); |
|
100 if (err != KErrNone || err != KErrAlreadyExists) |
|
101 { |
|
102 User::Leave(err); |
|
103 } |
|
104 file.Close(); |
|
105 } |
|
106 else |
|
107 { |
|
108 TInt err = fs.Delete(heapErrFile); |
|
109 if (err != KErrNone && err != KErrNotFound) |
|
110 { |
|
111 User::Leave(err); |
|
112 } |
|
113 } |
|
114 } |
|
115 |
|
116 #endif |