1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/pccd/t_crrdrv.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,313 @@
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_crrdrv.cpp
1.18 +// Test the Compact Rom (Programmable) card media driver
1.19 +//
1.20 +//
1.21 +
1.22 +#include <e32test.h>
1.23 +#include <e32svr.h>
1.24 +#include <e32uid.h>
1.25 +#define TWOMEG
1.26 +
1.27 +LOCAL_D RTest test(_L("T_CRRDRV"));
1.28 +
1.29 +#if defined (__MARM__)
1.30 +
1.31 +const TInt KTestBufLen=0x100;
1.32 +
1.33 +#define PDD_NAME _L("MEDCRR")
1.34 +const TInt KDriveNumber=1; // D:
1.35 +#if defined (TWOMEG)
1.36 +const TInt KMaxDriveLen=0x00200000; // 2M
1.37 +#else
1.38 +const TInt KMaxDriveLen=0x00600000; // 6M
1.39 +#endif
1.40 +const TUint16 KMagicSum=0x1234;
1.41 +const TInt KCRomPrivateAreaLen=0x800; // 1st 2K of CRom contains CIS
1.42 +
1.43 +
1.44 +const TInt KCRomCisDataLength=0xD0;
1.45 +
1.46 +LOCAL_D TBuf8<KTestBufLen> wrBuf,rdBuf;
1.47 +#if defined (TWOMEG)
1.48 +LOCAL_D const TText8 CompactRomCisData[KCRomCisDataLength]={
1.49 + 0x01,0xff,0x03,0xff,0x1c,0xff,0x01,0xff,0xff,0xff,0x1c,0xff,0x04,0xff,0x02,0xff,
1.50 + 0x1b,0xff,0x01,0xff,0xff,0xff,0x20,0xff,0x04,0xff,0x00,0xff,0x00,0xff,0x00,0xff,
1.51 + 0x00,0xff,0x15,0xff,0x24,0xff,0x05,0xff,0x00,0xff,0x50,0xff,0x73,0xff,0x69,0xff,
1.52 + 0x6f,0xff,0x6e,0xff,0x20,0xff,0x50,0xff,0x4c,0xff,0x43,0xff,0x00,0xff,0x43,0xff,
1.53 + 0x6f,0xff,0x6d,0xff,0x70,0xff,0x61,0xff,0x63,0xff,0x74,0xff,0x20,0xff,0x52,0xff,
1.54 + 0x6f,0xff,0x6d,0xff,0x20,0xff,0x43,0xff,0x61,0xff,0x72,0xff,0x64,0xff,0x00,0xff,
1.55 + 0x56,0xff,0x30,0xff,0x2e,0xff,0x30,0xff,0x30,0xff,0x00,0xff,0xff,0xff,0x80,0xff,
1.56 + 0x03,0xff,0x58,0xff,0x06,0xff,0xff,0xff,0x21,0xff,0x02,0xff,0x01,0xff,0x00,0xff,
1.57 + 0x40,0xff,0x0b,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x08,0xff,0x00,0xff,0x00,0xff,
1.58 + 0x00,0xff,0x00,0xff,0x01,0xff,0x00,0xff,0x00,0xff,0x41,0xff,0x0a,0xff,0x01,0xff,
1.59 + 0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0xf8,0xff,0x1f,0xff,
1.60 + 0x00,0xff,0x14,0xff,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1.61 + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
1.62 + };
1.63 +#else
1.64 +LOCAL_D const TText8 CompactRomCisData[KCRomCisDataLength]={
1.65 + 0x01,0xff,0x03,0xff,0x1c,0xff,0x01,0xff,0xff,0xff,0x1c,0xff,0x04,0xff,0x02,0xff,
1.66 + 0x1b,0xff,0x01,0xff,0xff,0xff,0x20,0xff,0x04,0xff,0x00,0xff,0x00,0xff,0x00,0xff,
1.67 + 0x00,0xff,0x15,0xff,0x24,0xff,0x05,0xff,0x00,0xff,0x50,0xff,0x73,0xff,0x69,0xff,
1.68 + 0x6f,0xff,0x6e,0xff,0x20,0xff,0x50,0xff,0x4c,0xff,0x43,0xff,0x00,0xff,0x43,0xff,
1.69 + 0x6f,0xff,0x6d,0xff,0x70,0xff,0x61,0xff,0x63,0xff,0x74,0xff,0x20,0xff,0x52,0xff,
1.70 + 0x6f,0xff,0x6d,0xff,0x20,0xff,0x43,0xff,0x61,0xff,0x72,0xff,0x64,0xff,0x00,0xff,
1.71 + 0x56,0xff,0x30,0xff,0x2e,0xff,0x30,0xff,0x30,0xff,0x00,0xff,0xff,0xff,0x80,0xff,
1.72 + 0x0b,0xff,0x58,0xff,0x06,0xff,0x08,0xff,0x76,0xff,0x58,0xff,0x06,0xff,0x08,0xff,
1.73 + 0x76,0xff,0x58,0xff,0x06,0xff,0xff,0xff,0x21,0xff,0x02,0xff,0x01,0xff,0x00,0xff,
1.74 + 0x40,0xff,0x0b,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x08,0xff,0x00,0xff,0x00,0xff,
1.75 + 0x00,0xff,0x00,0xff,0x01,0xff,0x00,0xff,0x00,0xff,0x41,0xff,0x0a,0xff,0x01,0xff,
1.76 + 0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0xf8,0xff,0x5f,0xff,
1.77 + 0x00,0xff,0x14,0xff,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
1.78 + };
1.79 +#endif
1.80 +
1.81 +/* A sample multifunction CIS to test out tuple parsing by blowing onto CRom card.
1.82 +const TInt KMfcCisDataLen=0x180;
1.83 +LOCAL_D const TText8 MfcCisData[KMfcCisDataLen]={
1.84 + 0x13,0xff,0x03,0xff,0x43,0xff,0x49,0xff,0x53,0xff,0x06,0xff,0x10,0xff,0x03,0xff,
1.85 + 0x00,0xff,0x30,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x60,0xff,0x00,0xff,
1.86 + 0x00,0xff,0x00,0xff,0x00,0xff,0x90,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0xff,0xff,
1.87 + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1.88 + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1.89 + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1.90 + 0x01,0xff,0x03,0xff,0xda,0xff,0x00,0xff,0xff,0xff,0x1c,0xff,0x04,0xff,0x02,0xff,
1.91 + 0xda,0xff,0x00,0xff,0xff,0xff,0x21,0xff,0x02,0xff,0x02,0xff,0x00,0xff,0x1a,0xff,
1.92 + 0x05,0xff,0x01,0xff,0x01,0xff,0x00,0xff,0x02,0xff,0x0f,0xff,0x1b,0xff,0x07,0xff,
1.93 + 0xc1,0xff,0x41,0xff,0x09,0xff,0x01,0xff,0xb5,0xff,0x1e,0xff,0x49,0xff,0x14,0xff,
1.94 + 0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1.95 + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1.96 + 0x01,0xff,0x03,0xff,0xda,0xff,0x00,0xff,0xff,0xff,0x1c,0xff,0x04,0xff,0x02,0xff,
1.97 + 0xda,0xff,0x00,0xff,0xff,0xff,0x21,0xff,0x02,0xff,0x06,0xff,0x00,0xff,0x1a,0xff,
1.98 + 0x05,0xff,0x01,0xff,0x02,0xff,0x00,0xff,0x04,0xff,0x0f,0xff,0x1b,0xff,0x06,0xff,
1.99 + 0xc2,0xff,0x41,0xff,0x09,0xff,0x01,0xff,0x55,0xff,0x49,0xff,0x14,0xff,0x00,0xff,
1.100 + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1.101 + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1.102 + 0x01,0xff,0x03,0xff,0xda,0xff,0x00,0xff,0xff,0xff,0x1c,0xff,0x04,0xff,0x02,0xff,
1.103 + 0xda,0xff,0x00,0xff,0xff,0xff,0x21,0xff,0x02,0xff,0x03,0xff,0x00,0xff,0x1a,0xff,
1.104 + 0x05,0xff,0x01,0xff,0x03,0xff,0x00,0xff,0x06,0xff,0x0f,0xff,0x1b,0xff,0x06,0xff,
1.105 + 0xc3,0xff,0x41,0xff,0x09,0xff,0x01,0xff,0x55,0xff,0x49,0xff,0x14,0xff,0x00,0xff,
1.106 + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1.107 + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
1.108 + }; */
1.109 +
1.110 +
1.111 +LOCAL_C void ProgressBar(TInt aPos,TInt anEndPos,TInt anXPos)
1.112 +//
1.113 +// Display progress of local drive operation on screen (1-16 dots)
1.114 +//
1.115 + {
1.116 + static TInt prev;
1.117 + TInt curr;
1.118 + if ((curr=(aPos-1)/(anEndPos>>4))>prev)
1.119 + { // Update progress bar
1.120 + test.Console()->SetPos(anXPos);
1.121 + for (TInt i=curr;i>=0;i--)
1.122 + test.Printf(_L("."));
1.123 + }
1.124 + prev=curr;
1.125 + }
1.126 +
1.127 +GLDEF_C TInt E32Main()
1.128 + {
1.129 + TInt i;
1.130 + TBuf<32> b;
1.131 +
1.132 + test.Title();
1.133 +
1.134 +// UserSvr::ForceRemountMedia(ERemovableMedia0); // Generate media change (in case normal CROM driver open on target).
1.135 + User::After(300000); // Allow 0.3s for controller to detect door closed.
1.136 +
1.137 + test.Start(_L("Load CROM(repro) Media Driver"));
1.138 + TInt r=User::LoadPhysicalDevice(PDD_NAME);
1.139 + test(r==KErrNone||r==KErrAlreadyExists);
1.140 +
1.141 + b.Format(_L("Connect to local drive (%c:)"),KDriveNumber+'C');
1.142 + test.Next(b);
1.143 + TBusLocalDrive theCRomDrive;
1.144 + TBool changeFlag=FALSE;
1.145 + test(theCRomDrive.Connect(KDriveNumber,changeFlag)==KErrNone);
1.146 +
1.147 + test.Next(_L("CROM drive: capabilities"));
1.148 +// UserSvr::ForceRemountMedia(ERemovableMedia0); // Generate media change (in case normal CROM driver open on target).
1.149 + User::After(300000); // Allow 0.3s for controller to detect door closed.
1.150 + TLocalDriveCapsV2Buf info;
1.151 + test(theCRomDrive.Caps(info)==KErrNone);
1.152 + test(info().iSize==(TInt64)KMaxDriveLen);
1.153 + test(info().iType==EMediaFlash);
1.154 + test(info().iConnectionBusType==EConnectionBusInternal);
1.155 + test(info().iDriveAtt==(KDriveAttLocal|KDriveAttRemovable));
1.156 + test(info().iMediaAtt==KMediaAttFormattable);
1.157 + test(info().iFileSystemId==KDriveFileSysFAT);
1.158 +
1.159 + test.Next(_L("CROM drive: format"));
1.160 + TFormatInfo fi;
1.161 + test.Printf(_L("Formatting "));
1.162 + TInt ret;
1.163 + while((ret=theCRomDrive.Format(fi))!=KErrEof)
1.164 + {
1.165 + ProgressBar((fi.i512ByteSectorsFormatted<<9),KMaxDriveLen,11);
1.166 + test(ret==KErrNone);
1.167 + }
1.168 + test.Printf(_L("\r\nReading "));
1.169 + TInt len;
1.170 + TInt msgHandle = KLocalMessageHandle;
1.171 + for (i=0;i<KMaxDriveLen;i+=len)
1.172 + {
1.173 + ProgressBar(i,KMaxDriveLen,11);
1.174 + len=Min(KTestBufLen,(KMaxDriveLen-i));
1.175 + rdBuf.Fill(0x55,len); // Sets length too
1.176 + test(theCRomDrive.Read(i,len,&rdBuf,msgHandle,0)==KErrNone);
1.177 + wrBuf.Fill(0xFF,len); // Sets length too
1.178 + if ((ret=rdBuf.Compare(wrBuf))!=0)
1.179 + {
1.180 + test.Printf(_L(" (C:%d@%xH)\r\n"),ret,i);
1.181 + test(0);
1.182 + }
1.183 + }
1.184 + test.Printf(_L("\r\n"));
1.185 +
1.186 + wrBuf.SetLength(KTestBufLen);
1.187 + for (i=0;i<KTestBufLen;i++)
1.188 + wrBuf[i]=(TUint8)i;
1.189 +/*
1.190 + test.Next(_L("CROM drive: Write at start of Drive"));
1.191 + test(theCRomDrive.Write(0,KTestBufLen,&wrBuf,msgHandle,0)==KErrNone);
1.192 + rdBuf.Fill(0,KTestBufLen);
1.193 + test(theCRomDrive.Read(0,KTestBufLen,&rdBuf,msgHandle,0)==KErrNone);
1.194 + test(rdBuf.Compare(wrBuf)==0);
1.195 +
1.196 + test.Next(_L("CROM drive: Write at end of Drive"));
1.197 + test(theCRomDrive.Write(KMaxDriveLen-KTestBufLen,KTestBufLen,&wrBuf,msgHandle,0)==KErrNone);
1.198 + rdBuf.Fill(0,KTestBufLen);
1.199 + test(theCRomDrive.Read(KMaxDriveLen-KTestBufLen,KTestBufLen,&rdBuf,msgHandle,0)==KErrNone);
1.200 + test(rdBuf.Compare(wrBuf)==0);
1.201 +
1.202 + test.Next(_L("CROM drive: Write across 64K block boundary"));
1.203 + test(theCRomDrive.Write((0x10000-(KTestBufLen>>1)),KTestBufLen,&wrBuf,msgHandle,0)==KErrNone);
1.204 + rdBuf.Fill(0,KTestBufLen);
1.205 + test(theCRomDrive.Read((0x10000-(KTestBufLen>>1)),KTestBufLen,&rdBuf,msgHandle,0)==KErrNone);
1.206 + test(rdBuf.Compare(wrBuf)==0);
1.207 +
1.208 + test.Next(_L("CROM drive: Write across 28F016 device boundary"));
1.209 + test(theCRomDrive.Write((0x200000-(KTestBufLen>>1)),KTestBufLen,&wrBuf,msgHandle,0)==KErrNone);
1.210 + rdBuf.Fill(0,KTestBufLen);
1.211 + test(theCRomDrive.Read((0x200000-(KTestBufLen>>1)),KTestBufLen,&rdBuf,msgHandle,0)==KErrNone);
1.212 + test(rdBuf.Compare(wrBuf)==0);
1.213 +*/
1.214 + test.Next(_L("CROM drive: Write/Read the entire disk"));
1.215 + TInt rdwrTestLen=(KTestBufLen-3); // Test it works off word boundary
1.216 + TUint *p=(TUint*)&wrBuf[0];
1.217 + TInt j;
1.218 + test.Printf(_L("Writing "));
1.219 + for (i=0,j=0;i<KMaxDriveLen;i+=len,j++)
1.220 + {
1.221 + ProgressBar(i,KMaxDriveLen,11);
1.222 + len=Min(rdwrTestLen,(KMaxDriveLen-i));
1.223 + (*p)=j;
1.224 + test(theCRomDrive.Write(i,len,&wrBuf,msgHandle,0)==KErrNone);
1.225 + }
1.226 + test.Printf(_L("\r\nReading "));
1.227 + for (i=0,j=0;i<KMaxDriveLen;i+=len,j++)
1.228 + {
1.229 + ProgressBar(i,KMaxDriveLen,11);
1.230 + len=Min(rdwrTestLen,(KMaxDriveLen-i));
1.231 + rdBuf.Fill(0,len);
1.232 + if ((ret=theCRomDrive.Read(i,len,&rdBuf,msgHandle,0))!=KErrNone)
1.233 + {
1.234 + test.Printf(_L(" (R:%d@%xH)\r\n"),ret,j);
1.235 + test(0);
1.236 + }
1.237 + (*p)=j;
1.238 + wrBuf.SetLength(len);
1.239 + if ((ret=rdBuf.Compare(wrBuf))!=0)
1.240 + {
1.241 + test.Printf(_L(" (C:%d@%xH)\r\n"),ret,j);
1.242 + test(0);
1.243 + }
1.244 + }
1.245 + test.Printf(_L("\r\n"));
1.246 +
1.247 + test.Next(_L("CROM drive: Re-format"));
1.248 + test.Printf(_L("Formatting "));
1.249 + while((ret=theCRomDrive.Format(fi))!=KErrEof)
1.250 + {
1.251 + ProgressBar((fi.i512ByteSectorsFormatted<<9),KMaxDriveLen,11);
1.252 + test(ret==KErrNone);
1.253 + }
1.254 + test.Printf(_L("\r\n"));
1.255 +
1.256 + test.Next(_L("CROM drive: Write CIS at start of Drive"));
1.257 + TPtrC8 buf(&CompactRomCisData[0],KCRomCisDataLength);
1.258 +// TPtrC8 buf(&MfcCisData[0],KMfcCisDataLen); // ???
1.259 + test(theCRomDrive.Write(0,buf)==KErrNone);
1.260 +
1.261 + rdBuf.Fill(0,KTestBufLen);
1.262 + test(theCRomDrive.Read(0,KCRomCisDataLength,rdBuf)==KErrNone);
1.263 + test(rdBuf.Compare(buf)==0);
1.264 +
1.265 + test.Next(_L("Calculating & writing checksum"));
1.266 + TUint16 checksum=0; // 16bit arithmetic
1.267 + test.Printf(_L("Reading"));
1.268 + for (i=0;i<KMaxDriveLen;i+=len)
1.269 + {
1.270 + ProgressBar(i,KMaxDriveLen,11);
1.271 + len=Min(KTestBufLen,(KMaxDriveLen-i));
1.272 + test(theCRomDrive.Read(i,len,rdBuf)==KErrNone);
1.273 + test((len%2)==0); // 16bit checksum - length must never be odd
1.274 + for (TInt j=0;j<len;j+=2)
1.275 + checksum+=*(TUint16*)(rdBuf.Ptr()+j);
1.276 + }
1.277 + checksum-=0xFFFF; // Subtract for checksum itself
1.278 + TUint16 adjust=KMagicSum-checksum;
1.279 + test.Printf(_L("\r\n (CS:%xH)\r\n"),adjust);
1.280 + TPtrC8 cs((TUint8*)&adjust,2);
1.281 + test(theCRomDrive.Write(KCRomPrivateAreaLen-2,cs)==KErrNone);
1.282 +
1.283 + test.Next(_L("CROM drive: Caps following media change"));
1.284 +// UserSvr::ForceRemountMedia(ERemovableMedia0); // Generate media change
1.285 + User::After(300000); // Allow 0.3s after power down for controller to detect door closed.
1.286 + test(changeFlag!=FALSE);
1.287 + test(theCRomDrive.Caps(info)==KErrNone);
1.288 + test(info().iSize==(TInt64)KMaxDriveLen);
1.289 + test(info().iType==EMediaFlash);
1.290 +
1.291 + b.Format(_L("Disconnect from local drive (%c:)"),KDriveNumber+'C');
1.292 + test.Next(b);
1.293 + theCRomDrive.Disconnect();
1.294 +
1.295 + TFindPhysicalDevice fDr;
1.296 + test.Next(_L("Unload CROM(prog) Media Driver"));
1.297 + TFullName drivName;
1.298 + fDr.Find(_L("Media.RomPrg"));
1.299 + test(fDr.Next(drivName)==KErrNone);
1.300 + test(User::FreePhysicalDevice(drivName)==KErrNone);
1.301 +// UserSvr::ForceRemountMedia(ERemovableMedia0); // Generate media change (allow normal CROM driver on next target access).
1.302 +
1.303 + test.End();
1.304 + return(0);
1.305 + }
1.306 +
1.307 +#else
1.308 +TInt E32Main()
1.309 + {
1.310 + test.Title();
1.311 + test.Start(_L("T_CRRDRV only runs under ARM build."));
1.312 + test.End();
1.313 + return(KErrNone);
1.314 + }
1.315 +#endif
1.316 +