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