|
1 // Copyright (c) 2007-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 // |
|
15 |
|
16 /** |
|
17 @file |
|
18 @test |
|
19 @internalComponent - Internal Symbian test code |
|
20 */ |
|
21 |
|
22 #include "sysmontesthelper.h" |
|
23 #include <f32file.h> |
|
24 #include <s32file.h> |
|
25 |
|
26 _LIT(KEIgnoreOnFailure, "EIgnoreOnFailure"); |
|
27 _LIT(KERestartOS, "ERestartOS"); |
|
28 _LIT(KERestartOSWithMode, "ERestartOSWithMode"); |
|
29 _LIT(KECriticalNoRetriesMode, "ECriticalNoRetries"); |
|
30 |
|
31 EXPORT_C TRecoveryMethod CSysMonTestHelper::StringToRecoveryMethodL(const TDesC& aRecoveryMethodString) |
|
32 { |
|
33 if (aRecoveryMethodString == KEIgnoreOnFailure) |
|
34 { |
|
35 return EIgnoreOnFailure; |
|
36 } |
|
37 else if (aRecoveryMethodString == KERestartOS) |
|
38 { |
|
39 return ERestartOS; |
|
40 } |
|
41 else if (aRecoveryMethodString == KERestartOSWithMode) |
|
42 { |
|
43 return ERestartOSWithMode; |
|
44 } |
|
45 else if (aRecoveryMethodString == KECriticalNoRetriesMode) |
|
46 { |
|
47 return ECriticalNoRetries; |
|
48 } |
|
49 |
|
50 User::Leave(KErrArgument); |
|
51 return EIgnoreOnFailure; //lint !e527 Unreachable |
|
52 } |
|
53 |
|
54 EXPORT_C CSysMonTestHelper* CSysMonTestHelper::NewLC() |
|
55 { |
|
56 CSysMonTestHelper* self = new(ELeave) CSysMonTestHelper(); |
|
57 CleanupStack::PushL(self); |
|
58 self->ConstructL(); |
|
59 return self; |
|
60 } |
|
61 |
|
62 EXPORT_C CSysMonTestHelper* CSysMonTestHelper::NewL() |
|
63 { |
|
64 CSysMonTestHelper* self = CSysMonTestHelper::NewLC(); |
|
65 CleanupStack::Pop(self); |
|
66 return self; |
|
67 } |
|
68 |
|
69 EXPORT_C void CSysMonTestHelper::GetRecoveryMethodArgsL(TRecoveryMethod& aRecoveryMethod, TInt& aRecoveryMode) |
|
70 { |
|
71 aRecoveryMethod = CSysMonTestHelper::StringToRecoveryMethodL(iArgs->Arg(2)); |
|
72 TLex lex(iArgs->Arg(3)); |
|
73 User::LeaveIfError(lex.Val(aRecoveryMode)); |
|
74 } |
|
75 |
|
76 EXPORT_C void CSysMonTestHelper::GetTimeoutArgL(TInt& aTimeout) |
|
77 { |
|
78 TLex lex(iArgs->Arg(2)); |
|
79 User::LeaveIfError(lex.Val(aTimeout)); |
|
80 } |
|
81 |
|
82 EXPORT_C void CSysMonTestHelper::WriteResultL(const TInt& aResult) |
|
83 { |
|
84 RDebug::Print(_L("Result for %S: %d"), &iTestId, aResult); |
|
85 TBuf<KMaxFileName> fileName; |
|
86 fileName.Append(KResultsRoot); |
|
87 fileName.Append(iTestId); |
|
88 |
|
89 RFs fs; |
|
90 User::LeaveIfError(fs.Connect()); |
|
91 CleanupClosePushL(fs); |
|
92 TInt err = fs.MkDirAll(KResultsRoot); |
|
93 if (err != KErrAlreadyExists) |
|
94 { |
|
95 User::LeaveIfError(err); |
|
96 } |
|
97 |
|
98 RFileWriteStream file; |
|
99 file.PushL(); |
|
100 User::LeaveIfError(file.Replace(fs, fileName, EFileWrite)); |
|
101 file.WriteInt32L(aResult); |
|
102 file.Close(); |
|
103 |
|
104 CleanupStack::PopAndDestroy(2, &fs); |
|
105 } |
|
106 |
|
107 EXPORT_C void CSysMonTestHelper::WriteDeregResultL(const TInt& aResult) |
|
108 { |
|
109 RDebug::Print(_L("Dereg Result for %S: %d"), &iTestId, aResult); |
|
110 TBuf<KMaxFileName> fileName; |
|
111 fileName.Append(KResultsRootDereg); |
|
112 fileName.Append(iTestId); |
|
113 |
|
114 RFs fs; |
|
115 User::LeaveIfError(fs.Connect()); |
|
116 CleanupClosePushL(fs); |
|
117 TInt err = fs.MkDirAll(KResultsRoot); |
|
118 if (err != KErrAlreadyExists) |
|
119 { |
|
120 User::LeaveIfError(err); |
|
121 } |
|
122 |
|
123 RFileWriteStream file; |
|
124 file.PushL(); |
|
125 User::LeaveIfError(file.Replace(fs, fileName, EFileWrite)); |
|
126 file.WriteInt32L(aResult); |
|
127 file.Close(); |
|
128 |
|
129 CleanupStack::PopAndDestroy(2, &fs); |
|
130 } |
|
131 |
|
132 EXPORT_C void CSysMonTestHelper::GetResultIntL(const TDesC& aTestId, TInt& aResult) |
|
133 { |
|
134 TBuf<KMaxFileName> fileName; |
|
135 fileName.Append(KResultsRoot); |
|
136 fileName.Append(aTestId); |
|
137 |
|
138 RFs fs; |
|
139 User::LeaveIfError(fs.Connect()); |
|
140 CleanupClosePushL(fs); |
|
141 |
|
142 RFileReadStream file; |
|
143 file.PushL(); |
|
144 User::LeaveIfError(file.Open(fs, fileName, EFileRead)); |
|
145 aResult = file.ReadInt32L(); |
|
146 file.Close(); |
|
147 |
|
148 CleanupStack::PopAndDestroy(2, &fs); |
|
149 } |
|
150 |
|
151 EXPORT_C void CSysMonTestHelper::GetDeregResultIntL(const TDesC& aTestId, TInt& aResult) |
|
152 { |
|
153 TBuf<KMaxFileName> fileName; |
|
154 fileName.Append(KResultsRootDereg); |
|
155 fileName.Append(aTestId); |
|
156 |
|
157 RFs fs; |
|
158 User::LeaveIfError(fs.Connect()); |
|
159 CleanupClosePushL(fs); |
|
160 |
|
161 RFileReadStream file; |
|
162 file.PushL(); |
|
163 User::LeaveIfError(file.Open(fs, fileName, EFileRead)); |
|
164 aResult = file.ReadInt32L(); |
|
165 file.Close(); |
|
166 |
|
167 CleanupStack::PopAndDestroy(2, &fs); |
|
168 } |
|
169 |
|
170 EXPORT_C TInt CSysMonTestHelper::ReadRunCountL(const TDesC& aProcessFilename) |
|
171 { |
|
172 RFs fs; |
|
173 User::LeaveIfError(fs.Connect()); |
|
174 CleanupClosePushL(fs); |
|
175 |
|
176 TParse parse; |
|
177 fs.Parse(aProcessFilename, parse); |
|
178 |
|
179 TBuf<KMaxFileName> fileName; |
|
180 fileName.Append(KRunCountsRoot); |
|
181 fileName.Append(parse.NameAndExt()); |
|
182 fileName.Append(KTxtExtension); |
|
183 |
|
184 RFileReadStream file; |
|
185 TInt err = 0; |
|
186 err = file.Open(fs, fileName, EFileRead); |
|
187 TInt result = 0; |
|
188 if (err == KErrNotFound || err == KErrPathNotFound) |
|
189 { |
|
190 CleanupStack::PopAndDestroy(&fs); |
|
191 } |
|
192 else |
|
193 { |
|
194 file.PushL(); |
|
195 User::LeaveIfError(err); |
|
196 result = file.ReadInt32L(); |
|
197 file.Close(); |
|
198 CleanupStack::PopAndDestroy(2, &fs); |
|
199 } |
|
200 RDebug::Print(_L("Number of previous runs for %S : %d"), &aProcessFilename, result); |
|
201 return result; |
|
202 } |
|
203 |
|
204 EXPORT_C void CSysMonTestHelper::IncrementRunCountL(const TDesC& aProcessFilename) |
|
205 { |
|
206 TInt runcount = ReadRunCountL(aProcessFilename); |
|
207 runcount++; |
|
208 |
|
209 RFs fs; |
|
210 User::LeaveIfError(fs.Connect()); |
|
211 CleanupClosePushL(fs); |
|
212 |
|
213 TParse parse; |
|
214 fs.Parse(aProcessFilename, parse); |
|
215 |
|
216 TBuf<KMaxFileName> fileName; |
|
217 fileName.Append(KRunCountsRoot); |
|
218 fileName.Append(parse.NameAndExt()); |
|
219 fileName.Append(KTxtExtension); |
|
220 |
|
221 TInt err = fs.MkDirAll(KRunCountsRoot); |
|
222 if (err != KErrAlreadyExists) |
|
223 { |
|
224 User::LeaveIfError(err); |
|
225 } |
|
226 |
|
227 RFileWriteStream file; |
|
228 User::LeaveIfError(file.Replace(fs, fileName, EFileWrite)); |
|
229 file.PushL(); |
|
230 file.WriteInt32L(runcount); |
|
231 file.Close(); |
|
232 |
|
233 RDebug::Print(_L("New runcount for %S : %d"), &aProcessFilename, runcount); |
|
234 |
|
235 CleanupStack::PopAndDestroy(2, &fs); |
|
236 } |
|
237 |
|
238 EXPORT_C TInt CSysMonTestHelper::GetRestartCountL() |
|
239 { |
|
240 RFs fs; |
|
241 User::LeaveIfError(fs.Connect()); |
|
242 CleanupClosePushL(fs); |
|
243 |
|
244 RFile file; |
|
245 TInt err = 0; |
|
246 err = file.Open(fs, KRestartCountFile, EFileRead); |
|
247 TInt result = 0; |
|
248 if (err == KErrNotFound || err == KErrPathNotFound) |
|
249 { |
|
250 CleanupStack::PopAndDestroy(&fs); |
|
251 } |
|
252 else |
|
253 { |
|
254 CleanupClosePushL(file); |
|
255 User::LeaveIfError(err); |
|
256 TBuf8<8> content; |
|
257 file.Read(content); |
|
258 content.Delete(0,6); |
|
259 TLex8 myLex(content); |
|
260 User::LeaveIfError(myLex.Val(result)); |
|
261 file.Close(); |
|
262 CleanupStack::PopAndDestroy(2, &fs); |
|
263 } |
|
264 return result; |
|
265 } |
|
266 |
|
267 EXPORT_C TInt CSysMonTestHelper::GetRegisterCountL() |
|
268 { |
|
269 RFs fs; |
|
270 User::LeaveIfError(fs.Connect()); |
|
271 CleanupClosePushL(fs); |
|
272 |
|
273 RFile file; |
|
274 TInt err = 0; |
|
275 err = file.Open(fs, KRegisterCountFile, EFileRead); |
|
276 TInt result = 0; |
|
277 if (err == KErrNotFound || err == KErrPathNotFound) |
|
278 { |
|
279 CleanupStack::PopAndDestroy(&fs); |
|
280 } |
|
281 else |
|
282 { |
|
283 CleanupClosePushL(file); |
|
284 User::LeaveIfError(err); |
|
285 TBuf8<11> content; |
|
286 file.Read(content); |
|
287 content.Delete(0,9); |
|
288 TLex8 myLex(content); |
|
289 User::LeaveIfError(myLex.Val(result)); |
|
290 file.Close(); |
|
291 CleanupStack::PopAndDestroy(2, &fs); |
|
292 } |
|
293 return result; |
|
294 } |
|
295 |
|
296 EXPORT_C void CSysMonTestHelper::GetTestId(TDes& aTestId) |
|
297 { |
|
298 aTestId = iTestId; |
|
299 } |
|
300 |
|
301 EXPORT_C void CSysMonTestHelper::TestErrorcodeL(TInt& aErrorcode) |
|
302 { |
|
303 if (aErrorcode != KErrNone) |
|
304 { |
|
305 this->WriteResultL(aErrorcode); |
|
306 this->WriteDeregResultL(aErrorcode); |
|
307 User::Leave(aErrorcode); |
|
308 } |
|
309 } |
|
310 |
|
311 void CSysMonTestHelper::ConstructL() |
|
312 { |
|
313 iArgs = CCommandLineArguments::NewL(); |
|
314 iTestId = TBufC<KMaxTestIdLength>(iArgs->Arg(1)); |
|
315 } |
|
316 |
|
317 CSysMonTestHelper::CSysMonTestHelper() |
|
318 {} |
|
319 |
|
320 EXPORT_C CSysMonTestHelper::~CSysMonTestHelper() |
|
321 { |
|
322 delete iArgs; |
|
323 } |