diff -r 000000000000 -r a41df078684a kerneltest/f32test/manager/t_oom.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/kerneltest/f32test/manager/t_oom.cpp Mon Oct 19 15:55:17 2009 +0100 @@ -0,0 +1,222 @@ +// Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies). +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of the License "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Nokia Corporation - initial contribution. +// +// Contributors: +// +// Description: +// f32test\manager\t_oom.cpp +// +// + +#include +#include +#include +#include "../server/t_server.h" + +GLDEF_D RTest test(_L("T_OOM")); + +LOCAL_C void FormatFat() +// +// Call all RFormat methods +// + { + + test.Next(_L("Format the disk")); + RFormat format; + TFileName sessionPath; + TInt r=TheFs.SessionPath(sessionPath); + test(r==KErrNone); + TInt count; + r=format.Open(TheFs,sessionPath,EHighDensity,count); + test(r==KErrNone); +// test(count==100); +// TRequestStatus status; +// TPckgBuf step; +// do { +// format.Next(step,status); +// User::WaitForRequest(status); +// test(status==KErrNone); +// } while (step() bfDrv(KDrvTmp); + TChar ch; + test(RFs::DriveToChar(d, ch) == KErrNone); + bfDrv[0] = static_cast(ch); + test.Printf(_L("Setting session path to \"%S\".\n"), &bfDrv); + test(TheFs.SetSessionPath(bfDrv) == KErrNone); + + FormatFat(); // remove all current files from drive + + TBuf<3 + 2> bfDir; // subdir to avoid root KErrDirFull + bfDir.Append(bfDrv); + _LIT(KTstDir, "t\\"); + bfDir.Append(KTstDir); + test.Printf(_L("creating directory \"%S\".\n"), &bfDir); + r = TheFs.MkDir(bfDir); + test(r == KErrNone); + + TBuf<3 + 3 + 8 + 1 + 3> bfFlNm(bfDir); + TInt ctr = 0; // create files until KErrDiskFull + do + { + bfFlNm.SetLength(bfDir.Length()); + bfFlNm.AppendFormat(_L("%08x.dat"), ctr); + + test.Printf( + _L("\rcreating %S @ %08x (total %08x)"), + &bfFlNm, KFileSize, ctr * KFileSize); + + RFile f; + r = f.Create(TheFs, bfFlNm, EFileShareExclusive | EFileStream | EFileWrite); + test(r == KErrNone || r == KErrDiskFull); + if (r == KErrNone) + { + r = f.SetSize(KFileSize); + test(r == KErrNone || r == KErrDiskFull); + } + f.Close(); + + ++ctr; + } while (r != KErrDiskFull); + test.Printf(_L("\n")); + + // new file takes KFileSize, any possibly metadata cluster + + TVolumeInfo vi; + test(TheFs.Volume(vi, d) == KErrNone); + test(vi.iSize < maxRam); // vi.iSize does not include FAT + test(vi.iFree < 2 * KFileSize); + + FormatFat(); + + // create single file and set to > maxRam + + RFile fS; + _LIT(bfFlNmS, "00000000.dat"); + test(fS.Create(TheFs, bfFlNmS, EFileShareExclusive | EFileStream | EFileWrite) == KErrNone); + test(fS.SetSize(maxRam) == KErrDiskFull); + fS.Close(); + } + } // for (TInt d = EDriveA; d <= EDriveZ; ++d) + + test.End(); + } + +GLDEF_C void CallTestsL() +// +// Call all tests +// + { + test.Title(); + test.Start(_L("Starting T_OOM test")); + + TDriveInfo driveInfo; + TInt r=TheFs.Drive(driveInfo); + test(r==KErrNone); + if (driveInfo.iType==EMediaNotPresent) + { + test.Printf(_L("ERROR: MEDIA NOT PRESENT\n")); +// Reintroduce when we can detect that the test is being run manually +// test.Getch(); + return; + } + + TFileName sessionPath; + r=TheFs.SessionPath(sessionPath); + test(r==KErrNone); + r=TheFs.MkDirAll(sessionPath); + test(r==KErrCorrupt || r==KErrAlreadyExists || r==KErrNone); + if (r==KErrCorrupt) + FormatFat(); + if (r==KErrAlreadyExists) + { + test.Next(_L("Remove test directory")); + CFileMan* fman=CFileMan::NewL(TheFs); + TInt ret=fman->RmDir(sessionPath); + test(ret==KErrNone); + delete fman; + } + if (r!=KErrNone) + { + r=TheFs.MkDirAll(sessionPath); + test(r==KErrNone); + } + + Test1(); + + TestRAMDriveLimit(); + test.End(); + test.Close(); + }