sl@0: // Copyright (c) 1998-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\fsstress\t_rmain.cpp sl@0: // sl@0: // sl@0: sl@0: #if !defined(__F32FILE_H__) sl@0: #include sl@0: #endif sl@0: #if !defined(__E32TEST_H__) sl@0: #include sl@0: #endif sl@0: #if !defined(__E32HAL_H__) sl@0: #include sl@0: #endif sl@0: #if !defined(__E32MATH_H__) sl@0: #include sl@0: #endif sl@0: #if !defined(__F32DBG_H__) sl@0: #include sl@0: #endif sl@0: #include "t_std.h" sl@0: sl@0: sl@0: GLDEF_D RFs TheFs; sl@0: GLDEF_D TFileName gSessionPath; sl@0: GLDEF_D TInt gAllocFailOff=KAllocFailureOff; sl@0: GLDEF_D TInt gAllocFailOn=KAllocFailureOff; sl@0: GLDEF_D TInt64 gSeed=51703; sl@0: const TInt KHeapSize=0x2000; sl@0: sl@0: sl@0: sl@0: GLDEF_C void TurnAllocFailureOff() sl@0: // sl@0: // Switch off all allocFailure sl@0: // sl@0: { sl@0: sl@0: test.Printf(_L("Disable Alloc Failure\n")); sl@0: TheFs.SetAllocFailure(gAllocFailOff); sl@0: gAllocFailOn=KAllocFailureOff; sl@0: } sl@0: sl@0: GLDEF_C void TurnAllocFailureOn() sl@0: // sl@0: // Switch off all allocFailure sl@0: // sl@0: { sl@0: sl@0: test.Printf(_L("Enable Alloc Failure\n")); sl@0: gAllocFailOn=KAllocFailureOn; sl@0: TheFs.SetAllocFailure(gAllocFailOn); sl@0: } sl@0: sl@0: sl@0: GLDEF_C void Format(TInt aDrive) sl@0: // sl@0: // Format current drive sl@0: // sl@0: { sl@0: sl@0: test.Next(_L("Format")); sl@0: TBuf<4> driveBuf=_L("?:\\"); sl@0: driveBuf[0]=(TText)(aDrive+'A'); sl@0: RFormat format; sl@0: TInt count; sl@0: TInt r=format.Open(TheFs,driveBuf,EHighDensity,count); sl@0: test(r==KErrNone); sl@0: while(count) sl@0: { sl@0: TInt r=format.Next(count); sl@0: test(r==KErrNone); sl@0: } sl@0: format.Close(); sl@0: } sl@0: sl@0: LOCAL_C void PushLotsL() sl@0: // sl@0: // Expand the cleanup stack sl@0: // sl@0: { sl@0: TInt i; sl@0: for(i=0;i<1000;i++) sl@0: CleanupStack::PushL((CBase*)NULL); sl@0: CleanupStack::Pop(1000); sl@0: } sl@0: sl@0: sl@0: LOCAL_C void DoTests(TInt aDrive) sl@0: // sl@0: // Do testing on aDrive sl@0: // sl@0: { sl@0: sl@0: gSessionPath=_L("?:\\F32-TST\\"); sl@0: TChar driveLetter; sl@0: TInt r=TheFs.DriveToChar(aDrive,driveLetter); sl@0: test(r==KErrNone); sl@0: gSessionPath[0]=(TText)driveLetter; sl@0: r=TheFs.SetSessionPath(gSessionPath); sl@0: test(r==KErrNone); sl@0: r=TheFs.MkDirAll(gSessionPath); sl@0: test(r==KErrNone || r==KErrAlreadyExists); sl@0: TheFs.ResourceCountMarkStart(); sl@0: sl@0: switch(aDrive) sl@0: { sl@0: #if defined (__MARM__) sl@0: case EDriveC: sl@0: TRAP(r,CallTestsYL(aDrive)); sl@0: break; sl@0: case EDriveD: sl@0: TRAP(r,CallTestsXL(aDrive)); sl@0: break; sl@0: #else sl@0: case EDriveX: sl@0: TRAP(r,CallTestsXL(aDrive)); sl@0: break; sl@0: case EDriveY: sl@0: TRAP(r,CallTestsYL(aDrive)); sl@0: break; sl@0: #endif sl@0: case EDriveQ: sl@0: TRAP(r,CallTestsQL(aDrive)); sl@0: break; sl@0: default: sl@0: TRAP(r,CallTestsDefaultL(aDrive)); sl@0: break; sl@0: } sl@0: sl@0: if (r==KErrNone) sl@0: TheFs.ResourceCountMarkEnd(); sl@0: else sl@0: { sl@0: test.Printf(_L("Error: Leave %d\n"),r); sl@0: test.Getch(); sl@0: } sl@0: } sl@0: sl@0: sl@0: LOCAL_C TInt TestXDrive(TAny * /*anArg*/) sl@0: // sl@0: // MARM CF card drive testing (WINS emulates CF card on X) sl@0: // sl@0: { sl@0: CTrapCleanup* cleanup; sl@0: cleanup=CTrapCleanup::New(); sl@0: sl@0: testx.Title(); sl@0: sl@0: TInt r=TheFs.Connect(); sl@0: testx(r==KErrNone); sl@0: // TheFs.SetAllocFailure(gAllocFailOn); sl@0: sl@0: #if defined (__WINS__) sl@0: sl@0: // Run tests on WINS drive X: sl@0: testx.Start(_L("Starting tests on drive X:")); sl@0: DoTests(EDriveX); sl@0: sl@0: #elif defined (__MARM__) sl@0: // Run tests on MARM drive D: sl@0: testx.Start(_L("Starting tests on drive D:")); sl@0: DoTests(EDriveD); sl@0: #endif sl@0: sl@0: // TheFs.SetAllocFailure(gAllocFailOff); sl@0: delete cleanup; sl@0: testx.End(); sl@0: sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: LOCAL_C TInt TestYDrive(TAny * /*anArg*/) sl@0: // sl@0: // MARM RAM drive testing (WINS emulates FAT filesystem on Y) sl@0: // sl@0: { sl@0: CTrapCleanup* cleanup; sl@0: cleanup=CTrapCleanup::New(); sl@0: sl@0: testy.Title(); sl@0: TInt r=TheFs.Connect(); sl@0: testy(r==KErrNone); sl@0: sl@0: // TheFs.SetAllocFailure(gAllocFailOn); sl@0: sl@0: #if defined (__WINS__) sl@0: sl@0: // Run tests on WINS drive Y: sl@0: testy.Start(_L("Starting tests on drive Y:")); sl@0: DoTests(EDriveY); sl@0: sl@0: #elif defined (__MARM__) sl@0: sl@0: // Run tests on MARM drive C: sl@0: testy.Start(_L("Starting tests on drive C:")); sl@0: DoTests(EDriveC); sl@0: #endif sl@0: sl@0: // TheFs.SetAllocFailure(gAllocFailOff); sl@0: delete cleanup; sl@0: testy.End(); sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: LOCAL_C TInt TestRemoteDrive(TAny * /*anArg*/) sl@0: // sl@0: // Run tests on remote drive Q: sl@0: // sl@0: { sl@0: CTrapCleanup* cleanup; sl@0: cleanup=CTrapCleanup::New(); sl@0: sl@0: testq.Title(); sl@0: testq.Start(_L("Starting async tests...")); sl@0: sl@0: TInt r=TheFs.Connect(); sl@0: testq(r==KErrNone); sl@0: // TheFs.SetAllocFailure(gAllocFailOn); sl@0: sl@0: testq.Next(_L("Mount Remote Drive simulator on Q:")); sl@0: sl@0: r=TheFs.AddFileSystem(_L("T_REMFSY")); sl@0: testq.Next(_L("Add remote file system")); sl@0: testq.Printf(_L("AddFileSystem returned %d\n"),r); sl@0: // testq(r==KErrNone || r==KErrAlreadyExists); sl@0: sl@0: r=TheFs.MountFileSystem(_L("T_REMFSY"),EDriveQ); sl@0: testq.Next(_L("Mount remote file system")); sl@0: testq.Printf(_L("MountFileSystem returned %d\n"),r); sl@0: testq(r==KErrNone || r==KErrCorrupt || r==KErrNotReady || r==KErrAlreadyExists); sl@0: if (r==KErrCorrupt || r==KErrNotReady) sl@0: Format(EDriveQ); sl@0: sl@0: DoTests(EDriveQ); sl@0: // TheFs.SetAllocFailure(gAllocFailOff); sl@0: sl@0: delete cleanup; sl@0: testq.End(); sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: GLDEF_C TInt E32Main() sl@0: // sl@0: // Test with drive nearly full sl@0: // sl@0: { sl@0: CTrapCleanup* cleanup; sl@0: cleanup=CTrapCleanup::New(); sl@0: TRAPD(r,PushLotsL()); sl@0: __UHEAP_MARK; sl@0: sl@0: test.Title(); sl@0: test.Start(_L("Starting tests...")); sl@0: r=TheFs.Connect(); sl@0: test(r==KErrNone); sl@0: // TheFs.SetAllocFailure(gAllocFailOn); sl@0: sl@0: // Default drive testing sl@0: DoTests(KDefaultDrive); sl@0: sl@0: // Remote drive testing sl@0: RThread clientThreadQ; sl@0: r=clientThreadQ.Create(_L("TestRemoteDrive"), TestRemoteDrive, KDefaultStackSize,KHeapSize,KHeapSize,NULL); sl@0: test(r==KErrNone); sl@0: TRequestStatus statq; sl@0: clientThreadQ.Logon(statq); sl@0: test.Next(_L("Resume clientThreadQ")); sl@0: clientThreadQ.Resume(); sl@0: sl@0: // MARM CF card drive testing (WINS emulates CF card on X) sl@0: RThread clientThreadX; sl@0: r=clientThreadX.Create(_L("TestXDrive"), TestXDrive, KDefaultStackSize,KHeapSize,KHeapSize,NULL); sl@0: test(r==KErrNone); sl@0: TRequestStatus statx; sl@0: clientThreadX.Logon(statx); sl@0: test.Next(_L("Resume clientThreadX")); sl@0: clientThreadX.Resume(); sl@0: sl@0: // MARM RAM drive testing (WINS emulates FAT filesystem on Y) sl@0: RThread clientThreadY; sl@0: r=clientThreadY.Create(_L("TestYDrive"), TestYDrive, KDefaultStackSize,KHeapSize,KHeapSize,NULL); sl@0: test(r==KErrNone); sl@0: TRequestStatus staty; sl@0: clientThreadY.Logon(staty); sl@0: test.Next(_L("Resume clientThreadY")); sl@0: clientThreadY.Resume(); sl@0: sl@0: User::WaitForRequest(statx); sl@0: User::WaitForRequest(staty); sl@0: User::WaitForRequest(statq); sl@0: sl@0: clientThreadQ.Close(); sl@0: clientThreadX.Close(); sl@0: clientThreadY.Close(); sl@0: sl@0: // TheFs.SetAllocFailure(gAllocFailOff); sl@0: TheFs.Close(); sl@0: sl@0: test.End(); sl@0: test.Close(); sl@0: __UHEAP_MARKEND; sl@0: delete cleanup; sl@0: return(KErrNone); sl@0: }