1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/f32test/fileshare/handshare64bit.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,401 @@
1.4 +// Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// File Name: f32test/fileshare/t_handshare64bit.cpp
1.18 +// 64 bit FileHandle Server. Used by t_file64bit for testing
1.19 +// RFile64::AdoptFromServer() and RFile64::TransferToServer()
1.20 +// functionality.
1.21 +//
1.22 +//
1.23 +
1.24 +
1.25 +#include <e32svr.h>
1.26 +#include <e32test.h>
1.27 +#include "handshare64bit.h"
1.28 +
1.29 +#ifdef __VC32__
1.30 +#pragma warning(disable:4706)
1.31 +#endif
1.32 +
1.33 +
1.34 +
1.35 +GLDEF_D RTest test(_L("HANDSHARE_SVR"));
1.36 +const TInt64 KGB = 1<<30;
1.37 +const TInt64 K4GB = 4 * KGB;
1.38 +
1.39 +
1.40 +#define PANIC() FHSvrPanic(__LINE__)
1.41 +#define FHS_ASSERT(c) ((void)((c)||(PANIC(),0)))
1.42 +
1.43 +const TTimeIntervalMicroSeconds32 KHalfSecond(500000);
1.44 +
1.45 +
1.46 +void FHSvrPanic(TInt aLine)
1.47 + {
1.48 + User::Panic(_L("FHServer"),aLine);
1.49 + }
1.50 +
1.51 +LOCAL_D TInt gTestDrive;
1.52 +
1.53 +/******************************************************************************
1.54 + * Class Definitions
1.55 + ******************************************************************************/
1.56 +
1.57 +
1.58 +class CFHServer64Bit : public CServer2
1.59 + {
1.60 +public:
1.61 + static CFHServer64Bit* NewL();
1.62 + void ConstructL();
1.63 + virtual ~CFHServer64Bit();
1.64 + virtual CSession2* NewSessionL(const TVersion& aVersion, const RMessage2& aMessage) const;
1.65 + virtual TInt RunError(TInt aError);
1.66 +private:
1.67 + CFHServer64Bit();
1.68 + };
1.69 +
1.70 +class CFHSession64Bit : public CSession2
1.71 + {
1.72 +public:
1.73 + virtual ~CFHSession64Bit();
1.74 + virtual void CreateL();
1.75 + virtual void ServiceL(const RMessage2& aMessage);
1.76 +public:
1.77 +
1.78 + void GetFileHandleLargeFile2(const RMessage2& aMsg);
1.79 + void PassFileHandleLargeFile(const RMessage2& aMsg);
1.80 + void PassFileHandleProcessLargeFile(const RMessage2& aMsg);
1.81 + };
1.82 +
1.83 +/******************************************************************************
1.84 + * Class CFHSession/CFHServer
1.85 + ******************************************************************************/
1.86 +void ExceptionHandler(TExcType)
1.87 + {
1.88 + User::Leave(KErrGeneral);
1.89 + }
1.90 +
1.91 +
1.92 +
1.93 +CFHSession64Bit::~CFHSession64Bit()
1.94 + {
1.95 + }
1.96 +
1.97 +void CFHSession64Bit::CreateL()
1.98 + {
1.99 +
1.100 + }
1.101 +
1.102 +void CFHSession64Bit::ServiceL(const RMessage2& aMessage)
1.103 + {
1.104 + __UHEAP_MARK;
1.105 + TInt mid=aMessage.Function();
1.106 + switch(mid)
1.107 + {
1.108 + case RFileHandleSharer64Bit::EMsgGetFileHandleLargeFile:
1.109 + GetFileHandleLargeFile2(aMessage);
1.110 + break;
1.111 +
1.112 + case RFileHandleSharer64Bit::EMsgPassFileHandleProcessLargeFileClient:
1.113 + PassFileHandleLargeFile(aMessage);
1.114 + break;
1.115 +
1.116 + case RFileHandleSharer64Bit::EMsgPassFileHandleProcessLargeFileCreator:
1.117 + PassFileHandleProcessLargeFile(aMessage);
1.118 + break;
1.119 +
1.120 + case RFileHandleSharer64Bit::EMsgExit:
1.121 + {
1.122 + aMessage.Complete(KErrNone);
1.123 +
1.124 + CActiveScheduler::Stop();
1.125 + }
1.126 + break;
1.127 +
1.128 + case RFileHandleSharer64Bit::EMsgSync:
1.129 + aMessage.Complete(KErrNone);
1.130 + break;
1.131 +
1.132 + case RFileHandleSharer64Bit::EMsgDrive:
1.133 + gTestDrive=aMessage.Int0();
1.134 + aMessage.Complete(KErrNone);
1.135 + break;
1.136 + default:
1.137 + break;
1.138 + }
1.139 + __UHEAP_MARKEND;
1.140 + }
1.141 +
1.142 +//
1.143 +// Returns a file handle from server
1.144 +//
1.145 +void CFHSession64Bit::GetFileHandleLargeFile2(const RMessage2& aMsg)
1.146 + {
1.147 + test.Next(_L("RFile64::AdoptFromServer()"));
1.148 + // get the requested file mode
1.149 + TFileMode fileMode = TFileMode(aMsg.Int1());
1.150 +
1.151 + RFs fs;
1.152 + TInt r = fs.Connect();
1.153 +
1.154 + if (r == KErrNone)
1.155 + r = fs.CreatePrivatePath(gTestDrive);
1.156 +
1.157 + if (r == KErrNone)
1.158 + r = fs.SetSessionToPrivate(gTestDrive);
1.159 +
1.160 + if (r == KErrNone)
1.161 + r = fs.ShareProtected();
1.162 +
1.163 + // make sure file exists & has valid data in it
1.164 + RFile64 file1;
1.165 + if (r == KErrNone)
1.166 + r = file1.Replace(fs,KServerFileName,EFileWrite);
1.167 + r=file1.SetSize(K4GB-1);
1.168 + test(r==KErrNone);
1.169 + r = file1.Write(K4GB-10,KTestData4());
1.170 +
1.171 + file1.Close();
1.172 +
1.173 +
1.174 + // re-open the file with the mode the client has requested & pass it to the client
1.175 +
1.176 + if (r == KErrNone)
1.177 + r = file1.Open(fs,KServerFileName, fileMode);
1.178 + if (r == KErrNone)
1.179 +
1.180 + test.Next(_L("RFile::TransferToClient()"));
1.181 +
1.182 + // transfer the file to the client
1.183 + r = file1.TransferToClient(aMsg, 0);
1.184 + test(r==KErrNone);
1.185 +
1.186 + // test we can still use the file
1.187 + TInt64 pos = 0;
1.188 + r = file1.Seek(ESeekStart, pos);
1.189 + test(r == KErrNone);
1.190 + TBuf8<9> rbuf;
1.191 + r=file1.Read(K4GB-10,rbuf);
1.192 + test(r == KErrNone);
1.193 + r=rbuf.CompareF(KTestData4());
1.194 + test(r == KErrNone);
1.195 +
1.196 + file1.Close();
1.197 + fs.Close();
1.198 + RDebug::Print(_L("completed"));
1.199 + }
1.200 +
1.201 +
1.202 +void CFHSession64Bit::PassFileHandleLargeFile(const RMessage2& aMsg)
1.203 +//
1.204 +// Adopts file from test program and tests what it can and can't do
1.205 +// Uses RFile64::AdoptFromClient() API
1.206 +//
1.207 + {
1.208 + test.Next(_L("RFile64::AdoptFromClient()"));
1.209 +
1.210 + RFile64 file;
1.211 +
1.212 + // Message slot 0 is a RFs handle
1.213 + // Message slot 1 is a RFile Subsession handle (RFile::SubSessionHandle())
1.214 + TInt r = file.AdoptFromClient(aMsg, 0, 1);
1.215 + test(r==KErrNone);
1.216 +
1.217 + TBuf8<9> rbuf;
1.218 + r=file.Read(K4GB-10,rbuf);
1.219 + test(r==KErrNone);
1.220 + r=rbuf.CompareF(KTestData3());
1.221 + test(r==KErrNone);
1.222 + r=file.Write(KTestData1());
1.223 + test(r==KErrAccessDenied);
1.224 + r=file.ChangeMode(EFileWrite);
1.225 + test(r==KErrArgument);
1.226 + r=file.Rename(_L("\\newname.txt"));
1.227 + test(r==KErrPermissionDenied || r==KErrAccessDenied);
1.228 + file.Close();
1.229 +
1.230 + aMsg.Complete(KErrNone);
1.231 + }
1.232 +
1.233 +//
1.234 +// Adopts file from test program and tests what it can and can't do
1.235 +// Uses RFile64::AdoptFromCreator() API
1.236 +//
1.237 +void CFHSession64Bit::PassFileHandleProcessLargeFile(const RMessage2& aMsg)
1.238 + {
1.239 + test.Next(_L("RFile64::AdoptFromCreator()"));
1.240 +
1.241 + RFile64 file;
1.242 + TInt r = file.AdoptFromCreator(1, 2);
1.243 + test(r == KErrNone);
1.244 +
1.245 + TBuf8<3> rbuf;
1.246 + r=file.Read(K4GB-10,rbuf,3);
1.247 + test(r==KErrNone);
1.248 + r=rbuf.CompareF(KTestData2());
1.249 + test(r==KErrNone);
1.250 +
1.251 + test.Next(_L("RFile::Rename()"));
1.252 +
1.253 + // define a filename in our private path
1.254 + RFs fs;
1.255 + r=fs.Connect();
1.256 + test(r==KErrNone);
1.257 +
1.258 + TFileName sessionp;
1.259 + fs.SessionPath(sessionp);
1.260 + r = fs.MkDirAll(sessionp);
1.261 + test(r==KErrNone || r==KErrAlreadyExists);
1.262 +
1.263 + r=fs.ShareProtected();
1.264 + test(r==KErrNone);
1.265 +
1.266 + r=fs.CreatePrivatePath(gTestDrive);
1.267 + test(r==KErrNone);
1.268 + r=fs.SetSessionToPrivate(gTestDrive);
1.269 + test(r==KErrNone);
1.270 +
1.271 + TPath newPath;
1.272 + fs.PrivatePath(newPath);
1.273 + TFileName newFileName;
1.274 + newFileName = newPath;
1.275 + newFileName.Append(_L("newname.txt"));
1.276 +
1.277 + // delete the file before we try to rename anything to it
1.278 + r = fs.Delete(newFileName);
1.279 + test(r == KErrNone || r == KErrNotFound);
1.280 +
1.281 + TFileName fileName;
1.282 + r = file.FullName(fileName);
1.283 + test (r == KErrNone);
1.284 +
1.285 + r=file.Rename(newFileName);
1.286 + test(r==KErrNone);
1.287 +
1.288 + file.Close();
1.289 +
1.290 + // Next verify that we can delete the file (which should now
1.291 + // have been moved to our private directory)
1.292 + test.Next(_L("RFs::Delete()"));
1.293 + r = fs.Delete(newFileName);
1.294 + test(r == KErrNone);
1.295 +
1.296 + fs.Close();
1.297 +
1.298 +
1.299 + aMsg.Complete(KErrNone);
1.300 + }
1.301 +
1.302 +
1.303 +
1.304 +
1.305 +CFHServer64Bit* CFHServer64Bit::NewL()
1.306 + {
1.307 + CFHServer64Bit* server = new (ELeave) CFHServer64Bit;
1.308 + CleanupStack::PushL(server);
1.309 + server->ConstructL();
1.310 + CleanupStack::Pop(server);
1.311 + return server;
1.312 + }
1.313 +
1.314 +void CFHServer64Bit::ConstructL()
1.315 + {
1.316 + }
1.317 +
1.318 +CFHServer64Bit::CFHServer64Bit()
1.319 + : CServer2(0,ESharableSessions)
1.320 + {
1.321 + }
1.322 +
1.323 +CFHServer64Bit::~CFHServer64Bit()
1.324 + {
1.325 + }
1.326 +
1.327 +CSession2* CFHServer64Bit::NewSessionL(const TVersion& aVersion, const RMessage2&) const
1.328 +//
1.329 +// Create New Session
1.330 +//
1.331 + {
1.332 + (void)aVersion;
1.333 + CFHSession64Bit* s = new (ELeave) CFHSession64Bit;
1.334 + return s;
1.335 + }
1.336 +
1.337 +_LIT(KErr,"FHSERVER64BIT_ERR");
1.338 +
1.339 +
1.340 +TInt CFHServer64Bit::RunError(TInt aError)
1.341 + {
1.342 + User::Panic(KErr,aError);
1.343 + return 0;
1.344 + }
1.345 +
1.346 +
1.347 +
1.348 +
1.349 +TInt E32Main()
1.350 +//
1.351 +// Test Server for file handle sharing
1.352 +//
1.353 + {
1.354 + test.Title();
1.355 + test.Start(_L("Starting FHServer64bit..."));
1.356 +
1.357 + // Remember the number of open handles. Just for a sanity check ....
1.358 + TInt start_thc, start_phc;
1.359 + RThread().HandleCount(start_phc, start_thc);
1.360 +
1.361 + CTrapCleanup* cleanup=CTrapCleanup::New();
1.362 +
1.363 + FHS_ASSERT(cleanup);
1.364 + CActiveScheduler* sched=new CActiveScheduler;
1.365 + FHS_ASSERT(sched);
1.366 + CActiveScheduler::Install(sched);
1.367 +
1.368 + // start server1
1.369 + CFHServer64Bit* svr = NULL;
1.370 + TRAP_IGNORE(svr = CFHServer64Bit::NewL());
1.371 + FHS_ASSERT(svr);
1.372 + FHS_ASSERT(svr->Start(_L("FHServer64bit"))== KErrNone||KErrAlreadyExists);
1.373 +
1.374 + test.Title();
1.375 + test.Start(_L("Starting tests..."));
1.376 +
1.377 +
1.378 + CActiveScheduler::Start();
1.379 +
1.380 + RFs cleanupfs;
1.381 + TInt r = cleanupfs.Connect();
1.382 + test(r==KErrNone);
1.383 + r=cleanupfs.SetSessionToPrivate(gTestDrive);
1.384 + test(r==KErrNone);
1.385 + r=cleanupfs.Delete(KSvrFileName);
1.386 + test(r==KErrNone || r==KErrNotFound);
1.387 + cleanupfs.Close();
1.388 +
1.389 +
1.390 + test.End();
1.391 +
1.392 + delete svr;
1.393 + delete sched;
1.394 + delete cleanup;
1.395 +
1.396 + // Sanity check for open handles and pending requests
1.397 + TInt end_thc, end_phc;
1.398 + RThread().HandleCount(end_phc, end_thc);
1.399 + test(start_thc == end_thc);
1.400 + test(start_phc == end_phc);
1.401 + test(RThread().RequestCount() == 0);
1.402 +
1.403 + return 0;
1.404 + }