0
|
1 |
// Copyright (c) 1996-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 |
// f32test\server\t_rcount.cpp
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
189
|
18 |
#define __E32TEST_EXTENSION__
|
0
|
19 |
#include <f32file.h>
|
|
20 |
#include <e32test.h>
|
|
21 |
|
|
22 |
#include "../server/t_server.h"
|
|
23 |
|
|
24 |
GLDEF_D RTest test(_L("T_RCOUNT"));
|
|
25 |
const TInt KHeapSize=0x2000;
|
|
26 |
|
|
27 |
LOCAL_C void Test1()
|
|
28 |
//
|
|
29 |
// Test resource counting success
|
|
30 |
//
|
|
31 |
{
|
|
32 |
|
|
33 |
test.Start(_L("Test resource count success"));
|
|
34 |
RFs TheFs;
|
|
35 |
TheFs.Connect();
|
|
36 |
RFile file;
|
|
37 |
TheFs.ResourceCountMarkStart();
|
|
38 |
TInt count=TheFs.ResourceCount();
|
|
39 |
test(count==0);
|
|
40 |
TFileName name=_L("Z:\\Test\\T_FILE.CPP");
|
|
41 |
name[0] = gExeFileName[0];
|
|
42 |
test.Printf(_L("%S\n"),&name);
|
|
43 |
TInt r=file.Open(TheFs,name,EFileRead);
|
189
|
44 |
test_KErrNone(r);
|
0
|
45 |
count=TheFs.ResourceCount();
|
|
46 |
test(count==1);
|
|
47 |
file.Close();
|
|
48 |
count=TheFs.ResourceCount();
|
|
49 |
test(count==0);
|
|
50 |
TheFs.ResourceCountMarkEnd();
|
|
51 |
TheFs.Close();
|
|
52 |
}
|
|
53 |
|
|
54 |
LOCAL_C TInt TestPanic(TAny*)
|
|
55 |
//
|
|
56 |
// The Test thread
|
|
57 |
//
|
|
58 |
{
|
|
59 |
|
|
60 |
User::SetJustInTime(EFalse);
|
|
61 |
RFs fs;
|
|
62 |
TInt r=fs.Connect();
|
189
|
63 |
test_KErrNone(r);
|
0
|
64 |
RFile file;
|
|
65 |
fs.ResourceCountMarkStart();
|
|
66 |
TFileName name=_L("Z:\\Test\\T_FILE.CPP");
|
|
67 |
name[0] = gExeFileName[0];
|
|
68 |
|
|
69 |
r=file.Open(fs,name,EFileRead);
|
189
|
70 |
test_KErrNone(r);
|
0
|
71 |
TInt count=fs.ResourceCount();
|
|
72 |
test(count==1);
|
|
73 |
fs.ResourceCountMarkEnd(); // MarkEnd without close
|
|
74 |
fs.Close();
|
|
75 |
return KErrNone;
|
|
76 |
}
|
|
77 |
|
|
78 |
LOCAL_C void Test2()
|
|
79 |
//
|
|
80 |
// Test resource count failure
|
|
81 |
//
|
|
82 |
{
|
|
83 |
|
|
84 |
test.Next(_L("Test resource count failure"));
|
|
85 |
TRequestStatus stat;
|
|
86 |
RThread t;
|
|
87 |
TInt r=t.Create(_L("TestPanicThread"),TestPanic,KDefaultStackSize,KHeapSize,KHeapSize,NULL);
|
189
|
88 |
test_KErrNone(r);
|
0
|
89 |
t.Logon(stat);
|
|
90 |
t.Resume();
|
|
91 |
User::WaitForRequest(stat);
|
|
92 |
test(t.ExitReason()==CSession2::ESesFoundResCountHeaven);
|
|
93 |
test(t.ExitType()==EExitPanic);
|
|
94 |
CLOSE_AND_WAIT(t);
|
|
95 |
}
|
|
96 |
|
|
97 |
|
|
98 |
_LIT(KDirName1, "c:\\f32-tst");
|
|
99 |
_LIT(KFileName1, "c:\\crash001.txt");
|
|
100 |
_LIT(KFileName2, "c:\\crash002.txt");
|
|
101 |
|
|
102 |
LOCAL_C TInt SendBadHandle1(TAny *)
|
|
103 |
//
|
|
104 |
// Thread is panicked when server leaves when DoFsSubCloseL() calls CObjectIx::AtL().
|
|
105 |
// Avoid case where thread is panicked by CObjectIx::Remove() because
|
|
106 |
// ! (i<iHighWaterMark) closing the first file removes all of the CObjects.
|
|
107 |
//
|
|
108 |
{
|
|
109 |
RFs fs;
|
|
110 |
test(fs.Connect() == KErrNone);
|
|
111 |
|
|
112 |
RFile f1;
|
|
113 |
test(f1.Replace(fs, KFileName1, EFileWrite) == KErrNone);
|
|
114 |
RFile fc(f1);
|
|
115 |
|
|
116 |
f1.Close();
|
|
117 |
fc.Close(); // file server panics thread here
|
|
118 |
|
|
119 |
test(EFalse);
|
|
120 |
fs.Close();
|
|
121 |
return KErrNone; // shouldn't reach here
|
|
122 |
}
|
|
123 |
|
|
124 |
|
|
125 |
LOCAL_C TInt SendBadHandle2(TAny *)
|
|
126 |
//
|
|
127 |
// Thread is panicked when server leaves when DoFsSubClose() calls CObjectIx::AtL().
|
|
128 |
// Avoid case where thread is panicked by CObjectIx() because ! pR->obj, with handle
|
|
129 |
// having been already removed.
|
|
130 |
//
|
|
131 |
{
|
|
132 |
RFs fs;
|
|
133 |
test(fs.Connect() == KErrNone);
|
|
134 |
|
|
135 |
RFile f1;
|
|
136 |
test(f1.Replace(fs, KFileName1, EFileWrite) == KErrNone);
|
|
137 |
RFile f2;
|
|
138 |
test(f2.Replace(fs, KFileName2, EFileWrite) == KErrNone);
|
|
139 |
|
|
140 |
RFile fc(f1);
|
|
141 |
f1.Close();
|
|
142 |
fc.Close(); // file server panics thread here
|
|
143 |
|
|
144 |
test(EFalse);
|
|
145 |
fs.Close();
|
|
146 |
return KErrNone; // shouldn't reach here
|
|
147 |
}
|
|
148 |
|
|
149 |
|
|
150 |
LOCAL_C TInt SendBadHandle3(TAny*)
|
|
151 |
//
|
|
152 |
// Setup a bad RFile handle then try to write to the file,
|
|
153 |
// the thread should get paniced by the file server
|
|
154 |
//
|
|
155 |
{
|
|
156 |
RFs f;
|
|
157 |
TInt r = f.Connect();
|
189
|
158 |
test_KErrNone(r);
|
0
|
159 |
|
|
160 |
RFile a;
|
|
161 |
r=a.Replace(f,KFileName1,EFileWrite);
|
189
|
162 |
test_KErrNone(r);
|
0
|
163 |
RFile b(a);
|
|
164 |
a.Close();
|
|
165 |
|
|
166 |
r=b.Write(_L8("testing testing"));
|
|
167 |
|
|
168 |
//thread should get paniced here so should not reach this
|
|
169 |
|
|
170 |
test(EFalse);
|
|
171 |
f.Close();
|
|
172 |
|
|
173 |
return KErrNone;
|
|
174 |
}
|
|
175 |
|
|
176 |
|
|
177 |
LOCAL_C TInt SendBadHandle4(TAny*)
|
|
178 |
//
|
|
179 |
// Setup a bad RDir handle then try to read the Directory,
|
|
180 |
// the thread should get panniced by the server
|
|
181 |
//
|
|
182 |
{
|
|
183 |
RFs f;
|
|
184 |
TInt r = f.Connect();
|
189
|
185 |
test_KErrNone(r);
|
0
|
186 |
|
|
187 |
RDir a;
|
|
188 |
r=a.Open(f,KDirName1,KEntryAttNormal);
|
189
|
189 |
test_KErrNone(r);
|
0
|
190 |
RDir b(a);
|
|
191 |
a.Close();
|
|
192 |
|
|
193 |
TEntryArray dummyarray;
|
|
194 |
r=b.Read(dummyarray);
|
|
195 |
|
|
196 |
//thread should get paniced here so should not reach this
|
|
197 |
|
|
198 |
test(EFalse);
|
|
199 |
f.Close();
|
|
200 |
|
|
201 |
return KErrNone;
|
|
202 |
}
|
|
203 |
|
|
204 |
LOCAL_C TInt SendBadHandle5(TAny*)
|
|
205 |
//
|
|
206 |
// Setup a bad RFormat handle then try to call next on the Format object,
|
|
207 |
// the thread should get panniced by the server
|
|
208 |
//
|
|
209 |
{
|
|
210 |
|
|
211 |
#if defined(__EPOC32__)
|
|
212 |
_LIT(KDrive1, "C:\\");
|
|
213 |
#else
|
|
214 |
_LIT(KDrive1, "X:\\");
|
|
215 |
#endif
|
|
216 |
|
|
217 |
RFs f;
|
|
218 |
TInt r = f.Connect();
|
189
|
219 |
test_KErrNone(r);
|
0
|
220 |
|
|
221 |
RFormat a;
|
|
222 |
TInt count;
|
|
223 |
r=a.Open(f,KDrive1,EQuickFormat,count);
|
189
|
224 |
test_KErrNone(r);
|
0
|
225 |
RFormat b(a);
|
|
226 |
a.Close();
|
|
227 |
|
|
228 |
r=b.Next(count);
|
|
229 |
|
|
230 |
//thread should get paniced here so should not reach this
|
|
231 |
|
|
232 |
test(EFalse);
|
|
233 |
f.Close();
|
|
234 |
|
|
235 |
return KErrNone;
|
|
236 |
}
|
|
237 |
|
|
238 |
|
|
239 |
LOCAL_C TInt SendBadHandle6(TAny*)
|
|
240 |
//
|
|
241 |
// Setup a bad RRawDisk handle then try to call read on the raw disk object,
|
|
242 |
// the thread should get panniced by the server
|
|
243 |
//
|
|
244 |
{
|
|
245 |
|
|
246 |
#if defined(__EPOC32__)
|
|
247 |
const TInt KDrive1 = EDriveC;
|
|
248 |
#else
|
|
249 |
const TInt KDrive1 = EDriveX;
|
|
250 |
#endif
|
|
251 |
|
|
252 |
RFs f;
|
|
253 |
TInt r = f.Connect();
|
189
|
254 |
test_KErrNone(r);
|
0
|
255 |
|
|
256 |
RRawDisk a;
|
|
257 |
r=a.Open(f,KDrive1);
|
|
258 |
|
189
|
259 |
test_KErrNone(r);
|
0
|
260 |
RRawDisk b(a);
|
|
261 |
a.Close();
|
|
262 |
TBuf8<19> buffer;
|
|
263 |
r=b.Read(0,buffer);
|
|
264 |
|
|
265 |
//thread should get paniced here so should not reach this
|
|
266 |
|
|
267 |
test(EFalse);
|
|
268 |
f.Close();
|
|
269 |
|
|
270 |
return KErrNone;
|
|
271 |
}
|
|
272 |
|
|
273 |
|
|
274 |
|
|
275 |
|
|
276 |
|
|
277 |
LOCAL_C void Test3()
|
|
278 |
//
|
|
279 |
// Test how the file server copes with bad handles
|
|
280 |
//
|
|
281 |
{
|
|
282 |
test.Start(_L("RunTests()"));
|
|
283 |
|
|
284 |
TRequestStatus rs;
|
|
285 |
|
|
286 |
RThread t1;
|
|
287 |
User::SetJustInTime(EFalse);
|
|
288 |
test(t1.Create(_L("Handle1Test"), SendBadHandle1, KDefaultStackSize, KHeapSize, KHeapSize, NULL) == KErrNone);
|
|
289 |
t1.Logon(rs);
|
|
290 |
t1.Resume();
|
|
291 |
User::WaitForRequest(rs);
|
|
292 |
User::SetJustInTime(ETrue);
|
|
293 |
test(t1.ExitType() == EExitPanic);
|
|
294 |
test(t1.ExitReason() == KErrBadHandle);
|
|
295 |
CLOSE_AND_WAIT(t1);
|
|
296 |
|
|
297 |
RThread t2;
|
|
298 |
User::SetJustInTime(EFalse);
|
|
299 |
test(t2.Create(_L("Handle2Test"), SendBadHandle2, KDefaultStackSize, KHeapSize, KHeapSize, NULL) == KErrNone);
|
|
300 |
t2.Logon(rs);
|
|
301 |
t2.Resume();
|
|
302 |
User::WaitForRequest(rs);
|
|
303 |
User::SetJustInTime(ETrue);
|
|
304 |
test(t2.ExitType() == EExitPanic);
|
|
305 |
test(t2.ExitReason() == KErrBadHandle);
|
|
306 |
CLOSE_AND_WAIT(t2);
|
|
307 |
|
|
308 |
RThread t3;
|
|
309 |
User::SetJustInTime(EFalse);
|
|
310 |
test(t3.Create(_L("Handle2Test"), SendBadHandle3, KDefaultStackSize, KHeapSize, KHeapSize, NULL) == KErrNone);
|
|
311 |
t3.Logon(rs);
|
|
312 |
t3.Resume();
|
|
313 |
User::WaitForRequest(rs);
|
|
314 |
User::SetJustInTime(ETrue);
|
|
315 |
test(t3.ExitType() == EExitPanic);
|
|
316 |
test(t3.ExitReason() == KErrBadHandle);
|
|
317 |
CLOSE_AND_WAIT(t3);
|
|
318 |
|
|
319 |
RThread t4;
|
|
320 |
User::SetJustInTime(EFalse);
|
|
321 |
test(t4.Create(_L("Handle2Test"), SendBadHandle4, KDefaultStackSize, KHeapSize, KHeapSize, NULL) == KErrNone);
|
|
322 |
t4.Logon(rs);
|
|
323 |
t4.Resume();
|
|
324 |
User::WaitForRequest(rs);
|
|
325 |
User::SetJustInTime(ETrue);
|
|
326 |
test(t4.ExitType() == EExitPanic);
|
|
327 |
test(t4.ExitReason() == KErrBadHandle);
|
|
328 |
CLOSE_AND_WAIT(t4);
|
|
329 |
|
|
330 |
RThread t5;
|
|
331 |
User::SetJustInTime(EFalse);
|
|
332 |
test(t5.Create(_L("Handle2Test"), SendBadHandle5, KDefaultStackSize, KHeapSize, KHeapSize, NULL) == KErrNone);
|
|
333 |
t5.Logon(rs);
|
|
334 |
t5.Resume();
|
|
335 |
User::WaitForRequest(rs);
|
|
336 |
User::SetJustInTime(ETrue);
|
|
337 |
test(t5.ExitType() == EExitPanic);
|
|
338 |
test(t5.ExitReason() == KErrBadHandle);
|
|
339 |
CLOSE_AND_WAIT(t5);
|
|
340 |
|
|
341 |
RThread t6;
|
|
342 |
User::SetJustInTime(EFalse);
|
|
343 |
test(t6.Create(_L("Handle2Test"), SendBadHandle6, KDefaultStackSize, KHeapSize, KHeapSize, NULL) == KErrNone);
|
|
344 |
t6.Logon(rs);
|
|
345 |
t6.Resume();
|
|
346 |
User::WaitForRequest(rs);
|
|
347 |
User::SetJustInTime(ETrue);
|
|
348 |
test(t6.ExitType() == EExitPanic);
|
|
349 |
test(t6.ExitReason() == KErrBadHandle);
|
|
350 |
CLOSE_AND_WAIT(t6);
|
|
351 |
|
|
352 |
User::SetJustInTime(ETrue);
|
|
353 |
test.End();
|
|
354 |
|
|
355 |
}
|
|
356 |
|
|
357 |
|
|
358 |
LOCAL_C void DoTestsL()
|
|
359 |
//
|
|
360 |
// Call all tests
|
|
361 |
//
|
|
362 |
{
|
|
363 |
Test1();
|
|
364 |
Test2();
|
|
365 |
Test3();
|
|
366 |
}
|
|
367 |
|
|
368 |
GLDEF_C void CallTestsL(void)
|
|
369 |
//
|
|
370 |
// Test resource counting
|
|
371 |
//
|
|
372 |
{
|
|
373 |
|
|
374 |
test.Title();
|
|
375 |
test.Start(_L("Starting T_RCOUNT test"));
|
|
376 |
|
|
377 |
DoTestsL();
|
|
378 |
|
|
379 |
test.End();
|
|
380 |
test.End();
|
|
381 |
test.Close();
|
|
382 |
|
|
383 |
return;
|
|
384 |
}
|
|
385 |
|