os/kernelhwsrv/kerneltest/e32test/pccd/t_meddrv.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/pccd/t_meddrv.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,246 @@
     1.4 +// Copyright (c) 1998-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_meddrv.cpp
    1.18 +// General media driver tests
    1.19 +// 
    1.20 +//
    1.21 +
    1.22 +#include <e32base.h>
    1.23 +#include <e32base_private.h>
    1.24 +#include <e32test.h>
    1.25 +#include <e32svr.h>
    1.26 +#include <e32hal.h>
    1.27 +#include <e32uid.h>
    1.28 +const TInt KHeapSize=0x4000;
    1.29 +const TInt KTestDriverMediaSize=0x1000;	// 4K
    1.30 +const TInt KShortBufferSize=0x100;
    1.31 +
    1.32 +#define MEDDRV_ATA_NAME _L("MEDATA")
    1.33 +#define MEDDRV_SINGLE_REQ_NAME _L("MEDT1")
    1.34 +#define MEDDRV_SIMULTANEOUS_REQ_NAME _L("MEDT2")
    1.35 +
    1.36 +LOCAL_D RTest test(_L("T_MEDDRV"));
    1.37 +LOCAL_D TInt TheDriveNumber=3;	
    1.38 +
    1.39 +
    1.40 +LOCAL_C TInt formatThread(TAny*)
    1.41 +	{
    1.42 +
    1.43 +	TBusLocalDrive anotherDrive;
    1.44 +	RTest ftest(_L("Formatting thread"));
    1.45 +	ftest.Title();
    1.46 +
    1.47 +	ftest.Start(_L("Connect to local drive"));
    1.48 +	TBool changeFlag=EFalse;
    1.49 +	ftest(anotherDrive.Connect(TheDriveNumber,changeFlag)==KErrNone);
    1.50 +
    1.51 +	ftest.Next(_L("Format disk"));
    1.52 +	ftest(anotherDrive.Format(0,KTestDriverMediaSize)==KErrNone);
    1.53 +	anotherDrive.Disconnect();
    1.54 +
    1.55 +    ftest.End();
    1.56 +	return(KErrNone);
    1.57 +	}
    1.58 +
    1.59 +GLDEF_C TInt E32Main()
    1.60 +    {
    1.61 +	TBuf<64> b;
    1.62 +	TInt r;
    1.63 +	TInt i;
    1.64 +
    1.65 +	test.Title();
    1.66 +	test.Start(_L("Check loader running"));
    1.67 +
    1.68 +#if !defined (__WINS__)
    1.69 +    test.Next(_L("Read drive information"));
    1.70 +	TDriveInfoV1Buf dinfo;
    1.71 +	r=UserHal::DriveInfo(dinfo);
    1.72 +	test(r==KErrNone);
    1.73 +	if (dinfo().iTotalSockets==2)
    1.74 +        TheDriveNumber=3;
    1.75 +    else if (dinfo().iTotalSockets==1)
    1.76 +        TheDriveNumber=2;
    1.77 +    else
    1.78 +		{
    1.79 +		test.Printf(_L("Test not supported on this platform"));
    1.80 +		test.End();
    1.81 +		return(0);
    1.82 +		}
    1.83 +#else
    1.84 +    TheDriveNumber=3;
    1.85 +#endif
    1.86 +
    1.87 +	test.Next(_L("Load 1st Media Driver"));
    1.88 +	r=User::LoadPhysicalDevice(MEDDRV_ATA_NAME);
    1.89 +	test(r==KErrNone||r==KErrAlreadyExists);
    1.90 +	r=User::LoadPhysicalDevice(MEDDRV_SINGLE_REQ_NAME);
    1.91 +	test(r==KErrNone||r==KErrAlreadyExists);
    1.92 +	test.Printf(_L("Media drivers installed:\n\r"));
    1.93 +	TFindPhysicalDevice findMediaDrv(_L("Media.*"));
    1.94 +	TFullName findResult;
    1.95 +	r=findMediaDrv.Next(findResult);
    1.96 +	while (r==KErrNone)
    1.97 +		{
    1.98 +		test.Printf(_L("   %S\n\r"),&findResult);
    1.99 +		r=findMediaDrv.Next(findResult);
   1.100 +		}
   1.101 +
   1.102 +	b.Format(_L("Connect to local drive %d"),TheDriveNumber);
   1.103 +	test.Next(b);
   1.104 +	TBusLocalDrive theDrive;
   1.105 +	TBool changeFlag=EFalse;
   1.106 +	test(theDrive.Connect(TheDriveNumber,changeFlag)==KErrNone);
   1.107 +
   1.108 +	test.Next(_L("Local drive: Capabilities"));
   1.109 +	// Generate a media change to open the profiler media driver rather than the standard one
   1.110 +//	UserSvr::ForceRemountMedia(ERemovableMedia0);
   1.111 +	User::After(300000); // Wait 0.3Sec
   1.112 +	TLocalDriveCapsV2Buf info;
   1.113 +	test(theDrive.Caps(info)==KErrNone);
   1.114 +	test(I64LOW(info().iSize)==(TUint)KTestDriverMediaSize);
   1.115 +	test(info().iType==EMediaRam);
   1.116 +
   1.117 +	test.Next(_L("Local drive: Write/Read"));
   1.118 +	TInt len;
   1.119 +	TBuf8<KShortBufferSize> rdBuf,wrBuf;
   1.120 +	wrBuf.SetLength(KShortBufferSize);
   1.121 +	for (i=0;i<KShortBufferSize;i++)
   1.122 +		wrBuf[i]=(TUint8)i;
   1.123 +	for (i=0;i<KTestDriverMediaSize;i+=len)
   1.124 +		{
   1.125 +		len=Min(KShortBufferSize,(KTestDriverMediaSize-i));
   1.126 +		wrBuf.SetLength(len);
   1.127 +		test(theDrive.Write(i,wrBuf)==KErrNone);
   1.128 +		}
   1.129 +	for (i=0;i<KTestDriverMediaSize;i+=len)
   1.130 +		{
   1.131 +		len=Min(KShortBufferSize,(KTestDriverMediaSize-i));
   1.132 +		rdBuf.Fill(0,len);
   1.133 + 		test(theDrive.Read(i,len,rdBuf)==KErrNone);
   1.134 +		wrBuf.SetLength(len);
   1.135 +  	    test(rdBuf.Compare(wrBuf)==0);
   1.136 +		}
   1.137 +
   1.138 +	test.Next(_L("Start 2nd thread to format drive"));
   1.139 +	RThread thread;
   1.140 +	TRequestStatus stat;
   1.141 +	test(thread.Create(_L("Thread"),formatThread,KDefaultStackSize,KHeapSize,KHeapSize,NULL)==KErrNone);
   1.142 +	thread.Logon(stat);
   1.143 +	thread.Resume();
   1.144 +  
   1.145 +	test.Next(_L("Drive read/write during format"));
   1.146 +	User::After(2000000); // Wait 2Secs for format to get going
   1.147 +    rdBuf.SetLength(KShortBufferSize);
   1.148 + 	test(theDrive.Read(0,KShortBufferSize,rdBuf)==KErrInUse);
   1.149 +	wrBuf.SetLength(KShortBufferSize);
   1.150 +	test(theDrive.Write(0,wrBuf)==KErrInUse);
   1.151 +    
   1.152 +    // Verify format unaffected
   1.153 +    User::WaitForRequest(stat);
   1.154 +	test(stat==KErrNone);
   1.155 +	CLOSE_AND_WAIT(thread);
   1.156 +	wrBuf.Fill(0xFF,KShortBufferSize);
   1.157 +	for (i=0;i<KTestDriverMediaSize;i+=len)
   1.158 +		{
   1.159 +		len=Min(KShortBufferSize,(KTestDriverMediaSize-i));
   1.160 +		rdBuf.Fill(0,len);
   1.161 + 		test(theDrive.Read(i,len,rdBuf)==KErrNone);
   1.162 +		wrBuf.SetLength(len);
   1.163 +  	    test(rdBuf.Compare(wrBuf)==0);
   1.164 +		}
   1.165 +
   1.166 +	test.Next(_L("Load 2nd Media Driver"));
   1.167 +	r=User::FreePhysicalDevice(_L("Media.Tst1"));
   1.168 +	test(r==KErrNone);
   1.169 +	r=User::LoadPhysicalDevice(MEDDRV_SIMULTANEOUS_REQ_NAME);
   1.170 +	test(r==KErrNone||r==KErrAlreadyExists);
   1.171 +	test.Printf(_L("Media drivers installed:\n\r"));
   1.172 +	findMediaDrv.Find(_L("Media.*"));
   1.173 +	r=findMediaDrv.Next(findResult);
   1.174 +	while (r==KErrNone)
   1.175 +		{
   1.176 +		test.Printf(_L("   %S\n\r"),&findResult);
   1.177 +		r=findMediaDrv.Next(findResult);
   1.178 +		}
   1.179 +
   1.180 +	test.Next(_L("Local drive: Capabilities"));
   1.181 +	// Generate a media change to open the profiler media driver rather than the standard one
   1.182 +//	UserSvr::ForceRemountMedia(ERemovableMedia0);
   1.183 +	User::After(300000); // Wait 0.3Sec
   1.184 +	test(theDrive.Caps(info)==KErrNone);
   1.185 +	test(I64LOW(info().iSize)==(TUint)KTestDriverMediaSize);
   1.186 +	test(info().iType==EMediaFlash);
   1.187 +
   1.188 +	test.Next(_L("Local drive: Write/Read"));
   1.189 +	wrBuf.SetLength(KShortBufferSize);
   1.190 +	for (i=0;i<KShortBufferSize;i++)
   1.191 +		wrBuf[i]=(TUint8)i;
   1.192 +	for (i=0;i<KTestDriverMediaSize;i+=len)
   1.193 +		{
   1.194 +		len=Min(KShortBufferSize,(KTestDriverMediaSize-i));
   1.195 +		wrBuf.SetLength(len);
   1.196 +		test(theDrive.Write(i,wrBuf)==KErrNone);
   1.197 +		}
   1.198 +	for (i=0;i<KTestDriverMediaSize;i+=len)
   1.199 +		{
   1.200 +		len=Min(KShortBufferSize,(KTestDriverMediaSize-i));
   1.201 +		rdBuf.Fill(0,len);
   1.202 + 		test(theDrive.Read(i,len,rdBuf)==KErrNone);
   1.203 +		wrBuf.SetLength(len);
   1.204 +  	    test(rdBuf.Compare(wrBuf)==0);
   1.205 +		}
   1.206 +
   1.207 +	test.Next(_L("Start 2nd thread again to format drive"));
   1.208 +	test(thread.Create(_L("Thread"),formatThread,KDefaultStackSize,KHeapSize,KHeapSize,NULL)==KErrNone);
   1.209 +	thread.Logon(stat);
   1.210 +	thread.Resume();
   1.211 +  
   1.212 +	test.Next(_L("Drive read/write during format"));
   1.213 +	User::After(2000000); // Wait 2Secs for format to get going
   1.214 +    rdBuf.SetLength(KShortBufferSize);
   1.215 + 	test(theDrive.Read(0,KShortBufferSize,rdBuf)==KErrNone);
   1.216 +	wrBuf.Fill(0xFF,KShortBufferSize);
   1.217 +  	test(rdBuf.Compare(wrBuf)==0);
   1.218 +	
   1.219 +    for (i=0;i<KShortBufferSize;i++)
   1.220 +		wrBuf[i]=(TUint8)i;
   1.221 +	test(theDrive.Write(0,wrBuf)==KErrNone);
   1.222 + 	test(theDrive.Read(0,KShortBufferSize,rdBuf)==KErrNone);
   1.223 +  	test(rdBuf.Compare(wrBuf)==0);
   1.224 +    
   1.225 +    // Verify remaining part of format
   1.226 +    User::WaitForRequest(stat);
   1.227 +	test(stat==KErrNone);
   1.228 +	CLOSE_AND_WAIT(thread);
   1.229 +	wrBuf.Fill(0xFF,KShortBufferSize);
   1.230 +	for (i=KShortBufferSize;i<KTestDriverMediaSize;i+=len)
   1.231 +		{
   1.232 +		len=Min(KShortBufferSize,(KTestDriverMediaSize-i));
   1.233 +		rdBuf.Fill(0,len);
   1.234 + 		test(theDrive.Read(i,len,rdBuf)==KErrNone);
   1.235 +		wrBuf.SetLength(len);
   1.236 +  	    test(rdBuf.Compare(wrBuf)==0);
   1.237 +		}
   1.238 +
   1.239 +	test.Next(_L("Unload 2nd Media Driver"));
   1.240 +	User::FreePhysicalDevice(_L("Media.Tst2"));
   1.241 +	// Generate a media change to restore the standard one next mount
   1.242 +//	UserSvr::ForceRemountMedia(ERemovableMedia0);
   1.243 +	User::After(300000); // Wait 0.3Sec
   1.244 +
   1.245 +	theDrive.Disconnect();
   1.246 +	test.End();
   1.247 +	return(0);
   1.248 +	}
   1.249 +