os/kernelhwsrv/kerneltest/f32test/fileshare/handshare64bit.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) 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
// File Name:		f32test/fileshare/t_handshare64bit.cpp
sl@0
    15
// 64 bit FileHandle Server. Used by t_file64bit for testing
sl@0
    16
// RFile64::AdoptFromServer() and RFile64::TransferToServer()
sl@0
    17
// functionality.
sl@0
    18
// 
sl@0
    19
//
sl@0
    20
sl@0
    21
sl@0
    22
#include <e32svr.h>
sl@0
    23
#include <e32test.h>
sl@0
    24
#include "handshare64bit.h"
sl@0
    25
sl@0
    26
#ifdef __VC32__
sl@0
    27
#pragma warning(disable:4706)
sl@0
    28
#endif
sl@0
    29
sl@0
    30
sl@0
    31
sl@0
    32
GLDEF_D RTest test(_L("HANDSHARE_SVR"));
sl@0
    33
const TInt64 KGB  = 1<<30;
sl@0
    34
const TInt64 K4GB  = 4 * KGB;
sl@0
    35
sl@0
    36
sl@0
    37
#define PANIC()		FHSvrPanic(__LINE__)
sl@0
    38
#define FHS_ASSERT(c)	((void)((c)||(PANIC(),0)))
sl@0
    39
sl@0
    40
const TTimeIntervalMicroSeconds32 KHalfSecond(500000);
sl@0
    41
sl@0
    42
sl@0
    43
void FHSvrPanic(TInt aLine)
sl@0
    44
	{
sl@0
    45
	User::Panic(_L("FHServer"),aLine);
sl@0
    46
	}
sl@0
    47
sl@0
    48
LOCAL_D TInt gTestDrive;
sl@0
    49
sl@0
    50
/******************************************************************************
sl@0
    51
 * Class Definitions
sl@0
    52
 ******************************************************************************/
sl@0
    53
sl@0
    54
sl@0
    55
class CFHServer64Bit : public CServer2
sl@0
    56
	{
sl@0
    57
public:
sl@0
    58
	static CFHServer64Bit* NewL();
sl@0
    59
	void ConstructL();
sl@0
    60
	virtual ~CFHServer64Bit();
sl@0
    61
	virtual CSession2* NewSessionL(const TVersion& aVersion, const RMessage2& aMessage) const;
sl@0
    62
	virtual TInt RunError(TInt aError);
sl@0
    63
private:
sl@0
    64
	CFHServer64Bit();
sl@0
    65
	};
sl@0
    66
sl@0
    67
class CFHSession64Bit : public CSession2
sl@0
    68
	{
sl@0
    69
public:
sl@0
    70
	virtual ~CFHSession64Bit();
sl@0
    71
	virtual void CreateL();
sl@0
    72
	virtual void ServiceL(const RMessage2& aMessage);
sl@0
    73
public:
sl@0
    74
	
sl@0
    75
	void GetFileHandleLargeFile2(const RMessage2& aMsg);
sl@0
    76
	void PassFileHandleLargeFile(const RMessage2& aMsg);
sl@0
    77
	void PassFileHandleProcessLargeFile(const RMessage2& aMsg);
sl@0
    78
	};
sl@0
    79
sl@0
    80
/******************************************************************************
sl@0
    81
 * Class CFHSession/CFHServer
sl@0
    82
 ******************************************************************************/
sl@0
    83
void ExceptionHandler(TExcType)
sl@0
    84
	{
sl@0
    85
	User::Leave(KErrGeneral);
sl@0
    86
	}
sl@0
    87
sl@0
    88
sl@0
    89
sl@0
    90
CFHSession64Bit::~CFHSession64Bit()
sl@0
    91
	{
sl@0
    92
	}
sl@0
    93
sl@0
    94
void CFHSession64Bit::CreateL()
sl@0
    95
	{
sl@0
    96
sl@0
    97
	}
sl@0
    98
sl@0
    99
void CFHSession64Bit::ServiceL(const RMessage2& aMessage)
sl@0
   100
	{
sl@0
   101
	__UHEAP_MARK;
sl@0
   102
	TInt mid=aMessage.Function();
sl@0
   103
	switch(mid)
sl@0
   104
		{
sl@0
   105
		case RFileHandleSharer64Bit::EMsgGetFileHandleLargeFile:
sl@0
   106
			GetFileHandleLargeFile2(aMessage);
sl@0
   107
			break;
sl@0
   108
sl@0
   109
		case RFileHandleSharer64Bit::EMsgPassFileHandleProcessLargeFileClient:
sl@0
   110
			PassFileHandleLargeFile(aMessage);
sl@0
   111
			break;
sl@0
   112
sl@0
   113
		case RFileHandleSharer64Bit::EMsgPassFileHandleProcessLargeFileCreator:
sl@0
   114
			PassFileHandleProcessLargeFile(aMessage);
sl@0
   115
			break;
sl@0
   116
		
sl@0
   117
		case RFileHandleSharer64Bit::EMsgExit:
sl@0
   118
			{
sl@0
   119
			aMessage.Complete(KErrNone);	
sl@0
   120
sl@0
   121
			CActiveScheduler::Stop();
sl@0
   122
			}
sl@0
   123
			break;
sl@0
   124
sl@0
   125
		case RFileHandleSharer64Bit::EMsgSync:
sl@0
   126
			aMessage.Complete(KErrNone);	
sl@0
   127
			break;
sl@0
   128
sl@0
   129
		case RFileHandleSharer64Bit::EMsgDrive:
sl@0
   130
			gTestDrive=aMessage.Int0();
sl@0
   131
			aMessage.Complete(KErrNone);	
sl@0
   132
			break;
sl@0
   133
		default:
sl@0
   134
			break;
sl@0
   135
		}
sl@0
   136
	__UHEAP_MARKEND;
sl@0
   137
	}
sl@0
   138
sl@0
   139
//
sl@0
   140
//	Returns a file handle from server
sl@0
   141
//
sl@0
   142
void CFHSession64Bit::GetFileHandleLargeFile2(const RMessage2& aMsg)
sl@0
   143
	{
sl@0
   144
	test.Next(_L("RFile64::AdoptFromServer()"));
sl@0
   145
	// get the requested file mode
sl@0
   146
	TFileMode fileMode = TFileMode(aMsg.Int1());
sl@0
   147
sl@0
   148
	RFs fs;
sl@0
   149
	TInt r = fs.Connect();
sl@0
   150
sl@0
   151
	if (r == KErrNone)
sl@0
   152
	r = fs.CreatePrivatePath(gTestDrive);
sl@0
   153
sl@0
   154
	if (r == KErrNone)
sl@0
   155
	r = fs.SetSessionToPrivate(gTestDrive);
sl@0
   156
sl@0
   157
	if (r == KErrNone)
sl@0
   158
	r = fs.ShareProtected();
sl@0
   159
sl@0
   160
	// make sure file exists & has valid data in it
sl@0
   161
	RFile64 file1;
sl@0
   162
	if (r == KErrNone)
sl@0
   163
	r = file1.Replace(fs,KServerFileName,EFileWrite);
sl@0
   164
	r=file1.SetSize(K4GB-1);
sl@0
   165
	test(r==KErrNone);
sl@0
   166
	r = file1.Write(K4GB-10,KTestData4());
sl@0
   167
		
sl@0
   168
	file1.Close();
sl@0
   169
sl@0
   170
sl@0
   171
	// re-open the file with the mode the client has requested & pass it to the client
sl@0
   172
	
sl@0
   173
	if (r == KErrNone)
sl@0
   174
	r = file1.Open(fs,KServerFileName, fileMode);
sl@0
   175
	if (r == KErrNone)
sl@0
   176
	
sl@0
   177
	test.Next(_L("RFile::TransferToClient()"));
sl@0
   178
sl@0
   179
	// transfer the file to the client
sl@0
   180
	r = file1.TransferToClient(aMsg, 0);
sl@0
   181
	test(r==KErrNone);
sl@0
   182
sl@0
   183
	// test we can still use the file
sl@0
   184
	TInt64 pos = 0;
sl@0
   185
	r = file1.Seek(ESeekStart, pos);
sl@0
   186
	test(r == KErrNone);
sl@0
   187
	TBuf8<9> rbuf;
sl@0
   188
	r=file1.Read(K4GB-10,rbuf);
sl@0
   189
	test(r == KErrNone);
sl@0
   190
	r=rbuf.CompareF(KTestData4());
sl@0
   191
	test(r == KErrNone);
sl@0
   192
sl@0
   193
	file1.Close();
sl@0
   194
	fs.Close();
sl@0
   195
	RDebug::Print(_L("completed"));	
sl@0
   196
	}
sl@0
   197
sl@0
   198
sl@0
   199
void CFHSession64Bit::PassFileHandleLargeFile(const RMessage2& aMsg)
sl@0
   200
//
sl@0
   201
// Adopts file from test program and tests what it can and can't do
sl@0
   202
// Uses RFile64::AdoptFromClient() API
sl@0
   203
//	
sl@0
   204
	{
sl@0
   205
	test.Next(_L("RFile64::AdoptFromClient()"));
sl@0
   206
	
sl@0
   207
	RFile64 file;
sl@0
   208
sl@0
   209
	// Message slot 0 is a RFs handle
sl@0
   210
	// Message slot 1 is a RFile Subsession handle (RFile::SubSessionHandle())
sl@0
   211
	TInt r = file.AdoptFromClient(aMsg, 0, 1);
sl@0
   212
	test(r==KErrNone);
sl@0
   213
sl@0
   214
	TBuf8<9> rbuf;
sl@0
   215
	r=file.Read(K4GB-10,rbuf);
sl@0
   216
	test(r==KErrNone);
sl@0
   217
	r=rbuf.CompareF(KTestData3());
sl@0
   218
	test(r==KErrNone);
sl@0
   219
	r=file.Write(KTestData1());
sl@0
   220
	test(r==KErrAccessDenied);
sl@0
   221
	r=file.ChangeMode(EFileWrite);
sl@0
   222
	test(r==KErrArgument);
sl@0
   223
	r=file.Rename(_L("\\newname.txt"));
sl@0
   224
	test(r==KErrPermissionDenied || r==KErrAccessDenied);
sl@0
   225
	file.Close();
sl@0
   226
sl@0
   227
	aMsg.Complete(KErrNone);
sl@0
   228
	}
sl@0
   229
	
sl@0
   230
//
sl@0
   231
// Adopts file from test program and tests what it can and can't do
sl@0
   232
// Uses RFile64::AdoptFromCreator() API
sl@0
   233
//	
sl@0
   234
void CFHSession64Bit::PassFileHandleProcessLargeFile(const RMessage2& aMsg)
sl@0
   235
	{
sl@0
   236
	test.Next(_L("RFile64::AdoptFromCreator()"));
sl@0
   237
sl@0
   238
	RFile64 file;
sl@0
   239
	TInt r = file.AdoptFromCreator(1, 2);
sl@0
   240
	test(r == KErrNone);
sl@0
   241
sl@0
   242
	TBuf8<3> rbuf;
sl@0
   243
	r=file.Read(K4GB-10,rbuf,3);
sl@0
   244
	test(r==KErrNone);
sl@0
   245
	r=rbuf.CompareF(KTestData2());
sl@0
   246
	test(r==KErrNone);
sl@0
   247
sl@0
   248
	test.Next(_L("RFile::Rename()"));
sl@0
   249
sl@0
   250
	// define a filename in our private path
sl@0
   251
	RFs fs;
sl@0
   252
	r=fs.Connect();
sl@0
   253
	test(r==KErrNone);
sl@0
   254
sl@0
   255
	TFileName sessionp;
sl@0
   256
	fs.SessionPath(sessionp);
sl@0
   257
	r = fs.MkDirAll(sessionp);
sl@0
   258
	test(r==KErrNone || r==KErrAlreadyExists);
sl@0
   259
sl@0
   260
	r=fs.ShareProtected();
sl@0
   261
	test(r==KErrNone);
sl@0
   262
sl@0
   263
	r=fs.CreatePrivatePath(gTestDrive);
sl@0
   264
	test(r==KErrNone);
sl@0
   265
	r=fs.SetSessionToPrivate(gTestDrive);
sl@0
   266
	test(r==KErrNone);
sl@0
   267
sl@0
   268
	TPath newPath;
sl@0
   269
	fs.PrivatePath(newPath);
sl@0
   270
	TFileName newFileName;
sl@0
   271
	newFileName = newPath;
sl@0
   272
	newFileName.Append(_L("newname.txt"));
sl@0
   273
	
sl@0
   274
	// delete the file before we try to rename anything to it
sl@0
   275
	r = fs.Delete(newFileName);
sl@0
   276
	test(r == KErrNone || r == KErrNotFound);
sl@0
   277
sl@0
   278
	TFileName fileName;
sl@0
   279
	r = file.FullName(fileName);
sl@0
   280
	test (r == KErrNone);
sl@0
   281
	
sl@0
   282
	r=file.Rename(newFileName);
sl@0
   283
	test(r==KErrNone);
sl@0
   284
sl@0
   285
	file.Close();
sl@0
   286
sl@0
   287
	// Next verify that we can delete the file (which should now 
sl@0
   288
	// have been moved to our private directory)
sl@0
   289
	test.Next(_L("RFs::Delete()"));
sl@0
   290
	r = fs.Delete(newFileName);
sl@0
   291
	test(r == KErrNone);
sl@0
   292
sl@0
   293
	fs.Close();
sl@0
   294
sl@0
   295
	
sl@0
   296
	aMsg.Complete(KErrNone);
sl@0
   297
	}
sl@0
   298
sl@0
   299
sl@0
   300
sl@0
   301
sl@0
   302
CFHServer64Bit* CFHServer64Bit::NewL()
sl@0
   303
	{
sl@0
   304
	CFHServer64Bit* server = new (ELeave) CFHServer64Bit;
sl@0
   305
	CleanupStack::PushL(server);
sl@0
   306
	server->ConstructL();
sl@0
   307
	CleanupStack::Pop(server);
sl@0
   308
	return server;
sl@0
   309
	}
sl@0
   310
sl@0
   311
void CFHServer64Bit::ConstructL()
sl@0
   312
	{
sl@0
   313
	}
sl@0
   314
sl@0
   315
CFHServer64Bit::CFHServer64Bit()
sl@0
   316
	: CServer2(0,ESharableSessions)
sl@0
   317
	{
sl@0
   318
	}
sl@0
   319
sl@0
   320
CFHServer64Bit::~CFHServer64Bit()
sl@0
   321
	{
sl@0
   322
	}
sl@0
   323
sl@0
   324
CSession2* CFHServer64Bit::NewSessionL(const TVersion& aVersion, const RMessage2&) const
sl@0
   325
//
sl@0
   326
//	 Create New Session
sl@0
   327
//
sl@0
   328
	{
sl@0
   329
	(void)aVersion;
sl@0
   330
	CFHSession64Bit* s = new (ELeave) CFHSession64Bit;
sl@0
   331
	return s;
sl@0
   332
	}
sl@0
   333
sl@0
   334
_LIT(KErr,"FHSERVER64BIT_ERR");
sl@0
   335
sl@0
   336
sl@0
   337
TInt CFHServer64Bit::RunError(TInt aError)
sl@0
   338
	{
sl@0
   339
	User::Panic(KErr,aError);
sl@0
   340
	return 0;
sl@0
   341
	}
sl@0
   342
sl@0
   343
sl@0
   344
sl@0
   345
sl@0
   346
TInt E32Main()
sl@0
   347
//
sl@0
   348
// Test Server for file handle sharing
sl@0
   349
//
sl@0
   350
	{
sl@0
   351
	test.Title();
sl@0
   352
	test.Start(_L("Starting FHServer64bit..."));
sl@0
   353
sl@0
   354
	// Remember the number of open handles. Just for a sanity check ....
sl@0
   355
	TInt start_thc, start_phc;
sl@0
   356
	RThread().HandleCount(start_phc, start_thc);
sl@0
   357
sl@0
   358
	CTrapCleanup* cleanup=CTrapCleanup::New();
sl@0
   359
sl@0
   360
	FHS_ASSERT(cleanup);
sl@0
   361
	CActiveScheduler* sched=new CActiveScheduler;
sl@0
   362
	FHS_ASSERT(sched);
sl@0
   363
	CActiveScheduler::Install(sched);
sl@0
   364
sl@0
   365
	// start server1
sl@0
   366
	CFHServer64Bit* svr = NULL;
sl@0
   367
	TRAP_IGNORE(svr = CFHServer64Bit::NewL());
sl@0
   368
	FHS_ASSERT(svr);
sl@0
   369
	FHS_ASSERT(svr->Start(_L("FHServer64bit"))== KErrNone||KErrAlreadyExists);
sl@0
   370
sl@0
   371
	test.Title();
sl@0
   372
	test.Start(_L("Starting tests..."));
sl@0
   373
sl@0
   374
sl@0
   375
	CActiveScheduler::Start();
sl@0
   376
sl@0
   377
	RFs cleanupfs;
sl@0
   378
	TInt r = cleanupfs.Connect();
sl@0
   379
	test(r==KErrNone);
sl@0
   380
	r=cleanupfs.SetSessionToPrivate(gTestDrive);
sl@0
   381
	test(r==KErrNone);
sl@0
   382
	r=cleanupfs.Delete(KSvrFileName);
sl@0
   383
	test(r==KErrNone || r==KErrNotFound);
sl@0
   384
	cleanupfs.Close();
sl@0
   385
sl@0
   386
sl@0
   387
	test.End();
sl@0
   388
sl@0
   389
	delete svr;
sl@0
   390
	delete sched;
sl@0
   391
	delete cleanup;
sl@0
   392
sl@0
   393
	// Sanity check for open handles and pending requests
sl@0
   394
	TInt end_thc, end_phc;
sl@0
   395
	RThread().HandleCount(end_phc, end_thc);
sl@0
   396
	test(start_thc == end_thc);
sl@0
   397
	test(start_phc == end_phc);
sl@0
   398
	test(RThread().RequestCount() == 0);
sl@0
   399
	
sl@0
   400
	return 0;
sl@0
   401
	}