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_pccdsr.cpp
|
|
15 |
// Stress test a single sector of Compact Flash card (ATA).
|
|
16 |
//
|
|
17 |
//
|
|
18 |
|
|
19 |
|
|
20 |
//#define USE_F32_ACCESS
|
|
21 |
#include <e32test.h>
|
|
22 |
#include <e32svr.h>
|
|
23 |
#include <e32hal.h>
|
|
24 |
#include <e32uid.h>
|
|
25 |
#if defined (USE_F32_ACCESS)
|
|
26 |
#include <f32fsys.h>
|
|
27 |
#include <f32file.h>
|
|
28 |
#endif
|
|
29 |
|
|
30 |
#define ATA_PDD_NAME _L("MEDATA")
|
|
31 |
|
|
32 |
const TInt KAtaSectorSize=512;
|
|
33 |
const TInt KMaxSectors=8;
|
|
34 |
const TInt KMaxRdWrBufLen=(KAtaSectorSize*KMaxSectors); // 4K
|
44
|
35 |
const TInt KHeapSize=0x4000;
|
0
|
36 |
const TInt KMaxErr=8;
|
|
37 |
|
|
38 |
#if defined (USE_F32_ACCESS)
|
|
39 |
GLDEF_D RFs TheFs;
|
|
40 |
#else
|
|
41 |
LOCAL_D TBusLocalDrive TheDrive;
|
|
42 |
LOCAL_D TBool ChangedFlag;
|
|
43 |
#endif
|
|
44 |
RTest test(_L("Local Drive Stress test"));
|
|
45 |
LOCAL_D TBuf8<KMaxRdWrBufLen> wrBufPat1,wrBufPat2,rdBuf;
|
|
46 |
|
|
47 |
enum TOper {ENone,EWrite,ERead,ECompare};
|
|
48 |
class TErrInfo
|
|
49 |
{
|
|
50 |
public:
|
|
51 |
TErrInfo();
|
|
52 |
public:
|
|
53 |
TInt iError;
|
|
54 |
TOper iOperation;
|
|
55 |
TInt iCycle;
|
|
56 |
};
|
|
57 |
|
|
58 |
class TResult
|
|
59 |
{
|
|
60 |
public:
|
|
61 |
TResult();
|
|
62 |
void Display(CConsoleBase *aConsole, TInt aCycles);
|
|
63 |
void Add(TInt anError,TOper anOperation,TInt aCycle);
|
|
64 |
public:
|
|
65 |
TInt iTotalErrs;
|
|
66 |
TErrInfo iFirstErr;
|
|
67 |
TErrInfo iLastErrs[KMaxErr];
|
|
68 |
TInt iNextFreeErr;
|
|
69 |
TBool iHadAnError;
|
|
70 |
};
|
|
71 |
|
|
72 |
|
|
73 |
LOCAL_C TUint OperationToChar(TOper anOperation)
|
|
74 |
//
|
|
75 |
// Convert operation enum to corresponding display character
|
|
76 |
//
|
|
77 |
{
|
|
78 |
|
|
79 |
switch(anOperation)
|
|
80 |
{
|
|
81 |
case EWrite:
|
|
82 |
return('W');
|
|
83 |
case ERead:
|
|
84 |
return('R');
|
|
85 |
case ECompare:
|
|
86 |
return('C');
|
|
87 |
default:
|
|
88 |
return('?');
|
|
89 |
}
|
|
90 |
}
|
|
91 |
|
|
92 |
TErrInfo::TErrInfo()
|
|
93 |
//
|
|
94 |
// Constructor
|
|
95 |
//
|
|
96 |
{
|
|
97 |
|
|
98 |
iError=KErrNone;
|
|
99 |
iOperation=ENone;
|
|
100 |
iCycle=0;
|
|
101 |
}
|
|
102 |
|
|
103 |
TResult::TResult()
|
|
104 |
//
|
|
105 |
// Constructor
|
|
106 |
//
|
|
107 |
{
|
|
108 |
|
|
109 |
iNextFreeErr=0;
|
|
110 |
iTotalErrs=0;
|
|
111 |
iHadAnError=EFalse;
|
|
112 |
}
|
|
113 |
|
|
114 |
void TResult::Display(CConsoleBase *aConsole, TInt aCycles)
|
|
115 |
//
|
|
116 |
// Display test results
|
|
117 |
//
|
|
118 |
{
|
|
119 |
|
|
120 |
TInt xStartPos=0;
|
|
121 |
TInt yStartPos=7;
|
|
122 |
|
|
123 |
aConsole->SetPos(xStartPos,yStartPos);
|
|
124 |
test.Printf(_L("CYCLES-> %07d ERRORS-> %d"),aCycles,iTotalErrs);
|
|
125 |
|
|
126 |
aConsole->SetPos(xStartPos,yStartPos+1);
|
|
127 |
test.Printf(_L("FIRST ERROR-> "));
|
|
128 |
if (iHadAnError)
|
|
129 |
test.Printf(_L("Error:%d Oper:%c Cycle:%07d"),iFirstErr.iError,OperationToChar(iFirstErr.iOperation),iFirstErr.iCycle);
|
|
130 |
|
|
131 |
aConsole->SetPos(xStartPos,yStartPos+2);
|
|
132 |
test.Printf(_L("LAST ERRORS->"));
|
|
133 |
if (iHadAnError)
|
|
134 |
{
|
|
135 |
TInt i;
|
|
136 |
aConsole->SetPos(xStartPos+3,yStartPos+3);
|
|
137 |
test.Printf(_L("Error: "));
|
|
138 |
for (i=0;(i<KMaxErr && iLastErrs[i].iOperation!=ENone);i++)
|
|
139 |
test.Printf(_L("% 7d,"),iLastErrs[i].iError);
|
|
140 |
|
|
141 |
aConsole->SetPos(xStartPos+3,yStartPos+4);
|
|
142 |
test.Printf(_L("Oper: "));
|
|
143 |
for (i=0;(i<KMaxErr && iLastErrs[i].iOperation!=ENone);i++)
|
|
144 |
test.Printf(_L(" %c,"),OperationToChar(iLastErrs[i].iOperation));
|
|
145 |
|
|
146 |
aConsole->SetPos(xStartPos+3,yStartPos+5);
|
|
147 |
test.Printf(_L("Cycle: "));
|
|
148 |
for (i=0;(i<KMaxErr && iLastErrs[i].iOperation!=ENone);i++)
|
|
149 |
test.Printf(_L("% 7d,"),iLastErrs[i].iCycle);
|
|
150 |
}
|
|
151 |
|
|
152 |
test.Printf(_L("\r\n"));
|
|
153 |
}
|
|
154 |
|
|
155 |
void TResult::Add(TInt anError,TOper anOperation,TInt aCycle)
|
|
156 |
//
|
|
157 |
// Add a test result
|
|
158 |
//
|
|
159 |
{
|
|
160 |
|
|
161 |
iTotalErrs++;
|
|
162 |
if (!iHadAnError)
|
|
163 |
{
|
|
164 |
iFirstErr.iError=anError;
|
|
165 |
iFirstErr.iOperation=anOperation;
|
|
166 |
iFirstErr.iCycle=aCycle;
|
|
167 |
iHadAnError=ETrue;
|
|
168 |
}
|
|
169 |
if (iNextFreeErr>=KMaxErr)
|
|
170 |
{
|
|
171 |
for (TInt i=0;i<(KMaxErr-1);i++)
|
|
172 |
iLastErrs[i]=iLastErrs[i+1];
|
|
173 |
iNextFreeErr=(KMaxErr-1);
|
|
174 |
}
|
|
175 |
iLastErrs[iNextFreeErr].iError=anError;
|
|
176 |
iLastErrs[iNextFreeErr].iOperation=anOperation;
|
|
177 |
iLastErrs[iNextFreeErr].iCycle=aCycle;
|
|
178 |
iNextFreeErr++;
|
|
179 |
}
|
|
180 |
|
|
181 |
GLDEF_C TInt E32Main()
|
|
182 |
{
|
|
183 |
TBuf<64> b;
|
|
184 |
|
|
185 |
test.Title();
|
|
186 |
TDriveInfoV1Buf diBuf;
|
|
187 |
UserHal::DriveInfo(diBuf);
|
|
188 |
TDriveInfoV1 &di=diBuf();
|
|
189 |
test.Printf(_L("Select Local Drive (C-%c): "),'C'+(di.iTotalSupportedDrives-1));
|
|
190 |
TChar c;
|
|
191 |
TInt drv;
|
|
192 |
FOREVER
|
|
193 |
{
|
|
194 |
c=(TUint)test.Getch();
|
|
195 |
c.UpperCase();
|
|
196 |
drv=((TUint)c)-'C';
|
|
197 |
if (drv>=0&&drv<di.iTotalSupportedDrives)
|
|
198 |
break;
|
|
199 |
}
|
|
200 |
test.Printf(_L("%c:\r\n"),'C'+drv);
|
|
201 |
|
|
202 |
TInt rdWrLen;
|
|
203 |
#if !defined (USE_F32_ACCESS)
|
|
204 |
test.Printf(_L("Select total sectors to write(1-8): "));
|
|
205 |
FOREVER
|
|
206 |
{
|
|
207 |
c=(TUint)test.Getch();
|
|
208 |
rdWrLen=((TUint)c)-'0';
|
|
209 |
if (rdWrLen>=1&&rdWrLen<=8)
|
|
210 |
break;
|
|
211 |
}
|
|
212 |
test.Printf(_L("%dSector(s)\r\n"),rdWrLen);
|
|
213 |
rdWrLen*=KAtaSectorSize;
|
|
214 |
#else
|
|
215 |
rdWrLen=(KAtaSectorSize*2)+1;
|
|
216 |
#endif
|
|
217 |
|
|
218 |
b.Format(_L("Init test on drive %c:"),'C'+drv);
|
|
219 |
test.Start(b);
|
|
220 |
|
|
221 |
TInt r;
|
|
222 |
#if defined (USE_F32_ACCESS)
|
|
223 |
r=TheFs.Connect();
|
|
224 |
test(r==KErrNone);
|
|
225 |
|
|
226 |
RFile f;
|
|
227 |
b.Format(_L("%c:\\TEMP.BIN"),'C'+drv);
|
|
228 |
r=f.Replace(TheFs,b,EFileShareAny|EFileStream|EFileWrite);
|
|
229 |
test(r==KErrNone);
|
|
230 |
b.Format(_L("Start testing (%c:\\TEMP.BIN):"),'C'+drv);
|
|
231 |
#else
|
|
232 |
r=User::LoadPhysicalDevice(ATA_PDD_NAME);
|
|
233 |
test(r==KErrNone || r==KErrAlreadyExists);
|
|
234 |
|
|
235 |
ChangedFlag=EFalse;
|
|
236 |
TheDrive.Connect(drv,ChangedFlag);
|
|
237 |
|
|
238 |
TLocalDriveCapsV2Buf info;
|
|
239 |
test(TheDrive.Caps(info)==KErrNone);
|
|
240 |
test(info().iType==EMediaHardDisk);
|
|
241 |
TInt trgPos=I64LOW(info().iSize)-rdWrLen; // Hammer the very end of the disk
|
|
242 |
b.Format(_L("Start testing (sector %xH):"),trgPos/KAtaSectorSize);
|
|
243 |
#endif
|
|
244 |
|
|
245 |
test.Next(b);
|
|
246 |
wrBufPat1.SetLength(rdWrLen);
|
|
247 |
TInt j;
|
|
248 |
for (j=0;j<rdWrLen;j++)
|
|
249 |
wrBufPat1[j]=(TUint8)j;
|
|
250 |
wrBufPat2.SetLength(rdWrLen);
|
|
251 |
for (j=0;j<rdWrLen;j++)
|
|
252 |
wrBufPat2[j]=(TUint8)((rdWrLen-1)-j);
|
|
253 |
|
|
254 |
TInt cycles=0;
|
|
255 |
TResult results;
|
|
256 |
TBool toggleTest=EFalse;
|
|
257 |
|
|
258 |
TRequestStatus kStat;
|
|
259 |
test.Console()->Read(kStat);
|
|
260 |
FOREVER
|
|
261 |
{
|
|
262 |
if ((cycles%10)==0)
|
|
263 |
results.Display(test.Console(),cycles);
|
|
264 |
|
|
265 |
TInt res;
|
|
266 |
#if defined (USE_F32_ACCESS)
|
|
267 |
TInt len=(toggleTest)?rdWrLen:1;
|
|
268 |
|
|
269 |
wrBufPat1.SetLength(len);
|
|
270 |
if ((res=f.SetSize(len))==KErrNone)
|
|
271 |
res=f.Write(0,wrBufPat1); // Write test (Pos=0)
|
|
272 |
if (res!=KErrNone)
|
|
273 |
results.Add(res,EWrite,cycles);
|
|
274 |
|
|
275 |
// Read test
|
|
276 |
rdBuf.Fill(0,len);
|
|
277 |
res=f.Read(0,rdBuf,len);
|
|
278 |
if (res!=KErrNone)
|
|
279 |
results.Add(res,ERead,cycles);
|
|
280 |
if (rdBuf.Compare(wrBufPat1)!=0)
|
|
281 |
results.Add(0,ECompare,cycles);
|
|
282 |
#else
|
|
283 |
TDes8* wrBuf=(toggleTest)?&wrBufPat2:&wrBufPat1; // Change pattern written
|
|
284 |
|
|
285 |
res=TheDrive.Write(trgPos,*wrBuf); // Write test
|
|
286 |
if (res!=KErrNone)
|
|
287 |
results.Add(res,EWrite,cycles);
|
|
288 |
|
|
289 |
rdBuf.Fill(0,rdWrLen);
|
|
290 |
res=TheDrive.Read(trgPos,rdWrLen,rdBuf); // Read test
|
|
291 |
if (res!=KErrNone)
|
|
292 |
results.Add(res,ERead,cycles);
|
|
293 |
if (rdBuf.Compare(*wrBuf)!=0)
|
|
294 |
results.Add(0,ECompare,cycles);
|
|
295 |
#endif
|
|
296 |
cycles++;
|
|
297 |
toggleTest^=0x01;
|
|
298 |
|
|
299 |
if (kStat!=KRequestPending)
|
|
300 |
{
|
|
301 |
TKeyCode c=test.Console()->KeyCode();
|
|
302 |
if (c==EKeySpace)
|
|
303 |
break;
|
|
304 |
test.Console()->Read(kStat);
|
|
305 |
}
|
|
306 |
}
|
|
307 |
|
|
308 |
test.Next(_L("Close"));
|
|
309 |
#if defined (USE_F32_ACCESS)
|
|
310 |
f.Close();
|
|
311 |
TheFs.Close();
|
|
312 |
#else
|
|
313 |
TheDrive.Disconnect();
|
|
314 |
#endif
|
|
315 |
|
|
316 |
test.End();
|
|
317 |
return(0);
|
|
318 |
}
|
|
319 |
|