Update contrib.
1 // Copyright (c) 2002-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 // Soak tests reading from files
19 #include <e32std_private.h>
26 GLDEF_D TInt gDriveNum;
28 RTest test( _L("T_ROFSSOAK") );
30 _LIT( KTestFile1, "ReadTest\\A\\file1" );
31 _LIT( KTestFile2, "ReadTest\\A\\file2" );
32 _LIT( KTestFile3, "ReadTest\\B\\B3\\testfile" );
33 _LIT( KTestFile4, "ReadTest\\B\\B4\\testfile" );
34 _LIT( KTestFile5, "ReadTest\\D\\eoftest4" );
35 _LIT( KTestFile6, "ReadTest\\D\\eoftest5" );
36 _LIT( KTestFile7, "ReadTest\\E\\stream3" );
37 _LIT( KTestFile8, "ReadTest\\E\\stream4" );
38 _LIT( KTestFile9, "ReadTest\\C\\seektest" );
39 _LIT( KTestFile10, "ReadTest\\D\\eoftest1" );
40 _LIT( KTestFile11, "ReadTest\\D\\eoftest2" );
41 _LIT( KTestFile12, "ReadTest\\D\\eoftest3" );
42 _LIT( KTestFile13, "ReadTest\\A\\file3" );
43 _LIT( KTestFile14, "ReadTest\\A\\file4" );
44 _LIT( KTestFile15, "ReadTest\\B\\B2\\testfile" );
45 _LIT( KTestFile16, "ReadTest\\E\\stream2" );
47 const TInt KTestFileCount = 16;
56 const TestFiles TheFileArray[KTestFileCount] =
58 { &KTestFile1, 256, 0xEF1113BC},
59 { &KTestFile2, 256, 0x04082195},
60 { &KTestFile3, 800, 0x42D4BF02},
61 { &KTestFile4, 304, 0x47C728FB},
62 { &KTestFile5, 30, 0x0CAAF228},
63 { &KTestFile6, 7000, 0x1128A9A5},
64 { &KTestFile7, 2000, 0x8DA9AA5A},
65 { &KTestFile8, 17466, 0x8DA9AA5A},
66 { &KTestFile9, 17466, 0x8DA9AA5A},
67 { &KTestFile10, 3, 0x8DA9AA5A},
68 { &KTestFile11, 7, 0x8DA9AA5A},
69 { &KTestFile12, 64, 0x8DA9AA5A},
70 { &KTestFile13, 256, 0xEC36D359},
71 { &KTestFile14, 256, 0x07D4DAC2},
72 { &KTestFile15, 500, 0x735AA240},
73 { &KTestFile16, 5000, 0x8DA9AA5A}
77 _LIT( KDriveBase, " :\\" );
82 LOCAL_C void FillRandomBuffer( TDes8& aDes, TRandomGenerator& aRand, TInt aLength )
84 aDes.SetLength( aLength );
85 TUint* ptr = (TUint*)aDes.Ptr();
88 TUint v = aRand.Next();
94 TUint v = aRand.Next();
95 TUint8* p8 = (TUint8*)ptr;
98 *p8++ = (TUint8)(v & 0xFF);
108 _LIT( KCat, "Fail" );
109 RProcess().Panic( KCat, 0 );
110 //RProcess().Terminate(0);
114 LOCAL_C void DoTestFile( TInt aFileIndex, TInt aThreadNumber )
117 TRandomGenerator rand;
119 TFileName name(KDriveBase);
120 name[0] = TText('A' + gDriveNum);
121 name.Append( *TheFileArray[aFileIndex].iName );
123 _LIT( KOpeningMessage, "Thread %d opening file %S" );
124 RDebug::Print( KOpeningMessage, aThreadNumber, &name );
126 TInt r = file.Open( TheFs, name, EFileRead | EFileShareReadersOnly );
129 _LIT( KOpenFailMessage, "Thread %d open failed (%d)" );
130 RDebug::Print( KOpenFailMessage, aThreadNumber, r );
136 r = file.Size( fileLength );
139 _LIT( KSizeFailMessage, "Thread %d open failed (%d)" );
140 RDebug::Print( KSizeFailMessage, aThreadNumber, r );
144 if( fileLength != TheFileArray[aFileIndex].iLength )
146 _LIT( KLengthFailMessage, "Thread %d file length mismatch (%d %d)" );
147 RDebug::Print( KLengthFailMessage, aThreadNumber, fileLength, TheFileArray[aFileIndex].iLength );
151 const TInt KReadLen = 16;
152 TBuf8<KReadLen> readBuf;
153 TBuf8<KReadLen> randomBuf;
155 rand.SetSeed( TheFileArray[aFileIndex].iSeed );
157 TInt fragmentCount = (fileLength + KReadLen - 1) / KReadLen;
158 TInt lengthRemaining = fileLength;
160 for( TInt fragment = 0; fragment < fragmentCount; ++fragment )
162 TInt readLen = Min( KReadLen, lengthRemaining );
164 // read next fragment from each file and compare
165 FillRandomBuffer( randomBuf, rand, readLen );
166 r = file.Read( readBuf );
170 _LIT( KReadFailMessage, "Thread %d read failed (%d)" );
171 RDebug::Print( KReadFailMessage, aThreadNumber, r );
174 if( readLen != readBuf.Length() )
176 _LIT( KReadLenFailMessage, "Thread %d read length mismatch (%d %d)" );
177 RDebug::Print( KReadLenFailMessage, aThreadNumber, readLen, readBuf.Length() );
181 if( readBuf != randomBuf )
183 _LIT( KCmpFailMessage, "Thread %d read data mismatch" );
184 RDebug::Print( KCmpFailMessage, aThreadNumber );
187 lengthRemaining -= readLen;
196 LOCAL_C TInt SoakThread( TAny* aParam )
198 // Runs through the list of files opening and reading them
199 // comparing against the random number generator
201 // aParam is the index in TheFileArray of the first file to test
202 // and is also the thread number
205 const TInt threadNumber = (TInt)aParam;
206 TInt nextFileIndex = (3 * threadNumber) % KTestFileCount;
208 TRandomGenerator randTime;
209 randTime.SetSeed( 0xA4BB926A * nextFileIndex );
213 DoTestFile( nextFileIndex, threadNumber );
214 User::After( randTime.Next() % 250000 );
215 nextFileIndex = (nextFileIndex + 1) % KTestFileCount;
225 //************************
228 void DoTestL(TInt aDriveToTest)
231 test.Start( _L("Testing ROFS file reading") );
233 gDriveNum = aDriveToTest;
234 // Share file server session between all threads
242 thread1.Create( _L("ROFSSOAK1"), SoakThread, 4096, 4096, 65536, (TAny*)0 );
243 thread2.Create( _L("ROFSSOAK2"), SoakThread, 4096, 4096, 65536, (TAny*)1 );
244 thread3.Create( _L("ROFSSOAK3"), SoakThread, 4096, 4096, 65536, (TAny*)2 );
245 thread4.Create( _L("ROFSSOAK4"), SoakThread, 4096, 4096, 65536, (TAny*)3 );