os/kernelhwsrv/kerneltest/f32test/demandpaging/t_denyclamp.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2006-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\demandpaging\t_denyclamp.cpp
sl@0
    15
// This test suite has a reduced set of the tests in T_CLAMP, to verify
sl@0
    16
// the behaviour when file clamping is attempted by an invalid user.
sl@0
    17
// 002 GetDriveLetters() Assign the first drive that matches the required criteria
sl@0
    18
// 003 Test1() Basic clamp operation
sl@0
    19
// 004 Test2() Invalid clamp requests
sl@0
    20
// 005 Test4() Clamp tests for non-writable file system
sl@0
    21
// 006 Test5() Clamp requests on non-clamping file systems
sl@0
    22
// This file has a reduced set of tests present in T_CLAMP, to verify
sl@0
    23
// the behaviour when file clamping is attempted by an invalid user
sl@0
    24
// 
sl@0
    25
//
sl@0
    26
sl@0
    27
//! @SYMTestCaseID			KBASE-T_DENYCLAMP-0329
sl@0
    28
//! @SYMTestType			UT
sl@0
    29
//! @SYMPREQ				PREQ1110
sl@0
    30
//! @SYMTestCaseDesc		Demand Paging File Clamp tests (Deny)
sl@0
    31
//! @SYMTestActions			001 Starting T_DENYCLAMP ...
sl@0
    32
//! @SYMTestExpectedResults All tests should pass.
sl@0
    33
//! @SYMTestPriority        High
sl@0
    34
//! @SYMTestStatus          Implemented
sl@0
    35
sl@0
    36
#include <e32test.h>
sl@0
    37
RTest test(_L("T_DENYCLAMP"));
sl@0
    38
sl@0
    39
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
sl@0
    40
sl@0
    41
#include <f32file.h>
sl@0
    42
#include <f32dbg.h>
sl@0
    43
#include <e32ldr_private.h>
sl@0
    44
RFs TheFs;
sl@0
    45
sl@0
    46
_LIT(KFATName,"FAT");
sl@0
    47
//_LIT(KFAT32Name,"FAT32");
sl@0
    48
_LIT(KROFSName,"ROFS");
sl@0
    49
_LIT(KLFFSName,"LFFS");
sl@0
    50
_LIT(KCOMPName,"COMPOSITE"); // Z: name if Composite File System
sl@0
    51
//#ifdef __WINS__
sl@0
    52
//_LIT(KROMName,"WIN32");	// Clamping is not supported for non-composite filing system on Z:
sl@0
    53
//#else
sl@0
    54
_LIT(KROMName,"ROM");		 // Z: name if ROMFS (on hardware, not emulator)
sl@0
    55
//#endif
sl@0
    56
sl@0
    57
TChar NandFatDrv='?';
sl@0
    58
TChar RofsDrv='?';
sl@0
    59
TChar LffsDrv='?';
sl@0
    60
TChar CompDrv='?';
sl@0
    61
sl@0
    62
sl@0
    63
LOCAL_C void Test1()
sl@0
    64
	{
sl@0
    65
// Basic clamp operation
sl@0
    66
	test.Next(_L("T_DENYCLAMP - Test1()"));
sl@0
    67
sl@0
    68
	TBuf<256> fileName;	
sl@0
    69
	TBuf<256> buf(_L("buffer for file used"));
sl@0
    70
sl@0
    71
	fileName = _L("clampFile.tst");
sl@0
    72
	RFile testFile;
sl@0
    73
	TInt r=testFile.Replace(TheFs,fileName,EFileWrite);
sl@0
    74
	test(r==KErrNone);
sl@0
    75
	TPtrC8 pBuf((TUint8*)&buf);
sl@0
    76
	testFile.Write(pBuf);
sl@0
    77
	testFile.Flush();
sl@0
    78
sl@0
    79
	// Attempt to clamp file should be rejected
sl@0
    80
	RFileClamp handle;
sl@0
    81
	r=handle.Clamp(testFile);
sl@0
    82
	test(r==KErrPermissionDenied);
sl@0
    83
sl@0
    84
	// Attempt to unclamp a file should be rejected
sl@0
    85
	// Using an invalid-content cookie is OK - the request should
sl@0
    86
	// be rejected before the content is examined
sl@0
    87
	handle.iCookie[0]=MAKE_TINT64(-1,-1);
sl@0
    88
	handle.iCookie[1]=0;
sl@0
    89
	r=handle.Close(TheFs);
sl@0
    90
	test (r==KErrPermissionDenied);
sl@0
    91
sl@0
    92
	// Tidy up
sl@0
    93
	testFile.Close();
sl@0
    94
	r=TheFs.Delete(_L("clampFile.tst"));
sl@0
    95
	test (r==KErrNone);
sl@0
    96
	}
sl@0
    97
sl@0
    98
sl@0
    99
LOCAL_C void Test2()
sl@0
   100
	{
sl@0
   101
// Invalid clamp requests
sl@0
   102
	test.Next(_L("T_DENYCLAMP - Test2()"));
sl@0
   103
	
sl@0
   104
	// Test attempt to clamp empty file is rejected
sl@0
   105
	RFileClamp handle2;
sl@0
   106
	TBuf<256> file2Name;	
sl@0
   107
	file2Name = _L("clampFile2.tst");
sl@0
   108
	RFile testFile2;
sl@0
   109
	TInt r=testFile2.Replace(TheFs,file2Name,EFileWrite);
sl@0
   110
	test(r==KErrNone);
sl@0
   111
	r=handle2.Clamp(testFile2);
sl@0
   112
	test(r==KErrPermissionDenied);
sl@0
   113
sl@0
   114
sl@0
   115
	// Try to unclamp non-existant file
sl@0
   116
	// Using a invalid-content cookie is OK - the request should
sl@0
   117
	// be rejected before the content is examined
sl@0
   118
	handle2.iCookie[0] = MAKE_TINT64(-1,-1); // iCookie[0] holds the unique ID
sl@0
   119
	handle2.iCookie[1] = MAKE_TINT64(-1,-1);
sl@0
   120
	r=handle2.Close(TheFs);
sl@0
   121
	test (r==KErrPermissionDenied);
sl@0
   122
sl@0
   123
	// Tidy up
sl@0
   124
	testFile2.Close();
sl@0
   125
	r=TheFs.Delete(_L("clampFile2.tst"));
sl@0
   126
	test (r==KErrNone);
sl@0
   127
	}
sl@0
   128
sl@0
   129
sl@0
   130
LOCAL_C void Test4(TDesC& aRoot)
sl@0
   131
	{
sl@0
   132
// Clamp tests for non-writable file system
sl@0
   133
	test.Next(_L("T_DENYCLAMP - Test4()"));
sl@0
   134
sl@0
   135
	TBuf<256> pathName;	
sl@0
   136
#ifdef __WINS__
sl@0
   137
	if((aRoot[0]=='Z')||(aRoot[0]=='z'))
sl@0
   138
		pathName=_L("clean.txt");
sl@0
   139
	else
sl@0
   140
		pathName=_L("root.txt");
sl@0
   141
#else
sl@0
   142
	if((aRoot[0]=='Z')||(aRoot[0]=='z'))
sl@0
   143
		pathName=_L("UnicodeData.txt");
sl@0
   144
	else
sl@0
   145
		pathName=_L("\\Test\\clamp.txt");	// For (non-composite) ROFS drive
sl@0
   146
#endif
sl@0
   147
	RFile testFile;
sl@0
   148
	TInt r=testFile.Open(TheFs, pathName, EFileRead);
sl@0
   149
	test(r==KErrNone);
sl@0
   150
sl@0
   151
	// Attempt to clamp file
sl@0
   152
	RFileClamp handle;
sl@0
   153
	r=handle.Clamp(testFile);
sl@0
   154
	test(r==KErrPermissionDenied);
sl@0
   155
sl@0
   156
	// Unclamp file
sl@0
   157
	// Using an invalid-content cookie is OK - the request should
sl@0
   158
	// be rejected before the content is examined
sl@0
   159
	handle.iCookie[0]=MAKE_TINT64(-1,-1);
sl@0
   160
	handle.iCookie[1]=0;
sl@0
   161
	r=handle.Close(TheFs);
sl@0
   162
	test (r==KErrPermissionDenied);
sl@0
   163
sl@0
   164
	testFile.Close();
sl@0
   165
	}
sl@0
   166
sl@0
   167
sl@0
   168
LOCAL_C void Test5()
sl@0
   169
	{
sl@0
   170
// Clamp requests on non-clamping file systems
sl@0
   171
	test.Next(_L("T_DENYCLAMP - Test5()"));
sl@0
   172
sl@0
   173
	TBuf<256> unsuppFile;	
sl@0
   174
	unsuppFile = _L("unsuppFile.tst");
sl@0
   175
	RFile testFile;
sl@0
   176
	TInt r=testFile.Replace(TheFs,unsuppFile,EFileWrite);
sl@0
   177
	test(r==KErrNone);
sl@0
   178
sl@0
   179
	// Try to clamp a file on a file system that does
sl@0
   180
	// not support clamping
sl@0
   181
	RFileClamp handle;
sl@0
   182
	r=handle.Clamp(testFile);
sl@0
   183
	test(r==KErrPermissionDenied);
sl@0
   184
sl@0
   185
	// Tidy up
sl@0
   186
	testFile.Close();
sl@0
   187
	r=TheFs.Delete(_L("unsuppFile.tst"));
sl@0
   188
	test (r==KErrNone);
sl@0
   189
	}	
sl@0
   190
sl@0
   191
sl@0
   192
LOCAL_C void GetDriveLetters()
sl@0
   193
	{
sl@0
   194
// Assign the first drive that matches the required criteria
sl@0
   195
	test.Next(_L("T_DENYCLAMP - GetDriveLetters()"));
sl@0
   196
sl@0
   197
	TDriveList driveList;
sl@0
   198
	TDriveInfo driveInfo;
sl@0
   199
	TInt r=TheFs.DriveList(driveList);
sl@0
   200
	test(r==KErrNone);
sl@0
   201
	TInt drvNum;
sl@0
   202
	TBool drivesFound = EFalse;
sl@0
   203
	for(drvNum=0; (drvNum<KMaxDrives) && !drivesFound; drvNum++)
sl@0
   204
		{
sl@0
   205
		TChar drvLetter='?';
sl@0
   206
		TFileName fileSystem;
sl@0
   207
		if(!driveList[drvNum])
sl@0
   208
			continue;
sl@0
   209
		test(TheFs.Drive(driveInfo, drvNum) == KErrNone);
sl@0
   210
		test(TheFs.DriveToChar(drvNum,drvLetter) == KErrNone);
sl@0
   211
		r=TheFs.FileSystemName(fileSystem,drvNum);
sl@0
   212
		fileSystem.UpperCase();
sl@0
   213
		test((r==KErrNone)||(r==KErrNotFound));
sl@0
   214
		// Check for FAT on NAND
sl@0
   215
		if(NandFatDrv=='?')
sl@0
   216
			{
sl@0
   217
			if((driveInfo.iType==EMediaNANDFlash) && (fileSystem.Compare(KFATName)==0))
sl@0
   218
				NandFatDrv=drvLetter;
sl@0
   219
			}
sl@0
   220
		// Check for ROFS
sl@0
   221
		if(RofsDrv=='?')
sl@0
   222
			{
sl@0
   223
			if((driveInfo.iType==EMediaNANDFlash) && (fileSystem.Compare(KROFSName)==0))
sl@0
   224
				RofsDrv=drvLetter;
sl@0
   225
			}
sl@0
   226
		// Check for LFFS
sl@0
   227
		if(LffsDrv=='?')
sl@0
   228
			{
sl@0
   229
			if((driveInfo.iType==EMediaFlash) && (fileSystem.Compare(KLFFSName)==0))
sl@0
   230
				LffsDrv=drvLetter;
sl@0
   231
			}
sl@0
   232
		// Check for CompFSys
sl@0
   233
		if(CompDrv=='?')
sl@0
   234
			{
sl@0
   235
			if((driveInfo.iType==EMediaRom) && ((fileSystem.Compare(KROMName)==0)||(fileSystem.Compare(KCOMPName)==0)))
sl@0
   236
				CompDrv=drvLetter;
sl@0
   237
			}
sl@0
   238
		drivesFound=((NandFatDrv!='?')&&(RofsDrv!='?')&&(LffsDrv!='?')&&(CompDrv!='?'));
sl@0
   239
		}
sl@0
   240
	if(NandFatDrv!='?')
sl@0
   241
		test((NandFatDrv!=RofsDrv)&&(NandFatDrv!=LffsDrv)&&(NandFatDrv!=CompDrv));
sl@0
   242
	if(RofsDrv!='?')
sl@0
   243
		test((RofsDrv!=LffsDrv)&&(RofsDrv!=CompDrv));
sl@0
   244
	if(LffsDrv!='?')
sl@0
   245
		test(LffsDrv!=CompDrv);
sl@0
   246
sl@0
   247
	RDebug::Printf("T_DENYCLAMP: FAT drive=%C, ROFS drive=%C, LFFS drive=%C, ROM-COMP drive=%C \n",(TText)NandFatDrv,(TText)RofsDrv,(TText)LffsDrv,(TText)CompDrv);
sl@0
   248
	return;
sl@0
   249
	}
sl@0
   250
sl@0
   251
sl@0
   252
//
sl@0
   253
// E32Main
sl@0
   254
//
sl@0
   255
sl@0
   256
TInt E32Main()
sl@0
   257
	{
sl@0
   258
	TInt r;
sl@0
   259
	test.Title();
sl@0
   260
	test.Start(_L("Starting T_DENYCLAMP ..."));
sl@0
   261
	test(TheFs.Connect()==KErrNone);
sl@0
   262
sl@0
   263
	GetDriveLetters();
sl@0
   264
	TBuf<256> pathName;	
sl@0
   265
sl@0
   266
	//************************************************************************
sl@0
   267
	//
sl@0
   268
	// Test on FAT (writable file system)
sl@0
   269
	//
sl@0
   270
	//************************************************************************
sl@0
   271
	if(NandFatDrv!='?')
sl@0
   272
		{
sl@0
   273
		pathName=_L("?:\\CLAMP-TST\\");	// FAT on NAND
sl@0
   274
		pathName[0]=(TText)NandFatDrv;
sl@0
   275
		r=TheFs.MkDirAll(pathName);
sl@0
   276
		test(r==KErrNone || r== KErrAlreadyExists);
sl@0
   277
		TheFs.SetSessionPath(pathName);
sl@0
   278
		test.Printf( _L("T_DENYCLAMP: testing FAT drive on %C\n"),(TText)NandFatDrv);
sl@0
   279
sl@0
   280
		Test1();		// Basic clamp operation
sl@0
   281
		Test2();		// Invalid clamp requests
sl@0
   282
//		Test3(pathName);// Denied FS requests when files are clamped - invalid for T_DENYCLAMP
sl@0
   283
sl@0
   284
		r=TheFs.RmDir(pathName);
sl@0
   285
		test(r==KErrNone);
sl@0
   286
		}
sl@0
   287
	else
sl@0
   288
		test.Printf( _L("T_DENYCLAMP: FAT drive not tested\n"));
sl@0
   289
sl@0
   290
	//************************************************************************
sl@0
   291
	//
sl@0
   292
	// Test on ROFS (non-writable file system) 
sl@0
   293
	//
sl@0
   294
	//************************************************************************
sl@0
   295
	if(RofsDrv!='?')
sl@0
   296
		{
sl@0
   297
		pathName=_L("?:\\");
sl@0
   298
		pathName[0]=(TText)RofsDrv;
sl@0
   299
		TheFs.SetSessionPath(pathName);
sl@0
   300
		test.Printf( _L("T_DENYCLAMP: testing ROFS drive on %C\n"),(TText)RofsDrv);
sl@0
   301
sl@0
   302
		Test4(pathName);	// Clamp tests for non-writable file system
sl@0
   303
		}
sl@0
   304
	else
sl@0
   305
		test.Printf( _L("T_DENYCLAMP: ROFS drive not tested\n"));
sl@0
   306
sl@0
   307
	//************************************************************************
sl@0
   308
	//
sl@0
   309
	// Test on Z: - Composite File System, or ROMFS (non-writable file system)
sl@0
   310
	//
sl@0
   311
	//************************************************************************
sl@0
   312
	if(CompDrv!='?')
sl@0
   313
		{
sl@0
   314
		pathName=_L("?:\\TEST\\");
sl@0
   315
		pathName[0]=(TText)CompDrv;
sl@0
   316
		TheFs.SetSessionPath(pathName);
sl@0
   317
		test.Printf( _L("T_DENYCLAMP: testing Z drive (on %C)\n"),(TText)CompDrv);
sl@0
   318
sl@0
   319
		Test4(pathName);	// Clamp tests for non-writable file system
sl@0
   320
		}
sl@0
   321
	else
sl@0
   322
		test.Printf( _L("T_DENYCLAMP: Z drive not tested\n"));
sl@0
   323
sl@0
   324
	//************************************************************************
sl@0
   325
	//
sl@0
   326
	// Test on LFFS (non-clampable file system)
sl@0
   327
	//
sl@0
   328
	//************************************************************************
sl@0
   329
	if(LffsDrv!='?')
sl@0
   330
		{
sl@0
   331
		TBuf<256> unsuppPath;	
sl@0
   332
		unsuppPath=_L("?:\\CLAMP-TST\\");
sl@0
   333
		unsuppPath[0]=(TText)LffsDrv;
sl@0
   334
		r=TheFs.MkDirAll(unsuppPath);
sl@0
   335
		test(r==KErrNone || r== KErrAlreadyExists);
sl@0
   336
		TheFs.SetSessionPath(unsuppPath);
sl@0
   337
		test.Printf( _L("T_DENYCLAMP: testing LFFS drive on %C\n"),(TText)LffsDrv);
sl@0
   338
sl@0
   339
		Test5();		// Clamp requests on non-clamping file systems
sl@0
   340
		}
sl@0
   341
	else
sl@0
   342
		test.Printf( _L("T_DENYCLAMP: LFFS drive not tested\n"));
sl@0
   343
sl@0
   344
	test.End();
sl@0
   345
	return 0;
sl@0
   346
	}
sl@0
   347
sl@0
   348
#else
sl@0
   349
sl@0
   350
TInt E32Main()
sl@0
   351
	{
sl@0
   352
	test.Title();
sl@0
   353
	test.Start(_L("Test does not run on UREL builds."));
sl@0
   354
	test.End();
sl@0
   355
	return 0;
sl@0
   356
	}
sl@0
   357
#endif