sl@0
|
1 |
// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// Tests erasing of Flash while forcing suspend-resume cycles
|
sl@0
|
15 |
// This is a soak-test version that runs continously
|
sl@0
|
16 |
//
|
sl@0
|
17 |
//
|
sl@0
|
18 |
|
sl@0
|
19 |
#include <e32std.h>
|
sl@0
|
20 |
#include <e32std_private.h>
|
sl@0
|
21 |
#include <e32svr.h>
|
sl@0
|
22 |
#include <e32test.h>
|
sl@0
|
23 |
#include "randgen.h"
|
sl@0
|
24 |
#include "user_config.h"
|
sl@0
|
25 |
|
sl@0
|
26 |
RTest test( _L("TF_SUSPENDSOAK") );
|
sl@0
|
27 |
|
sl@0
|
28 |
|
sl@0
|
29 |
|
sl@0
|
30 |
|
sl@0
|
31 |
class CEraser
|
sl@0
|
32 |
{
|
sl@0
|
33 |
public:
|
sl@0
|
34 |
enum TFunction
|
sl@0
|
35 |
{
|
sl@0
|
36 |
EIdle,
|
sl@0
|
37 |
EEraseBlock
|
sl@0
|
38 |
};
|
sl@0
|
39 |
|
sl@0
|
40 |
public:
|
sl@0
|
41 |
~CEraser();
|
sl@0
|
42 |
void CreateL();
|
sl@0
|
43 |
void Stop();
|
sl@0
|
44 |
void WaitForReady();
|
sl@0
|
45 |
inline TBool CheckDone() const
|
sl@0
|
46 |
{
|
sl@0
|
47 |
return (EIdle == iRequestedFunction);
|
sl@0
|
48 |
}
|
sl@0
|
49 |
|
sl@0
|
50 |
inline void WaitForDone()
|
sl@0
|
51 |
{
|
sl@0
|
52 |
WaitForReady();
|
sl@0
|
53 |
iWaitingSignal.Signal(); // resignal, ready for next Start()
|
sl@0
|
54 |
};
|
sl@0
|
55 |
|
sl@0
|
56 |
void EraseBlock( TUint32 aOffset, TUint aLength );
|
sl@0
|
57 |
|
sl@0
|
58 |
private:
|
sl@0
|
59 |
void Panic( TInt aPanicNum );
|
sl@0
|
60 |
void Start( TFunction aFunction );
|
sl@0
|
61 |
|
sl@0
|
62 |
static TInt EraserThread( TAny* aParam );
|
sl@0
|
63 |
|
sl@0
|
64 |
void DoEraseBlock();
|
sl@0
|
65 |
|
sl@0
|
66 |
private:
|
sl@0
|
67 |
RThread iThread;
|
sl@0
|
68 |
|
sl@0
|
69 |
//
|
sl@0
|
70 |
// Shared between main & eraser thread
|
sl@0
|
71 |
//
|
sl@0
|
72 |
TFunction iRequestedFunction;
|
sl@0
|
73 |
RSemaphore iGoSignal;
|
sl@0
|
74 |
RSemaphore iWaitingSignal;
|
sl@0
|
75 |
TBool iStop;
|
sl@0
|
76 |
|
sl@0
|
77 |
//
|
sl@0
|
78 |
// These are local to the eraser thread
|
sl@0
|
79 |
//
|
sl@0
|
80 |
TUint iOffset;
|
sl@0
|
81 |
TUint iLength;
|
sl@0
|
82 |
TBusLocalDrive iDrive;
|
sl@0
|
83 |
};
|
sl@0
|
84 |
|
sl@0
|
85 |
|
sl@0
|
86 |
|
sl@0
|
87 |
CEraser::~CEraser()
|
sl@0
|
88 |
{
|
sl@0
|
89 |
iThread.Terminate( KErrNone );
|
sl@0
|
90 |
iThread.Close();
|
sl@0
|
91 |
iGoSignal.Close();
|
sl@0
|
92 |
iWaitingSignal.Close();
|
sl@0
|
93 |
}
|
sl@0
|
94 |
|
sl@0
|
95 |
void CEraser::Panic( TInt aPanicNum )
|
sl@0
|
96 |
{
|
sl@0
|
97 |
_LIT( KPanicCat, "ERASE-T" );
|
sl@0
|
98 |
User::Panic( KPanicCat, aPanicNum );
|
sl@0
|
99 |
RProcess().Panic( KPanicCat, aPanicNum );
|
sl@0
|
100 |
}
|
sl@0
|
101 |
|
sl@0
|
102 |
|
sl@0
|
103 |
void CEraser::CreateL()
|
sl@0
|
104 |
//
|
sl@0
|
105 |
// Create new thread and wait for it to become ready
|
sl@0
|
106 |
//
|
sl@0
|
107 |
{
|
sl@0
|
108 |
iGoSignal.CreateLocal( 0 ); // initially blocked
|
sl@0
|
109 |
iWaitingSignal.CreateLocal( 0 ); // initially blocked
|
sl@0
|
110 |
iStop = EFalse;
|
sl@0
|
111 |
User::LeaveIfError( iThread.Create( _L("ERASER"), EraserThread, 2048, 2048, 65536, this ) );
|
sl@0
|
112 |
test.Printf( _L("Eraser thread created\n") );
|
sl@0
|
113 |
|
sl@0
|
114 |
iThread.Resume();
|
sl@0
|
115 |
|
sl@0
|
116 |
test.Printf( _L("Waiting for thread to become ready\n") );
|
sl@0
|
117 |
WaitForReady();
|
sl@0
|
118 |
iWaitingSignal.Signal();
|
sl@0
|
119 |
}
|
sl@0
|
120 |
|
sl@0
|
121 |
void CEraser::Start( TFunction aFunction )
|
sl@0
|
122 |
//
|
sl@0
|
123 |
// Start the suspender thread executing function aFunction
|
sl@0
|
124 |
//
|
sl@0
|
125 |
{
|
sl@0
|
126 |
iStop = EFalse;
|
sl@0
|
127 |
WaitForReady();
|
sl@0
|
128 |
iRequestedFunction = aFunction;
|
sl@0
|
129 |
iGoSignal.Signal();
|
sl@0
|
130 |
}
|
sl@0
|
131 |
|
sl@0
|
132 |
void CEraser::Stop()
|
sl@0
|
133 |
//
|
sl@0
|
134 |
// Stop the thread
|
sl@0
|
135 |
//
|
sl@0
|
136 |
{
|
sl@0
|
137 |
iStop = ETrue;
|
sl@0
|
138 |
}
|
sl@0
|
139 |
|
sl@0
|
140 |
void CEraser::WaitForReady()
|
sl@0
|
141 |
{
|
sl@0
|
142 |
iWaitingSignal.Wait();
|
sl@0
|
143 |
}
|
sl@0
|
144 |
|
sl@0
|
145 |
void CEraser::EraseBlock( TUint32 aOffset, TUint aLength )
|
sl@0
|
146 |
//
|
sl@0
|
147 |
// Execute a single read immediately to cause a suspend
|
sl@0
|
148 |
//
|
sl@0
|
149 |
{
|
sl@0
|
150 |
iOffset = aOffset;
|
sl@0
|
151 |
iLength = aLength;
|
sl@0
|
152 |
Start( EEraseBlock );
|
sl@0
|
153 |
}
|
sl@0
|
154 |
|
sl@0
|
155 |
|
sl@0
|
156 |
TInt CEraser::EraserThread( TAny* aParam )
|
sl@0
|
157 |
//
|
sl@0
|
158 |
// The thread which executes suspend functions
|
sl@0
|
159 |
//
|
sl@0
|
160 |
{
|
sl@0
|
161 |
RDebug::Print( _L("Eraser thread starts") );
|
sl@0
|
162 |
|
sl@0
|
163 |
CEraser& self = *reinterpret_cast<CEraser*>(aParam);
|
sl@0
|
164 |
|
sl@0
|
165 |
//
|
sl@0
|
166 |
// Open our own TBusLogicalDevice channel
|
sl@0
|
167 |
//
|
sl@0
|
168 |
TBool changedFlag;
|
sl@0
|
169 |
if( KErrNone != self.iDrive.Connect( KDriveNumber, changedFlag ) )
|
sl@0
|
170 |
{
|
sl@0
|
171 |
self.Panic( 1 );
|
sl@0
|
172 |
}
|
sl@0
|
173 |
|
sl@0
|
174 |
RDebug::Print( _L("Eraser thread connected to drive") );
|
sl@0
|
175 |
|
sl@0
|
176 |
while( !self.iStop )
|
sl@0
|
177 |
{
|
sl@0
|
178 |
//
|
sl@0
|
179 |
// Signal that we are ready for a request
|
sl@0
|
180 |
//
|
sl@0
|
181 |
_LIT( KWaitMsg, "Eraser thread waiting..." );
|
sl@0
|
182 |
RDebug::Print( KWaitMsg );
|
sl@0
|
183 |
self.iWaitingSignal.Signal();
|
sl@0
|
184 |
|
sl@0
|
185 |
//
|
sl@0
|
186 |
// Wait for a request
|
sl@0
|
187 |
//
|
sl@0
|
188 |
self.iGoSignal.Wait();
|
sl@0
|
189 |
_LIT( KGoMsg, "Eraser thread go (%d)" );
|
sl@0
|
190 |
RDebug::Print( KGoMsg, self.iRequestedFunction );
|
sl@0
|
191 |
|
sl@0
|
192 |
switch( self.iRequestedFunction )
|
sl@0
|
193 |
{
|
sl@0
|
194 |
case EEraseBlock:
|
sl@0
|
195 |
self.DoEraseBlock();
|
sl@0
|
196 |
break;
|
sl@0
|
197 |
|
sl@0
|
198 |
case EIdle:
|
sl@0
|
199 |
default:
|
sl@0
|
200 |
self.Panic( 0 );
|
sl@0
|
201 |
}
|
sl@0
|
202 |
|
sl@0
|
203 |
self.iRequestedFunction = EIdle;
|
sl@0
|
204 |
}
|
sl@0
|
205 |
|
sl@0
|
206 |
self.iDrive.Disconnect();
|
sl@0
|
207 |
return KErrNone;
|
sl@0
|
208 |
}
|
sl@0
|
209 |
|
sl@0
|
210 |
void CEraser::DoEraseBlock()
|
sl@0
|
211 |
//
|
sl@0
|
212 |
// Issue an erase
|
sl@0
|
213 |
//
|
sl@0
|
214 |
{
|
sl@0
|
215 |
_LIT( KEraseStartMsg, "Eraser starting erase..." );
|
sl@0
|
216 |
RDebug::Print( KEraseStartMsg );
|
sl@0
|
217 |
|
sl@0
|
218 |
TInt r = iDrive.Format( TInt64(iOffset), iLength );
|
sl@0
|
219 |
|
sl@0
|
220 |
if( KErrNone != r )
|
sl@0
|
221 |
{
|
sl@0
|
222 |
RDebug::Print( _L("Eraser: FAIL: erase request returns %d"), r );
|
sl@0
|
223 |
Panic( 2 );
|
sl@0
|
224 |
}
|
sl@0
|
225 |
}
|
sl@0
|
226 |
|
sl@0
|
227 |
|
sl@0
|
228 |
|
sl@0
|
229 |
class CSuspendTest : public CBase
|
sl@0
|
230 |
{
|
sl@0
|
231 |
public:
|
sl@0
|
232 |
~CSuspendTest();
|
sl@0
|
233 |
|
sl@0
|
234 |
void CreateL();
|
sl@0
|
235 |
|
sl@0
|
236 |
void DoTest();
|
sl@0
|
237 |
|
sl@0
|
238 |
private:
|
sl@0
|
239 |
|
sl@0
|
240 |
TInt EraseOneBlock( TInt aBlockNumber );
|
sl@0
|
241 |
TInt ZeroFillBlock( TInt aBlockNumber );
|
sl@0
|
242 |
TBool ValidateBlock( TInt aBlockNumber, TUint32 aFillWord );
|
sl@0
|
243 |
TInt ZeroAllBlocks();
|
sl@0
|
244 |
TBool ValidateAllBlocks( TUint32 aFillWord );
|
sl@0
|
245 |
void TimeSinceStart() const;
|
sl@0
|
246 |
|
sl@0
|
247 |
void DoRandomReadSoak();
|
sl@0
|
248 |
|
sl@0
|
249 |
private:
|
sl@0
|
250 |
TBusLocalDrive iDrive;
|
sl@0
|
251 |
TBool iDriveOpened;
|
sl@0
|
252 |
|
sl@0
|
253 |
CEraser* iEraser;
|
sl@0
|
254 |
|
sl@0
|
255 |
TInt iFlashSize;
|
sl@0
|
256 |
TInt iBlockSize;
|
sl@0
|
257 |
TInt iBlockCount;
|
sl@0
|
258 |
|
sl@0
|
259 |
TTime iStartTime;
|
sl@0
|
260 |
|
sl@0
|
261 |
TBuf8<512> iReadBuffer;
|
sl@0
|
262 |
|
sl@0
|
263 |
};
|
sl@0
|
264 |
|
sl@0
|
265 |
|
sl@0
|
266 |
CSuspendTest::~CSuspendTest()
|
sl@0
|
267 |
{
|
sl@0
|
268 |
if( iDriveOpened )
|
sl@0
|
269 |
{
|
sl@0
|
270 |
iDrive.Disconnect();
|
sl@0
|
271 |
}
|
sl@0
|
272 |
|
sl@0
|
273 |
delete iEraser;
|
sl@0
|
274 |
}
|
sl@0
|
275 |
|
sl@0
|
276 |
|
sl@0
|
277 |
|
sl@0
|
278 |
void CSuspendTest::CreateL()
|
sl@0
|
279 |
{
|
sl@0
|
280 |
//
|
sl@0
|
281 |
// Create the eraser thread
|
sl@0
|
282 |
//
|
sl@0
|
283 |
iEraser = new(ELeave) CEraser;
|
sl@0
|
284 |
iEraser->CreateL();
|
sl@0
|
285 |
|
sl@0
|
286 |
//
|
sl@0
|
287 |
// Load the device drivers
|
sl@0
|
288 |
//
|
sl@0
|
289 |
TInt r;
|
sl@0
|
290 |
#ifndef SKIP_PDD_LOAD
|
sl@0
|
291 |
test.Printf( _L("Loading %S\n"), &KLfsDriverName );
|
sl@0
|
292 |
r = User::LoadPhysicalDevice( KLfsDriverName );
|
sl@0
|
293 |
test( KErrNone == r || KErrAlreadyExists == r );
|
sl@0
|
294 |
#endif
|
sl@0
|
295 |
|
sl@0
|
296 |
#ifdef UNMOUNT_DRIVE
|
sl@0
|
297 |
RFs fs;
|
sl@0
|
298 |
test( KErrNone == fs.Connect() );
|
sl@0
|
299 |
test( KErrNone == fs.SetSessionPath( _L("Z:\\") ) );
|
sl@0
|
300 |
TFullName name;
|
sl@0
|
301 |
fs.FileSystemName( name, KLffsLogicalDriveNumber );
|
sl@0
|
302 |
if( name.Length() > 0 )
|
sl@0
|
303 |
{
|
sl@0
|
304 |
test.Printf( _L("Unmounting drive") );
|
sl@0
|
305 |
test( KErrNone == fs.DismountFileSystem( _L("Lffs"), KLffsLogicalDriveNumber) );
|
sl@0
|
306 |
User::After( 2000000 );
|
sl@0
|
307 |
test.Printf( _L("Drive unmounted") );
|
sl@0
|
308 |
}
|
sl@0
|
309 |
fs.Close();
|
sl@0
|
310 |
#endif
|
sl@0
|
311 |
|
sl@0
|
312 |
//
|
sl@0
|
313 |
// Open a TBusLogicalDevice to it
|
sl@0
|
314 |
//
|
sl@0
|
315 |
test.Printf( _L("Opening media channel\n") );
|
sl@0
|
316 |
TBool changedFlag = EFalse;
|
sl@0
|
317 |
r = iDrive.Connect( KDriveNumber, changedFlag );
|
sl@0
|
318 |
User::LeaveIfError( r );
|
sl@0
|
319 |
iDriveOpened = ETrue;
|
sl@0
|
320 |
|
sl@0
|
321 |
//
|
sl@0
|
322 |
// Get size of Flash drive, block size, block count
|
sl@0
|
323 |
//
|
sl@0
|
324 |
TLocalDriveCapsV2Buf info;
|
sl@0
|
325 |
iDrive.Caps(info);
|
sl@0
|
326 |
iFlashSize = I64LOW(info().iSize);
|
sl@0
|
327 |
iBlockSize = info().iEraseBlockSize;
|
sl@0
|
328 |
iBlockCount = iFlashSize / iBlockSize;
|
sl@0
|
329 |
|
sl@0
|
330 |
test.Printf( _L("Flash size is 0x%x bytes\n"), iFlashSize );
|
sl@0
|
331 |
test.Printf( _L("Block size is 0x%x bytes\n"), iBlockSize );
|
sl@0
|
332 |
test.Printf( _L("Block count is %d\n"), iBlockCount );
|
sl@0
|
333 |
|
sl@0
|
334 |
test.Printf( _L("CreateL complete\n") );
|
sl@0
|
335 |
}
|
sl@0
|
336 |
|
sl@0
|
337 |
|
sl@0
|
338 |
void CSuspendTest::DoTest()
|
sl@0
|
339 |
//
|
sl@0
|
340 |
// Main test dispatcher
|
sl@0
|
341 |
//
|
sl@0
|
342 |
{
|
sl@0
|
343 |
DoRandomReadSoak();
|
sl@0
|
344 |
}
|
sl@0
|
345 |
|
sl@0
|
346 |
|
sl@0
|
347 |
TInt CSuspendTest::EraseOneBlock( TInt aBlockNumber )
|
sl@0
|
348 |
//
|
sl@0
|
349 |
// Erases block aBlockNumber on Flash
|
sl@0
|
350 |
//
|
sl@0
|
351 |
{
|
sl@0
|
352 |
TInt blockBaseOffset = aBlockNumber * iBlockSize;
|
sl@0
|
353 |
|
sl@0
|
354 |
test.Printf( _L("Erasing block %d (offs=0x%x)\n"), aBlockNumber, blockBaseOffset );
|
sl@0
|
355 |
|
sl@0
|
356 |
TInt r = iDrive.Format( blockBaseOffset, iBlockSize );
|
sl@0
|
357 |
|
sl@0
|
358 |
test.Printf( _L("... block erased, rv=%d\n"), r );
|
sl@0
|
359 |
return r;
|
sl@0
|
360 |
}
|
sl@0
|
361 |
|
sl@0
|
362 |
|
sl@0
|
363 |
TBool CSuspendTest::ValidateBlock( TInt aBlockNumber, TUint32 aFillWord )
|
sl@0
|
364 |
//
|
sl@0
|
365 |
// Checks that every word in block aBlockNumber has the value aFillWord
|
sl@0
|
366 |
//
|
sl@0
|
367 |
{
|
sl@0
|
368 |
TUint offset = aBlockNumber * iBlockSize;
|
sl@0
|
369 |
test.Printf( _L("Validating block %d (offs=0x%x)\n"), aBlockNumber, offset );
|
sl@0
|
370 |
|
sl@0
|
371 |
TBool failed = EFalse;
|
sl@0
|
372 |
const TInt readBufLen = iReadBuffer.MaxLength();
|
sl@0
|
373 |
|
sl@0
|
374 |
for( TInt len = iBlockSize; len > 0 && !failed ;)
|
sl@0
|
375 |
{
|
sl@0
|
376 |
TInt r = iDrive.Read( offset, readBufLen, iReadBuffer );
|
sl@0
|
377 |
if( r != KErrNone )
|
sl@0
|
378 |
{
|
sl@0
|
379 |
test.Printf( _L("... FAIL: read failed (%d) at offset 0x%x\n"), r, offset );
|
sl@0
|
380 |
test( KErrNone == r );
|
sl@0
|
381 |
}
|
sl@0
|
382 |
test( iReadBuffer.Length() == readBufLen );
|
sl@0
|
383 |
|
sl@0
|
384 |
TUint32* p = (TUint32*)iReadBuffer.Ptr();
|
sl@0
|
385 |
for( TInt i = 0; i < readBufLen; i += 4 )
|
sl@0
|
386 |
{
|
sl@0
|
387 |
if( aFillWord != *p )
|
sl@0
|
388 |
{
|
sl@0
|
389 |
failed = ETrue;
|
sl@0
|
390 |
test.Printf( _L("... FAILED: word @ offs=0x%x, read=0x%x, expected=0x%x\n"),
|
sl@0
|
391 |
offset+i, p[0], aFillWord );
|
sl@0
|
392 |
break;
|
sl@0
|
393 |
}
|
sl@0
|
394 |
++p;
|
sl@0
|
395 |
}
|
sl@0
|
396 |
offset += readBufLen;
|
sl@0
|
397 |
len -= readBufLen;
|
sl@0
|
398 |
}
|
sl@0
|
399 |
|
sl@0
|
400 |
return !failed;
|
sl@0
|
401 |
}
|
sl@0
|
402 |
|
sl@0
|
403 |
|
sl@0
|
404 |
TInt CSuspendTest::ZeroFillBlock( TInt aBlockNumber )
|
sl@0
|
405 |
//
|
sl@0
|
406 |
// Zero-fills and entire block
|
sl@0
|
407 |
// The requires that writing works
|
sl@0
|
408 |
//
|
sl@0
|
409 |
{
|
sl@0
|
410 |
test.Printf( _L("Zero-filling block %d\n"), aBlockNumber );
|
sl@0
|
411 |
|
sl@0
|
412 |
//
|
sl@0
|
413 |
// Create a buffer full of zeros
|
sl@0
|
414 |
//
|
sl@0
|
415 |
const TInt KZeroBufSize = 512;
|
sl@0
|
416 |
|
sl@0
|
417 |
TBuf8<KZeroBufSize> buf;
|
sl@0
|
418 |
buf.FillZ( buf.MaxLength() );
|
sl@0
|
419 |
|
sl@0
|
420 |
//
|
sl@0
|
421 |
// Write the data out to the Flash
|
sl@0
|
422 |
//
|
sl@0
|
423 |
TInt writeCount = iBlockSize / KZeroBufSize;
|
sl@0
|
424 |
TInt r = KErrNone;
|
sl@0
|
425 |
TUint blockBaseOffset = aBlockNumber * iBlockSize;
|
sl@0
|
426 |
TInt pos = blockBaseOffset;
|
sl@0
|
427 |
for( ; (writeCount > 0) && (KErrNone == r); writeCount-- )
|
sl@0
|
428 |
{
|
sl@0
|
429 |
r = iDrive.Write( pos, buf );
|
sl@0
|
430 |
if( r != KErrNone )
|
sl@0
|
431 |
{
|
sl@0
|
432 |
test.Printf( _L("... FAIL: write failed (%d) at offset 0x%x\n"), pos );
|
sl@0
|
433 |
}
|
sl@0
|
434 |
pos += KZeroBufSize;
|
sl@0
|
435 |
}
|
sl@0
|
436 |
|
sl@0
|
437 |
return r;
|
sl@0
|
438 |
}
|
sl@0
|
439 |
|
sl@0
|
440 |
|
sl@0
|
441 |
TInt CSuspendTest::ZeroAllBlocks()
|
sl@0
|
442 |
//
|
sl@0
|
443 |
// Writes zeros to all blocks
|
sl@0
|
444 |
//
|
sl@0
|
445 |
{
|
sl@0
|
446 |
test.Printf( _L("Zeroing all blocks\n") );
|
sl@0
|
447 |
|
sl@0
|
448 |
TInt r = KErrNone;
|
sl@0
|
449 |
for( TInt i = 0; (i < iBlockCount) && (KErrNone == r); i++ )
|
sl@0
|
450 |
{
|
sl@0
|
451 |
r = ZeroFillBlock( i );
|
sl@0
|
452 |
}
|
sl@0
|
453 |
|
sl@0
|
454 |
return r;
|
sl@0
|
455 |
}
|
sl@0
|
456 |
|
sl@0
|
457 |
TBool CSuspendTest::ValidateAllBlocks( TUint32 aFillWord )
|
sl@0
|
458 |
//
|
sl@0
|
459 |
// Checks that all blocks contain aFillWord
|
sl@0
|
460 |
//
|
sl@0
|
461 |
{
|
sl@0
|
462 |
test.Printf( _L("Validating all blocks\n") );
|
sl@0
|
463 |
|
sl@0
|
464 |
TBool failed = EFalse;
|
sl@0
|
465 |
for( TInt i = 0; (i < iBlockCount) && (!failed); i++ )
|
sl@0
|
466 |
{
|
sl@0
|
467 |
failed = !ValidateBlock( i, aFillWord );
|
sl@0
|
468 |
}
|
sl@0
|
469 |
|
sl@0
|
470 |
return !failed;
|
sl@0
|
471 |
}
|
sl@0
|
472 |
|
sl@0
|
473 |
|
sl@0
|
474 |
void CSuspendTest::TimeSinceStart() const
|
sl@0
|
475 |
{
|
sl@0
|
476 |
TTimeIntervalSeconds timeTaken;
|
sl@0
|
477 |
TTime time;
|
sl@0
|
478 |
time.HomeTime();
|
sl@0
|
479 |
TInt r = time.SecondsFrom(iStartTime, timeTaken);
|
sl@0
|
480 |
test(r == KErrNone);
|
sl@0
|
481 |
TInt totalTime = timeTaken.Int();
|
sl@0
|
482 |
|
sl@0
|
483 |
TInt seconds = totalTime % 60;
|
sl@0
|
484 |
TInt minutes = (totalTime / 60) % 60;
|
sl@0
|
485 |
TInt hours = totalTime / 3600;
|
sl@0
|
486 |
|
sl@0
|
487 |
test.Printf( _L("Time since test started = %d:%d:%d\n"), hours, minutes, seconds );
|
sl@0
|
488 |
}
|
sl@0
|
489 |
|
sl@0
|
490 |
|
sl@0
|
491 |
|
sl@0
|
492 |
void CSuspendTest::DoRandomReadSoak()
|
sl@0
|
493 |
//
|
sl@0
|
494 |
// For each block issues an erase and then
|
sl@0
|
495 |
// starts issuing read requests. The intervals
|
sl@0
|
496 |
// between read requests are derived from the
|
sl@0
|
497 |
// pseudo-random number generator.
|
sl@0
|
498 |
// Each block is checked after is has been erased
|
sl@0
|
499 |
//
|
sl@0
|
500 |
{
|
sl@0
|
501 |
|
sl@0
|
502 |
TRandomGenerator random;
|
sl@0
|
503 |
random.SetSeed( MAKE_TINT64(0xA05BE111,0x00101111) );
|
sl@0
|
504 |
|
sl@0
|
505 |
test.Next( _L("Random read soak test") );
|
sl@0
|
506 |
|
sl@0
|
507 |
iStartTime.HomeTime();
|
sl@0
|
508 |
|
sl@0
|
509 |
//
|
sl@0
|
510 |
// We repeat the test for each block, erasing block n and reading from
|
sl@0
|
511 |
// block (n+1) modulo iBlockCount
|
sl@0
|
512 |
//
|
sl@0
|
513 |
for(;;)
|
sl@0
|
514 |
{
|
sl@0
|
515 |
TimeSinceStart();
|
sl@0
|
516 |
|
sl@0
|
517 |
for( TInt eraseBlock = 0; eraseBlock < iBlockCount; eraseBlock++ )
|
sl@0
|
518 |
{
|
sl@0
|
519 |
TUint32 readBlock = (eraseBlock + 1) % iBlockCount;
|
sl@0
|
520 |
TUint32 erasePos = eraseBlock * iBlockSize;
|
sl@0
|
521 |
TInt readPos = readBlock * iBlockSize;
|
sl@0
|
522 |
|
sl@0
|
523 |
//
|
sl@0
|
524 |
// Zero the block we are about to erase
|
sl@0
|
525 |
//
|
sl@0
|
526 |
test( KErrNone == ZeroFillBlock( eraseBlock ) );
|
sl@0
|
527 |
test( ValidateBlock( eraseBlock, 0 ) );
|
sl@0
|
528 |
|
sl@0
|
529 |
TBuf8<32> buf;
|
sl@0
|
530 |
|
sl@0
|
531 |
//
|
sl@0
|
532 |
// Start the erase
|
sl@0
|
533 |
//
|
sl@0
|
534 |
_LIT( KEraseNotify, "Main thread starting erase\n" );
|
sl@0
|
535 |
test.Printf( KEraseNotify );
|
sl@0
|
536 |
iEraser->EraseBlock( erasePos, iBlockSize );
|
sl@0
|
537 |
|
sl@0
|
538 |
//
|
sl@0
|
539 |
// Now we loop, waiting for random intervals, issuing
|
sl@0
|
540 |
// reads, until the erase completes
|
sl@0
|
541 |
//
|
sl@0
|
542 |
|
sl@0
|
543 |
while( !iEraser->CheckDone() )
|
sl@0
|
544 |
{
|
sl@0
|
545 |
//
|
sl@0
|
546 |
// Get a pseudo-random interval between 0 and 524.288 milliseconds
|
sl@0
|
547 |
//
|
sl@0
|
548 |
TInt delayInMicroseconds = random.Next() % 0x80000;
|
sl@0
|
549 |
User::After( delayInMicroseconds );
|
sl@0
|
550 |
|
sl@0
|
551 |
test( KErrNone == iDrive.Read( readPos, buf.MaxLength(), buf ) );
|
sl@0
|
552 |
_LIT( KReadNotify, "Done Read" );
|
sl@0
|
553 |
test.Printf( KReadNotify );
|
sl@0
|
554 |
}
|
sl@0
|
555 |
|
sl@0
|
556 |
//
|
sl@0
|
557 |
// Now check that the block was erased
|
sl@0
|
558 |
//
|
sl@0
|
559 |
test( ValidateBlock( eraseBlock, 0xFFFFFFFF ) );
|
sl@0
|
560 |
|
sl@0
|
561 |
}
|
sl@0
|
562 |
}
|
sl@0
|
563 |
|
sl@0
|
564 |
}
|
sl@0
|
565 |
|
sl@0
|
566 |
|
sl@0
|
567 |
|
sl@0
|
568 |
|
sl@0
|
569 |
void E32Main()
|
sl@0
|
570 |
{
|
sl@0
|
571 |
test.Title();
|
sl@0
|
572 |
test.Start(_L("Testing media erase+suspend operations"));
|
sl@0
|
573 |
|
sl@0
|
574 |
CSuspendTest suspendTest;
|
sl@0
|
575 |
TRAPD( ret, suspendTest.CreateL() );
|
sl@0
|
576 |
if( KErrNone == ret )
|
sl@0
|
577 |
{
|
sl@0
|
578 |
suspendTest.DoTest();
|
sl@0
|
579 |
}
|
sl@0
|
580 |
|
sl@0
|
581 |
test.End();
|
sl@0
|
582 |
}
|