EXPORT_C TInt CTestConfig::ResolveFile(RFs& aFs, const TDesC& aComponent, const TDesC& aFileName, TParse& aParseOut) { TFileName* savedPath = new TFileName; TFileName* fileName = new TFileName; if ((savedPath == NULL) || (fileName == NULL)) { delete savedPath; delete fileName; return KErrNoMemory; } fileName->Append(KScriptPathSep); // fileName->Append(KSmsTestFileInputBase); // fileName->Append(KScriptPathSep); fileName->Append(aComponent); fileName->Append(KScriptPathSep); fileName->Append(aFileName); // file finder will look in the session drive first, then Y->A,Z // so set session drive to Y (save old and restore it afterwards) aFs.SessionPath(*savedPath); _LIT(KTopDrive,"Y:\\"); aFs.SetSessionPath(KTopDrive); TFindFile file_finder(aFs); TInt err = file_finder.FindByDir(*fileName,KNullDesC); if(err==KErrNone) aParseOut.Set(file_finder.File(),NULL,NULL); aFs.SetSessionPath(*savedPath); delete savedPath; delete fileName; return(err); }
// // Prepare the test directory. // static void SetupTestDirectory() { TInt r=TheFsSession.MkDir(KTestDir); TEST(r==KErrNone || r==KErrAlreadyExists); r=TheFsSession.SetSessionPath(KTestDir); TEST2(r,KErrNone); }
void CHttpCacheManager::CrashCheckL( const TInt& aSecIdInt ) { if( aSecIdInt == KUIDBROWSERNG ) { ////////////////////////////////////////////////////////////////////////////////////////////////////// // Remove orphan files if browser didn't close cache properly - should only happen very occasionally // // We leave a file on the drive when we are in use and remove it when we close properly // If the file is already there we expect files in the cache which have not been added to the index. // ////////////////////////////////////////////////////////////////////////////////////////////////////// RFs rfs; User::LeaveIfError( rfs.Connect() ); CleanupClosePushL( rfs ); rfs.SetSessionPath( iCacheFolder ); RFile crashTest; TInt err = crashTest.Create(rfs,KCrashCheck(),EFileRead); crashTest.Close(); if ( err == KErrAlreadyExists ) { #ifdef __CACHELOG__ HttpCacheUtil::WriteLog(0, _L("Crash detected - removing orphan files")); #endif RemoveOrphanedFilesL(); } CleanupStack::PopAndDestroy( &rfs ); } }
// ----------------------------------------------------------------------------- // Destructor // ----------------------------------------------------------------------------- CHttpCacheManager::~CHttpCacheManager() { #ifdef __CACHELOG__ HttpCacheUtil::WriteLog( 0, _L("-----------------------------------------")); HttpCacheUtil::WriteLog( 0, _L("| Destroying CHttpCacheManager Instance | "), (TInt)this); HttpCacheUtil::WriteLog( 0, _L("-----------------------------------------")); #endif if( IsBrowser() ) // only enabled in browser { // delete crashcheck.dat file RFs rfs; rfs.Connect(); rfs.SetSessionPath( iCacheFolder ); rfs.Delete(KCrashCheck()); rfs.Close(); } delete iOfflineNotifyHandler; delete iOfflineRepository; delete iCache; delete iOperatorCache; delete iOpDomain; delete iphoneSpecificCache; delete iVSSWhiteList; delete iFileWriteHandler; }
/** Delete a big file, in a different thread @return ETrue */ TInt DeleteBigFile(TAny* ) { RTest test(_L("T_FSCHED")); RFs fs; TInt r = fs.Connect(); TESTERROR(r); r = fs.SetSessionPath(gSessionPath); TESTERROR(r); gSync.Wait(); r = fs.Delete(gBigFile); #if defined(__WINS__) TEST(r == KErrInUse || r == KErrNone); #else test_Equal(KErrInUse, r); #endif client.Signal(); fs.Close(); test.Close(); return ETrue; }
// Tests the contents of a file void CTestContactsPBAPExportContents::TestContentsL() { // Tests that when a leave occurs, the exported file doesn't contain any data RFs fsSession; TInt returnVal; RFile file; TBuf8<20> buf; User::LeaveIfError(fsSession.Connect()); CleanupClosePushL(fsSession); TFindFile findFile(fsSession); fsSession.SetSessionPath(KPath); returnVal = findFile.FindByDir(KExportLeaveFile, KPath); if(returnVal == KErrNone) { User::LeaveIfError(file.Open(fsSession, KExportLeaveFile, EFileWrite)); file.Read(buf); // test that the exported file has no content if(buf.Length() == 0) { SetTestStepResult(EPass); } else { SetTestStepResult(EFail); } } else { SetTestStepResult(EFail); } file.Close(); CleanupStack::PopAndDestroy(&fsSession); }
void CSuspendTest::CreateL() { // // Create the eraser thread // iEraser = new(ELeave) CEraser; iEraser->CreateL(); // // Load the device drivers // TInt r; #ifndef SKIP_PDD_LOAD test.Printf( _L("Loading %S\n"), &KLfsDriverName ); r = User::LoadPhysicalDevice( KLfsDriverName ); test( KErrNone == r || KErrAlreadyExists == r ); #endif #ifdef UNMOUNT_DRIVE RFs fs; test( KErrNone == fs.Connect() ); test( KErrNone == fs.SetSessionPath( _L("Z:\\") ) ); TFullName name; fs.FileSystemName( name, KLffsLogicalDriveNumber ); if( name.Length() > 0 ) { test.Printf( _L("Unmounting drive") ); test( KErrNone == fs.DismountFileSystem( _L("Lffs"), KLffsLogicalDriveNumber) ); User::After( 2000000 ); test.Printf( _L("Drive unmounted") ); } fs.Close(); #endif // // Open a TBusLogicalDevice to it // test.Printf( _L("Opening media channel\n") ); TBool changedFlag = EFalse; r = iDrive.Connect( KDriveNumber, changedFlag ); User::LeaveIfError( r ); iDriveOpened = ETrue; // // Get size of Flash drive, block size, block count // TLocalDriveCapsV2Buf info; iDrive.Caps(info); iFlashSize = I64LOW(info().iSize); iBlockSize = info().iEraseBlockSize; iBlockCount = iFlashSize / iBlockSize; test.Printf( _L("Flash size is 0x%x bytes\n"), iFlashSize ); test.Printf( _L("Block size is 0x%x bytes\n"), iBlockSize ); test.Printf( _L("Block count is %d\n"), iBlockCount ); test.Printf( _L("CreateL complete\n") ); }
LOCAL_C TInt MakeFileName(TInt aThreadId, TInt aFileNumber, RFs & aFs, TFileName& aName, TBool aMakeDir) // // creates a file name and makes all the directory components, if required // { TFileName path; path.Format(KPath, aThreadId); TChar driveLetter; TInt r; r = aFs.DriveToChar(gDriveNumber, driveLetter); if (r != KErrNone) { LogError(r, KDriveToChar, KNullDesC, driveLetter, 0); aFs.Close(); return(r); } path[0] = (TText) driveLetter; r = aFs.SetSessionPath(path); if (r != KErrNone) { LogError(r, KSetSessPath, path, 0, 0); aFs.Close(); return(r); } // add additional directories TInt fileNumber; fileNumber = aFileNumber; r = AppendPath(path, fileNumber, 0); if(r != KErrNone) { LogError(r, KAppendPath, path, fileNumber, 0); aFs.Close(); return(r); } if(aMakeDir) { r = aFs.MkDirAll(path); if (r != KErrNone && r != KErrAlreadyExists) { LogError(r, KMdAll, path, 0, 0); aFs.Close(); return(r); } } // and finally add file name path.Append(KFilePrefix); path.AppendNum(aFileNumber); aName = path; return(KErrNone); }
void CSigComp::ConstructL(TMemorySize aDecompressionMemSize, TCyclesPerBit aCyclesPerBit, TMemorySize aStateMemorySize, const TDesC8& aAlgorithm, const TSigCompStateItem& aStateItem, TBool aUploadState) { ConstructL(aDecompressionMemSize, aCyclesPerBit, aStateMemorySize, aUploadState); RFs rfs; User::LeaveIfError(rfs.Connect()); CleanupClosePushL(rfs); #if !defined(__WINS__) && !defined(__WINSCW__) TParsePtrC parser(RProcess().FileName()); User::LeaveIfError(rfs.SetSessionPath(parser.Drive())); #endif TInt stateLen = 0; RFile file; User::LeaveIfError(file.Open(rfs, aStateItem.iStateValue, EFileRead)); CleanupClosePushL(file); file.Size(stateLen); HBufC8* valueBuf = HBufC8::NewL(stateLen); TPtr8 valueBufDes = valueBuf->Des(); file.Read(valueBufDes, stateLen); CleanupStack::PopAndDestroy(2); // file, rfs CleanupStack::PushL(valueBuf); TStateItem* stateItem = iStateMgr->CreateStateL(NULL, (TInt16)stateLen, aStateItem.iStateAddress, aStateItem.iStateInstruction, aStateItem.iMinimumAccessLength, valueBuf->Ptr(), 0xffff); if (aStateItem.iStateIdentifier.Size() > 0) { if (aStateItem.iStateIdentifier.Compare(TPtrC8( stateItem->iStateIdentifier, 20))) { User::Leave(KErrNotFound); } } iCompressor = CSigCompCompressor::NewL(aAlgorithm, iStateMgr, stateItem, aStateItem.iStateLength, aUploadState); CleanupStack::PopAndDestroy(valueBuf); }
TInt PosixFilesystem::SetDefaultDir (RFs& aFs) { TParse parse; parse.Set(RProcess().FileName(), NULL, NULL); #ifdef __SECURE_DATA__ return aFs.SetSessionToPrivate(TDriveUnit(parse.Drive())); #else return aFs.SetSessionPath(parse.DriveAndPath()); #endif }
// Prepare the test directory. LOCAL_C void setupTestDirectory() { TInt err=TheFs.Connect(); TEST2(err, KErrNone); TPtrC testDir=_L("\\STOR-TST\\"); err=TheFs.MkDir(testDir); TEST(err == KErrNone || err == KErrAlreadyExists); err=TheFs.SetSessionPath(testDir); TEST2(err, KErrNone); }
void TestWriteOrder() { RFs fs; TInt r = fs.Connect(); TESTERROR(r); r = fs.SetSessionPath(gSessionPath); TESTERROR(r); WriteOrderTest(TheFs, gBigFileSize, KBlockSize); fs.Close(); }
void CreateTestDirectory(const TDesC& aSessionPath) // // Create directory for test // { TParsePtrC path(aSessionPath); test(path.DrivePresent()==EFalse); TInt r=TheFs.SetSessionPath(aSessionPath); test_KErrNone(r); r=TheFs.SessionPath(gSessionPath); test_KErrNone(r); r=TheFs.MkDirAll(gSessionPath); test_Value(r, r == KErrNone || r==KErrAlreadyExists); }
/** Reads a small file while writing a big one */ void TestDeletionWhileWriting() { TInt r = 0; // Sync test TBuf<20> buf = _L("Big Write V"); r = gBig.Create(buf, WriteBigFile, KDefaultStackSize, KHeapSize, KMaxHeapSize, NULL); TEST(r == KErrNone); buf = _L("Deletion"); r = gSmall.Create(buf, DeleteBigFile, KDefaultStackSize, KHeapSize, KMaxHeapSize, NULL); TEST(r == KErrNone); gSmall.Resume(); gBig.Resume(); CLIENTWAIT(); CLIENTWAIT(); gBig.Close(); gSmall.Close(); test.Printf(_L("The file was properly blocked when writing sync, not deleted\n")); // Async test TRequestStatus status[KWaitRequestsTableSize]; RFile bigFile; RFs fs; r = fs.Connect(); TESTERROR(r); r = fs.SetSessionPath(gSessionPath); TESTERROR(r); WriteFileAsync(TheFs, bigFile, gBigFile, gBigFileSize, KBigBlockSize, status); r = fs.Delete(gBigFile); TEST(r == KErrInUse); WaitForAll(status, gBigFileSize, KBigBlockSize); bigFile.Close(); fs.Close(); test.Printf(_L("The file was properly blocked when writing async, not deleted\n")); }
EXPORT_C void CTestUtils::CopyToSimTsyConfigFileL(RFs& aFs, const TDesC& aFilename) { _LIT(KFileName,"config.txt"); TChar driveChar=RFs::GetSystemDriveChar(); TBuf<2> systemDrive; systemDrive.Append(driveChar); systemDrive.Append(KDriveDelimiter); aFs.SetSessionPath(systemDrive); aFs.Delete(KFileName); //< Ignore Error CFileMan* fileMan = CFileMan::NewL(aFs); CleanupStack::PushL(fileMan); User::LeaveIfError(fileMan->Copy(aFilename, KFileName)); CleanupStack::PopAndDestroy(fileMan); }
/** Find entry in directory */ LOCAL_C TInt FindEntryAccess2(TAny*) { RFs fs; TInt r = fs.Connect(); RTest test(_L("test 2")); fs.SetSessionPath(gSessionPath); client.Signal(); FOREVER { TEntry entry; r = fs.Entry(gFindEntryDir2, entry); FailIfError(r); r = fs.Entry(gFindDir2,entry); FailIfError(r); } }
int PosixFilesystem::chdir (RFs& aFs, const wchar_t* aPath, int& anErrno) { TParse name; TInt err=GetFullPath(name, (const TText16 *)aPath, aFs, NULL); if (!err) { TPtrC path=name.DriveAndPath(); TUint att=0; if (path.Length()==3) // Problem in F32 - the root directory has no attributes att=KEntryAttDir; else err=aFs.Att(path, att); if (!err) if (att&KEntryAttDir) err=aFs.SetSessionPath(path); else err=ENOTDIR; } return MapError(err,anErrno); }
/** Write big file after a signalling thread has been scheduled, in a different thread @return ETrue */ TInt WriteBigFile2(TAny* ) { RTest test(_L("T_FSCHED")); RFs fs; TInt r=fs.Connect(); TESTERROR(r); r = fs.SetSessionPath(gSessionPath); TESTERROR(r); WriteFile(fs, gSmallFile, gBigFileSize, KBigBlockSize, EThreadWait); gTestTimer.Stop(); client.Signal(); fs.Close(); test.Close(); return ETrue; }
/** Write a big file async, in a different thread @return ETrue */ TInt WriteBigFileAsync(TAny* ) { RTest test(_L("T_FSCHED")); RFs fs; TInt r = fs.Connect(); TESTERROR(r); r=fs.SetSessionPath(gSessionPath); TESTERROR(r); RFile bigFile; WriteFileAsync(fs, bigFile, gSmallFile, gBigFileSize, KBlockSize,gStatus); gSync.Signal(); WaitForAll(gStatus, gBigFileSize, KBlockSize); fs.Close(); test.Close(); return ETrue; }
/** Delete entry in directory */ LOCAL_C TInt DeleteEntryAccess2(TAny* ) { RFs fs; TInt r = fs.Connect(); TBuf<100> dirfile; TBuf<50> filename; RFile file; RTest test(_L("test 2")); fs.SetSessionPath(gSessionPath); filename.Format(KDeleteMe2, gT2); dirfile = gDelEntryDir2; dirfile.Append(filename); client.Signal(); FOREVER { if(!gKillMe) { r = file.Create(fs, dirfile, EFileShareAny|EFileWrite); if(r == KErrAlreadyExists) r=file.Open(fs, dirfile, EFileShareAny|EFileWrite); file.Close(); FailIfError(r); r = fs.Delete(dirfile); if((r != KErrNone) && (r != KErrInUse)) { test.Printf(_L("error = %d\n"), r); } test(r == KErrNone || r == KErrInUse); } } }
TInt E32Main() { TInt r; test.Title(); test.Start(_L("Starting T_DENYCLAMP ...")); test(TheFs.Connect()==KErrNone); GetDriveLetters(); TBuf<256> pathName; //************************************************************************ // // Test on FAT (writable file system) // //************************************************************************ if(NandFatDrv!='?') { pathName=_L("?:\\CLAMP-TST\\"); // FAT on NAND pathName[0]=(TText)NandFatDrv; r=TheFs.MkDirAll(pathName); test(r==KErrNone || r== KErrAlreadyExists); TheFs.SetSessionPath(pathName); test.Printf( _L("T_DENYCLAMP: testing FAT drive on %C\n"),(TText)NandFatDrv); Test1(); // Basic clamp operation Test2(); // Invalid clamp requests // Test3(pathName);// Denied FS requests when files are clamped - invalid for T_DENYCLAMP r=TheFs.RmDir(pathName); test(r==KErrNone); } else test.Printf( _L("T_DENYCLAMP: FAT drive not tested\n")); //************************************************************************ // // Test on ROFS (non-writable file system) // //************************************************************************ if(RofsDrv!='?') { pathName=_L("?:\\"); pathName[0]=(TText)RofsDrv; TheFs.SetSessionPath(pathName); test.Printf( _L("T_DENYCLAMP: testing ROFS drive on %C\n"),(TText)RofsDrv); Test4(pathName); // Clamp tests for non-writable file system } else test.Printf( _L("T_DENYCLAMP: ROFS drive not tested\n")); //************************************************************************ // // Test on Z: - Composite File System, or ROMFS (non-writable file system) // //************************************************************************ if(CompDrv!='?') { pathName=_L("?:\\TEST\\"); pathName[0]=(TText)CompDrv; TheFs.SetSessionPath(pathName); test.Printf( _L("T_DENYCLAMP: testing Z drive (on %C)\n"),(TText)CompDrv); Test4(pathName); // Clamp tests for non-writable file system } else test.Printf( _L("T_DENYCLAMP: Z drive not tested\n")); //************************************************************************ // // Test on LFFS (non-clampable file system) // //************************************************************************ if(LffsDrv!='?') { TBuf<256> unsuppPath; unsuppPath=_L("?:\\CLAMP-TST\\"); unsuppPath[0]=(TText)LffsDrv; r=TheFs.MkDirAll(unsuppPath); test(r==KErrNone || r== KErrAlreadyExists); TheFs.SetSessionPath(unsuppPath); test.Printf( _L("T_DENYCLAMP: testing LFFS drive on %C\n"),(TText)LffsDrv); Test5(); // Clamp requests on non-clamping file systems } else test.Printf( _L("T_DENYCLAMP: LFFS drive not tested\n")); test.End(); return 0; }
LOCAL_C TInt testAsyncAccess(TAny* aData) // /// Test read file handling. /// /// @param aData pointer to the thread data area { TThreadData& data = *(TThreadData*)aData; TFileName fileName = data.iFile; TBool dowrite = (data.iData != NULL); TBuf8<KBufLen>* buffer = gBufferArr[data.iNum]; TRequestStatus* status = gStatusArr[data.iNum]; RFs myFs; TInt r = myFs.Connect(); TEST(r==KErrNone); r = myFs.SetSessionPath(gSessionPath); if (r != KErrNone) TTest::Fail(HERE, _L("SetSessionPath returned %d"), r); TVolumeInfo vol; TInt drv; r = myFs.CharToDrive(fileName[0], drv); if (r != KErrNone) TTest::Fail(HERE, _L("CharToDrive(%c) returned %d"), fileName[0], r); r = myFs.Volume(vol, drv); if (r != KErrNone) TTest::Fail(HERE, _L("Volume() returned %d"), r); TInt64 maxwrite = vol.iFree / 2 - KBufLen; if (maxwrite < KBufLen*2) TTest::Fail(HERE, _L("Not enough space to do test, only %d KB available"), TInt(vol.iFree/1024)); RFile f; RTimer timer; TRequestStatus tstat; TTime startTime; TTime endTime; TTimeIntervalMicroSeconds timeTaken; TInt wrnum = 0; TInt rdnum = 0; TInt opnum = 0; TInt opfin = 0; TInt i; timer.CreateLocal(); if (dowrite) { r = f.Replace(myFs, fileName, EFileStreamText | EFileWrite); TEST(r==KErrNone); // wait for both tasks to have a chance to complete opening the files User::After(1000); for (i = 0; i < KNumBuf; i++) buffer[i].Fill('_', KBufLen); timer.After(tstat, KTimeBM * KSecond); startTime.HomeTime(); while (tstat == KRequestPending) { TInt pos = TInt((wrnum * KBufLen) % maxwrite); TInt bnum = opnum++ % KNumBuf; f.Write(pos, buffer[bnum], status[bnum]); if (opnum - opfin > KMaxLag) { while (status[opfin % KNumBuf] == KRequestPending) User::WaitForRequest(status[opfin % KNumBuf]); opfin++; } ++wrnum; } while (opfin < opnum) { while (status[opfin % KNumBuf] == KRequestPending) User::WaitForRequest(status[opfin % KNumBuf]); opfin++; } endTime.HomeTime(); TTimeIntervalMicroSeconds timeTaken=endTime.MicroSecondsFrom(startTime); TInt64 dtime = timeTaken.Int64(); TInt64 dsize = wrnum * KBufLen * TInt64(KSecond); TInt32 speed = TInt32((dsize + dtime/2) / dtime); AddStats(gWrStats, dsize, dtime); TTest::Printf(_L("%8d writes in %6d mS = %8d bytes per second\n"), wrnum, TInt32(dtime)/1000, speed); } else { r = f.Open(myFs, fileName, EFileStreamText); TEST(r==KErrNone); timer.After(tstat, KTimeBM * KSecond); startTime.HomeTime(); while (tstat == KRequestPending) { TInt pos = TInt((rdnum * KBufLen) % maxwrite); TInt bnum = opnum++ % KNumBuf; f.Read(pos, buffer[bnum], status[bnum]); if (opnum - opfin > KMaxLag) { User::WaitForRequest(status[opfin++ % KNumBuf]); } ++rdnum; } while (opfin < opnum) { if (status[opfin % KNumBuf] == KRequestPending) User::WaitForRequest(status[opfin % KNumBuf]); opfin++; } endTime.HomeTime(); timeTaken=endTime.MicroSecondsFrom(startTime); TInt64 dtime = timeTaken.Int64(); TInt64 dsize = rdnum * KBufLen * TInt64(KSecond); TInt32 speed = TInt32((dsize + dtime/2) / dtime); AddStats(gRdStats, dsize, dtime); // wait to allow the dust to settle User::After(KSecond); TTest::Printf(_L("%8d reads in %6d mS = %8d bytes per second\n"), rdnum, TInt32(dtime)/1000, speed); myFs.Delete(fileName); } timer.Cancel(); timer.Close(); f.Close(); myFs.Close(); return r; }
// Member for thread function TInt CSMPSoakThread::DoSMPStressDeviceThread() { RTest test(_L("SMPStressDeviceThread")); test.Start(_L("SMPStressDeviceThread")); RTimer timer; RFs session; TFileName sessionPath; test_KErrNone(timer.CreateLocal()); TRequestStatus s; TDesC** ptrDevices = (TDesC**) (iThreadData.listPtr); PRINT ((_L("Devices Number %d [%s]\n"), ptrDevices[0]->Length(), ptrDevices[0]->Ptr())); for (TInt i = 1; ptrDevices[i] ; i++) PRINT ((_L("LDD%d=%s "),i,ptrDevices[i]->Ptr())); PRINT (_L("\n")); FOREVER { for (TInt i = 0; i < ptrDevices[0]->Length(); i++) { TText driveLetter = (*ptrDevices[0])[i]; PRINT ((_L("Device %c\n"),driveLetter)); test_KErrNone(session.Connect()); sessionPath=(_L("?:\\SESSION_TEST\\")); sessionPath[0]=driveLetter; test_KErrNone(session.SetSessionPath(sessionPath)); TInt driveNumber; test_KErrNone(session.CharToDrive(driveLetter, driveNumber)); TBuf<64> fileSystemName; test_KErrNone(session.FileSystemName(fileSystemName,driveNumber)); PRINT ((_L("File System Name %s\n"),fileSystemName.PtrZ())); TDriveInfo driveInfo; test_KErrNone(session.Drive(driveInfo, driveNumber)); TVolumeInfo volumeInfo; test_KErrNone(session.Volume(volumeInfo, driveNumber)); session.Close(); } for (TInt i = 1; ptrDevices[i] ; i += 2) { RDevice device; TInt r = User::LoadLogicalDevice(*ptrDevices[i]); if (r != KErrNone && r != KErrAlreadyExists) { test.Printf(_L("LDD %S not present\n"), ptrDevices[i]); continue; } test_KErrNone(device.Open(*ptrDevices[i+1])); TBuf8<64> deviceCaps; device.GetCaps(deviceCaps); TVersion deviceVersion; device.QueryVersionSupported(deviceVersion); device.Close(); } SetThreadPriority(); timer.After(s, iThreadData.delayTime*1000); User::WaitForRequest(s); test (s == KErrNone); if (gAbort) break; User::After(gPeriod); } timer.Close(); PRINT((_L("SMPStressDeviceThread MyTimer.Cancel() called\n"))); test.End(); test.Close(); return 0x00; }