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