author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 31 Aug 2010 16:34:26 +0300 | |
branch | RCL_3 |
changeset 43 | c1f20ce4abcf |
parent 0 | a41df078684a |
child 44 | 3e88ff8f41d5 |
permissions | -rw-r--r-- |
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\manager\t_oom.cpp |
|
15 |
// |
|
16 |
// |
|
17 |
||
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
18 |
#define __E32TEST_EXTENSION__ |
0 | 19 |
#include <hal.h> |
20 |
#include <f32file.h> |
|
21 |
#include <e32test.h> |
|
22 |
#include "../server/t_server.h" |
|
23 |
||
24 |
GLDEF_D RTest test(_L("T_OOM")); |
|
25 |
||
26 |
LOCAL_C void FormatFat() |
|
27 |
// |
|
28 |
// Call all RFormat methods |
|
29 |
// |
|
30 |
{ |
|
31 |
||
32 |
test.Next(_L("Format the disk")); |
|
33 |
RFormat format; |
|
34 |
TFileName sessionPath; |
|
35 |
TInt r=TheFs.SessionPath(sessionPath); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
36 |
test_KErrNone(r); |
0 | 37 |
TInt count; |
38 |
r=format.Open(TheFs,sessionPath,EHighDensity,count); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
39 |
test_KErrNone(r); |
0 | 40 |
// test(count==100); |
41 |
// TRequestStatus status; |
|
42 |
// TPckgBuf<TInt> step; |
|
43 |
// do { |
|
44 |
// format.Next(step,status); |
|
45 |
// User::WaitForRequest(status); |
|
46 |
// test(status==KErrNone); |
|
47 |
// } while (step()<count); |
|
48 |
// test(step()==count); |
|
49 |
const TInt total(count); |
|
50 |
while (count && r == KErrNone) |
|
51 |
{ |
|
52 |
test((r = format.Next(count)) == KErrNone); |
|
53 |
test.Printf(_L("\r%d/%d"), count, total); |
|
54 |
} |
|
55 |
test.Printf(_L("\n")); |
|
56 |
format.Close(); |
|
57 |
} |
|
58 |
||
59 |
LOCAL_C void Test1() |
|
60 |
// |
|
61 |
// Test openning a large file |
|
62 |
// |
|
63 |
{ |
|
64 |
||
65 |
test.Next(_L("Create a file GOBBLE.DAT")); |
|
66 |
TUint size=0x340000; // 3.25MB |
|
67 |
||
68 |
test.Printf(_L("FileSize = 0x%x\n"),size); |
|
69 |
RFile file; |
|
70 |
TInt r=file.Replace(TheFs,_L("\\F32-TST\\GOBBLE.DAT"),EFileRead); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
71 |
test_KErrNone(r); |
0 | 72 |
r=file.SetSize(size); |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
73 |
test_Value(r, r == KErrNone || r==KErrDiskFull); |
0 | 74 |
if (r==KErrDiskFull) |
75 |
{ |
|
76 |
TFileName sessionPath; |
|
77 |
r=TheFs.SessionPath(sessionPath); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
78 |
test_KErrNone(r); |
0 | 79 |
test.Printf(_L("Error %S diskfull\n"),&sessionPath); |
80 |
// Reintroduce when we can detect that the test is being run manually |
|
81 |
// test.Getch(); |
|
82 |
} |
|
83 |
file.Close(); |
|
84 |
} |
|
85 |
||
86 |
/** if internal RAM drive has a defined limit, test cannot be exceeded */ |
|
87 |
||
88 |
LOCAL_C void TestRAMDriveLimit() |
|
89 |
{ |
|
90 |
test.Start(_L("TestRAMDriveLimit")); |
|
91 |
||
92 |
TInt r; // error code |
|
93 |
||
94 |
for (TInt d = EDriveA; d <= EDriveZ; ++d) |
|
95 |
{ |
|
96 |
TDriveInfo di; |
|
97 |
test((r = TheFs.Drive(di, d)) == KErrNone); |
|
98 |
TInt maxRam; |
|
99 |
||
100 |
if (di.iType == EMediaRam && HAL::Get(HAL::EMaxRAMDriveSize, maxRam) == KErrNone) |
|
101 |
{ |
|
102 |
#ifdef __WINS__ // c: not EMediaRam on WINS |
|
103 |
if (d != EDriveY) |
|
104 |
continue; |
|
105 |
#endif |
|
106 |
||
107 |
test.Printf(_L("Testing RAM drive limit %08x on drive %x\n"), maxRam, d); |
|
108 |
||
109 |
// create lots of files and check KErrDiskFull after right number |
|
110 |
||
111 |
const TInt KFileSize = 16 * 1024; |
|
112 |
||
113 |
_LIT(KDrvTmp, "?:\\"); // set session path to limited drive |
|
114 |
TBuf<3> bfDrv(KDrvTmp); |
|
115 |
TChar ch; |
|
116 |
test(RFs::DriveToChar(d, ch) == KErrNone); |
|
117 |
bfDrv[0] = static_cast<TText>(ch); |
|
118 |
test.Printf(_L("Setting session path to \"%S\".\n"), &bfDrv); |
|
119 |
test(TheFs.SetSessionPath(bfDrv) == KErrNone); |
|
120 |
||
121 |
FormatFat(); // remove all current files from drive |
|
122 |
||
123 |
TBuf<3 + 2> bfDir; // subdir to avoid root KErrDirFull |
|
124 |
bfDir.Append(bfDrv); |
|
125 |
_LIT(KTstDir, "t\\"); |
|
126 |
bfDir.Append(KTstDir); |
|
127 |
test.Printf(_L("creating directory \"%S\".\n"), &bfDir); |
|
128 |
r = TheFs.MkDir(bfDir); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
129 |
test_KErrNone(r); |
0 | 130 |
|
131 |
TBuf<3 + 3 + 8 + 1 + 3> bfFlNm(bfDir); |
|
132 |
TInt ctr = 0; // create files until KErrDiskFull |
|
133 |
do |
|
134 |
{ |
|
135 |
bfFlNm.SetLength(bfDir.Length()); |
|
136 |
bfFlNm.AppendFormat(_L("%08x.dat"), ctr); |
|
137 |
||
138 |
test.Printf( |
|
139 |
_L("\rcreating %S @ %08x (total %08x)"), |
|
140 |
&bfFlNm, KFileSize, ctr * KFileSize); |
|
141 |
||
142 |
RFile f; |
|
143 |
r = f.Create(TheFs, bfFlNm, EFileShareExclusive | EFileStream | EFileWrite); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
144 |
test_Value(r, r == KErrNone || r == KErrDiskFull); |
0 | 145 |
if (r == KErrNone) |
146 |
{ |
|
147 |
r = f.SetSize(KFileSize); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
148 |
test_Value(r, r == KErrNone || r == KErrDiskFull); |
0 | 149 |
} |
150 |
f.Close(); |
|
151 |
||
152 |
++ctr; |
|
153 |
} while (r != KErrDiskFull); |
|
154 |
test.Printf(_L("\n")); |
|
155 |
||
156 |
// new file takes KFileSize, any possibly metadata cluster |
|
157 |
||
158 |
TVolumeInfo vi; |
|
159 |
test(TheFs.Volume(vi, d) == KErrNone); |
|
160 |
test(vi.iSize < maxRam); // vi.iSize does not include FAT |
|
161 |
test(vi.iFree < 2 * KFileSize); |
|
162 |
||
163 |
FormatFat(); |
|
164 |
||
165 |
// create single file and set to > maxRam |
|
166 |
||
167 |
RFile fS; |
|
168 |
_LIT(bfFlNmS, "00000000.dat"); |
|
169 |
test(fS.Create(TheFs, bfFlNmS, EFileShareExclusive | EFileStream | EFileWrite) == KErrNone); |
|
170 |
test(fS.SetSize(maxRam) == KErrDiskFull); |
|
171 |
fS.Close(); |
|
172 |
} |
|
173 |
} // for (TInt d = EDriveA; d <= EDriveZ; ++d) |
|
174 |
||
175 |
test.End(); |
|
176 |
} |
|
177 |
||
178 |
GLDEF_C void CallTestsL() |
|
179 |
// |
|
180 |
// Call all tests |
|
181 |
// |
|
182 |
{ |
|
183 |
test.Title(); |
|
184 |
test.Start(_L("Starting T_OOM test")); |
|
185 |
||
186 |
TDriveInfo driveInfo; |
|
187 |
TInt r=TheFs.Drive(driveInfo); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
188 |
test_KErrNone(r); |
0 | 189 |
if (driveInfo.iType==EMediaNotPresent) |
190 |
{ |
|
191 |
test.Printf(_L("ERROR: MEDIA NOT PRESENT\n")); |
|
192 |
// Reintroduce when we can detect that the test is being run manually |
|
193 |
// test.Getch(); |
|
194 |
return; |
|
195 |
} |
|
196 |
||
197 |
TFileName sessionPath; |
|
198 |
r=TheFs.SessionPath(sessionPath); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
199 |
test_KErrNone(r); |
0 | 200 |
r=TheFs.MkDirAll(sessionPath); |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
201 |
test_Value(r, r == KErrCorrupt || r==KErrAlreadyExists || r==KErrNone); |
0 | 202 |
if (r==KErrCorrupt) |
203 |
FormatFat(); |
|
204 |
if (r==KErrAlreadyExists) |
|
205 |
{ |
|
206 |
test.Next(_L("Remove test directory")); |
|
207 |
CFileMan* fman=CFileMan::NewL(TheFs); |
|
208 |
TInt ret=fman->RmDir(sessionPath); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
209 |
test_KErrNone(ret); |
0 | 210 |
delete fman; |
211 |
} |
|
212 |
if (r!=KErrNone) |
|
213 |
{ |
|
214 |
r=TheFs.MkDirAll(sessionPath); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
215 |
test_KErrNone(r); |
0 | 216 |
} |
217 |
||
218 |
Test1(); |
|
219 |
||
220 |
TestRAMDriveLimit(); |
|
221 |
test.End(); |
|
222 |
test.Close(); |
|
223 |
} |