sl@0
|
1 |
// Copyright (c) 2006-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 |
// f32test\server\t_CHECKDISK.cpp
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
#define __E32TEST_EXTENSION__
|
sl@0
|
18 |
#include <f32file.h>
|
sl@0
|
19 |
#include <e32test.h>
|
sl@0
|
20 |
//#include <e32svr.h>
|
sl@0
|
21 |
//#include <f32dbg.h>
|
sl@0
|
22 |
#include "t_server.h"
|
sl@0
|
23 |
//#include <e32twin.h>
|
sl@0
|
24 |
|
sl@0
|
25 |
RTest test(_L("T_CHECKDISK"));
|
sl@0
|
26 |
|
sl@0
|
27 |
RFs TheFs;
|
sl@0
|
28 |
TInt gDrive;
|
sl@0
|
29 |
TFileName gSessionPath;
|
sl@0
|
30 |
TChar gDriveToTest;
|
sl@0
|
31 |
|
sl@0
|
32 |
|
sl@0
|
33 |
HBufC8* gBuf = NULL;
|
sl@0
|
34 |
TPtr8 gBufReadPtr(NULL, 0);
|
sl@0
|
35 |
HBufC8* gBufSec = NULL;
|
sl@0
|
36 |
TPtr8 gBufWritePtr(NULL, 0);
|
sl@0
|
37 |
|
sl@0
|
38 |
const TInt KOneK = 1024;
|
sl@0
|
39 |
const TInt KOneMeg = KOneK * 1024;
|
sl@0
|
40 |
const TInt KBlockSize = KOneK * 129 ;
|
sl@0
|
41 |
const TInt KWaitRequestsTableSize = 70;
|
sl@0
|
42 |
|
sl@0
|
43 |
TInt gBigFileSize = 0;
|
sl@0
|
44 |
TInt gSmallFileSize = 0;
|
sl@0
|
45 |
TInt64 gMediaSize = 0;
|
sl@0
|
46 |
TBool gSkip=EFalse;
|
sl@0
|
47 |
TInt writeSize = KBlockSize;
|
sl@0
|
48 |
TInt seekSize = 0;
|
sl@0
|
49 |
TSeek seekType = ESeekAddress;
|
sl@0
|
50 |
TInt reduceSize = 0;
|
sl@0
|
51 |
|
sl@0
|
52 |
TTimeIntervalMicroSeconds32 gTimeTakenBigFile(0);
|
sl@0
|
53 |
TBuf16<45> gSmallFile, gBigFile;
|
sl@0
|
54 |
LOCAL_D TInt gNextFile=0;
|
sl@0
|
55 |
TTime gTime1;
|
sl@0
|
56 |
TTime gTime2;
|
sl@0
|
57 |
|
sl@0
|
58 |
LOCAL_D RSemaphore gSync;
|
sl@0
|
59 |
|
sl@0
|
60 |
// Concurrent Threads
|
sl@0
|
61 |
RThread gBig;
|
sl@0
|
62 |
RThread gSmall;
|
sl@0
|
63 |
LOCAL_D RSemaphore client;
|
sl@0
|
64 |
LOCAL_D const TInt KHeapSize=0x4000;
|
sl@0
|
65 |
LOCAL_D const TInt KMaxHeapSize=0x100000;
|
sl@0
|
66 |
TRequestStatus gStatus[KWaitRequestsTableSize];
|
sl@0
|
67 |
|
sl@0
|
68 |
enum TTestState
|
sl@0
|
69 |
{
|
sl@0
|
70 |
EThreadWait,
|
sl@0
|
71 |
EThreadSignal,
|
sl@0
|
72 |
ENoThreads
|
sl@0
|
73 |
};
|
sl@0
|
74 |
|
sl@0
|
75 |
//
|
sl@0
|
76 |
// Generates a name of the form FFFFF*<aPos>.TXT (aLong.3)
|
sl@0
|
77 |
//
|
sl@0
|
78 |
GLDEF_C void FileNameGen(TDes16& aBuffer, TInt aLong, TInt aPos)
|
sl@0
|
79 |
{
|
sl@0
|
80 |
TInt padding;
|
sl@0
|
81 |
TInt i=0;
|
sl@0
|
82 |
TBuf16<10> tempbuf;
|
sl@0
|
83 |
|
sl@0
|
84 |
_LIT(KNumber,"%d");
|
sl@0
|
85 |
tempbuf.Format(KNumber,aPos);
|
sl@0
|
86 |
padding=aLong-tempbuf.Size()/2;
|
sl@0
|
87 |
aBuffer=_L("");
|
sl@0
|
88 |
while(i<padding)
|
sl@0
|
89 |
{
|
sl@0
|
90 |
aBuffer.Append('F');
|
sl@0
|
91 |
i++;
|
sl@0
|
92 |
}
|
sl@0
|
93 |
aBuffer.Append(tempbuf);
|
sl@0
|
94 |
|
sl@0
|
95 |
_LIT(KExtension1, ".TXT");
|
sl@0
|
96 |
aBuffer.Append(KExtension1);
|
sl@0
|
97 |
}
|
sl@0
|
98 |
|
sl@0
|
99 |
|
sl@0
|
100 |
|
sl@0
|
101 |
|
sl@0
|
102 |
//
|
sl@0
|
103 |
// Expects a drive letter as a parameter
|
sl@0
|
104 |
//
|
sl@0
|
105 |
LOCAL_C void parseCommandLine()
|
sl@0
|
106 |
{
|
sl@0
|
107 |
TBuf<0x100> cmd;
|
sl@0
|
108 |
User::CommandLine(cmd);
|
sl@0
|
109 |
TLex lex(cmd);
|
sl@0
|
110 |
TPtrC token=lex.NextToken();
|
sl@0
|
111 |
TInt r=0;
|
sl@0
|
112 |
|
sl@0
|
113 |
if(token.Length()!=0)
|
sl@0
|
114 |
{
|
sl@0
|
115 |
gDriveToTest=token[0];
|
sl@0
|
116 |
gDriveToTest.UpperCase();
|
sl@0
|
117 |
}
|
sl@0
|
118 |
else
|
sl@0
|
119 |
{
|
sl@0
|
120 |
gDriveToTest='C';
|
sl@0
|
121 |
}
|
sl@0
|
122 |
|
sl@0
|
123 |
r=TheFs.CharToDrive(gDriveToTest,gDrive);
|
sl@0
|
124 |
test_KErrNone(r);
|
sl@0
|
125 |
gSessionPath=_L("?:\\F32-TST\\");
|
sl@0
|
126 |
gSessionPath[0]=(TText)gDriveToTest;
|
sl@0
|
127 |
test.Printf(_L("\nCLP=%S\n"),&token);
|
sl@0
|
128 |
}
|
sl@0
|
129 |
|
sl@0
|
130 |
//
|
sl@0
|
131 |
// Fills a buffer with character aC
|
sl@0
|
132 |
//
|
sl@0
|
133 |
LOCAL_C void FillBuffer(TDes8& aBuffer, TInt aLength, TChar aC)
|
sl@0
|
134 |
{
|
sl@0
|
135 |
test (aBuffer.MaxLength() >= aLength);
|
sl@0
|
136 |
for(TInt i=0; i<aLength; i++)
|
sl@0
|
137 |
{
|
sl@0
|
138 |
aBuffer.Append(aC);
|
sl@0
|
139 |
}
|
sl@0
|
140 |
}
|
sl@0
|
141 |
|
sl@0
|
142 |
//
|
sl@0
|
143 |
// Waits for all the TRequestStatus in status[] to complete
|
sl@0
|
144 |
//
|
sl@0
|
145 |
LOCAL_C void WaitForAll(TRequestStatus status[], TInt aSize)
|
sl@0
|
146 |
{
|
sl@0
|
147 |
TInt i=0;
|
sl@0
|
148 |
|
sl@0
|
149 |
while(i<aSize)
|
sl@0
|
150 |
{
|
sl@0
|
151 |
User::WaitForRequest(status[i++]);
|
sl@0
|
152 |
}
|
sl@0
|
153 |
}
|
sl@0
|
154 |
|
sl@0
|
155 |
|
sl@0
|
156 |
//
|
sl@0
|
157 |
// Writes a file synchronously in blocks of aBlockSize size
|
sl@0
|
158 |
// this function can be called from another thread, therefore requires its own RTest instance
|
sl@0
|
159 |
LOCAL_C TInt WriteFile(RFs& fs, TDes16& aFile, TInt aSize, TInt aBlockSize, TTestState aState)
|
sl@0
|
160 |
{
|
sl@0
|
161 |
RTest test(_L(""));
|
sl@0
|
162 |
|
sl@0
|
163 |
TInt r=0;
|
sl@0
|
164 |
RFile fileWrite;
|
sl@0
|
165 |
|
sl@0
|
166 |
test(aBlockSize>0); // Block size must be greater than 0
|
sl@0
|
167 |
|
sl@0
|
168 |
if(aState==EThreadWait)
|
sl@0
|
169 |
{
|
sl@0
|
170 |
gSync.Wait();
|
sl@0
|
171 |
}
|
sl@0
|
172 |
r=fileWrite.Replace(fs,aFile,EFileShareAny|EFileWrite);
|
sl@0
|
173 |
test_KErrNone(r);
|
sl@0
|
174 |
|
sl@0
|
175 |
TInt j=0;
|
sl@0
|
176 |
while(j<aSize)
|
sl@0
|
177 |
{
|
sl@0
|
178 |
r=fileWrite.Write(gBufWritePtr, writeSize);
|
sl@0
|
179 |
test_KErrNone(r);
|
sl@0
|
180 |
if(seekType)
|
sl@0
|
181 |
{
|
sl@0
|
182 |
r=fileWrite.Seek(seekType, seekSize);
|
sl@0
|
183 |
test_KErrNone(r);
|
sl@0
|
184 |
|
sl@0
|
185 |
if (writeSize + reduceSize >= 0)
|
sl@0
|
186 |
writeSize += reduceSize;
|
sl@0
|
187 |
|
sl@0
|
188 |
writeSize = Min(writeSize, gBufWritePtr.Length());
|
sl@0
|
189 |
|
sl@0
|
190 |
}
|
sl@0
|
191 |
if((j==0)&&(aState==EThreadSignal))
|
sl@0
|
192 |
{
|
sl@0
|
193 |
gSync.Signal();
|
sl@0
|
194 |
}
|
sl@0
|
195 |
j+=aBlockSize;
|
sl@0
|
196 |
}
|
sl@0
|
197 |
|
sl@0
|
198 |
fileWrite.Close();
|
sl@0
|
199 |
|
sl@0
|
200 |
return KErrNone;
|
sl@0
|
201 |
}
|
sl@0
|
202 |
|
sl@0
|
203 |
LOCAL_C void IniStatus(TRequestStatus aStatus[], TInt aSize)
|
sl@0
|
204 |
{
|
sl@0
|
205 |
TInt i=0;
|
sl@0
|
206 |
|
sl@0
|
207 |
while(i<aSize)
|
sl@0
|
208 |
{
|
sl@0
|
209 |
aStatus[i++]=KRequestPending;
|
sl@0
|
210 |
}
|
sl@0
|
211 |
}
|
sl@0
|
212 |
|
sl@0
|
213 |
//
|
sl@0
|
214 |
// Write big file
|
sl@0
|
215 |
// This is a thread function, therefore requires its own RTest instance
|
sl@0
|
216 |
LOCAL_C TInt WriteBigFile(TAny* )
|
sl@0
|
217 |
{
|
sl@0
|
218 |
RTest test(_L(""));
|
sl@0
|
219 |
RFs fs;
|
sl@0
|
220 |
TInt r=fs.Connect(gDriveToTest);
|
sl@0
|
221 |
test_KErrNone(r);
|
sl@0
|
222 |
|
sl@0
|
223 |
r=fs.SetSessionPath(gSessionPath);
|
sl@0
|
224 |
test_KErrNone(r);
|
sl@0
|
225 |
|
sl@0
|
226 |
WriteFile(fs, gBigFile, gBigFileSize, KBlockSize, EThreadSignal);
|
sl@0
|
227 |
gTime1.HomeTime();
|
sl@0
|
228 |
|
sl@0
|
229 |
client.Signal();
|
sl@0
|
230 |
return ETrue;
|
sl@0
|
231 |
}
|
sl@0
|
232 |
|
sl@0
|
233 |
//
|
sl@0
|
234 |
// Writes a file asynchronously in blocks of aBlockSize size
|
sl@0
|
235 |
// this function can be called from another thread, therefore requires its own RTest instance
|
sl@0
|
236 |
LOCAL_C void WriteFileAsync(RFs& fs, RFile& aFileWrite, TDes16& aFile, TInt aSize, TInt aBlockSize, TRequestStatus aStatus[])
|
sl@0
|
237 |
{
|
sl@0
|
238 |
RTest test(_L(""));
|
sl@0
|
239 |
|
sl@0
|
240 |
TInt r=0;
|
sl@0
|
241 |
|
sl@0
|
242 |
test(aBlockSize>0); // Block size must be greater than 0
|
sl@0
|
243 |
test((aSize%aBlockSize)==0); // Ensure the size of the file is a multiple of the block size
|
sl@0
|
244 |
|
sl@0
|
245 |
r=aFileWrite.Replace(fs,aFile,EFileShareAny|EFileWrite);
|
sl@0
|
246 |
test_KErrNone(r);
|
sl@0
|
247 |
|
sl@0
|
248 |
TInt j=0,i=0;
|
sl@0
|
249 |
while(j<aSize)
|
sl@0
|
250 |
{
|
sl@0
|
251 |
aFileWrite.Write(gBufWritePtr,aStatus[i++]);
|
sl@0
|
252 |
j+=aBlockSize;
|
sl@0
|
253 |
}
|
sl@0
|
254 |
}
|
sl@0
|
255 |
|
sl@0
|
256 |
|
sl@0
|
257 |
|
sl@0
|
258 |
//
|
sl@0
|
259 |
// Write big file async
|
sl@0
|
260 |
// This is a thread function, therefore requires its own RTest instance
|
sl@0
|
261 |
LOCAL_C TInt WriteBigFileAsync(TAny* )
|
sl@0
|
262 |
{
|
sl@0
|
263 |
RTest test(_L(""));
|
sl@0
|
264 |
RFs fs;
|
sl@0
|
265 |
TInt r=fs.Connect(gDriveToTest);
|
sl@0
|
266 |
test_KErrNone(r);
|
sl@0
|
267 |
|
sl@0
|
268 |
r=fs.SetSessionPath(gSessionPath);
|
sl@0
|
269 |
test_KErrNone(r);
|
sl@0
|
270 |
|
sl@0
|
271 |
|
sl@0
|
272 |
RFile bigFile;
|
sl@0
|
273 |
|
sl@0
|
274 |
IniStatus(gStatus,KWaitRequestsTableSize);
|
sl@0
|
275 |
WriteFileAsync(fs, bigFile, gSmallFile, gBigFileSize, KBlockSize,gStatus);
|
sl@0
|
276 |
gSync.Signal();
|
sl@0
|
277 |
WaitForAll(gStatus, gBigFileSize/KBlockSize);
|
sl@0
|
278 |
|
sl@0
|
279 |
return ETrue;
|
sl@0
|
280 |
}
|
sl@0
|
281 |
|
sl@0
|
282 |
static void TestClientDies()
|
sl@0
|
283 |
{
|
sl@0
|
284 |
test.Next(_L("Client dying unexpectedly"));
|
sl@0
|
285 |
|
sl@0
|
286 |
TInt r=0;
|
sl@0
|
287 |
TBuf<20> unit=_L("?:\\");
|
sl@0
|
288 |
unit[0]=(TText)gDriveToTest;
|
sl@0
|
289 |
|
sl@0
|
290 |
//-------------------------------------------
|
sl@0
|
291 |
test.Printf(_L("Sync test\n"));
|
sl@0
|
292 |
|
sl@0
|
293 |
r=gBig.Create(_L("TEST1"),WriteBigFile,KDefaultStackSize,KHeapSize,KMaxHeapSize,NULL);
|
sl@0
|
294 |
test_KErrNone(r);
|
sl@0
|
295 |
|
sl@0
|
296 |
gBig.Resume();
|
sl@0
|
297 |
gSync.Wait();
|
sl@0
|
298 |
|
sl@0
|
299 |
gBig.Kill(-2);
|
sl@0
|
300 |
gBig.Close();
|
sl@0
|
301 |
User::After(500000);
|
sl@0
|
302 |
|
sl@0
|
303 |
r=TheFs.CheckDisk(unit);
|
sl@0
|
304 |
test_Value(r, r == KErrNone || r == KErrNotSupported);
|
sl@0
|
305 |
|
sl@0
|
306 |
//-------------------------------------------
|
sl@0
|
307 |
test.Printf(_L("Async test\n"));
|
sl@0
|
308 |
r=gSmall.Create(_L("TEST2"),WriteBigFileAsync,KDefaultStackSize*2,KHeapSize,KMaxHeapSize,NULL);
|
sl@0
|
309 |
test_KErrNone(r);
|
sl@0
|
310 |
|
sl@0
|
311 |
gSmall.Resume();
|
sl@0
|
312 |
gSync.Wait();
|
sl@0
|
313 |
|
sl@0
|
314 |
gSmall.Kill(-2);
|
sl@0
|
315 |
gSmall.Close();
|
sl@0
|
316 |
User::After(500000);
|
sl@0
|
317 |
|
sl@0
|
318 |
r=TheFs.CheckDisk(unit);
|
sl@0
|
319 |
test_Value(r, r == KErrNone || r == KErrNotSupported);
|
sl@0
|
320 |
|
sl@0
|
321 |
//-------------------------------------------
|
sl@0
|
322 |
test.Printf(_L("Testing for size not multiple of blocksize\n"));
|
sl@0
|
323 |
|
sl@0
|
324 |
writeSize = 5000;
|
sl@0
|
325 |
r=gBig.Create(_L("TEST3"),WriteBigFile,KDefaultStackSize,KHeapSize,KMaxHeapSize,NULL);
|
sl@0
|
326 |
test_KErrNone(r);
|
sl@0
|
327 |
gBig.Resume();
|
sl@0
|
328 |
gSync.Wait();
|
sl@0
|
329 |
|
sl@0
|
330 |
gBig.Kill(-2);
|
sl@0
|
331 |
gBig.Close();
|
sl@0
|
332 |
User::After(500000);
|
sl@0
|
333 |
|
sl@0
|
334 |
r=TheFs.CheckDisk(unit);
|
sl@0
|
335 |
test_Value(r, r == KErrNone || r == KErrNotSupported);
|
sl@0
|
336 |
|
sl@0
|
337 |
//-------------------------------------------
|
sl@0
|
338 |
test.Printf(_L("Testing with seek current and write inside the file boundary\n"));
|
sl@0
|
339 |
|
sl@0
|
340 |
writeSize = 5000;
|
sl@0
|
341 |
seekType = ESeekCurrent;
|
sl@0
|
342 |
seekSize = -5000;
|
sl@0
|
343 |
reduceSize = -3000;
|
sl@0
|
344 |
r=gBig.Create(_L("TEST4"),WriteBigFile,KDefaultStackSize,KHeapSize,KMaxHeapSize,NULL);
|
sl@0
|
345 |
test_KErrNone(r);
|
sl@0
|
346 |
gBig.Resume();
|
sl@0
|
347 |
gSync.Wait();
|
sl@0
|
348 |
|
sl@0
|
349 |
gBig.Kill(-2);
|
sl@0
|
350 |
gBig.Close();
|
sl@0
|
351 |
User::After(500000);
|
sl@0
|
352 |
|
sl@0
|
353 |
r=TheFs.CheckDisk(unit);
|
sl@0
|
354 |
test_Value(r, r == KErrNone || r == KErrNotSupported);
|
sl@0
|
355 |
|
sl@0
|
356 |
//-------------------------------------------
|
sl@0
|
357 |
test.Printf(_L("Testing with seek current and overwrite entire file\n"));
|
sl@0
|
358 |
writeSize = 5000;
|
sl@0
|
359 |
seekType = ESeekCurrent;
|
sl@0
|
360 |
seekSize = -5000;
|
sl@0
|
361 |
reduceSize = 0;
|
sl@0
|
362 |
r=gBig.Create(_L("TEST5"),WriteBigFile,KDefaultStackSize,KHeapSize,KMaxHeapSize,NULL);
|
sl@0
|
363 |
test_KErrNone(r);
|
sl@0
|
364 |
gBig.Resume();
|
sl@0
|
365 |
gSync.Wait();
|
sl@0
|
366 |
|
sl@0
|
367 |
gBig.Kill(-2);
|
sl@0
|
368 |
gBig.Close();
|
sl@0
|
369 |
User::After(500000);
|
sl@0
|
370 |
|
sl@0
|
371 |
r=TheFs.CheckDisk(unit);
|
sl@0
|
372 |
test_Value(r, r == KErrNone || r == KErrNotSupported);
|
sl@0
|
373 |
|
sl@0
|
374 |
//-------------------------------------------
|
sl@0
|
375 |
test.Printf(_L("Testing with seek current and write outside the file boundary\n"));
|
sl@0
|
376 |
|
sl@0
|
377 |
writeSize = 5000;
|
sl@0
|
378 |
seekType = ESeekCurrent;
|
sl@0
|
379 |
seekSize = -5000;
|
sl@0
|
380 |
reduceSize = 5000;
|
sl@0
|
381 |
r=gBig.Create(_L("TEST6"),WriteBigFile,KDefaultStackSize,KHeapSize,KMaxHeapSize,NULL);
|
sl@0
|
382 |
test_KErrNone(r);
|
sl@0
|
383 |
gBig.Resume();
|
sl@0
|
384 |
gSync.Wait();
|
sl@0
|
385 |
|
sl@0
|
386 |
gBig.Kill(-2);
|
sl@0
|
387 |
gBig.Close();
|
sl@0
|
388 |
User::After(500000);
|
sl@0
|
389 |
|
sl@0
|
390 |
r=TheFs.CheckDisk(unit);
|
sl@0
|
391 |
test_Value(r, r == KErrNone || r == KErrNotSupported);
|
sl@0
|
392 |
|
sl@0
|
393 |
//-------------------------------------------
|
sl@0
|
394 |
test.Printf(_L("Testing with seek current and write within the file boundary\n"));
|
sl@0
|
395 |
writeSize = 5000;
|
sl@0
|
396 |
seekType = ESeekCurrent;
|
sl@0
|
397 |
seekSize = -3000;
|
sl@0
|
398 |
reduceSize = -4000;
|
sl@0
|
399 |
r=gBig.Create(_L("TEST7"),WriteBigFile,KDefaultStackSize,KHeapSize,KMaxHeapSize,NULL);
|
sl@0
|
400 |
test_KErrNone(r);
|
sl@0
|
401 |
gBig.Resume();
|
sl@0
|
402 |
gSync.Wait();
|
sl@0
|
403 |
|
sl@0
|
404 |
gBig.Kill(-2);
|
sl@0
|
405 |
gBig.Close();
|
sl@0
|
406 |
User::After(500000);
|
sl@0
|
407 |
|
sl@0
|
408 |
r=TheFs.CheckDisk(unit);
|
sl@0
|
409 |
test_Value(r, r == KErrNone || r == KErrNotSupported);
|
sl@0
|
410 |
|
sl@0
|
411 |
//-------------------------------------------
|
sl@0
|
412 |
test.Printf(_L("Testing with seek current and write exactly to file size\n"));
|
sl@0
|
413 |
writeSize = 5000;
|
sl@0
|
414 |
seekType = ESeekCurrent;
|
sl@0
|
415 |
seekSize = -3000;
|
sl@0
|
416 |
reduceSize = -3000;
|
sl@0
|
417 |
r=gBig.Create(_L("TEST8"),WriteBigFile,KDefaultStackSize,KHeapSize,KMaxHeapSize,NULL);
|
sl@0
|
418 |
test_KErrNone(r);
|
sl@0
|
419 |
gBig.Resume();
|
sl@0
|
420 |
gSync.Wait();
|
sl@0
|
421 |
|
sl@0
|
422 |
gBig.Kill(-2);
|
sl@0
|
423 |
gBig.Close();
|
sl@0
|
424 |
User::After(500000);
|
sl@0
|
425 |
|
sl@0
|
426 |
r=TheFs.CheckDisk(unit);
|
sl@0
|
427 |
test_Value(r, r == KErrNone || r == KErrNotSupported);
|
sl@0
|
428 |
|
sl@0
|
429 |
//-------------------------------------------
|
sl@0
|
430 |
test.Printf(_L("Testing with seek current and write greater than file size\n"));
|
sl@0
|
431 |
writeSize = 5000;
|
sl@0
|
432 |
seekType = ESeekCurrent;
|
sl@0
|
433 |
seekSize = -3000;
|
sl@0
|
434 |
reduceSize = 10000;
|
sl@0
|
435 |
r=gBig.Create(_L("TEST9"),WriteBigFile,KDefaultStackSize,KHeapSize,KMaxHeapSize,NULL);
|
sl@0
|
436 |
test_KErrNone(r);
|
sl@0
|
437 |
gBig.Resume();
|
sl@0
|
438 |
gSync.Wait();
|
sl@0
|
439 |
|
sl@0
|
440 |
gBig.Kill(-2);
|
sl@0
|
441 |
gBig.Close();
|
sl@0
|
442 |
User::After(500000);
|
sl@0
|
443 |
|
sl@0
|
444 |
r=TheFs.CheckDisk(unit);
|
sl@0
|
445 |
test_Value(r, r == KErrNone || r == KErrNotSupported);
|
sl@0
|
446 |
|
sl@0
|
447 |
TInt retries = 0;
|
sl@0
|
448 |
|
sl@0
|
449 |
do
|
sl@0
|
450 |
{
|
sl@0
|
451 |
r=TheFs.ScanDrive(unit);
|
sl@0
|
452 |
if (r != KErrNone)
|
sl@0
|
453 |
test.Printf(_L("ScanDrive() returned %d\n"), r);
|
sl@0
|
454 |
if (r == KErrInUse)
|
sl@0
|
455 |
User::After(500000);
|
sl@0
|
456 |
}
|
sl@0
|
457 |
while (r == KErrInUse && ++retries < 5);
|
sl@0
|
458 |
|
sl@0
|
459 |
test_Value(r, r == KErrNone || r == KErrNotSupported);
|
sl@0
|
460 |
|
sl@0
|
461 |
}
|
sl@0
|
462 |
|
sl@0
|
463 |
|
sl@0
|
464 |
//---------------------------------------------------------------------
|
sl@0
|
465 |
/**
|
sl@0
|
466 |
Test that CheckDisk will not cause stack overflow on very deep directory structure.
|
sl@0
|
467 |
*/
|
sl@0
|
468 |
void TestCheckDisk_VeryDeepDirectory()
|
sl@0
|
469 |
{
|
sl@0
|
470 |
test.Next(_L("Testing deep dir structure check"));
|
sl@0
|
471 |
|
sl@0
|
472 |
TInt nRes;
|
sl@0
|
473 |
TBuf<20> unit=_L("?:\\");
|
sl@0
|
474 |
unit[0]=(TText)gDriveToTest;
|
sl@0
|
475 |
|
sl@0
|
476 |
//-- 1. create deep dir structure, like \\0\\1\\2\\...... 90 levels deep
|
sl@0
|
477 |
const TInt KMaxDirDepth = 90;
|
sl@0
|
478 |
|
sl@0
|
479 |
test.Printf(_L("Creating directory with %d subdirs.\n"),KMaxDirDepth);
|
sl@0
|
480 |
|
sl@0
|
481 |
TFileName fn;
|
sl@0
|
482 |
for(TInt i=0; i<KMaxDirDepth; ++i)
|
sl@0
|
483 |
{
|
sl@0
|
484 |
fn.AppendFormat(_L("\\%d"), i%10);
|
sl@0
|
485 |
}
|
sl@0
|
486 |
fn.Append(_L("\\"));
|
sl@0
|
487 |
|
sl@0
|
488 |
nRes = TheFs.MkDirAll(fn);
|
sl@0
|
489 |
test_Value(nRes, nRes == KErrNone || nRes == KErrAlreadyExists);
|
sl@0
|
490 |
|
sl@0
|
491 |
//-- 2. invoke Check Disk and ensure that target doesn't die from stack overflow.
|
sl@0
|
492 |
test.Printf(_L("Running Check Disk...\n"));
|
sl@0
|
493 |
nRes = TheFs.CheckDisk(unit);
|
sl@0
|
494 |
|
sl@0
|
495 |
test_Value(nRes, nRes == KErrNone || nRes == KErrTooBig);
|
sl@0
|
496 |
}
|
sl@0
|
497 |
|
sl@0
|
498 |
|
sl@0
|
499 |
//---------------------------------------------------------------------
|
sl@0
|
500 |
//
|
sl@0
|
501 |
// This test tries to read a small file while writing a big one
|
sl@0
|
502 |
//
|
sl@0
|
503 |
GLDEF_C void CallTestsL()
|
sl@0
|
504 |
{
|
sl@0
|
505 |
TBuf16<45> dir;
|
sl@0
|
506 |
|
sl@0
|
507 |
test.Next(_L("Preparing the environmnet\n"));
|
sl@0
|
508 |
|
sl@0
|
509 |
FileNameGen(gSmallFile, 8, gNextFile++);
|
sl@0
|
510 |
FileNameGen(gBigFile, 8, gNextFile++);
|
sl@0
|
511 |
dir=gSessionPath;
|
sl@0
|
512 |
dir.Append(gSmallFile);
|
sl@0
|
513 |
gSmallFile=dir;
|
sl@0
|
514 |
dir=gSessionPath;
|
sl@0
|
515 |
dir.Append(gBigFile);
|
sl@0
|
516 |
gBigFile=dir;
|
sl@0
|
517 |
|
sl@0
|
518 |
TRAPD(res,gBuf = HBufC8::NewL(KBlockSize+1));
|
sl@0
|
519 |
test(res == KErrNone && gBuf != NULL);
|
sl@0
|
520 |
|
sl@0
|
521 |
gBufWritePtr.Set(gBuf->Des());
|
sl@0
|
522 |
FillBuffer(gBufWritePtr, KBlockSize, 'B');
|
sl@0
|
523 |
|
sl@0
|
524 |
TRAPD(res2,gBufSec = HBufC8::NewL(KBlockSize+1));
|
sl@0
|
525 |
test(res2 == KErrNone && gBufSec != NULL);
|
sl@0
|
526 |
gBufReadPtr.Set(gBufSec->Des());
|
sl@0
|
527 |
|
sl@0
|
528 |
//---------------------------
|
sl@0
|
529 |
|
sl@0
|
530 |
TestClientDies();
|
sl@0
|
531 |
TestCheckDisk_VeryDeepDirectory();
|
sl@0
|
532 |
|
sl@0
|
533 |
delete gBuf;
|
sl@0
|
534 |
delete gBufSec;
|
sl@0
|
535 |
}
|
sl@0
|
536 |
|
sl@0
|
537 |
LOCAL_C void DoTests()
|
sl@0
|
538 |
{
|
sl@0
|
539 |
TInt r=0;
|
sl@0
|
540 |
|
sl@0
|
541 |
r=client.CreateLocal(0);
|
sl@0
|
542 |
test_KErrNone(r);
|
sl@0
|
543 |
|
sl@0
|
544 |
r=gSync.CreateLocal(0);
|
sl@0
|
545 |
test_KErrNone(r);
|
sl@0
|
546 |
|
sl@0
|
547 |
r=TheFs.SetSessionPath(gSessionPath);
|
sl@0
|
548 |
test_KErrNone(r);
|
sl@0
|
549 |
|
sl@0
|
550 |
r=TheFs.MkDirAll(gSessionPath);
|
sl@0
|
551 |
test_Value(r, r == KErrNone || r == KErrAlreadyExists);
|
sl@0
|
552 |
|
sl@0
|
553 |
TheFs.ResourceCountMarkStart();
|
sl@0
|
554 |
TRAP(r,CallTestsL());
|
sl@0
|
555 |
test_KErrNone(r);
|
sl@0
|
556 |
TheFs.ResourceCountMarkEnd();
|
sl@0
|
557 |
}
|
sl@0
|
558 |
|
sl@0
|
559 |
TBool CheckForDiskSize()
|
sl@0
|
560 |
{
|
sl@0
|
561 |
TVolumeInfo volInfo;
|
sl@0
|
562 |
TInt r = TheFs.Volume(volInfo, gDrive);
|
sl@0
|
563 |
test_KErrNone(r);
|
sl@0
|
564 |
|
sl@0
|
565 |
gMediaSize = volInfo.iSize;
|
sl@0
|
566 |
gSmallFileSize = KBlockSize;
|
sl@0
|
567 |
gBigFileSize = KBlockSize*20;
|
sl@0
|
568 |
while(((2*gBigFileSize)+KOneMeg) > gMediaSize )
|
sl@0
|
569 |
{
|
sl@0
|
570 |
gBigFileSize -= (2*KBlockSize);
|
sl@0
|
571 |
}
|
sl@0
|
572 |
|
sl@0
|
573 |
if(gBigFileSize< (3*gSmallFileSize))
|
sl@0
|
574 |
return EFalse;
|
sl@0
|
575 |
else
|
sl@0
|
576 |
return ETrue;
|
sl@0
|
577 |
}
|
sl@0
|
578 |
|
sl@0
|
579 |
void Format(TInt aDrive)
|
sl@0
|
580 |
{
|
sl@0
|
581 |
|
sl@0
|
582 |
test.Next(_L("Format"));
|
sl@0
|
583 |
TBuf<4> driveBuf=_L("?:\\");
|
sl@0
|
584 |
driveBuf[0]=(TText)(aDrive+'A');
|
sl@0
|
585 |
RFormat format;
|
sl@0
|
586 |
TInt count;
|
sl@0
|
587 |
TInt r=format.Open(TheFs,driveBuf,EQuickFormat,count);
|
sl@0
|
588 |
test_KErrNone(r);
|
sl@0
|
589 |
|
sl@0
|
590 |
while(count)
|
sl@0
|
591 |
{
|
sl@0
|
592 |
TInt r=format.Next(count);
|
sl@0
|
593 |
test_KErrNone(r);
|
sl@0
|
594 |
}
|
sl@0
|
595 |
format.Close();
|
sl@0
|
596 |
}
|
sl@0
|
597 |
|
sl@0
|
598 |
|
sl@0
|
599 |
static TBool IsFAT(RFs &aFsSession, TInt aDrive)
|
sl@0
|
600 |
{
|
sl@0
|
601 |
_LIT(KFatName, "Fat");
|
sl@0
|
602 |
|
sl@0
|
603 |
TFileName f;
|
sl@0
|
604 |
TInt r = aFsSession.FileSystemName(f, aDrive);
|
sl@0
|
605 |
test_Value(r, r == KErrNone || r == KErrNotFound);
|
sl@0
|
606 |
return (f.CompareF(KFatName) == 0);
|
sl@0
|
607 |
}
|
sl@0
|
608 |
|
sl@0
|
609 |
|
sl@0
|
610 |
GLDEF_C TInt E32Main()
|
sl@0
|
611 |
{
|
sl@0
|
612 |
|
sl@0
|
613 |
CTrapCleanup* cleanup;
|
sl@0
|
614 |
cleanup=CTrapCleanup::New();
|
sl@0
|
615 |
|
sl@0
|
616 |
__UHEAP_MARK;
|
sl@0
|
617 |
test.Title();
|
sl@0
|
618 |
test.Start(_L("Starting tests..."));
|
sl@0
|
619 |
parseCommandLine();
|
sl@0
|
620 |
|
sl@0
|
621 |
TInt r = TheFs.Connect();
|
sl@0
|
622 |
test_KErrNone(r);
|
sl@0
|
623 |
|
sl@0
|
624 |
TDriveInfo info;
|
sl@0
|
625 |
TVolumeInfo volInfo;
|
sl@0
|
626 |
r=TheFs.Drive(info,gDrive);
|
sl@0
|
627 |
test_KErrNone(r);
|
sl@0
|
628 |
|
sl@0
|
629 |
if(info.iMediaAtt&KMediaAttVariableSize)
|
sl@0
|
630 |
{// Not testing in RAM Drives
|
sl@0
|
631 |
test.Printf(_L("Tests skipped in RAM drive\n"));
|
sl@0
|
632 |
goto out;
|
sl@0
|
633 |
}
|
sl@0
|
634 |
|
sl@0
|
635 |
r = TheFs.Volume(volInfo, gDrive);
|
sl@0
|
636 |
if (r == KErrNotReady)
|
sl@0
|
637 |
{
|
sl@0
|
638 |
if (info.iType == EMediaNotPresent)
|
sl@0
|
639 |
test.Printf(_L("%c: Medium not present - cannot perform test.\n"), (TUint)gDriveToTest);
|
sl@0
|
640 |
else
|
sl@0
|
641 |
test.Printf(_L("%c: medium found (type %d) but drive not ready\nPrevious test may have hung; else, check hardware.\n"), (TUint)gDriveToTest, (TInt)info.iType);
|
sl@0
|
642 |
}
|
sl@0
|
643 |
else if (r == KErrCorrupt)
|
sl@0
|
644 |
{
|
sl@0
|
645 |
test.Printf(_L("%c: Media corruption; previous test may have aborted; else, check hardware\n"), (TUint)gDriveToTest);
|
sl@0
|
646 |
}
|
sl@0
|
647 |
test_KErrNone(r);
|
sl@0
|
648 |
|
sl@0
|
649 |
if(!IsFAT(TheFs, gDrive))
|
sl@0
|
650 |
{
|
sl@0
|
651 |
test.Printf(_L("Tests skipped on non-FAT drive\n"));
|
sl@0
|
652 |
goto out;
|
sl@0
|
653 |
}
|
sl@0
|
654 |
|
sl@0
|
655 |
if ((volInfo.iDrive.iMediaAtt & KMediaAttFormattable))
|
sl@0
|
656 |
Format(gDrive);
|
sl@0
|
657 |
|
sl@0
|
658 |
if(CheckForDiskSize())
|
sl@0
|
659 |
{
|
sl@0
|
660 |
DoTests();
|
sl@0
|
661 |
if ((volInfo.iDrive.iMediaAtt & KMediaAttFormattable))
|
sl@0
|
662 |
Format(gDrive);
|
sl@0
|
663 |
}
|
sl@0
|
664 |
else
|
sl@0
|
665 |
{
|
sl@0
|
666 |
test.Printf(_L("Skipping tests due to lack of space to perform them in this unit\n"));
|
sl@0
|
667 |
}
|
sl@0
|
668 |
out:
|
sl@0
|
669 |
test.End();
|
sl@0
|
670 |
|
sl@0
|
671 |
TheFs.Close();
|
sl@0
|
672 |
test.Close();
|
sl@0
|
673 |
|
sl@0
|
674 |
__UHEAP_MARKEND;
|
sl@0
|
675 |
delete cleanup;
|
sl@0
|
676 |
return(KErrNone);
|
sl@0
|
677 |
}
|