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: // Based on t_main.cpp as used for other tests. sl@0: // sl@0: // sl@0: sl@0: //! @file f32test\concur\t_cfsmain.cpp sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #include "t_server.h" sl@0: #include "cfafsdlyif.h" 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: sl@0: GLDEF_D TChar gDriveToTest; sl@0: GLDEF_D TUint32 gDebugFlags = 0; sl@0: sl@0: GLDEF_D TPtrC gArgV[128]; sl@0: GLDEF_D TInt gArgC = 0; sl@0: sl@0: LOCAL_D TTestType TheTestType=ENotifierNone; sl@0: LOCAL_D RSemaphore ControlIoSem; sl@0: sl@0: TMediaPassword thePassword=_L8("abc"); sl@0: sl@0: enum TTestCode {ESimLockRemMed, EClearSimLockRemMed}; sl@0: sl@0: const TInt KControlIoRemMedLock=5; //setflag sl@0: const TInt KControlClearMedLock=6; //clears flag sl@0: const TInt KControIoRemMedRepeat=9; sl@0: sl@0: _LIT(KNotifierHang,"Hang"); sl@0: _LIT(KNotifierRepeat,"Repeat"); sl@0: _LIT(KNotifierWithRepeat,"WithRepeat"); sl@0: _LIT(KPrivate, "\\Private\\"); sl@0: sl@0: GLDEF_C TBool IsTestTypeNotifyHang() sl@0: // sl@0: // sl@0: // sl@0: { sl@0: return(TheTestType==ENotifierHang); sl@0: } sl@0: sl@0: GLDEF_C TBool IsTestTypeNotifyRepeat() sl@0: // sl@0: // sl@0: // sl@0: { sl@0: return(TheTestType==ENotifierRepeat); sl@0: } sl@0: sl@0: GLDEF_C TBool IsTestTypeNotifyWithRepeat() sl@0: // sl@0: // sl@0: // sl@0: { sl@0: return(TheTestType==ENotifierWithRepeat); sl@0: } sl@0: sl@0: sl@0: GLDEF_C TBool IsTestTypeStandard() sl@0: // sl@0: // sl@0: // sl@0: { sl@0: return(TheTestType==ENotifierNone); sl@0: } sl@0: sl@0: GLDEF_C TTestType TestType() sl@0: // sl@0: // sl@0: // sl@0: { sl@0: return(TheTestType); sl@0: } sl@0: sl@0: GLDEF_C void CreateShortName(TDes& aFileName,TInt64& aSeed) sl@0: // sl@0: // Create a random, dos legal 8.3 char name sl@0: // sl@0: { sl@0: sl@0: TInt length=Math::Rand(aSeed)%11; sl@0: if (length==0) sl@0: length=1; sl@0: else if (length==3) // don't create three letter names like 'AUX' or 'PRN' sl@0: length++; sl@0: else if (length>8) // end in '.' if no extension sl@0: length++; sl@0: sl@0: aFileName.SetLength(length); sl@0: for(TInt i=0;i0) sl@0: length=aLength; sl@0: else sl@0: { sl@0: length=Math::Rand(aSeed)%128; sl@0: length+=Math::Rand(aSeed)%128; sl@0: length+=Math::Rand(aSeed)%128; sl@0: length+=Math::Rand(aSeed)%128; sl@0: length-=256; sl@0: length=Abs(length); sl@0: if (length==0) sl@0: length=1; sl@0: if (length>220) sl@0: length=31; sl@0: } sl@0: if (length==3) // don't create three letter names like 'AUX' or 'PRN' sl@0: length++; sl@0: sl@0: aFileName.SetLength(length); sl@0: TInt spaceChar=-1; sl@0: TInt i; sl@0: for(i=0;i': sl@0: case ':': sl@0: case '"': sl@0: case '/': sl@0: case '|': sl@0: case '*': sl@0: case '?': sl@0: case '\\': sl@0: case '\0': sl@0: break; sl@0: default: sl@0: illegalChar=EFalse; sl@0: }; sl@0: } sl@0: aFileName[i]=(TText)letter; sl@0: } sl@0: sl@0: if (spaceChar!=-1) sl@0: { sl@0: i=spaceChar; sl@0: goto StartAgain; sl@0: } sl@0: } sl@0: sl@0: GLDEF_C void CheckEntry(const TDesC& aName,TUint anAttributes,const TTime& aModified) sl@0: // sl@0: // Checks the values associated with an entry sl@0: // sl@0: { sl@0: sl@0: TEntry entry; sl@0: TInt r=TheFs.Entry(aName,entry); sl@0: test(r==KErrNone); sl@0: test(entry.iAtt==anAttributes); sl@0: if (aModified!=TTime(0)) sl@0: test(entry.iModified==aModified); sl@0: } sl@0: sl@0: GLDEF_C void CheckDisk() sl@0: // sl@0: // Do a checkdisk and report failure sl@0: // sl@0: { sl@0: test.Next(_L("Check Disk")); sl@0: TInt r=TheFs.CheckDisk(gSessionPath); sl@0: if (r!=KErrNone && r!=KErrNotSupported && r!=KErrPermissionDenied) sl@0: ReportCheckDiskFailure(r); sl@0: } sl@0: sl@0: GLDEF_C void ReportCheckDiskFailure(TInt aRet) sl@0: // sl@0: // Report the failure of checkdisk sl@0: // sl@0: { sl@0: sl@0: test.Printf(_L("CHECKDISK FAILED: ")); sl@0: switch(aRet) sl@0: { sl@0: case 1: test.Printf(_L("File cluster chain contains a bad value (<2 or >maxCluster)\n")); break; sl@0: case 2: test.Printf(_L("Two files are linked to the same cluster\n")); break; sl@0: case 3: test.Printf(_L("Unallocated cluster contains a value != 0\n")); break; sl@0: case 4: test.Printf(_L("Size of file != number of clusters in chain\n")); break; sl@0: default: test.Printf(_L("Undefined Error value %d\n"),aRet); sl@0: } sl@0: test(EFalse); 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; // Disable gAllocFailOn 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; // Enable gAllocFailOn sl@0: TheFs.SetAllocFailure(gAllocFailOn); sl@0: } sl@0: sl@0: GLDEF_C void MakeFile(const TDesC& aFileName,const TUidType& aUidType,const TDesC8& aFileContents) sl@0: // sl@0: // Make a file and write uid and data sl@0: // sl@0: { sl@0: sl@0: RFile file; sl@0: TInt r=file.Replace(TheFs,aFileName,0); sl@0: test(r==KErrNone || r==KErrPathNotFound); sl@0: if (r==KErrPathNotFound) sl@0: { sl@0: r=TheFs.MkDirAll(aFileName); sl@0: test(r==KErrNone); sl@0: r=file.Replace(TheFs,aFileName,0); sl@0: test(r==KErrNone); sl@0: } sl@0: TCheckedUid checkedUid(aUidType); sl@0: TPtrC8 uidData((TUint8*)&checkedUid,sizeof(TCheckedUid)); sl@0: r=file.Write(uidData); sl@0: test(r==KErrNone); sl@0: r=file.Write(aFileContents); sl@0: test(r==KErrNone); sl@0: file.Close(); sl@0: } sl@0: sl@0: GLDEF_C void MakeFile(const TDesC& aFileName,const TDesC8& aFileContents) sl@0: // sl@0: // Make a file and write something in it sl@0: // sl@0: { sl@0: sl@0: RFile file; sl@0: TInt r=file.Replace(TheFs,aFileName,0); sl@0: if(r!=KErrNone && r!=KErrPathNotFound) sl@0: { sl@0: test.Printf(_L("ERROR: r=%d"),r); sl@0: test(EFalse); sl@0: } sl@0: test(r==KErrNone || r==KErrPathNotFound); sl@0: if (r==KErrPathNotFound) sl@0: { sl@0: r=TheFs.MkDirAll(aFileName); sl@0: test(r==KErrNone); sl@0: r=file.Replace(TheFs,aFileName,0); sl@0: test(r==KErrNone); sl@0: } sl@0: r=file.Write(aFileContents); sl@0: test(r==KErrNone); sl@0: file.Close(); sl@0: } sl@0: sl@0: GLDEF_C void MakeFile(const TDesC& aFileName,TInt anAttributes) sl@0: // sl@0: // Make a file and write something in it sl@0: // sl@0: { sl@0: sl@0: RFile file; sl@0: TInt r=file.Replace(TheFs,aFileName,0); sl@0: test(r==KErrNone || r==KErrPathNotFound); sl@0: if (r==KErrPathNotFound) sl@0: { sl@0: r=TheFs.MkDirAll(aFileName); sl@0: test(r==KErrNone); sl@0: r=file.Replace(TheFs,aFileName,0); sl@0: test(r==KErrNone); sl@0: } sl@0: file.Close(); sl@0: r=TheFs.SetAtt(aFileName,anAttributes,0); sl@0: test(r==KErrNone); sl@0: } sl@0: sl@0: GLDEF_C void SetSessionPath(const TDesC& aPathName) sl@0: // sl@0: // Set the session path and update gSessionPath sl@0: // sl@0: { sl@0: sl@0: TInt r=TheFs.SetSessionPath(aPathName); sl@0: test(r==KErrNone); sl@0: r=TheFs.SessionPath(gSessionPath); sl@0: test(r==KErrNone); sl@0: } sl@0: sl@0: GLDEF_C void MakeFile(const TDesC& aFileName) sl@0: // sl@0: // Make a file sl@0: // sl@0: { sl@0: sl@0: MakeFile(aFileName,_L8("")); sl@0: } sl@0: sl@0: GLDEF_C void MakeDir(const TDesC& aDirName) sl@0: // sl@0: // Make a directory sl@0: // sl@0: { sl@0: sl@0: TInt r=TheFs.MkDirAll(aDirName); sl@0: test(r==KErrNone || r==KErrAlreadyExists); sl@0: } sl@0: sl@0: GLDEF_C TInt CheckFileExists(const TDesC& aName,TInt aResult,TBool aCompRes/*=ETrue*/) sl@0: // sl@0: // Check aName exists sl@0: // sl@0: { sl@0: sl@0: TEntry entry; sl@0: TInt r=TheFs.Entry(aName,entry); sl@0: test(r==aResult); sl@0: if (aResult!=KErrNone) sl@0: return(0); sl@0: TParsePtrC nameParse(aName); sl@0: TParsePtrC entryParse(entry.iName); sl@0: TBool nameMatch=(entryParse.Name()==nameParse.Name()); sl@0: TBool extMatch=(entryParse.Ext()==nameParse.Ext()) || (entryParse.Ext().Length()<=1 && nameParse.Ext().Length()<=1); sl@0: test((nameMatch && extMatch)==aCompRes); sl@0: return(entry.iSize); sl@0: } sl@0: sl@0: GLDEF_C void CheckFileContents(const TDesC& aName,const TDesC8& aContents) sl@0: // sl@0: // Check contents of file sl@0: // sl@0: { sl@0: sl@0: RFile f; sl@0: TInt r=f.Open(TheFs,aName,EFileRead); sl@0: test(r==KErrNone); sl@0: HBufC8* testBuf=HBufC8::NewL(aContents.Length()); sl@0: test(testBuf!=NULL); sl@0: TPtr8 bufPtr(testBuf->Des()); sl@0: r=f.Read(bufPtr); sl@0: test(r==KErrNone); sl@0: test(bufPtr==aContents); sl@0: r=f.Read(bufPtr); sl@0: test(r==KErrNone); sl@0: test(bufPtr.Length()==0); sl@0: f.Close(); sl@0: User::Free(testBuf); sl@0: } sl@0: sl@0: GLDEF_C void DeleteTestDirectory() sl@0: // sl@0: // Delete the leaf session path directory sl@0: // sl@0: { sl@0: sl@0: TheFs.SetAtt(_L("\\F32-TST\\SCANTEST\\Left\\Dir3\\Dir4\\Hidden"), 0, KEntryAttHidden); sl@0: TheFs.SetAtt(_L("\\F32-TST\\SCANTEST\\Left\\Dir3\\Dir4\\Hidden\\HiddenFile"), 0, KEntryAttHidden); sl@0: TheFs.SetAtt(_L("\\F32-TST\\SCANTEST\\Left\\Dir3\\Dir4\\Hidden\\System"), 0, KEntryAttSystem); sl@0: test.Next(_L("Delete test directory")); sl@0: CFileMan* fMan=CFileMan::NewL(TheFs); sl@0: test(fMan!=NULL); sl@0: TInt r=TheFs.SessionPath(gSessionPath); sl@0: test(r==KErrNone); sl@0: r=TheFs.CheckDisk(gSessionPath); sl@0: if (r!=KErrNone && r!=KErrNotSupported) sl@0: ReportCheckDiskFailure(r); sl@0: r=fMan->RmDir(gSessionPath); sl@0: test(r==KErrNone); sl@0: delete fMan; sl@0: } sl@0: sl@0: GLDEF_C void CreateTestDirectory(const TDesC& aSessionPath) sl@0: // sl@0: // Create directory for test sl@0: // sl@0: { sl@0: TParsePtrC path(aSessionPath); sl@0: test(path.DrivePresent()==EFalse); sl@0: sl@0: TInt r=TheFs.SetSessionPath(aSessionPath); sl@0: test(r==KErrNone); sl@0: r=TheFs.SessionPath(gSessionPath); sl@0: test(r==KErrNone); sl@0: r=TheFs.MkDirAll(gSessionPath); sl@0: test(r==KErrNone || r==KErrAlreadyExists); sl@0: } sl@0: sl@0: GLDEF_C TInt CurrentDrive() sl@0: // sl@0: // Return the current drive number sl@0: // sl@0: { sl@0: sl@0: TInt driveNum; sl@0: TInt r=TheFs.CharToDrive(gSessionPath[0],driveNum); sl@0: test(r==KErrNone); sl@0: return(driveNum); 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: sl@0: // !!! Disable platform security tests until we get the new APIs sl@0: // if(User::Capability() & KCapabilityRoot) sl@0: // CheckMountLFFS(TheFs,driveLetter); sl@0: sl@0: r=TheFs.MkDirAll(gSessionPath); sl@0: TheFs.ResourceCountMarkStart(); sl@0: sl@0: TRAP(r,CallTestsL()); 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(EFalse); sl@0: } sl@0: sl@0: TestingLFFS(EFalse); sl@0: } sl@0: sl@0: void ParseCommandArguments() sl@0: // sl@0: // Parse command line. Put the parameters into global array gArgv for sl@0: // use by the tests, strip out flags starting with / or - and interpret sl@0: // them to set debug flags. sl@0: // sl@0: { sl@0: LOCAL_D TBuf<0x100> cmd; sl@0: User::CommandLine(cmd); sl@0: TLex lex(cmd); sl@0: TPtrC token=lex.NextToken(); sl@0: TFileName thisfile=RProcess().FileName(); sl@0: if (token.MatchF(thisfile)==0) sl@0: { sl@0: token.Set(lex.NextToken()); sl@0: } sl@0: // set up parameter list (offset zero is the filename) sl@0: gArgC = 0; sl@0: gArgV[gArgC++].Set(thisfile); sl@0: while (token.Length() != 0) sl@0: { sl@0: TChar ch = token[0]; sl@0: // strip out (and interpret) flags starting with - or / sl@0: if (ch == '-' || ch == '/') sl@0: { sl@0: for (TInt i = 1; i < token.Length(); i++) sl@0: { sl@0: switch (User::UpperCase(token[i])) sl@0: { sl@0: case 'D': sl@0: gDebugFlags |= KDLYFAST; sl@0: break; sl@0: case 'F': sl@0: gDebugFlags |= KFSYS; sl@0: break; sl@0: case 'I': sl@0: gDebugFlags |= KISO9660; sl@0: break; sl@0: case 'L': sl@0: gDebugFlags |= KFLDR; sl@0: break; sl@0: #ifdef __CONCURRENT_FILE_ACCESS__ sl@0: case 'M': sl@0: gDebugFlags |= KTHRD; sl@0: break; sl@0: #endif sl@0: case 'N': sl@0: gDebugFlags |= KNTFS; sl@0: break; sl@0: case 'S': sl@0: gDebugFlags |= KFSERV; sl@0: break; sl@0: case 'T': sl@0: gDebugFlags |= KLFFS; sl@0: break; sl@0: case 'Y': sl@0: gDebugFlags |= KDLYTRC; sl@0: break; sl@0: } sl@0: } sl@0: } sl@0: else sl@0: gArgV[gArgC++].Set(token); sl@0: token.Set(lex.NextToken()); sl@0: } sl@0: sl@0: // set up drive to test sl@0: gDriveToTest = 'C'; sl@0: if (gArgC > 1) sl@0: { sl@0: gDriveToTest = gArgV[1][0]; sl@0: gDriveToTest.UpperCase(); sl@0: } sl@0: } sl@0: sl@0: sl@0: GLDEF_C TInt E32Main() 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: sl@0: r=TheFs.Connect(); sl@0: test(r==KErrNone); sl@0: sl@0: ParseCommandArguments(); //need this for drive letter to test sl@0: sl@0: TheFs.SetAllocFailure(gAllocFailOn); sl@0: TTime timerC; sl@0: timerC.HomeTime(); sl@0: TFileName sessionp; sl@0: TheFs.SessionPath(sessionp); sl@0: sl@0: TBuf<30> privatedir; sl@0: privatedir = KPrivate; sl@0: sl@0: TUid thisUID = RProcess().Identity(); sl@0: privatedir.AppendFormat(_L("%08x"),thisUID.iUid); sl@0: privatedir.Append(_L("\\")); sl@0: sl@0: test(privatedir == sessionp.Mid(2,sessionp.Length()-2)); sl@0: sl@0: test.Printf(_L("sp=%S"),&sessionp); sl@0: sessionp[0]=(TText)gDriveToTest; sl@0: test.Printf(_L("sp1=%S"),&sessionp); sl@0: sl@0: TInt theDrive; sl@0: r=TheFs.CharToDrive(gDriveToTest,theDrive); sl@0: test(r==KErrNone); sl@0: sl@0: // set up debug register sl@0: test.Printf(_L("debug register = 0x%X"), gDebugFlags); sl@0: TheFs.SetDebugRegister(gDebugFlags); sl@0: sl@0: // actually do the tests! sl@0: DoTests(theDrive); sl@0: sl@0: // reset the debug register sl@0: TheFs.SetDebugRegister(0); sl@0: sl@0: TTime endTimeC; sl@0: endTimeC.HomeTime(); sl@0: TTimeIntervalSeconds timeTakenC; sl@0: r=endTimeC.SecondsFrom(timerC,timeTakenC); sl@0: test(r==KErrNone); sl@0: test.Printf(_L("Time taken for test = %d seconds\n"),timeTakenC); sl@0: TheFs.SetAllocFailure(gAllocFailOff); sl@0: TheFs.Close(); sl@0: test.End(); sl@0: test.Close(); sl@0: __UHEAP_MARKEND; sl@0: delete cleanup; sl@0: return(KErrNone); sl@0: }