Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // f32test\manager\t_oom.cpp
21 #include "../server/t_server.h"
23 GLDEF_D RTest test(_L("T_OOM"));
25 LOCAL_C void FormatFat()
27 // Call all RFormat methods
31 test.Next(_L("Format the disk"));
33 TFileName sessionPath;
34 TInt r=TheFs.SessionPath(sessionPath);
37 r=format.Open(TheFs,sessionPath,EHighDensity,count);
40 // TRequestStatus status;
41 // TPckgBuf<TInt> step;
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)
51 test((r = format.Next(count)) == KErrNone);
52 test.Printf(_L("\r%d/%d"), count, total);
54 test.Printf(_L("\n"));
60 // Test openning a large file
64 test.Next(_L("Create a file GOBBLE.DAT"));
65 TUint size=0x340000; // 3.25MB
67 test.Printf(_L("FileSize = 0x%x\n"),size);
69 TInt r=file.Replace(TheFs,_L("\\F32-TST\\GOBBLE.DAT"),EFileRead);
72 test(r==KErrNone || r==KErrDiskFull);
75 TFileName sessionPath;
76 r=TheFs.SessionPath(sessionPath);
78 test.Printf(_L("Error %S diskfull\n"),&sessionPath);
79 // Reintroduce when we can detect that the test is being run manually
85 /** if internal RAM drive has a defined limit, test cannot be exceeded */
87 LOCAL_C void TestRAMDriveLimit()
89 test.Start(_L("TestRAMDriveLimit"));
93 for (TInt d = EDriveA; d <= EDriveZ; ++d)
96 test((r = TheFs.Drive(di, d)) == KErrNone);
99 if (di.iType == EMediaRam && HAL::Get(HAL::EMaxRAMDriveSize, maxRam) == KErrNone)
101 #ifdef __WINS__ // c: not EMediaRam on WINS
106 test.Printf(_L("Testing RAM drive limit %08x on drive %x\n"), maxRam, d);
108 // create lots of files and check KErrDiskFull after right number
110 const TInt KFileSize = 16 * 1024;
112 _LIT(KDrvTmp, "?:\\"); // set session path to limited drive
113 TBuf<3> bfDrv(KDrvTmp);
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);
120 FormatFat(); // remove all current files from drive
122 TBuf<3 + 2> bfDir; // subdir to avoid root KErrDirFull
124 _LIT(KTstDir, "t\\");
125 bfDir.Append(KTstDir);
126 test.Printf(_L("creating directory \"%S\".\n"), &bfDir);
127 r = TheFs.MkDir(bfDir);
130 TBuf<3 + 3 + 8 + 1 + 3> bfFlNm(bfDir);
131 TInt ctr = 0; // create files until KErrDiskFull
134 bfFlNm.SetLength(bfDir.Length());
135 bfFlNm.AppendFormat(_L("%08x.dat"), ctr);
138 _L("\rcreating %S @ %08x (total %08x)"),
139 &bfFlNm, KFileSize, ctr * KFileSize);
142 r = f.Create(TheFs, bfFlNm, EFileShareExclusive | EFileStream | EFileWrite);
143 test(r == KErrNone || r == KErrDiskFull);
146 r = f.SetSize(KFileSize);
147 test(r == KErrNone || r == KErrDiskFull);
152 } while (r != KErrDiskFull);
153 test.Printf(_L("\n"));
155 // new file takes KFileSize, any possibly metadata cluster
158 test(TheFs.Volume(vi, d) == KErrNone);
159 test(vi.iSize < maxRam); // vi.iSize does not include FAT
160 test(vi.iFree < 2 * KFileSize);
164 // create single file and set to > maxRam
167 _LIT(bfFlNmS, "00000000.dat");
168 test(fS.Create(TheFs, bfFlNmS, EFileShareExclusive | EFileStream | EFileWrite) == KErrNone);
169 test(fS.SetSize(maxRam) == KErrDiskFull);
172 } // for (TInt d = EDriveA; d <= EDriveZ; ++d)
177 GLDEF_C void CallTestsL()
183 test.Start(_L("Starting T_OOM test"));
185 TDriveInfo driveInfo;
186 TInt r=TheFs.Drive(driveInfo);
188 if (driveInfo.iType==EMediaNotPresent)
190 test.Printf(_L("ERROR: MEDIA NOT PRESENT\n"));
191 // Reintroduce when we can detect that the test is being run manually
196 TFileName sessionPath;
197 r=TheFs.SessionPath(sessionPath);
199 r=TheFs.MkDirAll(sessionPath);
200 test(r==KErrCorrupt || r==KErrAlreadyExists || r==KErrNone);
203 if (r==KErrAlreadyExists)
205 test.Next(_L("Remove test directory"));
206 CFileMan* fman=CFileMan::NewL(TheFs);
207 TInt ret=fman->RmDir(sessionPath);
213 r=TheFs.MkDirAll(sessionPath);