kerneltest/f32test/server/t_hungfs.cpp
changeset 0 a41df078684a
child 109 b3a1d9898418
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of the License "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // f32test\server\t_hungfs.cpp
       
    15 // this test will either run with a secure mmc or will simulate a
       
    16 // mmc card.
       
    17 // 
       
    18 //
       
    19 
       
    20 
       
    21 #include <f32file.h>
       
    22 #include <e32test.h>
       
    23 #include "t_server.h"
       
    24 
       
    25 GLDEF_D RTest test(_L("T_HUNGFS"));
       
    26 GLREF_D RFs TheFs;
       
    27 
       
    28 LOCAL_D RFile SubFile1;
       
    29 LOCAL_D TInt HungReturnCodeC;
       
    30 
       
    31 LOCAL_D RSemaphore HungSemaphoreC;
       
    32 LOCAL_D TInt HungReturnCodeNC;
       
    33 LOCAL_D RSemaphore HungSemaphoreNC;
       
    34 
       
    35 GLREF_C void Format(TInt aDrive);
       
    36 
       
    37 LOCAL_D const TInt KControlIoLockMount=5;
       
    38 LOCAL_D const TInt KControlIoClearLockMount=6;
       
    39 LOCAL_D const TInt KControlIoCNotifier=7;
       
    40 LOCAL_D const TInt KControlIoClearCNotifier=8;
       
    41 
       
    42 LOCAL_D const TInt KControlIoCancelNCNotifier=KMaxTInt-1;
       
    43 
       
    44 LOCAL_D TBool isSecureMmc;
       
    45 LOCAL_D TFileName gLockedPath;
       
    46 LOCAL_D TFileName gLockedBase;
       
    47 LOCAL_D TInt gLockedDrive;
       
    48 GLREF_D TFileName gSessionPath;
       
    49 LOCAL_D TInt gSessionDrive;
       
    50 
       
    51 TBuf8<16> KPassword8=_L8("abc");
       
    52 TBuf16<8> KPassword=_L("abc");
       
    53 _LIT(File1,"file1");
       
    54 _LIT(File2,"file2");
       
    55 _LIT(Dir1,"\\dir1\\");
       
    56 _LIT(NotifyDir,"\\not\\");
       
    57 _LIT(NotifyDir2,"\\abc\\");
       
    58 _LIT(HungDirNC,"\\hungnc\\");
       
    59 _LIT(HungDirC,"\\hungc\\");
       
    60 
       
    61 LOCAL_D const TInt KHeapSize=0x2000;
       
    62 
       
    63 struct SNonCriticalInfo
       
    64 	{
       
    65 	TBool iSameSession;
       
    66 	TBool iUseRFile;
       
    67 	};
       
    68 
       
    69 LOCAL_C TInt ThreadFunctionNC(TAny* aInfo)
       
    70 //
       
    71 // Thread entry point to put up non-critical notifier
       
    72 //
       
    73 	{
       
    74 	RFs fs;
       
    75 	TInt r;
       
    76 
       
    77 	TBuf8<8> mmcBuf;
       
    78 	// pad out password if using lockable mmc
       
    79 	if(isSecureMmc)
       
    80 		{
       
    81 		TUint8 pBuf[]={0x61,0x00,0x62,0x00,0x63,00};
       
    82 		mmcBuf.SetLength(6);
       
    83 		for(TInt i=0;i<6;++i)
       
    84 			mmcBuf[i]=pBuf[i];
       
    85 		}
       
    86 
       
    87 	SNonCriticalInfo* info=NULL;
       
    88 	if(aInfo!=NULL)
       
    89 		info=(SNonCriticalInfo*)aInfo;
       
    90 
       
    91 	r=fs.Connect();
       
    92 	
       
    93 	if(isSecureMmc)
       
    94 		{
       
    95 		if(info && info->iSameSession)
       
    96 			r=TheFs.LockDrive(gLockedDrive,NULL,mmcBuf,EFalse);
       
    97 		else
       
    98 			{
       
    99 			r=fs.LockDrive(gLockedDrive,NULL,mmcBuf,EFalse);
       
   100 			RDebug::Print(_L("l=%d"),r);
       
   101 			}
       
   102 		}
       
   103 	else
       
   104 		{
       
   105 		if(info && info->iSameSession)
       
   106 			r=TheFs.ControlIo(gLockedDrive,KControlIoLockMount,KPassword8);
       
   107 		else
       
   108 			r=fs.ControlIo(gLockedDrive,KControlIoLockMount,KPassword8);
       
   109 		}
       
   110 //	UserSvr::ForceRemountMedia(ERemovableMedia0);
       
   111 	User::After(300000);
       
   112 	HungSemaphoreNC.Signal();
       
   113 
       
   114 	TFileName hungDir=gLockedBase;
       
   115 	hungDir+=HungDirNC;
       
   116 	if(info && info->iSameSession)
       
   117 		r=TheFs.RmDir(hungDir);
       
   118 	else if(info && info->iSameSession && info->iUseRFile)
       
   119 		{
       
   120 		TBuf8<16> buf=_L8("abc");
       
   121 		r=SubFile1.Write(buf);
       
   122 		}
       
   123 	else
       
   124 		{
       
   125 		r=fs.RmDir(hungDir);
       
   126 		RDebug::Print(_L("rd=%d"),r);
       
   127 		}
       
   128 	HungReturnCodeNC=r;
       
   129 
       
   130 	if(isSecureMmc)
       
   131 		{
       
   132 		r=fs.UnlockDrive(gLockedDrive,mmcBuf,EFalse);
       
   133 		r=fs.ClearPassword(gLockedDrive,mmcBuf);
       
   134 		}
       
   135 	else
       
   136 		r=fs.ControlIo(gLockedDrive,KControlIoClearLockMount,KPassword8);
       
   137 
       
   138 	HungSemaphoreNC.Signal();
       
   139 
       
   140 	fs.Close();
       
   141 
       
   142 	return(KErrNone);
       
   143 	}
       
   144 
       
   145 LOCAL_C TInt ThreadFunctionC(TAny* aDrive)
       
   146 //
       
   147 // Thread entry point to put up a critical notifier
       
   148 //
       
   149 	{
       
   150 	RFs fs;
       
   151 	TInt r=fs.Connect();
       
   152 	test(r==KErrNone);
       
   153 	
       
   154 	TInt drive;
       
   155 #if defined(__WINS__)
       
   156 	drive=EDriveY;
       
   157 #else	
       
   158 	drive=EDriveC;
       
   159 #endif
       
   160 	// can only get critcal notifer up using ControIo
       
   161 	// assumes fat file system running on one of the drives named below
       
   162 	r=fs.ControlIo(drive,KControlIoCNotifier);
       
   163 	
       
   164 	TBool isRemovable=*(TBool*)aDrive;
       
   165 	TFileName hungDir=(_L("?:"));
       
   166 #if defined(__WINS__)
       
   167 	if(isRemovable)
       
   168 		hungDir[0]=(TText)('A'+EDriveX);
       
   169 	else
       
   170 		hungDir[0]=(TText)('A'+EDriveY);
       
   171 #else
       
   172 	if(isRemovable)
       
   173 		hungDir[0]=(TText)('A'+EDriveD);
       
   174 	else
       
   175 		hungDir[0]=(TText)('A'+EDriveC);
       
   176 #endif
       
   177 	hungDir+=HungDirC;
       
   178 	r=fs.RmDir(hungDir);
       
   179 	r=fs.MkDir(hungDir);
       
   180 	HungReturnCodeC=r;
       
   181 
       
   182 	r=fs.ControlIo(drive,KControlIoClearCNotifier);
       
   183 
       
   184 	HungSemaphoreC.Signal();
       
   185 	r=fs.RmDir(hungDir);
       
   186 	fs.Close();
       
   187 	return(KErrNone);
       
   188 	}
       
   189 
       
   190 LOCAL_C void PutNonCriticalNotifier(TAny* aInfo,RThread& aThread)
       
   191 //
       
   192 // put up a non-critical notifier on a removable media
       
   193 //
       
   194 	{
       
   195 	TInt r=aThread.Create(_L("ThreadNC"),ThreadFunctionNC,KDefaultStackSize,KMinHeapSize,KMinHeapSize,aInfo);
       
   196 	test(r==KErrNone);	
       
   197 	aThread.SetPriority(EPriorityMore);
       
   198 	aThread.Resume();
       
   199 	HungSemaphoreNC.Wait();
       
   200 	User::After(1000000);
       
   201 
       
   202 	}
       
   203 
       
   204 LOCAL_C void PutCriticalNotifier(TBool aBool,RThread& aThread)
       
   205 //
       
   206 // put up a critical notifier on the specified drive
       
   207 //
       
   208 	{
       
   209 	TInt r=aThread.Create(_L("ThreadC"),ThreadFunctionC,KDefaultStackSize,KMinHeapSize,KMinHeapSize,&aBool);
       
   210 	test(r==KErrNone);
       
   211 	aThread.SetPriority(EPriorityMore);
       
   212 	aThread.Resume();
       
   213 	User::After(1000000);
       
   214 	}
       
   215 
       
   216 void TestNotifiers()
       
   217 //
       
   218 // Test non-critical notifier is cancelled when the critical notifier is put up
       
   219 // Needs to be carried out on platform with password notifier which handles requests
       
   220 // asynchronously and uses CAtaDisk in fat file system on c: drive ie. not internal ram
       
   221 // drive
       
   222 //
       
   223 	{
       
   224 	test.Next(_L("TestNotifiers"));
       
   225 	if(isSecureMmc)
       
   226 		return;
       
   227 	RThread threadNC,threadC;
       
   228 	PutNonCriticalNotifier(NULL,threadNC);
       
   229 	PutCriticalNotifier(EFalse,threadC);
       
   230 	// get rid of critical notifier
       
   231 	test.Printf(_L("Press cancel on for critcal notifier\n"));
       
   232 	test.Printf(_L("Press any character\n"));
       
   233 	test.Getch();
       
   234 	TRequestStatus deathStat;
       
   235 	threadNC.Logon( deathStat );
       
   236 	HungSemaphoreC.Wait();
       
   237 	// test(HungReturnCodeNC==KErrAbort);
       
   238 	TRequestStatus deathStat2;
       
   239 	threadC.Logon(deathStat2);
       
   240 	HungSemaphoreNC.Wait();
       
   241 	//test(HungReturnCodeNC==KErrLocked);
       
   242 	User::WaitForRequest(deathStat2);
       
   243 	threadNC.Close();
       
   244 	threadC.Close();
       
   245 	}
       
   246 
       
   247 void TestCriticalFunctions() 
       
   248 //
       
   249 // test that only a subset of functions are supported when the critical notifier is up
       
   250 //
       
   251 	{
       
   252 	test.Next(_L("test functions supported with critical notifier"));
       
   253 	// used for EFsSubClose
       
   254 	RFile file;
       
   255 	TInt r=file.Create(TheFs,File1,EFileShareAny|EFileWrite);
       
   256 	test(r==KErrNone||KErrAlreadyExists);
       
   257 	if(r==KErrAlreadyExists)
       
   258 		{
       
   259 		r=file.Open(TheFs,File1,EFileShareAny|EFileWrite);
       
   260 		test(r==KErrNone);
       
   261 		}
       
   262 	TBuf8<16> buf=_L8("abcdefghijklmnop");
       
   263 	r=file.Write(buf);
       
   264 	test(r==KErrNone);
       
   265 
       
   266 	r=TheFs.MkDir(NotifyDir);
       
   267 	test(r==KErrNone);
       
   268 
       
   269 	RThread thread;
       
   270 	PutCriticalNotifier(ETrue,thread);
       
   271 
       
   272 	// test functions that are supported with critical notifier
       
   273 	// EFsNotifyChange
       
   274 	test.Next(_L("test functions that are supported with critical notifier"));
       
   275 	TRequestStatus status;
       
   276 	TheFs.NotifyChange(ENotifyAll,status);
       
   277 	test(status==KRequestPending);
       
   278 	// EFsNotifyChangeCancel
       
   279 	TheFs.NotifyChangeCancel();
       
   280 	test(status==KErrCancel);
       
   281 	// EFsNotifyChangeEx
       
   282 	TheFs.NotifyChange(ENotifyAll,status,gSessionPath);
       
   283 	test(status==KRequestPending);
       
   284 	// EFsNotifyChangeCancelEx
       
   285 	TheFs.NotifyChangeCancel(status);
       
   286 	test(status==KErrCancel);
       
   287 	// EFsSubClose
       
   288 	// difficult  to test properly because this does not return an error value
       
   289 	file.Close();
       
   290 
       
   291 	// test that notifications are not completed when a critical notifier completes
       
   292 	test.Next(_L("test notifications not completed"));
       
   293 	TheFs.NotifyChange(ENotifyDisk,status);
       
   294 	test(status==KRequestPending);
       
   295 	TRequestStatus status2;
       
   296 	TheFs.NotifyChange(ENotifyDir,status2,NotifyDir);
       
   297 	test(status2==KRequestPending);
       
   298 
       
   299 	// test some functions that are not supported when critcical notifier up
       
   300 	// EFsFileOpen
       
   301 	test.Next(_L("test functions that are not supported with critical notifier"));
       
   302 	r=file.Open(TheFs,File2,EFileShareAny);
       
   303 	test(r==KErrInUse);
       
   304 	// EFsFileCreate
       
   305 	r=file.Create(TheFs,File2,EFileShareAny);
       
   306 	test(r==KErrInUse);
       
   307 	// EFsMkDir
       
   308 	r=TheFs.MkDir(Dir1);
       
   309 	test(r==KErrInUse);
       
   310 	// EFsVolume
       
   311 	TVolumeInfo info;
       
   312 	r=TheFs.Volume(info,gSessionDrive);
       
   313 	test(r==KErrInUse);
       
   314 
       
   315 	// get rid of critical notifier
       
   316 	test.Printf(_L("Press escape on the critical notifier\n"));
       
   317 	TRequestStatus deathStat;
       
   318 	thread.Logon(deathStat);
       
   319 	HungSemaphoreC.Wait();
       
   320 	test(HungReturnCodeC==KErrAbort);
       
   321 	User::WaitForRequest(deathStat);
       
   322 	thread.Close();
       
   323 
       
   324 	// test notifiers have not gone off
       
   325 	test(status==KRequestPending&&status2==KRequestPending);
       
   326 
       
   327 	// test that notification setup on  default drive has had the drive changed
       
   328 	// to * since the critical notifier was up
       
   329 	TFileName notDir=gLockedBase;
       
   330 	notDir+=NotifyDir;
       
   331 	r=TheFs.MkDir(notDir);
       
   332 	test(r==KErrNone);
       
   333 	test(status==KRequestPending&&status2==KErrNone);
       
   334 	TheFs.NotifyChangeCancel();
       
   335 	test(status==KErrCancel);
       
   336 	r=TheFs.Delete(File1);
       
   337 	test(r==KErrNone);
       
   338 	r=TheFs.RmDir(notDir);
       
   339 	test(r==KErrNone);
       
   340 	r=TheFs.RmDir(NotifyDir);
       
   341 	test(r==KErrNone);
       
   342 	}
       
   343 
       
   344 void TestParsingFunctions()	
       
   345 //
       
   346 // Test functions that use Parse* and Validate* functions with 
       
   347 // non-critical notifier up
       
   348 // 
       
   349 	{
       
   350 	test.Next(_L("TestParsingFunctions"));
       
   351 	RThread thread;
       
   352 	PutNonCriticalNotifier(NULL,thread);
       
   353 	
       
   354 	// test on same drive as notifier
       
   355 	test.Next(_L("test parsing functions on same drive"));
       
   356 	// Using ParseSubst
       
   357 	TFileName dir=gLockedBase;
       
   358 	dir+=Dir1;
       
   359 	TInt r=TheFs.MkDir(dir);
       
   360 	test(r==KErrInUse);
       
   361 	TFileName file=gLockedPath;
       
   362 	file+=File1;
       
   363 	RFile f;
       
   364 	r=f.Create(TheFs,file,EFileShareAny);
       
   365 	test(r==KErrInUse);
       
   366 	// Using ParsePathPtr0
       
   367 	r=TheFs.SetSubst(gLockedPath,EDriveO);
       
   368 	test(r==KErrInUse);
       
   369 	// ValidateDrive
       
   370 	TVolumeInfo info;
       
   371 	r=TheFs.Volume(info,gLockedDrive);
       
   372 	test(r==KErrInUse);
       
   373 
       
   374 	TFileName origSessPath;
       
   375 	r=TheFs.SessionPath(origSessPath);
       
   376 	test(r==KErrNone);
       
   377 
       
   378 	// test these work ok
       
   379 	r=TheFs.SetSessionPath(gLockedPath);
       
   380 	test(r==KErrNone);
       
   381 	r=TheFs.SetSessionPath(origSessPath);
       
   382 	test(r==KErrNone);
       
   383 
       
   384 	// test on different drive from notifier - the session path
       
   385 	test.Next(_L("test parsing functions on a different drive"));
       
   386 	// Using ParseSubst
       
   387 	r=TheFs.MkDir(Dir1);
       
   388 	test(r==KErrNone);
       
   389 	r=TheFs.RmDir(Dir1);
       
   390 	test(r==KErrNone);
       
   391 	r=f.Create(TheFs,File1,EFileShareAny);
       
   392 	test(r==KErrNone);
       
   393 	f.Close();
       
   394 	r=TheFs.Delete(File1);
       
   395 	test(r==KErrNone);
       
   396 	// Using ParsePathPtr0
       
   397 	r=TheFs.SetSubst(gSessionPath,EDriveO);
       
   398 	test(r==KErrNone);
       
   399 	r=TheFs.SetSubst(_L(""),EDriveO);
       
   400 	test(r==KErrNone);
       
   401 	// ValidateDrive
       
   402 	r=TheFs.Volume(info,gSessionDrive);
       
   403 	test(r==KErrNone);
       
   404 
       
   405 	// get rid of non-critical notifier
       
   406 	test.Printf(_L("Enter %S on the notifier\n"),&KPassword);
       
   407 
       
   408 	TRequestStatus deathStat;
       
   409 	thread.Logon( deathStat );
       
   410 	HungSemaphoreNC.Wait();
       
   411 	test(HungReturnCodeNC==KErrNotFound);
       
   412 	User::WaitForRequest( deathStat );
       
   413 	thread.Close();
       
   414 
       
   415 //	test.End();
       
   416 	}
       
   417 	
       
   418 void TestTFsFunctions()	
       
   419 //
       
   420 // test functions that do not use the Parse* and Validate* functions
       
   421 //
       
   422 	{
       
   423 	test.Next(_L("TestTFsFunctions"));
       
   424 	TFileName sessName,lockedName;
       
   425 	TInt r=TheFs.FileSystemName(sessName,gSessionDrive);
       
   426 	test(r==KErrNone);
       
   427 	r=TheFs.FileSystemName(lockedName,gLockedDrive);
       
   428 	test(r==KErrNone);
       
   429 
       
   430 	RThread thread;
       
   431 	PutNonCriticalNotifier(NULL,thread);
       
   432 
       
   433 	// test functions on hung drive - should return KErrInUse
       
   434 	test.Next(_L("test TFs functions on hung drive"));
       
   435 	// TFsDismountFileSystem
       
   436 	r=TheFs.DismountFileSystem(lockedName,gLockedDrive);
       
   437 	test(r==KErrInUse);
       
   438 	// TFsMountFileSystem
       
   439 	r=TheFs.MountFileSystem(lockedName,gLockedDrive);
       
   440 	test(r==KErrInUse);
       
   441 	// TFsFileSystemName
       
   442 	r=TheFs.FileSystemName(lockedName,gLockedDrive);
       
   443 	test(r==KErrInUse);
       
   444 
       
   445 	// test functions on drive other than hung drive
       
   446 	test.Next(_L("test TFs functions on drive that is not hung"));
       
   447 	// TFsDismountFileSystem
       
   448 #if defined(__WINS__)
       
   449 	// bug in TFsMountFileSystem which needs to be fixed before running on EDriveC on WINS
       
   450 	if(gSessionDrive!=EDriveC)
       
   451 		{
       
   452 #endif
       
   453 	r=TheFs.DismountFileSystem(sessName,gSessionDrive);
       
   454 	test(r==KErrNone);
       
   455 	// TFsMountFileSystem
       
   456 	r=TheFs.MountFileSystem(sessName,gSessionDrive);
       
   457 	test(r==KErrNone);
       
   458 #if defined(__WINS__)
       
   459 		}
       
   460 #endif
       
   461 	// TFsFileSystemName
       
   462 	TFileName fsName;
       
   463 	r=TheFs.FileSystemName(fsName,gSessionDrive);
       
   464 	test(r==KErrNone);
       
   465 	test(fsName==sessName);
       
   466 
       
   467 	// test functions that fail on all drives
       
   468 	test.Next(_L("test TFs functions that fail on all drives"));
       
   469 	// TFsListOpenFiles
       
   470 	CFileList* list=NULL;
       
   471 	TOpenFileScan fileScan(TheFs);
       
   472 	TRAP(r,fileScan.NextL(list));
       
   473 	test(r==KErrInUse);
       
   474 
       
   475 	// test functions that should pass on any drive
       
   476 	test.Next(_L("test TFs functions that pass on all drives"));
       
   477 	// TFsSetDefaultPath
       
   478 	// TFsSetSessionPath
       
   479 	r=TheFs.SetSessionPath(gLockedPath);
       
   480 	test(r==KErrNone);
       
   481 	r=TheFs.SetSessionPath(gSessionPath);
       
   482 	test(r==KErrNone);
       
   483 
       
   484 	// get rid of non-critical notifier
       
   485 	test.Printf(_L("Enter %S on the notifier\n"),&KPassword);
       
   486 	TRequestStatus deathStat;
       
   487 	thread.Logon( deathStat );
       
   488 	HungSemaphoreNC.Wait();
       
   489 	test(HungReturnCodeNC==KErrNotFound);
       
   490 	User::WaitForRequest( deathStat );
       
   491 	thread.Close();
       
   492 //	test.End();
       
   493 	}
       
   494 
       
   495 
       
   496 void TestSubsessions()	
       
   497 //
       
   498 // test subsession functions
       
   499 //
       
   500 	{
       
   501 	test.Next(_L("TestSubsessions"));
       
   502 	RThread thread;
       
   503 	PutNonCriticalNotifier(NULL,thread);
       
   504 
       
   505 	// test that subsessions cannot be opened on a hung drive
       
   506 	test.Next(_L("test subsessions cannot be opened on a hung drive"));
       
   507 	// EFsFileCreate
       
   508 	RFile file;
       
   509 	TFileName fileName=gLockedPath;
       
   510 	fileName+=File1;
       
   511 	TInt r=file.Create(TheFs,fileName,EFileShareAny);
       
   512 	test(r==KErrInUse);
       
   513 	// EFsFormatOpen
       
   514 	RFormat format;
       
   515 	TInt count;
       
   516 	r=format.Open(TheFs,gLockedPath,EHighDensity,count);
       
   517 	test(r==KErrInUse);
       
   518 	// EFsDirOpen
       
   519 	RDir dir;
       
   520 	r=dir.Open(TheFs,gLockedPath,KEntryAttMaskSupported);
       
   521 	test(r==KErrInUse);
       
   522 	// EFsRawDiskOpen
       
   523 	RRawDisk raw;
       
   524 	r=raw.Open(TheFs,gLockedDrive);
       
   525 	test(r==KErrInUse);
       
   526 
       
   527 	// get rid of non-critical notifier
       
   528 	test.Printf(_L("Enter %S on the notifier\n"),&KPassword);
       
   529 	TRequestStatus deathStat;
       
   530 	thread.Logon( deathStat );
       
   531 	HungSemaphoreNC.Wait();
       
   532 	test(HungReturnCodeNC==KErrNotFound);
       
   533 	User::WaitForRequest( deathStat );
       
   534 	thread.Close();
       
   535 
       
   536 	// now open the subsessions
       
   537 	r=file.Create(TheFs,fileName,EFileShareAny);
       
   538 	test(r==KErrNone||KErrAlreadyExists);
       
   539 	if(r==KErrAlreadyExists)
       
   540 		{
       
   541 		r=file.Open(TheFs,fileName,EFileShareAny);
       
   542 		test(r==KErrNone);
       
   543 		}
       
   544 	r=dir.Open(TheFs,gLockedPath,KEntryAttMaskSupported);
       
   545 	test(r==KErrNone);
       
   546 	
       
   547 	// put notifier back up
       
   548 	PutNonCriticalNotifier(NULL,thread);
       
   549 
       
   550 	// test subsession operations fail on a hung drive
       
   551 	test.Next(_L("test subsession operations fail on a hung drive"));
       
   552 	// EFsFileRead
       
   553 	TBuf8<16> readBuf;
       
   554 	r=file.Read(readBuf);
       
   555 	test(r==KErrInUse);
       
   556 	// subsession should be able to be closed ok
       
   557 	file.Close();
       
   558 	// EFsDelete
       
   559 	r=TheFs.Delete(fileName);
       
   560 	test(r==KErrInUse);
       
   561 	// EFsDirRead
       
   562 	TEntry entry;
       
   563 	r=dir.Read(entry);
       
   564 	test(r==KErrInUse);
       
   565 	// subsession should be able to be closed ok
       
   566 	dir.Close();
       
   567 
       
   568 	// not going to test operations on a drive the is not hung
       
   569 	// since this will be tested on other tests
       
   570 
       
   571 	// get rid of non-critical notifier
       
   572 	test.Printf(_L("Enter %S on the notifier\n"),&KPassword);
       
   573 	thread.Logon( deathStat );
       
   574 	HungSemaphoreNC.Wait();
       
   575 	test(HungReturnCodeNC==KErrNotFound);
       
   576 	User::WaitForRequest( deathStat );
       
   577 	thread.Close();
       
   578 
       
   579 	r=TheFs.Delete(fileName);
       
   580 	test(r==KErrNone);
       
   581 //	test.End();
       
   582 	}
       
   583 
       
   584 void TestSameSession()
       
   585 //
       
   586 // Test functions that can and cannot be handled from same session when notifier is up
       
   587 //
       
   588 	{
       
   589 	test.Next(_L("TestSameSession"));
       
   590 
       
   591 	RFile file;
       
   592 	TInt r=file.Create(TheFs,File1,EFileWrite);
       
   593 	test(r==KErrNone);
       
   594 
       
   595 	// put notifier up using TheFs session
       
   596 	SNonCriticalInfo info={ETrue,0};
       
   597 	RThread thread;
       
   598 	PutNonCriticalNotifier(&info,thread);
       
   599 
       
   600 	// test critical functions can be handled
       
   601 	test.Next(_L("test critical functions can be handled"));
       
   602 	// EFsNotifyChange
       
   603 	TRequestStatus status;
       
   604 	TheFs.NotifyChange(ENotifyAll,status);
       
   605 	test(status==KRequestPending);
       
   606 	// EFsNotifyChangeCancel
       
   607 	TheFs.NotifyChangeCancel();
       
   608 	test(status==KErrCancel);
       
   609 	// EFsNotifyChange again
       
   610 	TheFs.NotifyChange(ENotifyAll,status);
       
   611 	test(status==KRequestPending);
       
   612 	// EFsNotifyChangeCancelEx
       
   613 	TheFs.NotifyChangeCancel(status);
       
   614 	test(status==KErrCancel);
       
   615 	// not going to test EFsSubClose
       
   616 
       
   617 	// test other functions are not handled
       
   618 	test.Next(_L("test other functions cannot be handled"));
       
   619 	// EFsNotifyChangeEx
       
   620 	TheFs.NotifyChange(ENotifyAll,status,gSessionPath);
       
   621 	test(status==KErrInUse);
       
   622 	TFileName defPath;
       
   623 	// EFsCheckDisk
       
   624 	r=TheFs.CheckDisk(gSessionPath);
       
   625 	test(r==KErrInUse);
       
   626 	// EFsFileWrite
       
   627 	_LIT8(buffer,"abc");
       
   628 	TBuf8<8> buf(buffer);
       
   629 	r=file.Write(buf);
       
   630 	test(r==KErrInUse);
       
   631 
       
   632 	// this file should be able to be closed
       
   633 	file.Close();
       
   634 
       
   635 	// get rid of non-critical notifier
       
   636 	test.Printf(_L("Enter %S on the notifier\n"),&KPassword);
       
   637 	
       
   638 	TRequestStatus deathStat;
       
   639 	thread.Logon( deathStat );
       
   640 	HungSemaphoreNC.Wait();
       
   641 	test(HungReturnCodeNC==KErrNotFound);
       
   642 	User::WaitForRequest( deathStat );
       
   643 	thread.Close();
       
   644 
       
   645 	r=TheFs.Delete(File1);
       
   646 	test(r==KErrNone);
       
   647 //	test.End();
       
   648 	}
       
   649 
       
   650 void TestSameSubSession()
       
   651 // 
       
   652 // test hung file server with same subsession
       
   653 //
       
   654 	{
       
   655 	_LIT(file1Name,"\\SubFile1");
       
   656 	_LIT(file2Name,"\\SubFile2");
       
   657 	_LIT(file3Name,"\\SubFile3");
       
   658 	_LIT(file4Name,"\\SubFile4");
       
   659 	TFileName origSession;
       
   660 	TInt r=TheFs.SessionPath(origSession);
       
   661 	test(r==KErrNone);
       
   662 	TFileName file1Path(gLockedBase);
       
   663 	file1Path+=file1Name;
       
   664 	TFileName file2Path(file2Name);
       
   665 	TFileName file3Path(gLockedBase);
       
   666 	file3Path+=file3Name;
       
   667 	TFileName file4Path(file4Name);
       
   668 	// create file that will be used to hang file server
       
   669 	r=SubFile1.Create(TheFs,file1Path,EFileWrite);
       
   670 	test(r==KErrNone);
       
   671 	// create file with same session but on different drive
       
   672 	RFile subfile2;
       
   673 	r=subfile2.Create(TheFs,file2Path,EFileWrite);
       
   674 	test(r==KErrNone);
       
   675 	// create file on unhung drive and with different session
       
   676 	RFs fs2;
       
   677 	r=fs2.Connect();
       
   678 	test(r==KErrNone);
       
   679 	r=fs2.SetSessionPath(origSession);
       
   680 	test(r==KErrNone);
       
   681 	RFile subfile3;
       
   682 	r=subfile3.Create(fs2,file3Path,EFileWrite);
       
   683 	test(r==KErrNone);
       
   684 	// create file on unhung drive and with different session
       
   685 	RFile subfile4;
       
   686 	r=subfile4.Create(fs2,file4Path,EFileWrite);
       
   687 	test(r==KErrNone);
       
   688 	// in a different thread cause the server to hang using one of the File1 subsession
       
   689 	// put notifier up using TheFs session
       
   690 	SNonCriticalInfo info={ETrue,ETrue};
       
   691 	RThread thread;
       
   692 	PutNonCriticalNotifier(&info,thread);
       
   693 	test.Next(_L("test writing to files with hung file server"));
       
   694 	// check only file4 can be written to
       
   695 	_LIT8(buffer,"abc");
       
   696 	TBuf8<8> buf(buffer);
       
   697 	// File1 caused hung file server
       
   698 	r=SubFile1.Write(buf);
       
   699 	test(r==KErrInUse);
       
   700 	// file2 is same session as subsession that caused hung file server
       
   701 	r=subfile2.Write(buf);
       
   702 	test(r==KErrInUse);
       
   703 	// file3 is opened on hung drive
       
   704 	r=subfile3.Write(buf);
       
   705 	test(r==KErrInUse);
       
   706 	// file4 should be ok
       
   707 	r=subfile4.Write(buf);
       
   708 	test(r==KErrNone);
       
   709 	// hard to test EFsSubClose since does not return an error value
       
   710 	test.Next(_L("test closing down the subsessions"));
       
   711 	subfile4.Close();
       
   712 	// calling close on the same subsession as is hung will cause this subsession
       
   713 	// to be closed once the original request is completed
       
   714 	SubFile1.Close();
       
   715 	subfile2.Close();
       
   716 
       
   717 	// get rid of non-critical notifier
       
   718 	test.Printf(_L("Enter %S on the notifier\n"),&KPassword);
       
   719 	TRequestStatus deathStat;
       
   720 	thread.Logon( deathStat );
       
   721 	HungSemaphoreNC.Wait();
       
   722 	test(HungReturnCodeNC==KErrNotFound);
       
   723 	User::WaitForRequest( deathStat );
       
   724 	thread.Close();
       
   725 	// close remaining files
       
   726 	subfile3.Close();
       
   727 	// clean up
       
   728 	fs2.Close();
       
   729 	r=TheFs.Delete(file1Path);
       
   730 	test(r==KErrNone);
       
   731 	r=TheFs.Delete(file2Path);
       
   732 	test(r==KErrNone);
       
   733 	r=TheFs.Delete(file3Path);
       
   734 	test(r==KErrNone);
       
   735 	r=TheFs.Delete(file4Path);
       
   736 	test(r==KErrNone);
       
   737 	}
       
   738 
       
   739 void TestExtendedNotifier()
       
   740 //
       
   741 //
       
   742 //
       
   743 	{
       
   744 	test.Next(_L("TestExtendedNotifier"));
       
   745 	// setup a notification on a removable media
       
   746 	test.Next(_L("test with drive specified"));
       
   747 	TFileName notDir=gLockedBase;
       
   748 	notDir+=NotifyDir;
       
   749 	TRequestStatus status;
       
   750 	TheFs.NotifyChange(ENotifyAll,status,notDir);
       
   751 	test(status==KRequestPending);
       
   752 	// now do an operation on c: and test no notification
       
   753 	TInt r=TheFs.MkDir(NotifyDir);
       
   754 	test(r==KErrNone);
       
   755 	r=TheFs.RmDir(NotifyDir);
       
   756 	test(r==KErrNone);
       
   757 	User::After(1000000);
       
   758 	test(status==KRequestPending);
       
   759 	TheFs.NotifyChangeCancel(status);
       
   760 	test(status==KErrCancel);
       
   761 
       
   762 	// now put up the notifier
       
   763 	RThread thread;
       
   764 	PutNonCriticalNotifier(NULL,thread);
       
   765 
       
   766 	// repeat the above notification
       
   767 	// setup a notification on a removable media - the drive should be changed
       
   768 	// to * since notifier is up
       
   769 	test.Next(_L("test with wildcard for drive"));
       
   770 	TheFs.NotifyChange(ENotifyAll,status,notDir);
       
   771 	test(status==KRequestPending);
       
   772 	// test notification does not go off with wrong path
       
   773 	r=TheFs.MkDir(NotifyDir2);
       
   774 	test(r==KErrNone);
       
   775 	r=TheFs.RmDir(NotifyDir2);
       
   776 	test(r==KErrNone);
       
   777 	test(status==KRequestPending);
       
   778 	// now do an operation on c: and test there has been a notification
       
   779 	r=TheFs.MkDir(NotifyDir);
       
   780 	test(r==KErrNone);
       
   781 	r=TheFs.RmDir(NotifyDir);
       
   782 	test(r==KErrNone);
       
   783 	User::After(1000000);
       
   784 	// request should be completed this time
       
   785 	test(status==KErrNone);
       
   786 
       
   787 	// set up a notification on drive that is not removable
       
   788 	// the path should not be changed
       
   789 	test.Next(_L("test with non-removable drive"));
       
   790 	TheFs.NotifyChange(ENotifyAll,status,notDir);
       
   791 	test(status==KRequestPending);
       
   792 	TRequestStatus status2;
       
   793 	TFileName origSession;
       
   794 	r=TheFs.SessionPath(origSession);
       
   795 	test(r==KErrNone);
       
   796 	RFs fs2;
       
   797 	r=fs2.Connect();
       
   798 	test(r==KErrNone);
       
   799 	r=fs2.SetSessionPath(origSession);
       
   800 	test(r==KErrNone);
       
   801 	_LIT(notifyDirZ,"z:\\test\\");
       
   802 	_LIT(notifyDirSess,"\\test\\");
       
   803 	// notifyDirZ already exists, create test dir in session path
       
   804 	r=fs2.MkDir(notifyDirSess);
       
   805 	test(r==KErrNone);
       
   806 	fs2.NotifyChange(ENotifyDir,status2,notifyDirZ);
       
   807 	test(status2==KRequestPending);
       
   808 	TRequestStatus status3;
       
   809 	fs2.NotifyChange(ENotifyDir,status3,notifyDirSess);
       
   810 	test(status3==KRequestPending);
       
   811 	// now delete session dir and test no notification
       
   812 	r=TheFs.RmDir(notifyDirSess);
       
   813 	test(r==KErrNone);
       
   814 	test(status2==KRequestPending && status3==KErrNone);
       
   815 
       
   816 	// get rid of non-critical notifier
       
   817 	test.Printf(_L("Enter %S on the notifier\n"),&KPassword);
       
   818 	TRequestStatus deathStat;
       
   819 	thread.Logon( deathStat );
       
   820 	HungSemaphoreNC.Wait();
       
   821 	test(HungReturnCodeNC==KErrNotFound);
       
   822 	User::WaitForRequest( deathStat );
       
   823 	thread.Close();
       
   824 	test(status==KErrNone&&status2==KErrNone);
       
   825 	fs2.Close();
       
   826 
       
   827 	test.Next(_L("test extended notification with critical notifier"));
       
   828 	RThread threadC;
       
   829 	// put a a critical notifier
       
   830 	PutCriticalNotifier(ETrue,threadC);
       
   831 	// setup extended change notification on session path, drive should be changed to *
       
   832 	TheFs.NotifyChange(ENotifyAll,status,NotifyDir);
       
   833 	test(status==KRequestPending);
       
   834 	// get rid of notifier
       
   835 	test.Printf(_L("Press cancel on for critcal notifier\n"));
       
   836 	threadC.Logon(deathStat);
       
   837 	HungSemaphoreC.Wait();
       
   838 	User::WaitForRequest(deathStat);
       
   839 	threadC.Close();
       
   840 	// test that notification has not gone off
       
   841 	test(status==KRequestPending);
       
   842 	// create directory on locked drive
       
   843 	r=TheFs.MkDir(notDir);
       
   844 	test(r==KErrNone);
       
   845 	// test notifier goes off
       
   846 	test(status==KErrNone);
       
   847 	r=TheFs.RmDir(notDir);
       
   848 	test(r==KErrNone);
       
   849 	// get rid of critical notifier
       
   850 	}	
       
   851 
       
   852 LOCAL_C TBool TestSessionPath()
       
   853 //
       
   854 // 
       
   855 //
       
   856 	{
       
   857 #if defined(__WINS__)
       
   858 	TInt r=TheFs.CharToDrive(gSessionPath[0],gSessionDrive);
       
   859 	test(r==KErrNone);
       
   860 	if(gSessionDrive==EDriveX)
       
   861 		return(EFalse);
       
   862 #else
       
   863 	TInt r=TheFs.CharToDrive(gSessionPath[0],gSessionDrive);
       
   864 	test(r==KErrNone);
       
   865 	TDriveList list;
       
   866 	r=TheFs.DriveList(list);
       
   867 	test(r==KErrNone);
       
   868 	if((list[gSessionDrive])&KDriveAttRemovable)
       
   869 		return(EFalse);
       
   870 #endif
       
   871 	return(ETrue);
       
   872 	}
       
   873 
       
   874 
       
   875 GLDEF_C void CallTestsL()
       
   876 //
       
   877 // Test a hung file server
       
   878 //
       
   879 	{
       
   880 	if(!IsTestTypeStandard())
       
   881 		return;
       
   882 
       
   883 	if(!TestSessionPath())
       
   884 		{
       
   885 		test.Printf(_L("Not testing on %S\n"),&gSessionPath);
       
   886 		return;
       
   887 		}
       
   888 #if defined(__WINS__)
       
   889 	gLockedDrive=EDriveX;
       
   890 	gLockedPath=_L("?:\\");
       
   891 	gLockedBase=_L("?:");
       
   892 	gLockedPath[0]=gLockedBase[0]=(TText)('A'+gLockedDrive);
       
   893 #else
       
   894 	gLockedDrive=EDriveD;
       
   895 	gLockedPath=_L("?:\\");
       
   896 	gLockedBase=_L("?:");
       
   897 	gLockedPath[0]=gLockedBase[0]=(TText)('A'+gLockedDrive);
       
   898 #endif
       
   899 
       
   900 	test.Printf(_L("Is a secure mmc present? Press y for yes\n"));
       
   901 	TChar c=test.Getch();
       
   902 	if(c=='y'||c=='Y')
       
   903 		isSecureMmc=ETrue;
       
   904 	else
       
   905 		isSecureMmc=EFalse;
       
   906 
       
   907 	TInt r=HungSemaphoreC.CreateLocal(0);
       
   908 	test(r==KErrNone);
       
   909 	r=HungSemaphoreNC.CreateLocal(0);
       
   910 	test(r==KErrNone);
       
   911 
       
   912 	// create sharable session
       
   913 	TheFs.ShareAuto();
       
   914 
       
   915 	TestParsingFunctions();
       
   916 	TestTFsFunctions();
       
   917 	TestExtendedNotifier();
       
   918 	TestSubsessions();
       
   919 //	TestNotifiers();
       
   920 	TestCriticalFunctions();
       
   921 	TestSameSession();
       
   922 	TestSameSubSession();
       
   923 
       
   924 	HungSemaphoreC.Close();
       
   925 	HungSemaphoreNC.Close();
       
   926 }