Update contrib.
1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\pccd\t_meddrv.cpp
15 // General media driver tests
20 #include <e32base_private.h>
25 const TInt KHeapSize=0x4000;
26 const TInt KTestDriverMediaSize=0x1000; // 4K
27 const TInt KShortBufferSize=0x100;
29 #define MEDDRV_ATA_NAME _L("MEDATA")
30 #define MEDDRV_SINGLE_REQ_NAME _L("MEDT1")
31 #define MEDDRV_SIMULTANEOUS_REQ_NAME _L("MEDT2")
33 LOCAL_D RTest test(_L("T_MEDDRV"));
34 LOCAL_D TInt TheDriveNumber=3;
37 LOCAL_C TInt formatThread(TAny*)
40 TBusLocalDrive anotherDrive;
41 RTest ftest(_L("Formatting thread"));
44 ftest.Start(_L("Connect to local drive"));
45 TBool changeFlag=EFalse;
46 ftest(anotherDrive.Connect(TheDriveNumber,changeFlag)==KErrNone);
48 ftest.Next(_L("Format disk"));
49 ftest(anotherDrive.Format(0,KTestDriverMediaSize)==KErrNone);
50 anotherDrive.Disconnect();
56 GLDEF_C TInt E32Main()
63 test.Start(_L("Check loader running"));
65 #if !defined (__WINS__)
66 test.Next(_L("Read drive information"));
67 TDriveInfoV1Buf dinfo;
68 r=UserHal::DriveInfo(dinfo);
70 if (dinfo().iTotalSockets==2)
72 else if (dinfo().iTotalSockets==1)
76 test.Printf(_L("Test not supported on this platform"));
84 test.Next(_L("Load 1st Media Driver"));
85 r=User::LoadPhysicalDevice(MEDDRV_ATA_NAME);
86 test(r==KErrNone||r==KErrAlreadyExists);
87 r=User::LoadPhysicalDevice(MEDDRV_SINGLE_REQ_NAME);
88 test(r==KErrNone||r==KErrAlreadyExists);
89 test.Printf(_L("Media drivers installed:\n\r"));
90 TFindPhysicalDevice findMediaDrv(_L("Media.*"));
92 r=findMediaDrv.Next(findResult);
95 test.Printf(_L(" %S\n\r"),&findResult);
96 r=findMediaDrv.Next(findResult);
99 b.Format(_L("Connect to local drive %d"),TheDriveNumber);
101 TBusLocalDrive theDrive;
102 TBool changeFlag=EFalse;
103 test(theDrive.Connect(TheDriveNumber,changeFlag)==KErrNone);
105 test.Next(_L("Local drive: Capabilities"));
106 // Generate a media change to open the profiler media driver rather than the standard one
107 // UserSvr::ForceRemountMedia(ERemovableMedia0);
108 User::After(300000); // Wait 0.3Sec
109 TLocalDriveCapsV2Buf info;
110 test(theDrive.Caps(info)==KErrNone);
111 test(I64LOW(info().iSize)==(TUint)KTestDriverMediaSize);
112 test(info().iType==EMediaRam);
114 test.Next(_L("Local drive: Write/Read"));
116 TBuf8<KShortBufferSize> rdBuf,wrBuf;
117 wrBuf.SetLength(KShortBufferSize);
118 for (i=0;i<KShortBufferSize;i++)
120 for (i=0;i<KTestDriverMediaSize;i+=len)
122 len=Min(KShortBufferSize,(KTestDriverMediaSize-i));
123 wrBuf.SetLength(len);
124 test(theDrive.Write(i,wrBuf)==KErrNone);
126 for (i=0;i<KTestDriverMediaSize;i+=len)
128 len=Min(KShortBufferSize,(KTestDriverMediaSize-i));
130 test(theDrive.Read(i,len,rdBuf)==KErrNone);
131 wrBuf.SetLength(len);
132 test(rdBuf.Compare(wrBuf)==0);
135 test.Next(_L("Start 2nd thread to format drive"));
138 test(thread.Create(_L("Thread"),formatThread,KDefaultStackSize,KHeapSize,KHeapSize,NULL)==KErrNone);
142 test.Next(_L("Drive read/write during format"));
143 User::After(2000000); // Wait 2Secs for format to get going
144 rdBuf.SetLength(KShortBufferSize);
145 test(theDrive.Read(0,KShortBufferSize,rdBuf)==KErrInUse);
146 wrBuf.SetLength(KShortBufferSize);
147 test(theDrive.Write(0,wrBuf)==KErrInUse);
149 // Verify format unaffected
150 User::WaitForRequest(stat);
151 test(stat==KErrNone);
152 CLOSE_AND_WAIT(thread);
153 wrBuf.Fill(0xFF,KShortBufferSize);
154 for (i=0;i<KTestDriverMediaSize;i+=len)
156 len=Min(KShortBufferSize,(KTestDriverMediaSize-i));
158 test(theDrive.Read(i,len,rdBuf)==KErrNone);
159 wrBuf.SetLength(len);
160 test(rdBuf.Compare(wrBuf)==0);
163 test.Next(_L("Load 2nd Media Driver"));
164 r=User::FreePhysicalDevice(_L("Media.Tst1"));
166 r=User::LoadPhysicalDevice(MEDDRV_SIMULTANEOUS_REQ_NAME);
167 test(r==KErrNone||r==KErrAlreadyExists);
168 test.Printf(_L("Media drivers installed:\n\r"));
169 findMediaDrv.Find(_L("Media.*"));
170 r=findMediaDrv.Next(findResult);
173 test.Printf(_L(" %S\n\r"),&findResult);
174 r=findMediaDrv.Next(findResult);
177 test.Next(_L("Local drive: Capabilities"));
178 // Generate a media change to open the profiler media driver rather than the standard one
179 // UserSvr::ForceRemountMedia(ERemovableMedia0);
180 User::After(300000); // Wait 0.3Sec
181 test(theDrive.Caps(info)==KErrNone);
182 test(I64LOW(info().iSize)==(TUint)KTestDriverMediaSize);
183 test(info().iType==EMediaFlash);
185 test.Next(_L("Local drive: Write/Read"));
186 wrBuf.SetLength(KShortBufferSize);
187 for (i=0;i<KShortBufferSize;i++)
189 for (i=0;i<KTestDriverMediaSize;i+=len)
191 len=Min(KShortBufferSize,(KTestDriverMediaSize-i));
192 wrBuf.SetLength(len);
193 test(theDrive.Write(i,wrBuf)==KErrNone);
195 for (i=0;i<KTestDriverMediaSize;i+=len)
197 len=Min(KShortBufferSize,(KTestDriverMediaSize-i));
199 test(theDrive.Read(i,len,rdBuf)==KErrNone);
200 wrBuf.SetLength(len);
201 test(rdBuf.Compare(wrBuf)==0);
204 test.Next(_L("Start 2nd thread again to format drive"));
205 test(thread.Create(_L("Thread"),formatThread,KDefaultStackSize,KHeapSize,KHeapSize,NULL)==KErrNone);
209 test.Next(_L("Drive read/write during format"));
210 User::After(2000000); // Wait 2Secs for format to get going
211 rdBuf.SetLength(KShortBufferSize);
212 test(theDrive.Read(0,KShortBufferSize,rdBuf)==KErrNone);
213 wrBuf.Fill(0xFF,KShortBufferSize);
214 test(rdBuf.Compare(wrBuf)==0);
216 for (i=0;i<KShortBufferSize;i++)
218 test(theDrive.Write(0,wrBuf)==KErrNone);
219 test(theDrive.Read(0,KShortBufferSize,rdBuf)==KErrNone);
220 test(rdBuf.Compare(wrBuf)==0);
222 // Verify remaining part of format
223 User::WaitForRequest(stat);
224 test(stat==KErrNone);
225 CLOSE_AND_WAIT(thread);
226 wrBuf.Fill(0xFF,KShortBufferSize);
227 for (i=KShortBufferSize;i<KTestDriverMediaSize;i+=len)
229 len=Min(KShortBufferSize,(KTestDriverMediaSize-i));
231 test(theDrive.Read(i,len,rdBuf)==KErrNone);
232 wrBuf.SetLength(len);
233 test(rdBuf.Compare(wrBuf)==0);
236 test.Next(_L("Unload 2nd Media Driver"));
237 User::FreePhysicalDevice(_L("Media.Tst2"));
238 // Generate a media change to restore the standard one next mount
239 // UserSvr::ForceRemountMedia(ERemovableMedia0);
240 User::After(300000); // Wait 0.3Sec
242 theDrive.Disconnect();