|
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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Soak tests reading from files |
|
15 // |
|
16 // |
|
17 |
|
18 #include <e32std.h> |
|
19 #include <e32std_private.h> |
|
20 #include <e32test.h> |
|
21 #include <f32file.h> |
|
22 #include "utl.h" |
|
23 #include "randgen.h" |
|
24 |
|
25 GLREF_D RFs TheFs; |
|
26 GLDEF_D TInt gDriveNum; |
|
27 |
|
28 RTest test( _L("T_ROFSSOAK") ); |
|
29 |
|
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" ); |
|
46 |
|
47 const TInt KTestFileCount = 16; |
|
48 |
|
49 struct TestFiles |
|
50 { |
|
51 const TDesC* iName; |
|
52 TInt iLength; |
|
53 TUint iSeed; |
|
54 }; |
|
55 |
|
56 const TestFiles TheFileArray[KTestFileCount] = |
|
57 { |
|
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} |
|
74 }; |
|
75 |
|
76 |
|
77 _LIT( KDriveBase, " :\\" ); |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 LOCAL_C void FillRandomBuffer( TDes8& aDes, TRandomGenerator& aRand, TInt aLength ) |
|
83 { |
|
84 aDes.SetLength( aLength ); |
|
85 TUint* ptr = (TUint*)aDes.Ptr(); |
|
86 while( aLength >= 4 ) |
|
87 { |
|
88 TUint v = aRand.Next(); |
|
89 *ptr++ = v; |
|
90 aLength -= 4; |
|
91 } |
|
92 if( aLength ) |
|
93 { |
|
94 TUint v = aRand.Next(); |
|
95 TUint8* p8 = (TUint8*)ptr; |
|
96 while( aLength ) |
|
97 { |
|
98 *p8++ = (TUint8)(v & 0xFF); |
|
99 v >>= 8; |
|
100 --aLength; |
|
101 } |
|
102 } |
|
103 } |
|
104 |
|
105 |
|
106 LOCAL_C void Die() |
|
107 { |
|
108 _LIT( KCat, "Fail" ); |
|
109 RProcess().Panic( KCat, 0 ); |
|
110 //RProcess().Terminate(0); |
|
111 } |
|
112 |
|
113 |
|
114 LOCAL_C void DoTestFile( TInt aFileIndex, TInt aThreadNumber ) |
|
115 { |
|
116 RFile file; |
|
117 TRandomGenerator rand; |
|
118 |
|
119 TFileName name(KDriveBase); |
|
120 name[0] = TText('A' + gDriveNum); |
|
121 name.Append( *TheFileArray[aFileIndex].iName ); |
|
122 |
|
123 _LIT( KOpeningMessage, "Thread %d opening file %S" ); |
|
124 RDebug::Print( KOpeningMessage, aThreadNumber, &name ); |
|
125 |
|
126 TInt r = file.Open( TheFs, name, EFileRead | EFileShareReadersOnly ); |
|
127 if( KErrNone != r ) |
|
128 { |
|
129 _LIT( KOpenFailMessage, "Thread %d open failed (%d)" ); |
|
130 RDebug::Print( KOpenFailMessage, aThreadNumber, r ); |
|
131 Die(); |
|
132 } |
|
133 |
|
134 |
|
135 TInt fileLength; |
|
136 r = file.Size( fileLength ); |
|
137 if( KErrNone != r ) |
|
138 { |
|
139 _LIT( KSizeFailMessage, "Thread %d open failed (%d)" ); |
|
140 RDebug::Print( KSizeFailMessage, aThreadNumber, r ); |
|
141 Die(); |
|
142 } |
|
143 |
|
144 if( fileLength != TheFileArray[aFileIndex].iLength ) |
|
145 { |
|
146 _LIT( KLengthFailMessage, "Thread %d file length mismatch (%d %d)" ); |
|
147 RDebug::Print( KLengthFailMessage, aThreadNumber, fileLength, TheFileArray[aFileIndex].iLength ); |
|
148 Die(); |
|
149 } |
|
150 |
|
151 const TInt KReadLen = 16; |
|
152 TBuf8<KReadLen> readBuf; |
|
153 TBuf8<KReadLen> randomBuf; |
|
154 |
|
155 rand.SetSeed( TheFileArray[aFileIndex].iSeed ); |
|
156 |
|
157 TInt fragmentCount = (fileLength + KReadLen - 1) / KReadLen; |
|
158 TInt lengthRemaining = fileLength; |
|
159 |
|
160 for( TInt fragment = 0; fragment < fragmentCount; ++fragment ) |
|
161 { |
|
162 TInt readLen = Min( KReadLen, lengthRemaining ); |
|
163 |
|
164 // read next fragment from each file and compare |
|
165 FillRandomBuffer( randomBuf, rand, readLen ); |
|
166 r = file.Read( readBuf ); |
|
167 |
|
168 if( KErrNone != r ) |
|
169 { |
|
170 _LIT( KReadFailMessage, "Thread %d read failed (%d)" ); |
|
171 RDebug::Print( KReadFailMessage, aThreadNumber, r ); |
|
172 Die(); |
|
173 } |
|
174 if( readLen != readBuf.Length() ) |
|
175 { |
|
176 _LIT( KReadLenFailMessage, "Thread %d read length mismatch (%d %d)" ); |
|
177 RDebug::Print( KReadLenFailMessage, aThreadNumber, readLen, readBuf.Length() ); |
|
178 Die(); |
|
179 } |
|
180 |
|
181 if( readBuf != randomBuf ) |
|
182 { |
|
183 _LIT( KCmpFailMessage, "Thread %d read data mismatch" ); |
|
184 RDebug::Print( KCmpFailMessage, aThreadNumber ); |
|
185 Die(); |
|
186 } |
|
187 lengthRemaining -= readLen; |
|
188 } |
|
189 file.Close(); |
|
190 } |
|
191 |
|
192 |
|
193 |
|
194 |
|
195 |
|
196 LOCAL_C TInt SoakThread( TAny* aParam ) |
|
197 // |
|
198 // Runs through the list of files opening and reading them |
|
199 // comparing against the random number generator |
|
200 // |
|
201 // aParam is the index in TheFileArray of the first file to test |
|
202 // and is also the thread number |
|
203 // |
|
204 { |
|
205 const TInt threadNumber = (TInt)aParam; |
|
206 TInt nextFileIndex = (3 * threadNumber) % KTestFileCount; |
|
207 |
|
208 TRandomGenerator randTime; |
|
209 randTime.SetSeed( 0xA4BB926A * nextFileIndex ); |
|
210 |
|
211 for(;;) |
|
212 { |
|
213 DoTestFile( nextFileIndex, threadNumber ); |
|
214 User::After( randTime.Next() % 250000 ); |
|
215 nextFileIndex = (nextFileIndex + 1) % KTestFileCount; |
|
216 } |
|
217 } |
|
218 |
|
219 |
|
220 |
|
221 |
|
222 |
|
223 |
|
224 |
|
225 //************************ |
|
226 // Entry point |
|
227 |
|
228 void DoTestL(TInt aDriveToTest) |
|
229 { |
|
230 test.Title(); |
|
231 test.Start( _L("Testing ROFS file reading") ); |
|
232 |
|
233 gDriveNum = aDriveToTest; |
|
234 // Share file server session between all threads |
|
235 TheFs.ShareAuto(); |
|
236 |
|
237 RThread thread1; |
|
238 RThread thread2; |
|
239 RThread thread3; |
|
240 RThread thread4; |
|
241 |
|
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 ); |
|
246 |
|
247 thread1.Resume(); |
|
248 thread2.Resume(); |
|
249 thread3.Resume(); |
|
250 thread4.Resume(); |
|
251 |
|
252 RThread().Suspend(); |
|
253 } |