sl@0: // Copyright (c) 1996-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\server\b_open.cpp sl@0: // sl@0: // sl@0: sl@0: #define __E32TEST_EXTENSION__ sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "t_server.h" sl@0: #include "t_chlffs.h" sl@0: sl@0: #ifdef __WINS__ sl@0: #define WIN32_LEAN_AND_MEAN sl@0: #pragma warning( disable : 4201 ) // nonstandard extension used : nameless struct/union sl@0: #include sl@0: #pragma warning( default : 4201 ) // nonstandard extension used : nameless struct/union sl@0: #endif sl@0: sl@0: GLDEF_D RTest test(_L("B_OPEN")); sl@0: sl@0: LOCAL_D const TInt KMaxFiles=200; sl@0: LOCAL_D TBuf<32> nameBuf[KMaxFiles]; sl@0: LOCAL_D TBuf<0x100> nameBuf1; sl@0: LOCAL_D RFile chan[KMaxFiles]; sl@0: LOCAL_D RFile chan1; sl@0: LOCAL_D TFileName fBuf; sl@0: LOCAL_D TVolumeInfo vInfo; sl@0: LOCAL_D TInt LeaveMemFree; sl@0: sl@0: LOCAL_C void testOpenFiles() sl@0: // sl@0: // Open files till memory is full sl@0: // Write, seek, read, seteof, close, check and delete all files. sl@0: // sl@0: { sl@0: sl@0: TChar currentDrive=gSessionPath[0]; sl@0: TInt driveNum; sl@0: TInt r=TheFs.CharToDrive(currentDrive,driveNum); sl@0: test_KErrNone(r); sl@0: sl@0: TInt i=0; sl@0: TInt totalRam; sl@0: FOREVER sl@0: { sl@0: sl@0: #if defined(__WINS__) sl@0: DWORD sectorsPerCluster; sl@0: DWORD bytesPerSector; sl@0: DWORD freeClusters; sl@0: DWORD sizeClusters; sl@0: BOOL b=GetDiskFreeSpaceA("C:\\",§orsPerCluster,&bytesPerSector,&freeClusters,&sizeClusters); sl@0: test(b==TRUE); sl@0: totalRam=sizeClusters*sectorsPerCluster*bytesPerSector; sl@0: #else sl@0: TMemoryInfoV1Buf memInfoBuf; sl@0: UserHal::MemoryInfo(memInfoBuf); sl@0: totalRam=memInfoBuf().iTotalRamInBytes; sl@0: #endif sl@0: test.Printf(_L("Open %u\n"),i); sl@0: nameBuf[i].Format(_L("B_OPEN test file %d"),i); sl@0: r=chan[i].Replace(TheFs,nameBuf[i],EFileStream|EFileWrite); sl@0: if (r==KErrNone) sl@0: { sl@0: r=chan[i].Write(_L8("SomeText")); sl@0: if ((gDriveCacheFlags & EFileCacheWriteOn) && (r == KErrNone)) sl@0: r = chan[i].Flush(); sl@0: if (r==KErrDiskFull) sl@0: { sl@0: chan[i].Close(); sl@0: test(TheFs.Delete(nameBuf[i])==KErrNone); sl@0: } sl@0: } sl@0: if (r==KErrDiskFull) sl@0: break; sl@0: if (r==KErrNoMemory) sl@0: break; sl@0: if (r!=KErrNone) sl@0: { sl@0: test.Printf(_L("ERROR: RFile::Replace returned %d\n"),r); sl@0: test(EFalse); sl@0: } sl@0: sl@0: r=TheFs.Volume(vInfo); sl@0: test_KErrNone(r); sl@0: if (driveNum==EDriveC) sl@0: test.Printf(_L("VInfo size=0x%x free=0x%x TotalRam = 0x%x\n"),vInfo.iSize,vInfo.iFree,totalRam); sl@0: test(vInfo.iFree<=vInfo.iSize); sl@0: sl@0: // r=TheFs.Volume(vInfo,(driveNum==EDriveC) ? EDriveD : EDriveC); sl@0: // if (r==KErrNone); sl@0: // test(vInfo.iFree<=vInfo.iSize); sl@0: i++; sl@0: if (i==KMaxFiles) sl@0: { sl@0: if (IsTestingLFFS()) sl@0: break; sl@0: else sl@0: test.Panic(_L("Too many files opened")); sl@0: } sl@0: } sl@0: sl@0: test.Printf(_L("Created %d extra files\n"),i); sl@0: const TInt n_files=i; sl@0: r=TheFs.Volume(vInfo); sl@0: test_KErrNone(r); sl@0: if (driveNum==EDriveC && (vInfo.iDrive.iMediaAtt & KMediaAttVariableSize)) sl@0: { sl@0: test(vInfo.iSize<=totalRam); sl@0: test(vInfo.iFree<=totalRam); sl@0: } sl@0: test(vInfo.iFree<=vInfo.iSize); sl@0: sl@0: test.Next(_L("SetSize to each file")); sl@0: for (i=0;i numBuf; sl@0: for (i=0;i checkBuf; sl@0: for (i=0;iLeaveMemFree) sl@0: size=vInfo.iFree-LeaveMemFree; sl@0: else sl@0: size=0; sl@0: sl@0: const TInt KMaxFileSize = 0x40000000; sl@0: sl@0: // test as 64 bit numbers in case size is very large (eg. enough that TInt is sl@0: // not large enough to hold it) sl@0: TInt64 KMaxFileSize64 = MAKE_TINT64(0, KMaxFileSize); sl@0: sl@0: test.Printf(_L("Free space available = %08x:%08x\n"), I64HIGH(size), I64LOW(size)); sl@0: if (size > KMaxFileSize64) sl@0: { sl@0: size = KMaxFileSize; sl@0: test.Printf(_L("Truncated to %d to avoid current FAT FSY file size limit !!!\n"), size); sl@0: fileSizeTruncated = ETrue; sl@0: } sl@0: sl@0: TFileName sessionPath; sl@0: TheFs.SessionPath(sessionPath); sl@0: TBuf<32> message=_L("?: has %ld bytes free\n"); sl@0: message[0]=sessionPath[0]; sl@0: test.Printf(message,vInfo.iFree); sl@0: if (((vInfo.iDrive.iMediaAtt)&KMediaAttVariableSize)==0) sl@0: { sl@0: // Not a variable sized drive, so should be safe to to just create big file sl@0: test.Printf(_L("Creating %S, 0x%08lx\n"),&nameBuf1,size); sl@0: r=chan1.SetSize((TUint)size); sl@0: } sl@0: else sl@0: { sl@0: // Variable sized drive (proabably RAM drive) needs a bit of special treatment sl@0: // Use a binary search to allocate largest sized file possible... sl@0: test.Printf(_L("Creating %S, 0x%08x\n"),&nameBuf1,size); sl@0: TInt lo = 0; sl@0: TInt hi = (TInt)size; sl@0: const TInt KSizeGranularity = 0x200; // must be power-of-2 sl@0: while(hi-lo>KSizeGranularity && r==KErrNone) sl@0: { sl@0: TInt trySize = (lo+hi)/2; sl@0: trySize &= ~(KSizeGranularity-1); sl@0: r = chan1.SetSize((TUint)trySize); sl@0: if(r==KErrNone) sl@0: { sl@0: size = trySize; sl@0: lo = trySize; sl@0: } sl@0: else if(r==KErrDiskFull) sl@0: { sl@0: hi = trySize; sl@0: r = KErrNone; sl@0: } sl@0: } sl@0: if(r==KErrNone) sl@0: { sl@0: // reduce size to leave some free for tests... sl@0: LeaveMemFree = 4096*4; // best leave several RAM pages worth of space so rest of test has some memory sl@0: size -= LeaveMemFree; sl@0: r = chan1.SetSize((TUint)size); sl@0: } sl@0: } sl@0: sl@0: if (r!=KErrNone) sl@0: { sl@0: test.Printf(_L("ERROR: Creating large file failed %d\n"),r); sl@0: test(EFalse); sl@0: } sl@0: test.Printf(_L("Created %S, 0x%08x\n"),&nameBuf1,size); sl@0: chan1.Close(); sl@0: } sl@0: while (fileSizeTruncated); sl@0: sl@0: } sl@0: sl@0: LOCAL_C void Cleanup() sl@0: // sl@0: // Cleanup test files sl@0: // sl@0: { sl@0: sl@0: TInt r=TheFs.Delete(nameBuf1); sl@0: test_KErrNone(r); sl@0: r=TheFs.RmDir(gSessionPath); sl@0: test_KErrNone(r); sl@0: } sl@0: sl@0: sl@0: GLDEF_C void CallTestsL() sl@0: // sl@0: // Call tests that may leave sl@0: // sl@0: { sl@0: sl@0: #ifdef __WINS__ sl@0: // These tests try to create a huge file to fill up the drive. sl@0: // This fails on WINS with drives with > 1/2G free because sl@0: // RFile::SetSize() (among other things) only takes a TInt. sl@0: // sl@0: if (gSessionPath.Left(1).CompareF(_L("C")) == 0) sl@0: return; sl@0: #endif sl@0: CreateTestDirectory(_L("\\B_OPEN\\")); sl@0: InitTest(); sl@0: testOpenFiles(); sl@0: Cleanup(); sl@0: } sl@0: