Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // f32test\manager\t_warm.cpp
24 _LIT(KProgressFileName,"C:\\Progress");
28 LOCAL_D RTest test(_L("T_WARM"));
31 TBuf8<BUF_SIZE> Buffer;
34 #if !defined(__WINS__)
37 TInt err = File.Write(Buffer);
38 if (err!=KErrNone && err!=KErrDiskFull)
42 test.Printf(_L("Error writing to file\n"));
49 LOCAL_C TInt OutputByte(TInt i)
51 TPtrC8 bytePtr( Buffer.Ptr()+i, 1 );
52 TInt err = File.Write(bytePtr);
53 if (err!=KErrNone && err!=KErrDiskFull)
57 test.Printf(_L("Error writing to file\n"));
67 TInt err = File.Read(Buffer);
68 if (err!=KErrNone && err!=KErrEof)
72 test.Printf(_L("Error reading from file\n"));
78 LOCAL_C void CreateFile()
80 if ( File.Create(Session, _L("C:\\TESTFILE.BIN"), EFileWrite) == KErrNone )
82 test.Printf(_L("C:\\TESTFILE.BIN created\n"));
88 test.Printf(_L("Error opening file\n"));
93 LOCAL_C void OpenFile()
95 if ( File.Open(Session, _L("C:\\TESTFILE.BIN"), EFileRead) != KErrNone )
99 test.Printf(_L("Error reading input file\n"));
104 test.Printf(_L("C:\\TESTFILE.BIN opened\n"));
108 __NAKED__ TUint Random( TUint * /*aSeed*/ )
111 // Random number generator
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
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
128 #if defined(__WINS__) || defined(__X86__)
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
138 _asm xor eax, ebx // first involved step
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
145 _asm ret // return with low word of result in eax
149 LOCAL_C void GenerateBuffer()
152 TUint *p = (TUint*)Buffer.Ptr();
153 for (i=0; i<BUF_SIZE/4; i++)
157 Buffer.SetLength(BUF_SIZE);
160 LOCAL_C TInt VerifyBuffer()
163 TUint *p = (TUint*)Buffer.Ptr();
164 for (i=0; i<Buffer.Length()/4; i++)
166 if (*p++ != Random(Seed))
174 LOCAL_C void GenerateFile()
178 test.Next(_L("Creating large file containing pseudo-random sequence"));
179 test( Session.Connect()==KErrNone );
180 Seed[0] = 0xB504F334;
183 // write PRBS sequence to file
193 // Fill RAM Drive to last byte
205 test.Printf(_L("Total bytes written %d\n"), size);
206 User::After(2000000);
209 LOCAL_C void VerifyFile()
213 test.Next(_L("Verifying file containing pseudo-random sequence"));
214 test( Session.Connect()==KErrNone );
215 Seed[0] = 0xB504F334;
218 // read and verify contents of file
224 if (err==KErrNone && Buffer.Length()!=0)
231 test.Printf(_L("Verify error at 0x%08X\n"), j+i );
239 test.Printf(_L("File verified OK\n"));
240 test.Printf(_L("Total bytes read %d\n"), i);
245 void CauseKernelException()
247 RThread().SetSystem(ETrue);
248 *((TUint*)0x58000900)=0xDEADDEAD;
252 #if defined(__WINS__)
256 // This test doesn't make sense under WINS
259 test.Start(_L("No tests under WINS"));
266 GLDEF_C TInt E32Main()
268 // T_WARM should be run by
269 // copying to RAM as C:\System\libs\eshell.exe and pressing the User Reset button
274 if(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin))
275 test.Start(_L("Test T_WARM is running from RAM as C:\\Sys\\Bin\\ESHELL.EXE"));
277 test.Start(_L("Test T_WARM is running from RAM as C:\\System\\Bin\\ESHELL.EXE"));
279 if(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin))
280 test(p.FileName().CompareF(_L("C:\\Sys\\Bin\\ESHELL.EXE"))==0);
282 test(p.FileName().CompareF(_L("C:\\System\\Bin\\ESHELL.EXE"))==0);
283 TBuf8<0x100> peaches=_L8("");
286 peaches.Append(_L8("PeachesAndCream_"));
288 test.Next(_L("Check test progress"));
294 r=progress.Open(fs,KProgressFileName(),EFileRead|EFileWrite);
297 test.Next(_L("Setting progress to first test"));
298 r=progress.Create(fs,KProgressFileName(),EFileRead|EFileWrite);
300 buf=_L8("Warm Reset");
301 r=progress.Write(buf);
306 r=progress.Read(buf);
313 test.Printf(_L("Performing %S test\n"), &bufU);
315 test.Next(_L("Get startup reason"));
316 TMachineStartupType reason;
317 UserHal::StartupReason(reason);
319 if (buf==_L8("Warm Reset"))
321 test.Next(_L("Test reason"));
322 test(reason==EStartupWarmReset);
324 test(UserHal::FaultReason(fault)==KErrGeneral);
327 else if (buf==_L8("Kernel Fault"))
329 test.Next(_L("Test reason"));
330 test(reason==EStartupKernelFault);
332 test(UserHal::FaultReason(fault)==KErrNone);
336 else if (buf==_L8("Kernel Exception"))
338 test.Next(_L("Test reason"));
339 test(reason==EStartupKernelFault);
340 #if defined(__MARM__)
342 test(UserHal::ExceptionInfo(excInfo)==KErrNone);
343 test(((TUint) excInfo.iCodeAddress & 0xf0000000)==0x20000000);
344 test((TUint)excInfo.iDataAddress==0x58000900);
346 test(UserHal::ExceptionId(id)==KErrNone);
347 test(id==EExcAccessViolation);
351 else if (buf==_L8("Finalise"))
353 test.Next(_L("Test reason"));
354 test(reason==EStartupWarmReset);
356 test(UserHal::FaultReason(fault)==KErrGeneral);
361 test.Next(_L("It's all gone horribly wrong"));
367 test.Next(_L("Move on to the next test"));
368 if (buf==_L8("Warm Reset"))
370 test(progress.Write(0,_L8("Kernel Fault"))==KErrNone);
371 test.Next(_L("Cause Kernel fault"));
372 RDebug::Fault(0x1234);
375 else if (buf==_L8("Kernel Fault"))
377 test(progress.Write(0,_L8("Kernel Exception"))==KErrNone);
378 test.Next(_L("Cause Kernel exception"));
379 CauseKernelException();
382 else if (buf==_L8("Kernel Exception"))
384 test(progress.Write(0,_L8("Finalise"))==KErrNone);
385 test.Next(_L("Press the user reset button..."));
388 else if (buf==_L8("Finalise"))
390 test.Next(_L("Removing progress file"));
392 r=fs.Delete(KProgressFileName());
397 test.Next(_L("It's all gone horribly wrong"));
401 test.Printf(_L("\n\nTest completed O.K.\nPress LEFT SHIFT, RIGHT SHIFT and USER RESET to test hard reset\n"));