sl@0: // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // f32test\manager\t_warm.cpp sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include "u32std.h" sl@0: #include sl@0: sl@0: _LIT(KProgressFileName,"C:\\Progress"); sl@0: sl@0: #define BUF_SIZE 4096 sl@0: sl@0: LOCAL_D RTest test(_L("T_WARM")); sl@0: GLDEF_D RFs Session; sl@0: GLDEF_D RFile File; sl@0: TBuf8 Buffer; sl@0: TUint Seed[2]; sl@0: sl@0: #if !defined(__WINS__) sl@0: LOCAL_C TInt Output() sl@0: { sl@0: TInt err = File.Write(Buffer); sl@0: if (err!=KErrNone && err!=KErrDiskFull) sl@0: { sl@0: File.Close(); sl@0: Session.Close(); sl@0: test.Printf(_L("Error writing to file\n")); sl@0: test(1==0); sl@0: } sl@0: return err; sl@0: } sl@0: /* sl@0: sl@0: LOCAL_C TInt OutputByte(TInt i) sl@0: { sl@0: TPtrC8 bytePtr( Buffer.Ptr()+i, 1 ); sl@0: TInt err = File.Write(bytePtr); sl@0: if (err!=KErrNone && err!=KErrDiskFull) sl@0: { sl@0: File.Close(); sl@0: Session.Close(); sl@0: test.Printf(_L("Error writing to file\n")); sl@0: test(1==0); sl@0: } sl@0: return err; sl@0: } sl@0: sl@0: */ sl@0: sl@0: LOCAL_C TInt Input() sl@0: { sl@0: TInt err = File.Read(Buffer); sl@0: if (err!=KErrNone && err!=KErrEof) sl@0: { sl@0: File.Close(); sl@0: Session.Close(); sl@0: test.Printf(_L("Error reading from file\n")); sl@0: test(1==0); sl@0: } sl@0: return err; sl@0: } sl@0: sl@0: LOCAL_C void CreateFile() sl@0: { sl@0: if ( File.Create(Session, _L("C:\\TESTFILE.BIN"), EFileWrite) == KErrNone ) sl@0: { sl@0: test.Printf(_L("C:\\TESTFILE.BIN created\n")); sl@0: } sl@0: else sl@0: { sl@0: File.Close(); sl@0: Session.Close(); sl@0: test.Printf(_L("Error opening file\n")); sl@0: test(1==0); sl@0: } sl@0: } sl@0: sl@0: LOCAL_C void OpenFile() sl@0: { sl@0: if ( File.Open(Session, _L("C:\\TESTFILE.BIN"), EFileRead) != KErrNone ) sl@0: { sl@0: File.Close(); sl@0: Session.Close(); sl@0: test.Printf(_L("Error reading input file\n")); sl@0: test(1==0); sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("C:\\TESTFILE.BIN opened\n")); sl@0: } sl@0: } sl@0: sl@0: __NAKED__ TUint Random( TUint * /*aSeed*/ ) sl@0: { sl@0: #ifdef __MARM__ sl@0: // Random number generator sl@0: // sl@0: // This uses a 33-bit feedback shift register to generate a pseudo-randomly sl@0: // ordered sequence of numbers which repeats in a cycle of length 2^33 - 1 sl@0: // sl@0: __SWITCH_TO_ARM; sl@0: asm("LDMIA r0, {r1, r2} "); // get seed value sl@0: asm("MOV r3, r1, LSR#1 "); // 33-bit rotate right sl@0: asm("ORR r3, r3, r2, LSL#31 "); // LSB of r2 into MSB of r3 sl@0: asm("AND r2, r1, #1 "); // LSB of r1 into LSB of r2 sl@0: asm("EOR r3, r3, r1, LSL#12 "); // (involved!) sl@0: asm("EOR r1, r3, r3, LSR#20 "); // (similarly involved!) sl@0: asm("STMIA r0, {r1, r2} "); // store new seed sl@0: asm("MOV r0, r1 "); // return low word of new seed sl@0: __JUMP(,lr); sl@0: __END_ARM; sl@0: #endif sl@0: #if defined(__WINS__) || defined(__X86__) sl@0: _asm push ebx sl@0: _asm mov ecx, [esp+8] // get seed pointer sl@0: _asm mov eax, [ecx] // get seed value into edx:eax sl@0: _asm mov edx, [ecx+4] sl@0: _asm mov ebx, eax // original eax into ebx sl@0: _asm shr edx, 1 // edx lsb into CF sl@0: _asm rcr eax, 1 // rotate into eax sl@0: _asm adc edx, edx // LSB into edx lsb sl@0: _asm shl ebx, 12 sl@0: _asm xor eax, ebx // first involved step sl@0: _asm mov ebx, eax sl@0: _asm shr ebx, 20 sl@0: _asm xor eax, ebx // second involved step sl@0: _asm mov [ecx+4], edx // store top bit of result sl@0: _asm mov [ecx], eax // store bottom 32 bits of result sl@0: _asm pop ebx sl@0: _asm ret // return with low word of result in eax sl@0: #endif sl@0: } sl@0: sl@0: LOCAL_C void GenerateBuffer() sl@0: { sl@0: TInt i; sl@0: TUint *p = (TUint*)Buffer.Ptr(); sl@0: for (i=0; i=0) sl@0: { sl@0: File.Close(); sl@0: Session.Close(); sl@0: test.Printf(_L("Verify error at 0x%08X\n"), j+i ); sl@0: test(1==0); sl@0: } sl@0: i+=Buffer.Length(); sl@0: } sl@0: else sl@0: break; sl@0: } sl@0: test.Printf(_L("File verified OK\n")); sl@0: test.Printf(_L("Total bytes read %d\n"), i); sl@0: File.Close(); sl@0: Session.Close(); sl@0: } sl@0: sl@0: void CauseKernelException() sl@0: { sl@0: RThread().SetSystem(ETrue); sl@0: *((TUint*)0x58000900)=0xDEADDEAD; sl@0: } sl@0: #endif sl@0: sl@0: #if defined(__WINS__) sl@0: sl@0: TInt E32Main() sl@0: // sl@0: // This test doesn't make sense under WINS sl@0: // sl@0: { sl@0: test.Start(_L("No tests under WINS")); sl@0: test.End(); sl@0: return KErrNone; sl@0: } sl@0: sl@0: #else sl@0: sl@0: GLDEF_C TInt E32Main() sl@0: // sl@0: // T_WARM should be run by sl@0: // copying to RAM as C:\System\libs\eshell.exe and pressing the User Reset button sl@0: // sl@0: { sl@0: sl@0: test.Title(); sl@0: if(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin)) sl@0: test.Start(_L("Test T_WARM is running from RAM as C:\\Sys\\Bin\\ESHELL.EXE")); sl@0: else sl@0: test.Start(_L("Test T_WARM is running from RAM as C:\\System\\Bin\\ESHELL.EXE")); sl@0: RProcess p; sl@0: if(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin)) sl@0: test(p.FileName().CompareF(_L("C:\\Sys\\Bin\\ESHELL.EXE"))==0); sl@0: else sl@0: test(p.FileName().CompareF(_L("C:\\System\\Bin\\ESHELL.EXE"))==0); sl@0: TBuf8<0x100> peaches=_L8(""); sl@0: TInt i; sl@0: for (i=0; i<16; i++) sl@0: peaches.Append(_L8("PeachesAndCream_")); sl@0: sl@0: test.Next(_L("Check test progress")); sl@0: RFs fs; sl@0: TInt r=fs.Connect(); sl@0: test(r==KErrNone); sl@0: RFile progress; sl@0: TBuf8<0x80> buf; sl@0: r=progress.Open(fs,KProgressFileName(),EFileRead|EFileWrite); sl@0: if (r==KErrNotFound) sl@0: { sl@0: test.Next(_L("Setting progress to first test")); sl@0: r=progress.Create(fs,KProgressFileName(),EFileRead|EFileWrite); sl@0: test(r==KErrNone); sl@0: buf=_L8("Warm Reset"); sl@0: r=progress.Write(buf); sl@0: test(r==KErrNone); sl@0: } sl@0: else sl@0: { sl@0: r=progress.Read(buf); sl@0: test(r==KErrNone); sl@0: } sl@0: sl@0: sl@0: TBuf<0x10> bufU; sl@0: bufU.Copy(buf); sl@0: test.Printf(_L("Performing %S test\n"), &bufU); sl@0: sl@0: test.Next(_L("Get startup reason")); sl@0: TMachineStartupType reason; sl@0: UserHal::StartupReason(reason); sl@0: sl@0: if (buf==_L8("Warm Reset")) sl@0: { sl@0: test.Next(_L("Test reason")); sl@0: test(reason==EStartupWarmReset); sl@0: TInt fault; sl@0: test(UserHal::FaultReason(fault)==KErrGeneral); sl@0: GenerateFile(); sl@0: } sl@0: else if (buf==_L8("Kernel Fault")) sl@0: { sl@0: test.Next(_L("Test reason")); sl@0: test(reason==EStartupKernelFault); sl@0: TInt fault; sl@0: test(UserHal::FaultReason(fault)==KErrNone); sl@0: test(fault==0x1234); sl@0: VerifyFile(); sl@0: } sl@0: else if (buf==_L8("Kernel Exception")) sl@0: { sl@0: test.Next(_L("Test reason")); sl@0: test(reason==EStartupKernelFault); sl@0: #if defined(__MARM__) sl@0: TExcInfo excInfo; sl@0: test(UserHal::ExceptionInfo(excInfo)==KErrNone); sl@0: test(((TUint) excInfo.iCodeAddress & 0xf0000000)==0x20000000); sl@0: test((TUint)excInfo.iDataAddress==0x58000900); sl@0: TInt id; sl@0: test(UserHal::ExceptionId(id)==KErrNone); sl@0: test(id==EExcAccessViolation); sl@0: #endif sl@0: VerifyFile(); sl@0: } sl@0: else if (buf==_L8("Finalise")) sl@0: { sl@0: test.Next(_L("Test reason")); sl@0: test(reason==EStartupWarmReset); sl@0: TInt fault; sl@0: test(UserHal::FaultReason(fault)==KErrGeneral); sl@0: VerifyFile(); sl@0: } sl@0: else sl@0: { sl@0: test.Next(_L("It's all gone horribly wrong")); sl@0: test(EFalse); sl@0: } sl@0: sl@0: sl@0: // sl@0: test.Next(_L("Move on to the next test")); sl@0: if (buf==_L8("Warm Reset")) sl@0: { sl@0: test(progress.Write(0,_L8("Kernel Fault"))==KErrNone); sl@0: test.Next(_L("Cause Kernel fault")); sl@0: RDebug::Fault(0x1234); sl@0: test(EFalse); sl@0: } sl@0: else if (buf==_L8("Kernel Fault")) sl@0: { sl@0: test(progress.Write(0,_L8("Kernel Exception"))==KErrNone); sl@0: test.Next(_L("Cause Kernel exception")); sl@0: CauseKernelException(); sl@0: test(EFalse); sl@0: } sl@0: else if (buf==_L8("Kernel Exception")) sl@0: { sl@0: test(progress.Write(0,_L8("Finalise"))==KErrNone); sl@0: test.Next(_L("Press the user reset button...")); sl@0: FOREVER ; sl@0: } sl@0: else if (buf==_L8("Finalise")) sl@0: { sl@0: test.Next(_L("Removing progress file")); sl@0: progress.Close(); sl@0: r=fs.Delete(KProgressFileName()); sl@0: test(r==KErrNone); sl@0: } sl@0: else sl@0: { sl@0: test.Next(_L("It's all gone horribly wrong")); sl@0: test(EFalse); sl@0: } sl@0: sl@0: test.Printf(_L("\n\nTest completed O.K.\nPress LEFT SHIFT, RIGHT SHIFT and USER RESET to test hard reset\n")); sl@0: test.Getch(); sl@0: test.End(); sl@0: return(KErrNone); sl@0: } sl@0: sl@0: #endif