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