kerneltest/f32test/demandpaging/t_fragmentdp.cpp
changeset 0 a41df078684a
child 6 0173bcd7697c
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 // Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of the License "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // f32test\demandpaging\t_fragment.cpp
       
    15 // This test exercises the fragmentation of write requests carried out 
       
    16 // by the Local Media subsystem, when the request is for a partition 
       
    17 // driven by a Media driver that supports paging.
       
    18 // 002 Check if LFFS drive (Mount LFFS if required)
       
    19 // 003 Testing Fragmentation of writes to writable drives in paging media
       
    20 // 004 Testing concurrent Fragmentation of writes on the same media
       
    21 // 005 Check Disk
       
    22 // 
       
    23 //
       
    24 
       
    25 //! @SYMTestCaseID			KBASE-T_FRAGMENTDP-0333
       
    26 //! @SYMTestType			UT
       
    27 //! @SYMPREQ				PREQ1110
       
    28 //! @SYMTestCaseDesc		Demand Paging Page cache fragmentation tests.
       
    29 //! @SYMTestActions			001 Starting tests...
       
    30 //! @SYMTestExpectedResults All tests should pass.
       
    31 //! @SYMTestPriority        High
       
    32 //! @SYMTestStatus          Implemented
       
    33 
       
    34 #include <f32file.h>
       
    35 #include <e32test.h>
       
    36 #include "t_server.h"
       
    37 #include <u32hal.h>
       
    38 #include <e32rom.h>
       
    39 #include <f32dbg.h>
       
    40 #include "testdefs.h"
       
    41 
       
    42 #ifdef __VC32__
       
    43     // Solve compilation problem caused by non-English locale
       
    44     #pragma setlocale("english")
       
    45 #endif
       
    46 
       
    47 const TInt KMuliplySize=10;
       
    48 const TInt KFileSizeInBytes=302498;
       
    49 
       
    50 LOCAL_D TBuf8<KMuliplySize*KFileSizeInBytes> Buffer;
       
    51 LOCAL_D RSemaphore WriteSemaphore;
       
    52 
       
    53 GLDEF_D RTest test(_L("T_FRAGMENTDP"));
       
    54 
       
    55 void DoTestF(TInt aDrvNum, TBool aNand);	// may want to do something weird on NAND later (e.g. trigger Garbage Collection)
       
    56 void DoTestC(TInt aDrvNum, TInt aNotherDrvNum, TBool aNand);	// may want to do something weird on NAND later (e.g. trigger Garbage Collection)
       
    57 TInt CreateEmptyFile(RFs& aFs, const TDesC& aFileName, TUint aFileSize);
       
    58 TInt GetLocDrvNumber(TInt aDrvNo);
       
    59 
       
    60 /*
       
    61   This plain looking test exercises the fragmentation of write requests carried out by the Local
       
    62   Media subsystem, when the request is for a partition driven by a Media driver that supports
       
    63   paging.
       
    64   It indirectly tests that the ELOCD fragmentation and EKERN locking mechanisms work as specified 
       
    65   to prevent deadlocks. It also causes an awful lot of paging activity.
       
    66 */
       
    67 
       
    68 LOCAL_C TBool TestSimpleFragmentation()
       
    69 //
       
    70 // Find ROM address of file and write from it to another file in writable partition in the same media as the backing store for ROM
       
    71 //
       
    72 
       
    73 	{
       
    74 	TDriveInfo driveInfo;
       
    75 	TBool tested=EFalse;
       
    76 
       
    77 	TFileName path;
       
    78 	TInt r=TheFs.SessionPath(path);
       
    79 	test(r==KErrNone);
       
    80 	TInt drv;
       
    81 	r=RFs::CharToDrive(path[0],drv);
       
    82 	test(r==KErrNone);
       
    83 
       
    84     test(TheFs.Drive(driveInfo, drv) == KErrNone);
       
    85 
       
    86 	//-- select a suitable drive for the testing. It shall be a writable drive on a media that services paging
       
    87 	if(driveInfo.iMediaAtt&KMediaAttPageable)
       
    88 		{
       
    89 		TBool readOnly = driveInfo.iMediaAtt & KMediaAttWriteProtected;		// skip ROFS partitions
       
    90 		if(!readOnly)
       
    91 			{
       
    92 			DoTestF(drv, (driveInfo.iType==EMediaNANDFlash)?(TBool)ETrue:(TBool)EFalse);
       
    93 			tested=ETrue;
       
    94 			}
       
    95 		}
       
    96 	if(!tested)
       
    97 		test.Printf(_L("Skipped T_FRAGMENTDP on drive %c\n"), path[0]);
       
    98 	return tested;
       
    99 	}
       
   100 
       
   101 
       
   102 void DoTestF(TInt aDrvNum, TBool aNand)
       
   103 	{
       
   104 	TInt pos=0;
       
   105 	TInt size, size1;
       
   106 	TInt r;
       
   107 	TFileName fileName;
       
   108 
       
   109 	test.Next(_L("Testing Fragmentation of writes to writable drives in paging media"));
       
   110 	if(aNand)
       
   111 		test.Printf(_L("Testing on NAND\n"));
       
   112 
       
   113     fileName.Format(_L("Testing drive %c:\n"), 'A'+aDrvNum);
       
   114     test.Printf(fileName);
       
   115 
       
   116 	_LIT(KTPagedCpp, "Z:\\test\\TEST_PAGED.cpp");
       
   117 	_LIT(KTUnpagedCpp, "Z:\\test\\TEST_UNPAGED.CPP");
       
   118 
       
   119 	if(TheFs.IsFileInRom(KTPagedCpp) != NULL && TheFs.IsFileInRom(KTUnpagedCpp) != NULL)	// .oby must include these files
       
   120 		{
       
   121 		RFile f;
       
   122 		r=f.Open(TheFs,KTUnpagedCpp,EFileStream);
       
   123 		test(r==KErrNone);
       
   124 		r=f.Seek(ESeekAddress,pos);
       
   125 		test(r==KErrNone);
       
   126 		TText8* ptrPos=*(TText8**)&pos;			// start address of unpaged file in ROM
       
   127 		test.Printf(_L("Start address of section to copy 0x%x\n"), ptrPos);
       
   128 
       
   129 		r=f.Size(size);							// size of unpaged file
       
   130 		test(r==KErrNone);
       
   131 		size+=((~(size&0xf)&0xf)+1);			// adjust for ROM alignement (EABI, 8 bytes)
       
   132 		f.Close();
       
   133 
       
   134 		r=f.Open(TheFs,KTPagedCpp,EFileStream);
       
   135 		test(r==KErrNone);
       
   136 		r=f.Size(size1);							// size of paged file
       
   137 		test(r==KErrNone);
       
   138 		size1+=((~(size1&0xf)&0xf)+1);			// adjust for ROM alignement (EABI, 8 bytes)
       
   139 		f.Close();
       
   140 
       
   141 		size+=size1;
       
   142 		test.Printf(_L("Set descriptor with size %d (paged+unpaged sections+ROMFS padding)\n"), size);
       
   143 		TPtrC8 ptr(ptrPos,size);
       
   144 
       
   145 		fileName.Format(_L("%c:\\TestFragFile.bin"), aDrvNum+'A');
       
   146 		TheFs.Delete(fileName); //-- just in case
       
   147 
       
   148 		test.Printf(_L("Create and open destination file\n"));
       
   149 		r = CreateEmptyFile(TheFs, fileName, (size));		// create file to hold both sizes
       
   150 		test(r == KErrNone);
       
   151 		r=f.Open(TheFs,fileName,EFileRead|EFileWrite);
       
   152 		test(r == KErrNone);
       
   153 
       
   154 		test.Printf(_L("Attempt to flush paged section\n"));
       
   155 		TInt r=UserSvr::HalFunction(EHalGroupVM,EVMHalFlushCache,0,0);
       
   156 		if(r==KErrNotSupported)
       
   157 			test.Printf(_L("Not Supported\n"));
       
   158 
       
   159 		test.Printf(_L("Write paged and unpaged sections, synchronoulsy\n"));
       
   160 		r=f.Write(ptr);
       
   161 		test(r==KErrNone);
       
   162 
       
   163 		test.Printf(_L("Read back and compare\n"));
       
   164 		pos=0;
       
   165 		r=f.Seek(ESeekStart,pos);
       
   166 		test(r==KErrNone);
       
   167 		TUint end=(TUint)ptrPos+(size);
       
   168 		TBuf8<1024> readBuf;
       
   169 		TPtrC8 memBuf(ptrPos,1024);
       
   170 
       
   171 		while((TUint)ptrPos+1024<end)
       
   172 			{
       
   173 			r=f.Read(readBuf);
       
   174 			test(r==KErrNone);
       
   175 			test(readBuf.Length()==readBuf.MaxLength());
       
   176 			if(memBuf!=readBuf)
       
   177 				{
       
   178 				test.Printf(_L("Failed on descriptor starting at address %x\n"), ptrPos);
       
   179 				test(0);
       
   180 				}
       
   181 			ptrPos+=1024;
       
   182 			memBuf.Set(ptrPos,1024);
       
   183 			}
       
   184 		r=f.Read(readBuf);
       
   185 		test(r==KErrNone);
       
   186 		test(readBuf.Length()==(TInt)(end-(TUint)ptrPos));
       
   187 		memBuf.Set(ptrPos,(end-(TUint)ptrPos));
       
   188 		if(memBuf!=readBuf)
       
   189 			{
       
   190 			test.Printf(_L("Failed on descriptor starting at address %x\n"), ptrPos);
       
   191 			test(0);
       
   192 			}
       
   193 		f.Close();
       
   194 		}
       
   195 	else
       
   196 		{
       
   197 		test.Printf(_L("Required test files not present\n"));
       
   198 		test(0);
       
   199 		}
       
   200 	}
       
   201 
       
   202 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
       
   203 LOCAL_C TInt ConcurrThread(TAny* aArg);
       
   204 /*
       
   205   This equally unimpressive looking test further exercises the fragmentation of write requests 
       
   206   carried out by the Local Media subsystem. This time write requests where the request source is
       
   207   in paged out ROM are issued concurrently.
       
   208   By having concurrent writes it indirectly tests both page in and fragment deferral mechaninsms.
       
   209 */
       
   210 
       
   211 LOCAL_C void TestConcurrentFragmentation()
       
   212 	{
       
   213 	// concurrently write from paged out ROM addresses to either files in separate writebla partitions or different locations in the same partition
       
   214 	TDriveList driveList;
       
   215 	TDriveInfo driveInfo;
       
   216 	TBool concurr=EFalse;
       
   217 
       
   218 	TFileName path;
       
   219 	TInt r=TheFs.SessionPath(path);
       
   220 	test(r==KErrNone);
       
   221 	TInt drvNum;
       
   222 	r=RFs::CharToDrive(path[0],drvNum);
       
   223 	test(r==KErrNone);
       
   224 
       
   225 	r=TheFs.DriveList(driveList);
       
   226     test(r == KErrNone);
       
   227 
       
   228 	test(TheFs.Drive(driveInfo, drvNum) == KErrNone);
       
   229 
       
   230 	//-- select suitable drives for the testing. They shall be writable drives on a media that services paging
       
   231 	if((driveInfo.iMediaAtt&KMediaAttPageable) && !(driveInfo.iMediaAtt&KMediaAttWriteProtected))
       
   232 		{
       
   233 		for (TInt drvNum1=drvNum+1; drvNum1<KMaxDrives; drvNum1++)	// if yes search for more drives suitable for concurrent fragmentation
       
   234 			{
       
   235 			if(!driveList[drvNum1])
       
   236 				continue;   //-- skip unexisting drive
       
   237 
       
   238 			TDriveInfo driveInfo2;	// for second drive
       
   239 			test(TheFs.Drive(driveInfo2, drvNum1) == KErrNone);
       
   240 			if ((driveInfo2.iMediaAtt&KMediaAttPageable) && 
       
   241 				!(driveInfo2.iMediaAtt&KMediaAttWriteProtected) &&
       
   242 				(driveInfo.iType == driveInfo2.iType))
       
   243 				{
       
   244 				DoTestC(drvNum, drvNum1, (driveInfo.iType==EMediaNANDFlash)?(TBool)ETrue:(TBool)EFalse);		// test concurrent
       
   245 				concurr=ETrue;
       
   246 				}
       
   247 			}
       
   248 		}
       
   249 	if(!concurr)
       
   250 		test.Printf(_L("Skipped concurrent test\n"));
       
   251 	}
       
   252 
       
   253 
       
   254 void silentFormat(TInt driveNo) 
       
   255 	{    
       
   256     TBuf<4> driveBuf=_L("?:\\");
       
   257     RFormat format;
       
   258     TInt    count;
       
   259     
       
   260 	driveBuf[0] = (TText)(driveNo + 'A');
       
   261     
       
   262     TInt r = format.Open(TheFs, driveBuf, EHighDensity, count);
       
   263     test(r == KErrNone);
       
   264     
       
   265     while(count) 
       
   266 		{
       
   267         r=format.Next(count);
       
   268         test(r == KErrNone);
       
   269 		}
       
   270     
       
   271     format.Close();
       
   272 	}
       
   273 
       
   274 
       
   275 void DoTestC(TInt aDrvNum, TInt aNotherDrvNum, TBool aNand)
       
   276 	{
       
   277 	TInt pos=0;
       
   278 	TInt size=0;
       
   279 	TInt r;
       
   280 	TRequestStatus logonStat;
       
   281 	RThread concurrThread;
       
   282 	TInt locDriveNumber;
       
   283 	TBusLocalDrive drive;
       
   284 	TLocalDriveCapsV4 driveCaps;
       
   285 	SDeferStats stats;
       
   286 
       
   287 	test.Next(_L("Testing concurrent Fragmentation of writes on the same media"));
       
   288 	if(aNand)
       
   289 		test.Printf(_L("Testing on NAND\n"));
       
   290 	test.Printf(_L("Testing on writable drives %c and %c\n"), 'A'+aDrvNum,'A'+aNotherDrvNum);
       
   291 
       
   292 	_LIT(KTPagedCpp, "Z:\\test\\TEST_PAGED.cpp");
       
   293 	_LIT(KTPaged1Cpp, "Z:\\test\\TEST_PAGED1.cpp");
       
   294 
       
   295 	if(TheFs.IsFileInRom(KTPagedCpp) != NULL && TheFs.IsFileInRom(KTPaged1Cpp) != NULL)	// .oby must include these files
       
   296 		{
       
   297 		RFile f;
       
   298 		r=f.Open(TheFs,KTPagedCpp,EFileStream);		// source 1
       
   299 		test(r==KErrNone);
       
   300 		r=f.Seek(ESeekAddress,pos);
       
   301 		test(r==KErrNone);
       
   302 		TText8* ptrPos=*(TText8**)&pos;			// start address of paged file 1 in ROM
       
   303 		test.Printf(_L("Main thread->Start address of paged out file 1 0x%x\n"), ptrPos);
       
   304 		r=f.Size(size);							// size of paged file 1
       
   305 		test(r==KErrNone);
       
   306 		f.Close();
       
   307 
       
   308 		TRomHeader* romHeader = (TRomHeader*)UserSvr::RomHeaderAddress();
       
   309 		TUint fsize=Min(KMuliplySize*size,romHeader->iPageableRomSize);
       
   310 
       
   311 		test.Printf(_L("Main thread->Set descriptor with size %d to point to paged out file 1 +...\n"), fsize);
       
   312 		TPtrC8 ptr(ptrPos,fsize);
       
   313 
       
   314 		Buffer.SetLength(fsize);
       
   315 		TPtr8 readBuf(&Buffer[0],fsize,fsize);
       
   316 
       
   317 		test.Printf(_L("Create and resume concurrent thread\n"));
       
   318 		const TInt KHeapSize=0x2000;
       
   319 
       
   320 		locDriveNumber = GetLocDrvNumber(aNotherDrvNum);
       
   321 		TInt r = concurrThread.Create(_L("ConcurrentWriteThread"),ConcurrThread,KDefaultStackSize,KHeapSize,KHeapSize,(TAny*)locDriveNumber);
       
   322 		test(r==KErrNone);
       
   323 		concurrThread.Logon(logonStat);
       
   324 
       
   325 		locDriveNumber = GetLocDrvNumber(aDrvNum);
       
   326 		test.Printf(_L("Connect to local drive %d\n"),locDriveNumber);
       
   327 		TBool changeFlag = EFalse;
       
   328 		r = drive.Connect(locDriveNumber,changeFlag);
       
   329 		TPckg<TLocalDriveCapsV4>	capsPack(driveCaps);
       
   330 		drive.Caps(capsPack);
       
   331 		test(r == KErrNone);
       
   332 
       
   333 		test(WriteSemaphore.CreateLocal(0)==KErrNone);
       
   334 
       
   335 		// try to ensure there is no other thread activity as this may prevent the 
       
   336 		// large write from being pre-empted by the ConcurrentWriteThread
       
   337 		test.Printf(_L("Waiting 2 secs for file server threads to quieten down...."));
       
   338 		User::After(2000000);
       
   339 
       
   340 		concurrThread.Resume();
       
   341 
       
   342 		WriteSemaphore.Wait();
       
   343 		WriteSemaphore.Signal();
       
   344 
       
   345 		// long write...
       
   346 //		test.Printf(_L("Starting file 1 write\n"));	
       
   347 		r = drive.Write(0,ptr);
       
   348 		test(r==KErrNone);
       
   349 
       
   350 		test.Printf(_L("Main thread->Write 1 completed\n"));
       
   351 
       
   352 		if(aNand)
       
   353 			{
       
   354 			test.Printf(_L("Read stats\n"));
       
   355 			TPtr8 statsBuf((TUint8*) &stats, sizeof(stats));
       
   356 	 		test(drive.ControlIO(KNandGetDeferStats, statsBuf, 0)==KErrNone);
       
   357 			test.Printf(_L("Fragmentation clashes %d Fragmentation deferrals %d Page In deferrals %d Other deferrals %d\n"),stats.iClashFragmenting,  stats.iNormalFragmenting, stats.iPageOther, stats.iNormalOther);
       
   358 			}
       
   359 
       
   360 		test.Printf(_L("Read back file 1 and compare\n"));
       
   361 		r = drive.Read(0,fsize,readBuf);
       
   362 		test(r==KErrNone);
       
   363 		test(ptr==readBuf);
       
   364 		test.Printf(_L("Verify file 1 OK\n"));
       
   365 		drive.Disconnect();
       
   366 
       
   367 		WriteSemaphore.Signal();
       
   368 		User::WaitForRequest(logonStat);
       
   369 		test(logonStat==KErrNone);
       
   370 		concurrThread.Close();
       
   371 		WriteSemaphore.Close();
       
   372 
       
   373 		silentFormat(aDrvNum);
       
   374 		silentFormat(aNotherDrvNum);
       
   375 		}
       
   376 	else
       
   377 		{
       
   378 		test.Printf(_L("Required test files not present\n"));
       
   379 		test(0);
       
   380 		}
       
   381 	}
       
   382 
       
   383 	
       
   384 GLDEF_D RFs TheFsT;
       
   385 GLDEF_D RTest testT(_L("T_CONCURRENT_WRITE_THREAD"));
       
   386 
       
   387 LOCAL_C TInt ConcurrThread(TAny* aArg)
       
   388 	{
       
   389 	// the whole test is dodgy and hangs if this thread fails an assert,
       
   390 	// so at least make sure thread panic takes out whole test process...
       
   391 	User::SetCritical(User::EProcessCritical);
       
   392 
       
   393 	RFile f;
       
   394 	TInt pos=0;
       
   395 	TInt size=0;
       
   396 	TInt locDriveNumber;
       
   397 	TBusLocalDrive drive;
       
   398 	TLocalDriveCapsV4 driveCaps;
       
   399 	SDeferStats stats;
       
   400 	RThread thisThread;
       
   401 
       
   402 	TInt r = TheFsT.Connect();
       
   403 	_LIT(KTPaged1Cpp, "Z:\\test\\TEST_PAGED1.cpp");
       
   404 	r=f.Open(TheFsT,KTPaged1Cpp,EFileStream);		// source 2
       
   405 	testT(r==KErrNone);
       
   406 	r=f.Seek(ESeekAddress,pos);
       
   407 	testT(r==KErrNone);
       
   408 	TText8* ptrPos=*(TText8**)&pos;			// start address of paged file 2 in ROM
       
   409 	testT.Printf(_L("ConcurrThread->Start address of paged out file 2 0x%x\n"), ptrPos);
       
   410 	r=f.Size(size);							// size of paged file 2
       
   411 	testT(r==KErrNone);
       
   412 	f.Close();
       
   413 
       
   414 	testT.Printf(_L("ConcurrThread->Set descriptor with size %d to point to paged out file 2\n"), size);
       
   415 	TPtrC8 ptr(ptrPos,size);
       
   416 
       
   417 	TPtr8 readBuf(&Buffer[0],size,size);
       
   418 
       
   419 	locDriveNumber = (TInt)aArg;
       
   420 	testT.Printf(_L("Connect to local drive %d\n"),locDriveNumber);
       
   421 	TBool changeFlag = EFalse;
       
   422 	r = drive.Connect(locDriveNumber,changeFlag);
       
   423 	TPckg<TLocalDriveCapsV4>	capsPack(driveCaps);
       
   424 	drive.Caps(capsPack);
       
   425 	testT(r == KErrNone);
       
   426 
       
   427 	if (driveCaps.iType == EMediaNANDFlash)
       
   428 		{
       
   429 		testT.Printf(_L("Zero stats\n"));
       
   430 		TPtr8 statsBuf((TUint8*) &stats, sizeof(stats));
       
   431  		testT(drive.ControlIO(KNandGetDeferStats, statsBuf, 0)==KErrNone);
       
   432 		}
       
   433 
       
   434 	r=UserSvr::HalFunction(EHalGroupVM,EVMHalFlushCache,0,0);
       
   435 	if(r==KErrNotSupported)
       
   436 		testT.Printf(_L("ConcurrThread->Flushing of paging not Supported\n"));
       
   437 
       
   438 	// pause one second to make sure main thread has executed WriteSemaphore.Wait();
       
   439 	User::After(1000000);
       
   440 
       
   441 	WriteSemaphore.Signal();
       
   442 	WriteSemaphore.Wait();
       
   443 	// up our priority
       
   444 	thisThread.SetPriority(EPriorityMore);
       
   445 
       
   446 	// wait a very short time to give the other thread a better chance to initiate the write
       
   447 	User::After(1);	
       
   448 //	testT.Printf(_L("Starting file 2 write\n"));
       
   449 
       
   450 	// write
       
   451 	r = drive.Write(0,ptr);
       
   452 	testT(r==KErrNone);
       
   453 	// read back
       
   454 	r = drive.Read(0,size,readBuf);
       
   455 	testT(r==KErrNone);
       
   456 	// erase
       
   457 	r=drive.Format(0,size);
       
   458 	testT(r==KErrNone);
       
   459 
       
   460 	testT.Printf(_L("ConcurrThread->Write of file 2 completed\n"));
       
   461 
       
   462 	WriteSemaphore.Wait();
       
   463 	testT.Printf(_L("Read back file 2 and compare\n"));
       
   464 	testT(ptr==readBuf);
       
   465 	testT.Printf(_L("Verify file 2 OK\n"));
       
   466 
       
   467 	drive.Disconnect();
       
   468 	TheFsT.Close();
       
   469 	return KErrNone;
       
   470 	}
       
   471 
       
   472 #endif // #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
       
   473 
       
   474 //--------------------------------------------------------
       
   475 
       
   476 /**
       
   477     Create an empty file of specified size.
       
   478     @param  aFs		    ref. to the FS
       
   479     @param  aFileName   name of the file
       
   480     @param  aFileSize   size of the file to be created
       
   481     @return    KErrNone on success, system-wide error code otherwise
       
   482 */
       
   483 TInt CreateEmptyFile(RFs& aFs, const TDesC& aFileName, TUint aFileSize)
       
   484 	{
       
   485     RFile   file;
       
   486 	TInt    nRes;
       
   487 
       
   488 	nRes = file.Create(aFs, aFileName, EFileWrite);
       
   489     if(nRes != KErrNone)
       
   490         return nRes;
       
   491 
       
   492 	nRes = file.SetSize(aFileSize);
       
   493     if(nRes != KErrNone)
       
   494         return nRes;
       
   495 
       
   496     file.Close();
       
   497 
       
   498     return KErrNone;
       
   499 	}
       
   500 
       
   501 TInt GetLocDrvNumber(TInt aDrvNo)
       
   502 	{
       
   503 	test.Printf(_L("GetLocDrvNumber\r\n"));
       
   504 	TInt locDriveNumber;
       
   505 	RFile file;
       
   506 	TBuf<256> fileName;	
       
   507 	fileName.Append((TChar)('A'+aDrvNo));
       
   508 	fileName+=_L(":\\f32-tst\\");
       
   509 	TInt r=TheFs.MkDirAll(fileName);
       
   510 	test(r==KErrNone || r== KErrAlreadyExists);
       
   511 	fileName += _L("maggots.txt");
       
   512 	r=file.Replace(TheFs,fileName,EFileWrite|EFileWriteDirectIO);
       
   513 	if (r!=KErrNone)
       
   514 		test.Printf(_L("Error %d: file '%S' could not be created\n"),r,&fileName);
       
   515 	test(r==KErrNone);
       
   516 	r=file.Write(_L8("Writhing bundles of maggots, this was truly their finest hour"));
       
   517 	if (r!=KErrNone)
       
   518 		test.Printf(_L("Error %d: could not write to file\n"),r);
       
   519 	test(r==KErrNone);
       
   520 
       
   521 	SBlockMapInfo info;
       
   522 	TInt64 start=0;
       
   523 	r=file.BlockMap(info,start, -1,ETestDebug);
       
   524 	if (r!=KErrNone && r!=KErrCompletion)
       
   525 		test.Printf(_L("Error %d: could not obtain block map\n"),r);
       
   526 	test(r==KErrNone || r==KErrCompletion);
       
   527 	locDriveNumber=info.iLocalDriveNumber;
       
   528 	test.Printf(_L("From drive: %c to Local drive %d\r\n"), aDrvNo+'A',locDriveNumber);
       
   529 	file.Close();
       
   530 	return locDriveNumber;
       
   531 	}
       
   532 
       
   533 GLDEF_C void CallTestsL()
       
   534 	{
       
   535 	TRomHeader* romHeader = (TRomHeader*)UserSvr::RomHeaderAddress();
       
   536 	if(!romHeader->iPageableRomStart)
       
   537 		{
       
   538 		test.Printf(_L("Test not supported (not a paged ROM)\n"));
       
   539 		return; // Not a paged ROM, skip test
       
   540 		}
       
   541 	test.Title();
       
   542 
       
   543 	TBool r=TestSimpleFragmentation();
       
   544 	if(!r)
       
   545 		return;
       
   546 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
       
   547 	TestConcurrentFragmentation();
       
   548 #endif
       
   549 	}