1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/pccd/t_idrv.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,321 @@
1.4 +// Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// e32test\pccd\t_idrv.cpp
1.18 +// Overview:
1.19 +// Tests for the internal RAM drive
1.20 +// API Information:
1.21 +// TBusLocalDrive
1.22 +// Details:
1.23 +// - Load a Physical Device Driver for the RAM Media Driver.
1.24 +// - Find the internal drive: type == EMediaRam
1.25 +// - Display and adjust various drive capabilities, verify results
1.26 +// are as expected.
1.27 +// - Read and write the drive using various drive sizes, verify results
1.28 +// are as expected.
1.29 +// - Format the drive, verify results.
1.30 +// - Set original size and reformat.
1.31 +// Platforms/Drives/Compatibility:
1.32 +// All.
1.33 +// Assumptions/Requirement/Pre-requisites:
1.34 +// Failures and causes:
1.35 +// Base Port information:
1.36 +//
1.37 +//
1.38 +
1.39 +#include <e32test.h>
1.40 +#include <e32svr.h>
1.41 +#include <e32hal.h>
1.42 +#include <e32uid.h>
1.43 +#include "../mmu/mmudetect.h"
1.44 +#include <f32file.h>
1.45 +
1.46 +#define PDD_NAME _L("MEDINT")
1.47 +
1.48 +const TInt KTestDriveLen=0x00040000; //256K
1.49 +const TInt KSmallDriveInc=0x00000400; //1K
1.50 +const TInt KBigDriveLen=0x00100000; //1M - WINS
1.51 +const TInt KTestBufLen=256;
1.52 +
1.53 +
1.54 +RTest test(_L("T_IDRV"));
1.55 +
1.56 +void Format(TInt aDrive, RFs& aFs)
1.57 +//
1.58 +// Format current drive
1.59 +//
1.60 + {
1.61 + test.Next(_L("Format"));
1.62 + TBuf<4> driveBuf=_L("?:\\");
1.63 + driveBuf[0]=(TText)(aDrive+'A');
1.64 + RFormat format;
1.65 + TInt count;
1.66 + TInt r=format.Open(aFs,driveBuf,EHighDensity,count);
1.67 + test(r==KErrNone);
1.68 + while(count)
1.69 + {
1.70 + TInt r=format.Next(count);
1.71 + test(r==KErrNone);
1.72 + }
1.73 + format.Close();
1.74 + }
1.75 +
1.76 +GLDEF_C TInt E32Main()
1.77 + {
1.78 +
1.79 + test.Title();
1.80 + if (!HaveVirtMem())
1.81 + {
1.82 + test.Printf(_L("Needs MMU\n"));
1.83 + return 0;
1.84 + }
1.85 +#if defined(__EPOC32__) && defined(__CPU_X86)
1.86 + test.Printf(_L("Doesn't run on X86\n"));
1.87 +#else
1.88 +
1.89 + TBusLocalDrive theInternalDrive;
1.90 + TInt msgHandle = KLocalMessageHandle;
1.91 +
1.92 + UserSvr::UnlockRamDrive();
1.93 +
1.94 + test.Printf(_L("Warning - this will destroy internal drive.\r\n"));
1.95 + TChar c= 'C';
1.96 + c.UpperCase();
1.97 + if (c!='C')
1.98 + return(0);
1.99 +
1.100 + test.Start(_L("Check loader running"));
1.101 +
1.102 + test.Next(_L("Load Internal Ram Media Driver"));
1.103 + TInt r=User::LoadPhysicalDevice(PDD_NAME);
1.104 + test(r==KErrNone || r==KErrAlreadyExists);
1.105 +
1.106 + test.Next(_L("Find internal drive"));
1.107 +
1.108 + TDriveInfoV1Buf driveInfoBuf;
1.109 + UserHal::DriveInfo(driveInfoBuf);
1.110 + TDriveInfoV1& driveInfo = driveInfoBuf();
1.111 +
1.112 + TInt drive = 0;
1.113 + for ( ; drive < driveInfo.iTotalSupportedDrives; ++drive)
1.114 + {
1.115 + TBool changedFlag;
1.116 + theInternalDrive.Connect(drive, changedFlag);
1.117 +
1.118 + TLocalDriveCapsV2 info;
1.119 + TPckg<TLocalDriveCapsV2> infoPckg(info);
1.120 + theInternalDrive.Caps(infoPckg);
1.121 +
1.122 + if (info.iType == EMediaRam)
1.123 + {
1.124 + break;
1.125 + }
1.126 +
1.127 + theInternalDrive.Disconnect();
1.128 + }
1.129 + test(drive < driveInfo.iTotalSupportedDrives);
1.130 +
1.131 + test.Next(_L("Capabilities"));
1.132 + TLocalDriveCapsV2 info;
1.133 + TPckg<TLocalDriveCapsV2> infoPckg(info);
1.134 + test(theInternalDrive.Caps(infoPckg)==KErrNone);
1.135 + TUint saveSize=I64LOW(info.iSize);
1.136 + test(info.iType==EMediaRam);
1.137 + test(info.iConnectionBusType==EConnectionBusInternal);
1.138 + test(info.iDriveAtt==(KDriveAttLocal|KDriveAttInternal));
1.139 + test(info.iMediaAtt==(KMediaAttVariableSize|KMediaAttFormattable));
1.140 + test(info.iFileSystemId==KDriveFileSysFAT);
1.141 +
1.142 + test.Printf(_L("Current drive size: %lx\n"),info.iSize);
1.143 +
1.144 + test.Next(_L("Set size to zero"));
1.145 + test(theInternalDrive.ReduceSize(0,saveSize)==KErrNone);
1.146 + test(theInternalDrive.Caps(infoPckg)==KErrNone);
1.147 + test(info.iSize==0);
1.148 + test(theInternalDrive.ReduceSize(0,-1)==KErrArgument);
1.149 + test(theInternalDrive.Enlarge(-1)==KErrArgument);
1.150 +
1.151 + test.Next(_L("Increase to large size"));
1.152 +#if defined (__WINS__)
1.153 + TUint cSize=KBigDriveLen;
1.154 +#else
1.155 + TMemoryInfoV1Buf memBuf;
1.156 + TMemoryInfoV1 &mi=memBuf();
1.157 + UserHal::MemoryInfo(memBuf);
1.158 +// TUint cSize=(mi.iTotalRamInBytes-KTestDriveLen); // Leave last 256K - used by Kernel etc.
1.159 +// TUint cSize=mi.iTotalRamInBytes>>1; // Half ram
1.160 +// TUint cSize=mi.iTotalRamInBytes>>2; // Quarter ram
1.161 + TUint cSize=mi.iTotalRamInBytes>>3; // Eighth ram
1.162 +#endif
1.163 + test.Printf(_L("(Increasing to %dbytes)\r\n"),cSize);
1.164 + test(theInternalDrive.Enlarge(cSize)==KErrNone);
1.165 +// test(theInternalDrive.Enlarge(cSize-saveSize)==KErrNone); // ???
1.166 + test(theInternalDrive.Caps(infoPckg)==KErrNone);
1.167 + test(I64LOW(info.iSize)==cSize);
1.168 +
1.169 + test.Next(_L("Increase by 1K"));
1.170 + cSize+=KSmallDriveInc;
1.171 + test(theInternalDrive.Enlarge(KSmallDriveInc)==KErrNone);
1.172 + test(theInternalDrive.Caps(infoPckg)==KErrNone);
1.173 + test(I64LOW(info.iSize)==cSize);
1.174 +
1.175 + test.Next(_L("Reduce to 256K"));
1.176 + test(theInternalDrive.ReduceSize(0,(cSize-KTestDriveLen))==KErrNone);
1.177 + cSize=KTestDriveLen;
1.178 + test(theInternalDrive.Caps(infoPckg)==KErrNone);
1.179 + test(I64LOW(info.iSize)==(TUint)KTestDriveLen);
1.180 +
1.181 + test.Next(_L("Write/Read"));
1.182 + TBuf8<KTestBufLen> wrBuf(KTestBufLen),rdBuf;
1.183 + TUint i,j,len;
1.184 + for (i=0 ; i<(TUint)KTestBufLen ; i++)
1.185 + wrBuf[i]=(TUint8)i;
1.186 + for (i=0,j=0;i<(TUint)KTestDriveLen;i+=len,j++)
1.187 + {
1.188 + len=Min(KTestBufLen,(KTestDriveLen-i));
1.189 + rdBuf.Fill(0,len);
1.190 + wrBuf[0]=(TUint8)j;
1.191 + test(theInternalDrive.Write(i,len,&wrBuf,msgHandle,0)==KErrNone);
1.192 + test(theInternalDrive.Read(i,len,&rdBuf,msgHandle,0)==KErrNone);
1.193 + wrBuf.SetLength(len);
1.194 + test(rdBuf.Compare(wrBuf)==0);
1.195 + }
1.196 +
1.197 + test.Next(_L("Reduce size - 256 bytes from start"));
1.198 + test(theInternalDrive.ReduceSize(0,KTestBufLen)==KErrNone);
1.199 + test(theInternalDrive.Caps(infoPckg)==KErrNone);
1.200 + cSize-=KTestBufLen;
1.201 + test(I64LOW(info.iSize)==(TUint)cSize);
1.202 + for (i=0,j=1;i<cSize;i+=len,j++)
1.203 + {
1.204 + len=Min(KTestBufLen,(cSize-i));
1.205 + rdBuf.Fill(0,len);
1.206 + wrBuf[0]=(TUint8)j;
1.207 + test(theInternalDrive.Read(i,len,&rdBuf,msgHandle,0)==KErrNone);
1.208 + wrBuf.SetLength(len);
1.209 + test(rdBuf.Compare(wrBuf)==0);
1.210 + }
1.211 +
1.212 + test.Next(_L("Reduce size - (4K+127) bytes from middle"));
1.213 + TInt reduction=((KTestBufLen<<4)+((KTestBufLen>>1)-1));
1.214 + test(theInternalDrive.ReduceSize(KTestBufLen,reduction)==KErrNone);
1.215 + test(theInternalDrive.Caps(infoPckg)==KErrNone);
1.216 + cSize-=reduction;
1.217 + test(I64LOW(info.iSize)==(TUint)cSize);
1.218 + TBuf8<KTestBufLen> odBuf(KTestBufLen); // To verify new pattern
1.219 + for (i=0 ; i<(TUint)KTestBufLen ; i++)
1.220 + {
1.221 + if (i<=(KTestBufLen>>1))
1.222 + odBuf[i]=(TUint8)(i+((KTestBufLen>>1)-1));
1.223 + else
1.224 + odBuf[i]=(TUint8)(i-((KTestBufLen>>1)+1));
1.225 + }
1.226 + for (i=0,j=1;i<cSize;i+=len,j++)
1.227 + {
1.228 + len=Min(KTestBufLen,(cSize-i));
1.229 + rdBuf.Fill(0,len);
1.230 + test(theInternalDrive.Read(i,len,&rdBuf,msgHandle,0)==KErrNone);
1.231 + if (j==2)
1.232 + j+=17;
1.233 + if (j==1)
1.234 + {
1.235 + wrBuf[0]=(TUint8)j;
1.236 + wrBuf.SetLength(len);
1.237 + test(rdBuf.Compare(wrBuf)==0);
1.238 + }
1.239 + else
1.240 + {
1.241 + odBuf.SetLength(KTestBufLen);
1.242 + odBuf[((KTestBufLen>>1)+1)]=(TUint8)j;
1.243 + odBuf.SetLength(len);
1.244 + test(rdBuf.Compare(odBuf)==0);
1.245 + }
1.246 + }
1.247 +
1.248 + test.Next(_L("Reduce size - (8K-1) bytes from end"));
1.249 + reduction=((KTestBufLen<<5)-1);
1.250 + test(theInternalDrive.ReduceSize((cSize-reduction),reduction)==KErrNone);
1.251 + test(theInternalDrive.Caps(infoPckg)==KErrNone);
1.252 + cSize-=reduction;
1.253 + test(info.iSize==cSize);
1.254 + for (i=0,j=1;i<cSize;i+=len,j++)
1.255 + {
1.256 + len=Min(KTestBufLen,(cSize-i));
1.257 + rdBuf.Fill(0,len);
1.258 + test(theInternalDrive.Read(i,len,&rdBuf,msgHandle,0)==KErrNone);
1.259 + if (j==2)
1.260 + j+=17;
1.261 + if (j==1)
1.262 + {
1.263 + wrBuf[0]=(TUint8)j;
1.264 + wrBuf.SetLength(len);
1.265 + test(rdBuf.Compare(wrBuf)==0);
1.266 + }
1.267 + else
1.268 + {
1.269 + odBuf.SetLength(KTestBufLen);
1.270 + odBuf[((KTestBufLen>>1)+1)]=(TUint8)j;
1.271 + odBuf.SetLength(len);
1.272 + test(rdBuf.Compare(odBuf)==0);
1.273 + }
1.274 + }
1.275 +
1.276 + test.Next(_L("Format"));
1.277 + wrBuf.Fill(0,KTestBufLen);
1.278 + TFormatInfo fi;
1.279 + TInt ret;
1.280 + while((ret=theInternalDrive.Format(fi))!=KErrEof)
1.281 + test(ret==KErrNone);
1.282 + for (i=0;i<cSize;i+=len)
1.283 + {
1.284 + len=Min(KTestBufLen,(cSize-i));
1.285 + rdBuf.Fill(0xAA,len);
1.286 + test(theInternalDrive.Read(i,len,&rdBuf,msgHandle,0)==KErrNone);
1.287 + wrBuf.SetLength(len);
1.288 + test(rdBuf.Compare(wrBuf)==0);
1.289 + }
1.290 +
1.291 + test.Next(_L("Restore original size"));
1.292 + TInt sizeDif=cSize-saveSize;
1.293 + if (sizeDif>0)
1.294 + test(theInternalDrive.ReduceSize(0,sizeDif)==KErrNone);
1.295 + else
1.296 + test(theInternalDrive.Enlarge(sizeDif*-1)==KErrNone);
1.297 +
1.298 + test.Next(_L("Disconnect from internal drive"));
1.299 + theInternalDrive.Disconnect();
1.300 +
1.301 + RFs fs;
1.302 + test(fs.Connect()==KErrNone);
1.303 + for(drive=25 ; drive>=0; --drive)
1.304 + {
1.305 + TDriveInfo info;
1.306 + if(fs.Drive(info,drive)==KErrNone)
1.307 + if(info.iType==EMediaRam)
1.308 + {
1.309 + TBuf<256> text;
1.310 + text.Append(_L("Formatting drive "));
1.311 + text.Append(TText(drive+'A'));
1.312 + text.Append(_L(": ..."));
1.313 + test.Next(text);
1.314 + Format(drive,fs);
1.315 + break;
1.316 + }
1.317 + }
1.318 +
1.319 + test.End();
1.320 +
1.321 +#endif // x86
1.322 + return(0);
1.323 + }
1.324 +