|
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 the License "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 // f32test\manager\t_warm.cpp |
|
15 // |
|
16 // |
|
17 |
|
18 #include <e32test.h> |
|
19 #include <e32svr.h> |
|
20 #include <e32hal.h> |
|
21 #include "u32std.h" |
|
22 #include <f32file.h> |
|
23 |
|
24 _LIT(KProgressFileName,"C:\\Progress"); |
|
25 |
|
26 #define BUF_SIZE 4096 |
|
27 |
|
28 LOCAL_D RTest test(_L("T_WARM")); |
|
29 GLDEF_D RFs Session; |
|
30 GLDEF_D RFile File; |
|
31 TBuf8<BUF_SIZE> Buffer; |
|
32 TUint Seed[2]; |
|
33 |
|
34 #if !defined(__WINS__) |
|
35 LOCAL_C TInt Output() |
|
36 { |
|
37 TInt err = File.Write(Buffer); |
|
38 if (err!=KErrNone && err!=KErrDiskFull) |
|
39 { |
|
40 File.Close(); |
|
41 Session.Close(); |
|
42 test.Printf(_L("Error writing to file\n")); |
|
43 test(1==0); |
|
44 } |
|
45 return err; |
|
46 } |
|
47 /* |
|
48 |
|
49 LOCAL_C TInt OutputByte(TInt i) |
|
50 { |
|
51 TPtrC8 bytePtr( Buffer.Ptr()+i, 1 ); |
|
52 TInt err = File.Write(bytePtr); |
|
53 if (err!=KErrNone && err!=KErrDiskFull) |
|
54 { |
|
55 File.Close(); |
|
56 Session.Close(); |
|
57 test.Printf(_L("Error writing to file\n")); |
|
58 test(1==0); |
|
59 } |
|
60 return err; |
|
61 } |
|
62 |
|
63 */ |
|
64 |
|
65 LOCAL_C TInt Input() |
|
66 { |
|
67 TInt err = File.Read(Buffer); |
|
68 if (err!=KErrNone && err!=KErrEof) |
|
69 { |
|
70 File.Close(); |
|
71 Session.Close(); |
|
72 test.Printf(_L("Error reading from file\n")); |
|
73 test(1==0); |
|
74 } |
|
75 return err; |
|
76 } |
|
77 |
|
78 LOCAL_C void CreateFile() |
|
79 { |
|
80 if ( File.Create(Session, _L("C:\\TESTFILE.BIN"), EFileWrite) == KErrNone ) |
|
81 { |
|
82 test.Printf(_L("C:\\TESTFILE.BIN created\n")); |
|
83 } |
|
84 else |
|
85 { |
|
86 File.Close(); |
|
87 Session.Close(); |
|
88 test.Printf(_L("Error opening file\n")); |
|
89 test(1==0); |
|
90 } |
|
91 } |
|
92 |
|
93 LOCAL_C void OpenFile() |
|
94 { |
|
95 if ( File.Open(Session, _L("C:\\TESTFILE.BIN"), EFileRead) != KErrNone ) |
|
96 { |
|
97 File.Close(); |
|
98 Session.Close(); |
|
99 test.Printf(_L("Error reading input file\n")); |
|
100 test(1==0); |
|
101 } |
|
102 else |
|
103 { |
|
104 test.Printf(_L("C:\\TESTFILE.BIN opened\n")); |
|
105 } |
|
106 } |
|
107 |
|
108 __NAKED__ TUint Random( TUint * /*aSeed*/ ) |
|
109 { |
|
110 #ifdef __MARM__ |
|
111 // Random number generator |
|
112 // |
|
113 // This uses a 33-bit feedback shift register to generate a pseudo-randomly |
|
114 // ordered sequence of numbers which repeats in a cycle of length 2^33 - 1 |
|
115 // |
|
116 __SWITCH_TO_ARM; |
|
117 asm("LDMIA r0, {r1, r2} "); // get seed value |
|
118 asm("MOV r3, r1, LSR#1 "); // 33-bit rotate right |
|
119 asm("ORR r3, r3, r2, LSL#31 "); // LSB of r2 into MSB of r3 |
|
120 asm("AND r2, r1, #1 "); // LSB of r1 into LSB of r2 |
|
121 asm("EOR r3, r3, r1, LSL#12 "); // (involved!) |
|
122 asm("EOR r1, r3, r3, LSR#20 "); // (similarly involved!) |
|
123 asm("STMIA r0, {r1, r2} "); // store new seed |
|
124 asm("MOV r0, r1 "); // return low word of new seed |
|
125 __JUMP(,lr); |
|
126 __END_ARM; |
|
127 #endif |
|
128 #if defined(__WINS__) || defined(__X86__) |
|
129 _asm push ebx |
|
130 _asm mov ecx, [esp+8] // get seed pointer |
|
131 _asm mov eax, [ecx] // get seed value into edx:eax |
|
132 _asm mov edx, [ecx+4] |
|
133 _asm mov ebx, eax // original eax into ebx |
|
134 _asm shr edx, 1 // edx lsb into CF |
|
135 _asm rcr eax, 1 // rotate into eax |
|
136 _asm adc edx, edx // LSB into edx lsb |
|
137 _asm shl ebx, 12 |
|
138 _asm xor eax, ebx // first involved step |
|
139 _asm mov ebx, eax |
|
140 _asm shr ebx, 20 |
|
141 _asm xor eax, ebx // second involved step |
|
142 _asm mov [ecx+4], edx // store top bit of result |
|
143 _asm mov [ecx], eax // store bottom 32 bits of result |
|
144 _asm pop ebx |
|
145 _asm ret // return with low word of result in eax |
|
146 #endif |
|
147 } |
|
148 |
|
149 LOCAL_C void GenerateBuffer() |
|
150 { |
|
151 TInt i; |
|
152 TUint *p = (TUint*)Buffer.Ptr(); |
|
153 for (i=0; i<BUF_SIZE/4; i++) |
|
154 { |
|
155 *p++ = Random(Seed); |
|
156 } |
|
157 Buffer.SetLength(BUF_SIZE); |
|
158 } |
|
159 |
|
160 LOCAL_C TInt VerifyBuffer() |
|
161 { |
|
162 TInt i; |
|
163 TUint *p = (TUint*)Buffer.Ptr(); |
|
164 for (i=0; i<Buffer.Length()/4; i++) |
|
165 { |
|
166 if (*p++ != Random(Seed)) |
|
167 { |
|
168 return(i*4); |
|
169 } |
|
170 } |
|
171 return -1; |
|
172 } |
|
173 |
|
174 LOCAL_C void GenerateFile() |
|
175 { |
|
176 TInt size=0; |
|
177 TInt err = KErrNone; |
|
178 test.Next(_L("Creating large file containing pseudo-random sequence")); |
|
179 test( Session.Connect()==KErrNone ); |
|
180 Seed[0] = 0xB504F334; |
|
181 Seed[1] = 0; |
|
182 |
|
183 // write PRBS sequence to file |
|
184 CreateFile(); |
|
185 while(err==KErrNone) |
|
186 { |
|
187 GenerateBuffer(); |
|
188 err=Output(); |
|
189 if (err==KErrNone) |
|
190 size+=BUF_SIZE; |
|
191 } |
|
192 /* |
|
193 // Fill RAM Drive to last byte |
|
194 err=KErrNone; |
|
195 TInt i=0; |
|
196 while(err==KErrNone) |
|
197 { |
|
198 err=OutputByte(i++); |
|
199 if (err==KErrNone) |
|
200 size++; |
|
201 } |
|
202 */ |
|
203 File.Close(); |
|
204 Session.Close(); |
|
205 test.Printf(_L("Total bytes written %d\n"), size); |
|
206 User::After(2000000); |
|
207 } |
|
208 |
|
209 LOCAL_C void VerifyFile() |
|
210 { |
|
211 TInt err = KErrNone; |
|
212 TInt i,j; |
|
213 test.Next(_L("Verifying file containing pseudo-random sequence")); |
|
214 test( Session.Connect()==KErrNone ); |
|
215 Seed[0] = 0xB504F334; |
|
216 Seed[1] = 0; |
|
217 |
|
218 // read and verify contents of file |
|
219 OpenFile(); |
|
220 i=0; |
|
221 FOREVER |
|
222 { |
|
223 err=Input(); |
|
224 if (err==KErrNone && Buffer.Length()!=0) |
|
225 { |
|
226 j = VerifyBuffer(); |
|
227 if (j>=0) |
|
228 { |
|
229 File.Close(); |
|
230 Session.Close(); |
|
231 test.Printf(_L("Verify error at 0x%08X\n"), j+i ); |
|
232 test(1==0); |
|
233 } |
|
234 i+=Buffer.Length(); |
|
235 } |
|
236 else |
|
237 break; |
|
238 } |
|
239 test.Printf(_L("File verified OK\n")); |
|
240 test.Printf(_L("Total bytes read %d\n"), i); |
|
241 File.Close(); |
|
242 Session.Close(); |
|
243 } |
|
244 |
|
245 void CauseKernelException() |
|
246 { |
|
247 RThread().SetSystem(ETrue); |
|
248 *((TUint*)0x58000900)=0xDEADDEAD; |
|
249 } |
|
250 #endif |
|
251 |
|
252 #if defined(__WINS__) |
|
253 |
|
254 TInt E32Main() |
|
255 // |
|
256 // This test doesn't make sense under WINS |
|
257 // |
|
258 { |
|
259 test.Start(_L("No tests under WINS")); |
|
260 test.End(); |
|
261 return KErrNone; |
|
262 } |
|
263 |
|
264 #else |
|
265 |
|
266 GLDEF_C TInt E32Main() |
|
267 // |
|
268 // T_WARM should be run by |
|
269 // copying to RAM as C:\System\libs\eshell.exe and pressing the User Reset button |
|
270 // |
|
271 { |
|
272 |
|
273 test.Title(); |
|
274 if(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin)) |
|
275 test.Start(_L("Test T_WARM is running from RAM as C:\\Sys\\Bin\\ESHELL.EXE")); |
|
276 else |
|
277 test.Start(_L("Test T_WARM is running from RAM as C:\\System\\Bin\\ESHELL.EXE")); |
|
278 RProcess p; |
|
279 if(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin)) |
|
280 test(p.FileName().CompareF(_L("C:\\Sys\\Bin\\ESHELL.EXE"))==0); |
|
281 else |
|
282 test(p.FileName().CompareF(_L("C:\\System\\Bin\\ESHELL.EXE"))==0); |
|
283 TBuf8<0x100> peaches=_L8(""); |
|
284 TInt i; |
|
285 for (i=0; i<16; i++) |
|
286 peaches.Append(_L8("PeachesAndCream_")); |
|
287 |
|
288 test.Next(_L("Check test progress")); |
|
289 RFs fs; |
|
290 TInt r=fs.Connect(); |
|
291 test(r==KErrNone); |
|
292 RFile progress; |
|
293 TBuf8<0x80> buf; |
|
294 r=progress.Open(fs,KProgressFileName(),EFileRead|EFileWrite); |
|
295 if (r==KErrNotFound) |
|
296 { |
|
297 test.Next(_L("Setting progress to first test")); |
|
298 r=progress.Create(fs,KProgressFileName(),EFileRead|EFileWrite); |
|
299 test(r==KErrNone); |
|
300 buf=_L8("Warm Reset"); |
|
301 r=progress.Write(buf); |
|
302 test(r==KErrNone); |
|
303 } |
|
304 else |
|
305 { |
|
306 r=progress.Read(buf); |
|
307 test(r==KErrNone); |
|
308 } |
|
309 |
|
310 |
|
311 TBuf<0x10> bufU; |
|
312 bufU.Copy(buf); |
|
313 test.Printf(_L("Performing %S test\n"), &bufU); |
|
314 |
|
315 test.Next(_L("Get startup reason")); |
|
316 TMachineStartupType reason; |
|
317 UserHal::StartupReason(reason); |
|
318 |
|
319 if (buf==_L8("Warm Reset")) |
|
320 { |
|
321 test.Next(_L("Test reason")); |
|
322 test(reason==EStartupWarmReset); |
|
323 TInt fault; |
|
324 test(UserHal::FaultReason(fault)==KErrGeneral); |
|
325 GenerateFile(); |
|
326 } |
|
327 else if (buf==_L8("Kernel Fault")) |
|
328 { |
|
329 test.Next(_L("Test reason")); |
|
330 test(reason==EStartupKernelFault); |
|
331 TInt fault; |
|
332 test(UserHal::FaultReason(fault)==KErrNone); |
|
333 test(fault==0x1234); |
|
334 VerifyFile(); |
|
335 } |
|
336 else if (buf==_L8("Kernel Exception")) |
|
337 { |
|
338 test.Next(_L("Test reason")); |
|
339 test(reason==EStartupKernelFault); |
|
340 #if defined(__MARM__) |
|
341 TExcInfo excInfo; |
|
342 test(UserHal::ExceptionInfo(excInfo)==KErrNone); |
|
343 test(((TUint) excInfo.iCodeAddress & 0xf0000000)==0x20000000); |
|
344 test((TUint)excInfo.iDataAddress==0x58000900); |
|
345 TInt id; |
|
346 test(UserHal::ExceptionId(id)==KErrNone); |
|
347 test(id==EExcAccessViolation); |
|
348 #endif |
|
349 VerifyFile(); |
|
350 } |
|
351 else if (buf==_L8("Finalise")) |
|
352 { |
|
353 test.Next(_L("Test reason")); |
|
354 test(reason==EStartupWarmReset); |
|
355 TInt fault; |
|
356 test(UserHal::FaultReason(fault)==KErrGeneral); |
|
357 VerifyFile(); |
|
358 } |
|
359 else |
|
360 { |
|
361 test.Next(_L("It's all gone horribly wrong")); |
|
362 test(EFalse); |
|
363 } |
|
364 |
|
365 |
|
366 // |
|
367 test.Next(_L("Move on to the next test")); |
|
368 if (buf==_L8("Warm Reset")) |
|
369 { |
|
370 test(progress.Write(0,_L8("Kernel Fault"))==KErrNone); |
|
371 test.Next(_L("Cause Kernel fault")); |
|
372 RDebug::Fault(0x1234); |
|
373 test(EFalse); |
|
374 } |
|
375 else if (buf==_L8("Kernel Fault")) |
|
376 { |
|
377 test(progress.Write(0,_L8("Kernel Exception"))==KErrNone); |
|
378 test.Next(_L("Cause Kernel exception")); |
|
379 CauseKernelException(); |
|
380 test(EFalse); |
|
381 } |
|
382 else if (buf==_L8("Kernel Exception")) |
|
383 { |
|
384 test(progress.Write(0,_L8("Finalise"))==KErrNone); |
|
385 test.Next(_L("Press the user reset button...")); |
|
386 FOREVER ; |
|
387 } |
|
388 else if (buf==_L8("Finalise")) |
|
389 { |
|
390 test.Next(_L("Removing progress file")); |
|
391 progress.Close(); |
|
392 r=fs.Delete(KProgressFileName()); |
|
393 test(r==KErrNone); |
|
394 } |
|
395 else |
|
396 { |
|
397 test.Next(_L("It's all gone horribly wrong")); |
|
398 test(EFalse); |
|
399 } |
|
400 |
|
401 test.Printf(_L("\n\nTest completed O.K.\nPress LEFT SHIFT, RIGHT SHIFT and USER RESET to test hard reset\n")); |
|
402 test.Getch(); |
|
403 test.End(); |
|
404 return(KErrNone); |
|
405 } |
|
406 |
|
407 #endif |