0
|
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".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
// e32test\pccd\t_meddrv.cpp
|
|
15 |
// General media driver tests
|
|
16 |
//
|
|
17 |
//
|
|
18 |
|
|
19 |
#include <e32base.h>
|
|
20 |
#include <e32base_private.h>
|
|
21 |
#include <e32test.h>
|
|
22 |
#include <e32svr.h>
|
|
23 |
#include <e32hal.h>
|
|
24 |
#include <e32uid.h>
|
|
25 |
const TInt KHeapSize=0x4000;
|
|
26 |
const TInt KTestDriverMediaSize=0x1000; // 4K
|
|
27 |
const TInt KShortBufferSize=0x100;
|
|
28 |
|
|
29 |
#define MEDDRV_ATA_NAME _L("MEDATA")
|
|
30 |
#define MEDDRV_SINGLE_REQ_NAME _L("MEDT1")
|
|
31 |
#define MEDDRV_SIMULTANEOUS_REQ_NAME _L("MEDT2")
|
|
32 |
|
|
33 |
LOCAL_D RTest test(_L("T_MEDDRV"));
|
|
34 |
LOCAL_D TInt TheDriveNumber=3;
|
|
35 |
|
|
36 |
|
|
37 |
LOCAL_C TInt formatThread(TAny*)
|
|
38 |
{
|
|
39 |
|
|
40 |
TBusLocalDrive anotherDrive;
|
|
41 |
RTest ftest(_L("Formatting thread"));
|
|
42 |
ftest.Title();
|
|
43 |
|
|
44 |
ftest.Start(_L("Connect to local drive"));
|
|
45 |
TBool changeFlag=EFalse;
|
|
46 |
ftest(anotherDrive.Connect(TheDriveNumber,changeFlag)==KErrNone);
|
|
47 |
|
|
48 |
ftest.Next(_L("Format disk"));
|
|
49 |
ftest(anotherDrive.Format(0,KTestDriverMediaSize)==KErrNone);
|
|
50 |
anotherDrive.Disconnect();
|
|
51 |
|
|
52 |
ftest.End();
|
|
53 |
return(KErrNone);
|
|
54 |
}
|
|
55 |
|
|
56 |
GLDEF_C TInt E32Main()
|
|
57 |
{
|
|
58 |
TBuf<64> b;
|
|
59 |
TInt r;
|
|
60 |
TInt i;
|
|
61 |
|
|
62 |
test.Title();
|
|
63 |
test.Start(_L("Check loader running"));
|
|
64 |
|
|
65 |
#if !defined (__WINS__)
|
|
66 |
test.Next(_L("Read drive information"));
|
|
67 |
TDriveInfoV1Buf dinfo;
|
|
68 |
r=UserHal::DriveInfo(dinfo);
|
|
69 |
test(r==KErrNone);
|
|
70 |
if (dinfo().iTotalSockets==2)
|
|
71 |
TheDriveNumber=3;
|
|
72 |
else if (dinfo().iTotalSockets==1)
|
|
73 |
TheDriveNumber=2;
|
|
74 |
else
|
|
75 |
{
|
|
76 |
test.Printf(_L("Test not supported on this platform"));
|
|
77 |
test.End();
|
|
78 |
return(0);
|
|
79 |
}
|
|
80 |
#else
|
|
81 |
TheDriveNumber=3;
|
|
82 |
#endif
|
|
83 |
|
|
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.*"));
|
|
91 |
TFullName findResult;
|
|
92 |
r=findMediaDrv.Next(findResult);
|
|
93 |
while (r==KErrNone)
|
|
94 |
{
|
|
95 |
test.Printf(_L(" %S\n\r"),&findResult);
|
|
96 |
r=findMediaDrv.Next(findResult);
|
|
97 |
}
|
|
98 |
|
|
99 |
b.Format(_L("Connect to local drive %d"),TheDriveNumber);
|
|
100 |
test.Next(b);
|
|
101 |
TBusLocalDrive theDrive;
|
|
102 |
TBool changeFlag=EFalse;
|
|
103 |
test(theDrive.Connect(TheDriveNumber,changeFlag)==KErrNone);
|
|
104 |
|
|
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);
|
|
113 |
|
|
114 |
test.Next(_L("Local drive: Write/Read"));
|
|
115 |
TInt len;
|
|
116 |
TBuf8<KShortBufferSize> rdBuf,wrBuf;
|
|
117 |
wrBuf.SetLength(KShortBufferSize);
|
|
118 |
for (i=0;i<KShortBufferSize;i++)
|
|
119 |
wrBuf[i]=(TUint8)i;
|
|
120 |
for (i=0;i<KTestDriverMediaSize;i+=len)
|
|
121 |
{
|
|
122 |
len=Min(KShortBufferSize,(KTestDriverMediaSize-i));
|
|
123 |
wrBuf.SetLength(len);
|
|
124 |
test(theDrive.Write(i,wrBuf)==KErrNone);
|
|
125 |
}
|
|
126 |
for (i=0;i<KTestDriverMediaSize;i+=len)
|
|
127 |
{
|
|
128 |
len=Min(KShortBufferSize,(KTestDriverMediaSize-i));
|
|
129 |
rdBuf.Fill(0,len);
|
|
130 |
test(theDrive.Read(i,len,rdBuf)==KErrNone);
|
|
131 |
wrBuf.SetLength(len);
|
|
132 |
test(rdBuf.Compare(wrBuf)==0);
|
|
133 |
}
|
|
134 |
|
|
135 |
test.Next(_L("Start 2nd thread to format drive"));
|
|
136 |
RThread thread;
|
|
137 |
TRequestStatus stat;
|
|
138 |
test(thread.Create(_L("Thread"),formatThread,KDefaultStackSize,KHeapSize,KHeapSize,NULL)==KErrNone);
|
|
139 |
thread.Logon(stat);
|
|
140 |
thread.Resume();
|
|
141 |
|
|
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);
|
|
148 |
|
|
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)
|
|
155 |
{
|
|
156 |
len=Min(KShortBufferSize,(KTestDriverMediaSize-i));
|
|
157 |
rdBuf.Fill(0,len);
|
|
158 |
test(theDrive.Read(i,len,rdBuf)==KErrNone);
|
|
159 |
wrBuf.SetLength(len);
|
|
160 |
test(rdBuf.Compare(wrBuf)==0);
|
|
161 |
}
|
|
162 |
|
|
163 |
test.Next(_L("Load 2nd Media Driver"));
|
|
164 |
r=User::FreePhysicalDevice(_L("Media.Tst1"));
|
|
165 |
test(r==KErrNone);
|
|
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);
|
|
171 |
while (r==KErrNone)
|
|
172 |
{
|
|
173 |
test.Printf(_L(" %S\n\r"),&findResult);
|
|
174 |
r=findMediaDrv.Next(findResult);
|
|
175 |
}
|
|
176 |
|
|
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);
|
|
184 |
|
|
185 |
test.Next(_L("Local drive: Write/Read"));
|
|
186 |
wrBuf.SetLength(KShortBufferSize);
|
|
187 |
for (i=0;i<KShortBufferSize;i++)
|
|
188 |
wrBuf[i]=(TUint8)i;
|
|
189 |
for (i=0;i<KTestDriverMediaSize;i+=len)
|
|
190 |
{
|
|
191 |
len=Min(KShortBufferSize,(KTestDriverMediaSize-i));
|
|
192 |
wrBuf.SetLength(len);
|
|
193 |
test(theDrive.Write(i,wrBuf)==KErrNone);
|
|
194 |
}
|
|
195 |
for (i=0;i<KTestDriverMediaSize;i+=len)
|
|
196 |
{
|
|
197 |
len=Min(KShortBufferSize,(KTestDriverMediaSize-i));
|
|
198 |
rdBuf.Fill(0,len);
|
|
199 |
test(theDrive.Read(i,len,rdBuf)==KErrNone);
|
|
200 |
wrBuf.SetLength(len);
|
|
201 |
test(rdBuf.Compare(wrBuf)==0);
|
|
202 |
}
|
|
203 |
|
|
204 |
test.Next(_L("Start 2nd thread again to format drive"));
|
|
205 |
test(thread.Create(_L("Thread"),formatThread,KDefaultStackSize,KHeapSize,KHeapSize,NULL)==KErrNone);
|
|
206 |
thread.Logon(stat);
|
|
207 |
thread.Resume();
|
|
208 |
|
|
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);
|
|
215 |
|
|
216 |
for (i=0;i<KShortBufferSize;i++)
|
|
217 |
wrBuf[i]=(TUint8)i;
|
|
218 |
test(theDrive.Write(0,wrBuf)==KErrNone);
|
|
219 |
test(theDrive.Read(0,KShortBufferSize,rdBuf)==KErrNone);
|
|
220 |
test(rdBuf.Compare(wrBuf)==0);
|
|
221 |
|
|
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)
|
|
228 |
{
|
|
229 |
len=Min(KShortBufferSize,(KTestDriverMediaSize-i));
|
|
230 |
rdBuf.Fill(0,len);
|
|
231 |
test(theDrive.Read(i,len,rdBuf)==KErrNone);
|
|
232 |
wrBuf.SetLength(len);
|
|
233 |
test(rdBuf.Compare(wrBuf)==0);
|
|
234 |
}
|
|
235 |
|
|
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
|
|
241 |
|
|
242 |
theDrive.Disconnect();
|
|
243 |
test.End();
|
|
244 |
return(0);
|
|
245 |
}
|
|
246 |
|