os/kernelhwsrv/kerneltest/e32test/pccd/t_idrv.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
// e32test\pccd\t_idrv.cpp
sl@0
    15
// Overview:
sl@0
    16
// Tests for the internal RAM drive
sl@0
    17
// API Information:
sl@0
    18
// TBusLocalDrive
sl@0
    19
// Details:
sl@0
    20
// - Load a Physical Device Driver for the RAM Media Driver.
sl@0
    21
// - Find the internal drive: type == EMediaRam
sl@0
    22
// - Display and adjust various drive capabilities, verify results
sl@0
    23
// are as expected.
sl@0
    24
// - Read and write the drive using various drive sizes, verify results
sl@0
    25
// are as expected.
sl@0
    26
// - Format the drive, verify results.
sl@0
    27
// - Set original size and reformat. 
sl@0
    28
// Platforms/Drives/Compatibility:
sl@0
    29
// All.
sl@0
    30
// Assumptions/Requirement/Pre-requisites:
sl@0
    31
// Failures and causes:
sl@0
    32
// Base Port information:
sl@0
    33
// 
sl@0
    34
//
sl@0
    35
sl@0
    36
#include <e32test.h>
sl@0
    37
#include <e32svr.h>
sl@0
    38
#include <e32hal.h>
sl@0
    39
#include <e32uid.h>
sl@0
    40
#include "../mmu/mmudetect.h"
sl@0
    41
#include <f32file.h>
sl@0
    42
sl@0
    43
#define PDD_NAME _L("MEDINT")
sl@0
    44
sl@0
    45
const TInt KTestDriveLen=0x00040000;	//256K
sl@0
    46
const TInt KSmallDriveInc=0x00000400;	//1K
sl@0
    47
const TInt KBigDriveLen=0x00100000;		//1M - WINS
sl@0
    48
const TInt KTestBufLen=256;
sl@0
    49
sl@0
    50
sl@0
    51
RTest test(_L("T_IDRV"));
sl@0
    52
sl@0
    53
void Format(TInt aDrive, RFs& aFs)
sl@0
    54
//
sl@0
    55
// Format current drive
sl@0
    56
//
sl@0
    57
	{
sl@0
    58
	test.Next(_L("Format"));
sl@0
    59
	TBuf<4> driveBuf=_L("?:\\");
sl@0
    60
	driveBuf[0]=(TText)(aDrive+'A');
sl@0
    61
	RFormat format;
sl@0
    62
	TInt count;
sl@0
    63
	TInt r=format.Open(aFs,driveBuf,EHighDensity,count);
sl@0
    64
	test(r==KErrNone);
sl@0
    65
	while(count)
sl@0
    66
		{
sl@0
    67
		TInt r=format.Next(count);
sl@0
    68
		test(r==KErrNone);
sl@0
    69
		}
sl@0
    70
	format.Close();
sl@0
    71
	}
sl@0
    72
sl@0
    73
GLDEF_C TInt E32Main()
sl@0
    74
    {
sl@0
    75
sl@0
    76
	test.Title();
sl@0
    77
	if (!HaveVirtMem())
sl@0
    78
		{
sl@0
    79
		test.Printf(_L("Needs MMU\n"));
sl@0
    80
		return 0;
sl@0
    81
		}
sl@0
    82
#if defined(__EPOC32__) && defined(__CPU_X86)
sl@0
    83
	test.Printf(_L("Doesn't run on X86\n"));
sl@0
    84
#else
sl@0
    85
sl@0
    86
	TBusLocalDrive theInternalDrive;
sl@0
    87
    TInt msgHandle = KLocalMessageHandle;
sl@0
    88
	
sl@0
    89
	UserSvr::UnlockRamDrive();
sl@0
    90
	
sl@0
    91
	test.Printf(_L("Warning - this will destroy internal drive.\r\n"));
sl@0
    92
	TChar c= 'C';
sl@0
    93
	c.UpperCase();
sl@0
    94
	if (c!='C')
sl@0
    95
		return(0);
sl@0
    96
sl@0
    97
	test.Start(_L("Check loader running"));
sl@0
    98
sl@0
    99
	test.Next(_L("Load Internal Ram Media Driver"));
sl@0
   100
	TInt r=User::LoadPhysicalDevice(PDD_NAME);
sl@0
   101
	test(r==KErrNone || r==KErrAlreadyExists);
sl@0
   102
sl@0
   103
	test.Next(_L("Find internal drive"));
sl@0
   104
	
sl@0
   105
	TDriveInfoV1Buf driveInfoBuf;
sl@0
   106
	UserHal::DriveInfo(driveInfoBuf);
sl@0
   107
	TDriveInfoV1& driveInfo = driveInfoBuf();
sl@0
   108
sl@0
   109
	TInt drive = 0;
sl@0
   110
	for ( ; drive < driveInfo.iTotalSupportedDrives; ++drive)
sl@0
   111
		{
sl@0
   112
		TBool changedFlag;
sl@0
   113
		theInternalDrive.Connect(drive, changedFlag);
sl@0
   114
sl@0
   115
		TLocalDriveCapsV2 info;
sl@0
   116
		TPckg<TLocalDriveCapsV2> infoPckg(info);
sl@0
   117
		theInternalDrive.Caps(infoPckg);
sl@0
   118
sl@0
   119
		if (info.iType == EMediaRam)
sl@0
   120
			{
sl@0
   121
			break;
sl@0
   122
			}
sl@0
   123
sl@0
   124
		theInternalDrive.Disconnect();
sl@0
   125
		}
sl@0
   126
	test(drive < driveInfo.iTotalSupportedDrives);
sl@0
   127
sl@0
   128
	test.Next(_L("Capabilities"));
sl@0
   129
	TLocalDriveCapsV2 info;
sl@0
   130
	TPckg<TLocalDriveCapsV2> infoPckg(info);
sl@0
   131
	test(theInternalDrive.Caps(infoPckg)==KErrNone);
sl@0
   132
	TUint saveSize=I64LOW(info.iSize);
sl@0
   133
	test(info.iType==EMediaRam);
sl@0
   134
	test(info.iConnectionBusType==EConnectionBusInternal);
sl@0
   135
	test(info.iDriveAtt==(KDriveAttLocal|KDriveAttInternal));
sl@0
   136
	test(info.iMediaAtt==(KMediaAttVariableSize|KMediaAttFormattable));
sl@0
   137
	test(info.iFileSystemId==KDriveFileSysFAT);
sl@0
   138
sl@0
   139
	test.Printf(_L("Current drive size: %lx\n"),info.iSize);
sl@0
   140
sl@0
   141
	test.Next(_L("Set size to zero"));
sl@0
   142
	test(theInternalDrive.ReduceSize(0,saveSize)==KErrNone);
sl@0
   143
	test(theInternalDrive.Caps(infoPckg)==KErrNone);
sl@0
   144
	test(info.iSize==0);
sl@0
   145
	test(theInternalDrive.ReduceSize(0,-1)==KErrArgument);
sl@0
   146
	test(theInternalDrive.Enlarge(-1)==KErrArgument);
sl@0
   147
sl@0
   148
	test.Next(_L("Increase to large size"));
sl@0
   149
#if defined (__WINS__)
sl@0
   150
	TUint cSize=KBigDriveLen;
sl@0
   151
#else
sl@0
   152
	TMemoryInfoV1Buf memBuf;
sl@0
   153
	TMemoryInfoV1 &mi=memBuf();
sl@0
   154
	UserHal::MemoryInfo(memBuf);
sl@0
   155
//	TUint cSize=(mi.iTotalRamInBytes-KTestDriveLen); // Leave last 256K - used by Kernel etc.
sl@0
   156
//	TUint cSize=mi.iTotalRamInBytes>>1; 			 // Half ram
sl@0
   157
//	TUint cSize=mi.iTotalRamInBytes>>2; 			 // Quarter ram
sl@0
   158
	TUint cSize=mi.iTotalRamInBytes>>3; 			 // Eighth ram
sl@0
   159
#endif
sl@0
   160
	test.Printf(_L("(Increasing to %dbytes)\r\n"),cSize);
sl@0
   161
	test(theInternalDrive.Enlarge(cSize)==KErrNone);
sl@0
   162
//	test(theInternalDrive.Enlarge(cSize-saveSize)==KErrNone); // ???
sl@0
   163
	test(theInternalDrive.Caps(infoPckg)==KErrNone);
sl@0
   164
	test(I64LOW(info.iSize)==cSize);
sl@0
   165
sl@0
   166
	test.Next(_L("Increase by 1K"));
sl@0
   167
	cSize+=KSmallDriveInc;
sl@0
   168
	test(theInternalDrive.Enlarge(KSmallDriveInc)==KErrNone);
sl@0
   169
	test(theInternalDrive.Caps(infoPckg)==KErrNone);
sl@0
   170
	test(I64LOW(info.iSize)==cSize);
sl@0
   171
sl@0
   172
	test.Next(_L("Reduce to 256K"));
sl@0
   173
	test(theInternalDrive.ReduceSize(0,(cSize-KTestDriveLen))==KErrNone);
sl@0
   174
	cSize=KTestDriveLen;
sl@0
   175
	test(theInternalDrive.Caps(infoPckg)==KErrNone);
sl@0
   176
	test(I64LOW(info.iSize)==(TUint)KTestDriveLen);
sl@0
   177
sl@0
   178
	test.Next(_L("Write/Read"));
sl@0
   179
	TBuf8<KTestBufLen> wrBuf(KTestBufLen),rdBuf;
sl@0
   180
	TUint i,j,len;
sl@0
   181
	for (i=0 ; i<(TUint)KTestBufLen ; i++)
sl@0
   182
		wrBuf[i]=(TUint8)i;
sl@0
   183
	for (i=0,j=0;i<(TUint)KTestDriveLen;i+=len,j++)
sl@0
   184
		{
sl@0
   185
		len=Min(KTestBufLen,(KTestDriveLen-i));
sl@0
   186
		rdBuf.Fill(0,len);
sl@0
   187
		wrBuf[0]=(TUint8)j;
sl@0
   188
		test(theInternalDrive.Write(i,len,&wrBuf,msgHandle,0)==KErrNone);
sl@0
   189
 		test(theInternalDrive.Read(i,len,&rdBuf,msgHandle,0)==KErrNone);
sl@0
   190
		wrBuf.SetLength(len);
sl@0
   191
  	    test(rdBuf.Compare(wrBuf)==0);
sl@0
   192
		}
sl@0
   193
sl@0
   194
	test.Next(_L("Reduce size - 256 bytes from start"));
sl@0
   195
 	test(theInternalDrive.ReduceSize(0,KTestBufLen)==KErrNone);
sl@0
   196
	test(theInternalDrive.Caps(infoPckg)==KErrNone);
sl@0
   197
	cSize-=KTestBufLen;
sl@0
   198
	test(I64LOW(info.iSize)==(TUint)cSize);
sl@0
   199
	for (i=0,j=1;i<cSize;i+=len,j++)
sl@0
   200
		{
sl@0
   201
		len=Min(KTestBufLen,(cSize-i));
sl@0
   202
		rdBuf.Fill(0,len);
sl@0
   203
		wrBuf[0]=(TUint8)j;
sl@0
   204
 		test(theInternalDrive.Read(i,len,&rdBuf,msgHandle,0)==KErrNone);
sl@0
   205
		wrBuf.SetLength(len);
sl@0
   206
  	    test(rdBuf.Compare(wrBuf)==0);
sl@0
   207
		}
sl@0
   208
sl@0
   209
	test.Next(_L("Reduce size - (4K+127) bytes from middle"));
sl@0
   210
	TInt reduction=((KTestBufLen<<4)+((KTestBufLen>>1)-1)); 
sl@0
   211
 	test(theInternalDrive.ReduceSize(KTestBufLen,reduction)==KErrNone); 
sl@0
   212
	test(theInternalDrive.Caps(infoPckg)==KErrNone);
sl@0
   213
	cSize-=reduction;
sl@0
   214
	test(I64LOW(info.iSize)==(TUint)cSize);
sl@0
   215
	TBuf8<KTestBufLen> odBuf(KTestBufLen); // To verify new pattern 
sl@0
   216
	for (i=0 ; i<(TUint)KTestBufLen ; i++)
sl@0
   217
		{
sl@0
   218
		if (i<=(KTestBufLen>>1))
sl@0
   219
			odBuf[i]=(TUint8)(i+((KTestBufLen>>1)-1));
sl@0
   220
		else
sl@0
   221
			odBuf[i]=(TUint8)(i-((KTestBufLen>>1)+1));
sl@0
   222
		}
sl@0
   223
	for (i=0,j=1;i<cSize;i+=len,j++)
sl@0
   224
		{
sl@0
   225
		len=Min(KTestBufLen,(cSize-i));
sl@0
   226
		rdBuf.Fill(0,len);
sl@0
   227
 		test(theInternalDrive.Read(i,len,&rdBuf,msgHandle,0)==KErrNone);
sl@0
   228
		if (j==2)
sl@0
   229
			j+=17;
sl@0
   230
		if (j==1)
sl@0
   231
			{
sl@0
   232
			wrBuf[0]=(TUint8)j;
sl@0
   233
			wrBuf.SetLength(len);
sl@0
   234
  	    	test(rdBuf.Compare(wrBuf)==0);
sl@0
   235
			}
sl@0
   236
		else
sl@0
   237
			{
sl@0
   238
			odBuf.SetLength(KTestBufLen);
sl@0
   239
			odBuf[((KTestBufLen>>1)+1)]=(TUint8)j;
sl@0
   240
			odBuf.SetLength(len);
sl@0
   241
  	    	test(rdBuf.Compare(odBuf)==0);
sl@0
   242
			}
sl@0
   243
		}
sl@0
   244
sl@0
   245
	test.Next(_L("Reduce size - (8K-1) bytes from end"));
sl@0
   246
	reduction=((KTestBufLen<<5)-1); 
sl@0
   247
	test(theInternalDrive.ReduceSize((cSize-reduction),reduction)==KErrNone);
sl@0
   248
	test(theInternalDrive.Caps(infoPckg)==KErrNone);
sl@0
   249
	cSize-=reduction;
sl@0
   250
	test(info.iSize==cSize);
sl@0
   251
	for (i=0,j=1;i<cSize;i+=len,j++)
sl@0
   252
		{
sl@0
   253
		len=Min(KTestBufLen,(cSize-i));
sl@0
   254
		rdBuf.Fill(0,len);
sl@0
   255
 		test(theInternalDrive.Read(i,len,&rdBuf,msgHandle,0)==KErrNone);
sl@0
   256
		if (j==2)
sl@0
   257
			j+=17;
sl@0
   258
		if (j==1)
sl@0
   259
			{
sl@0
   260
			wrBuf[0]=(TUint8)j;
sl@0
   261
			wrBuf.SetLength(len);
sl@0
   262
  	    	test(rdBuf.Compare(wrBuf)==0);
sl@0
   263
			}
sl@0
   264
		else
sl@0
   265
			{
sl@0
   266
			odBuf.SetLength(KTestBufLen);
sl@0
   267
			odBuf[((KTestBufLen>>1)+1)]=(TUint8)j;
sl@0
   268
			odBuf.SetLength(len);
sl@0
   269
  	    	test(rdBuf.Compare(odBuf)==0);
sl@0
   270
			}
sl@0
   271
		}
sl@0
   272
sl@0
   273
	test.Next(_L("Format"));
sl@0
   274
	wrBuf.Fill(0,KTestBufLen);
sl@0
   275
	TFormatInfo fi;
sl@0
   276
	TInt ret;
sl@0
   277
	while((ret=theInternalDrive.Format(fi))!=KErrEof)
sl@0
   278
		test(ret==KErrNone);
sl@0
   279
	for (i=0;i<cSize;i+=len)
sl@0
   280
		{
sl@0
   281
		len=Min(KTestBufLen,(cSize-i));
sl@0
   282
		rdBuf.Fill(0xAA,len);
sl@0
   283
 		test(theInternalDrive.Read(i,len,&rdBuf,msgHandle,0)==KErrNone);
sl@0
   284
		wrBuf.SetLength(len);
sl@0
   285
  	    test(rdBuf.Compare(wrBuf)==0);
sl@0
   286
		}
sl@0
   287
sl@0
   288
	test.Next(_L("Restore original size"));
sl@0
   289
	TInt sizeDif=cSize-saveSize;
sl@0
   290
	if (sizeDif>0)
sl@0
   291
		test(theInternalDrive.ReduceSize(0,sizeDif)==KErrNone);
sl@0
   292
	else
sl@0
   293
		test(theInternalDrive.Enlarge(sizeDif*-1)==KErrNone);
sl@0
   294
sl@0
   295
	test.Next(_L("Disconnect from internal drive"));
sl@0
   296
	theInternalDrive.Disconnect();
sl@0
   297
sl@0
   298
	RFs fs;
sl@0
   299
	test(fs.Connect()==KErrNone);
sl@0
   300
	for(drive=25 ; drive>=0; --drive)
sl@0
   301
		{
sl@0
   302
		TDriveInfo info;
sl@0
   303
		if(fs.Drive(info,drive)==KErrNone)
sl@0
   304
			if(info.iType==EMediaRam)
sl@0
   305
				{
sl@0
   306
				TBuf<256> text;
sl@0
   307
				text.Append(_L("Formatting drive "));
sl@0
   308
				text.Append(TText(drive+'A'));
sl@0
   309
				text.Append(_L(": ..."));
sl@0
   310
				test.Next(text);
sl@0
   311
				Format(drive,fs);
sl@0
   312
				break;
sl@0
   313
				}
sl@0
   314
		}
sl@0
   315
sl@0
   316
    test.End();
sl@0
   317
sl@0
   318
#endif	// x86
sl@0
   319
	return(0);
sl@0
   320
	}
sl@0
   321