kerneltest/f32test/server/t_ext1.cpp
changeset 0 a41df078684a
child 102 ef2a444a7410
child 149 d9f1e5bfe28c
child 175 5af6c74cd793
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 // Copyright (c) 2002-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\ext\t_ext1.cpp
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <f32file.h>
       
    19 #include <e32test.h>
       
    20 #include <e32svr.h>
       
    21 #include "t_server.h"
       
    22 #include "f32_test_utils.h"
       
    23 
       
    24 using namespace F32_Test_Utils;
       
    25 
       
    26 
       
    27 GLDEF_D RTest test(_L("T_EXT1"));
       
    28 
       
    29 _LIT(KExtensionLog,"T_LOGEXT");
       
    30 _LIT(KExtensionLogName,"Logger");
       
    31 _LIT(KExtensionEmpty,"T_EMPTYEXT");
       
    32 _LIT(KExtensionEmptyName,"Empty");
       
    33 _LIT(KExtensionBit,"T_BITEXT");
       
    34 _LIT(KExtensionBitName,"Bitchange");
       
    35 _LIT(KExtensionRubbish,"T_RUBBISH");
       
    36 _LIT(dir1,"\\dir1\\");
       
    37 _LIT(file1Name,"\\dir1\\file1.doc");
       
    38 _LIT8(toWrite,"abcdefghijklmnop");
       
    39 
       
    40 void TestSecondaryExtensions()
       
    41 //
       
    42 // a secondary extension is one that is added to a drive with an existing file system
       
    43 // therefore a mount is successful with or without the extension
       
    44 //
       
    45 	{
       
    46 	test.Next(_L("TestSecondaryExtensions()"));
       
    47 	TInt drive;
       
    48 	TInt err=RFs::CharToDrive(gDriveToTest,drive);
       
    49 	test(err==KErrNone);
       
    50 	
       
    51 	TPckgBuf<TBool> drvSyncBuf;
       
    52 	err = TheFs.QueryVolumeInfoExt(drive, EIsDriveSync, drvSyncBuf);
       
    53 	test(err==KErrNone);
       
    54 	const TBool bDrvSync = drvSyncBuf();
       
    55 			
       
    56 
       
    57 	TFullName fsName;
       
    58 	TInt r=TheFs.FileSystemName(fsName,drive);
       
    59 	test(r==KErrNone);
       
    60 	test.Printf(_L("fsName=%S\n"),&fsName);
       
    61 
       
    62 #if defined(__WINS__)
       
    63 	if(drive==EDriveC)
       
    64 		{
       
    65 		// check that the extension cannot be mounted since not supported by the file system
       
    66 		r=TheFs.AddExtension(KExtensionLog);
       
    67 		test(r==KErrNone);
       
    68 		r=TheFs.MountExtension(KExtensionLogName,drive);
       
    69 		test(r==KErrNotSupported);
       
    70 		r=TheFs.RemoveExtension(KExtensionLogName);
       
    71 		test(r==KErrNone);
       
    72 		return;
       
    73 		}
       
    74 #endif
       
    75 
       
    76 	test.Next(_L("RFs::AddExtension()"));
       
    77 	r=TheFs.AddExtension(KExtensionLog);
       
    78 	RDebug::Print(_L("addext=%d"),r);
       
    79 	test(r==KErrNone);
       
    80 	r=TheFs.AddExtension(KExtensionLog);
       
    81 	test(r==KErrAlreadyExists);
       
    82 	r=TheFs.AddExtension(KExtensionRubbish);
       
    83 	test(r==KErrNotFound);
       
    84 	r=TheFs.AddExtension(KExtensionEmpty);
       
    85 	test(r==KErrNone);
       
    86 
       
    87 	test.Next(_L("RFs::MountExtension()"));
       
    88 #if !defined(__WINS__)
       
    89 	// check that the extension cannot be mounted on file system that does not support extensions
       
    90 	r=TheFs.MountExtension(KExtensionLogName,EDriveZ);
       
    91 	test(r==KErrNotSupported);
       
    92 #endif
       
    93 	// test mounting on drive with no file system
       
    94 	r=TheFs.DismountFileSystem(fsName,drive);
       
    95 	test(r==KErrNone);
       
    96 	r=TheFs.MountExtension(KExtensionLogName,drive);
       
    97 	test(r==KErrNotReady);
       
    98 	r=TheFs.MountFileSystem(fsName,drive,bDrvSync);
       
    99 	test(r==KErrNone);
       
   100 	// test with a resource open
       
   101 	_LIT(KFileName,"testing.doc");
       
   102 	RFile file;
       
   103 	r=file.Replace(TheFs,KFileName,EFileShareExclusive);
       
   104 	test(r==KErrNone);
       
   105 	r=TheFs.MountExtension(KExtensionLogName,drive);
       
   106 	test(r==KErrInUse);
       
   107 	file.Close();
       
   108 	r=TheFs.Delete(KFileName);
       
   109 	test(r==KErrNone);
       
   110 	// test with a format open
       
   111 	TBuf<4> driveBuf=_L("?:\\");
       
   112 	driveBuf[0]=(TText)(drive+'A');
       
   113 	RFormat format;
       
   114 	TInt count;
       
   115 	r=format.Open(TheFs,driveBuf,EHighDensity,count);
       
   116 	test(r==KErrNone);
       
   117 	r=TheFs.MountExtension(KExtensionLogName,drive);
       
   118 	test(r==KErrInUse);
       
   119 	format.Close();
       
   120 	// get the extension name
       
   121 	TFullName extName;
       
   122 	r=TheFs.ExtensionName(extName,drive,0);
       
   123 	test(r==KErrNotFound);
       
   124 	// now load the extension
       
   125 	r=TheFs.MountExtension(KExtensionLogName,drive);
       
   126 	test(r==KErrNone);
       
   127 	r=TheFs.ExtensionName(extName,drive,0);
       
   128 	test(r==KErrNone && extName==KExtensionLogName);
       
   129 	r=TheFs.ExtensionName(extName,drive,1);
       
   130 	test(r==KErrNotFound);
       
   131 	// try remounting the same extension
       
   132 	r=TheFs.MountExtension(KExtensionLogName,drive);
       
   133 	test(r==KErrAlreadyExists);
       
   134 	// mount a second extension
       
   135 	r=TheFs.MountExtension(KExtensionEmptyName,drive);
       
   136 	test(r==KErrNone);
       
   137 	r=TheFs.ExtensionName(extName,drive,0);
       
   138 	test(r==KErrNone && extName==KExtensionLogName);
       
   139 	r=TheFs.ExtensionName(extName,drive,1);
       
   140 	test(r==KErrNone && extName==KExtensionEmptyName);
       
   141 	
       
   142     // force a remount on a removable media and check that extensions both exist
       
   143     test.Printf(_L("Test forcing remount\n"));
       
   144     TDriveInfo info;
       
   145 	r=TheFs.Drive(info,drive);
       
   146 	if(info.iDriveAtt&KDriveAttRemovable)
       
   147 		{
       
   148         const TInt KMediaRemountForceMediaChange = 0x00000001;
       
   149 
       
   150 
       
   151         TRequestStatus changeStatus;
       
   152         TheFs.NotifyChange(ENotifyAll, changeStatus);
       
   153 
       
   154         test.Printf(_L("Remounting the drive\n"), r);
       
   155         r = TheFs.RemountDrive(drive, NULL, (TUint) KMediaRemountForceMediaChange);
       
   156         test(r == KErrNotReady || r == KErrNone);
       
   157         
       
   158         do
       
   159         {
       
   160         test.Printf(_L("Waiting for media change...\n"));
       
   161         User::WaitForRequest(changeStatus);
       
   162 
       
   163         r=TheFs.Drive(info,drive);
       
   164         test.Printf(_L("Drive() returned %d\n"), r);
       
   165 
       
   166         TheFs.NotifyChange(ENotifyAll, changeStatus);
       
   167         }
       
   168     while (r == KErrNotReady);
       
   169     TheFs.NotifyChangeCancel(changeStatus);
       
   170 
       
   171     User::After(1000000); //-- don't know why we need this, otherwise for WINS mediadriver returns -18
       
   172 
       
   173 
       
   174 
       
   175 /*	
       
   176         //-- strange, but this variant caused Media Driver to always return -18 
       
   177         //-- and the media have become inaccessible forever (on H2). 
       
   178         //-- funny enough, but turning ON heavy logging from the drivers (PBUS & KLOCDRV) helped the problem
       
   179 
       
   180         test.Printf(_L("Force media change\n"));
       
   181     	RLocalDrive d;
       
   182 		TBool flag=EFalse;
       
   183 		r=d.Connect(1,flag);
       
   184 		test(r==KErrNone);
       
   185 		d.ForceMediaChange();
       
   186 		d.Close();
       
   187 //#if defined(__WINS__)
       
   188 		// ??? seems to work, find out why
       
   189 		//User::After(500000);
       
   190         User::After(2000000);
       
   191 //#endif
       
   192 */
       
   193 		}
       
   194 
       
   195 
       
   196 
       
   197 	r=TheFs.ExtensionName(extName,drive,0);
       
   198 	test(r==KErrNone && extName==KExtensionLogName);
       
   199 	r=TheFs.ExtensionName(extName,drive,1);
       
   200 	test(r==KErrNone && extName==KExtensionEmptyName);
       
   201 
       
   202     test.Printf(_L("Accessing media...\n"));
       
   203 	// and now do some file system operations
       
   204 	TBuf8<16> readBuf;
       
   205 	r=TheFs.MkDir(dir1);
       
   206     
       
   207     test.Printf(_L("res=%d\n"), r);
       
   208 
       
   209 
       
   210 	test(r==KErrNone||r==KErrAlreadyExists);
       
   211 	RFile file1;
       
   212 	r=file1.Replace(TheFs,file1Name,EFileShareExclusive);
       
   213 	test(r==KErrNone);
       
   214 	r=file1.Write(toWrite);
       
   215 	test(r==KErrNone);
       
   216 	r=file1.Read(0,readBuf);
       
   217 	test(readBuf==toWrite);
       
   218 	r=file1.SetSize(0);
       
   219 	test(r==KErrNone);
       
   220 	file1.Close();
       
   221 	r=TheFs.Delete(file1Name);
       
   222 	test(r==KErrNone);
       
   223 	r=TheFs.RmDir(dir1);
       
   224 	test(r==KErrNone);
       
   225 
       
   226 	test.Next(_L("RFs::DismountExtension()"));
       
   227 	// test with a resource open
       
   228 	r=file.Replace(TheFs,KFileName,EFileShareExclusive);
       
   229 	test(r==KErrNone);
       
   230 	r=TheFs.DismountExtension(KExtensionLogName,drive);
       
   231 	test(r==KErrInUse);
       
   232 	file.Close();
       
   233 	r=TheFs.Delete(KFileName);
       
   234 	test(r==KErrNone);
       
   235 	// test with a format open
       
   236 	r=format.Open(TheFs,driveBuf,EHighDensity,count);
       
   237 	test(r==KErrNone);
       
   238 	r=TheFs.DismountExtension(KExtensionLogName,drive);
       
   239 	test(r==KErrInUse);
       
   240 	format.Close();
       
   241 	// now dismount an extension
       
   242 	r=TheFs.DismountExtension(KExtensionLogName,drive);
       
   243 	test(r==KErrNone);
       
   244 	r=TheFs.ExtensionName(extName,drive,0);
       
   245 	test(r==KErrNone && extName==KExtensionEmptyName);
       
   246 	r=TheFs.ExtensionName(extName,drive,1);
       
   247 	test(r==KErrNotFound);
       
   248 	// try to dismount an extension that is not mounted
       
   249 	r=TheFs.DismountExtension(KExtensionLogName,drive);
       
   250 	test(r==KErrNotFound);
       
   251 	r=TheFs.ExtensionName(extName,drive,0);
       
   252 	test(r==KErrNone && extName==KExtensionEmptyName);
       
   253 	r=TheFs.ExtensionName(extName,drive,1);
       
   254 	test(r==KErrNotFound);
       
   255 	// dismount the remaining extension
       
   256 	r=TheFs.DismountExtension(KExtensionEmptyName,drive);
       
   257 	test(r==KErrNone);
       
   258 	r=TheFs.ExtensionName(extName,drive,0);
       
   259 	test(r==KErrNotFound);
       
   260 	r=TheFs.ExtensionName(extName,drive,1);
       
   261 	test(r==KErrNotFound);
       
   262 
       
   263 	test.Next(_L("RFs::RemoveExtension()"));
       
   264 	r=TheFs.RemoveExtension(KExtensionLogName);
       
   265 	test(r==KErrNone);
       
   266 	r=TheFs.RemoveExtension(KExtensionEmptyName);
       
   267 	test(r==KErrNone);
       
   268 	}
       
   269 
       
   270 void TestPrimaryExtensions()
       
   271 //
       
   272 // a primary extension is one that is added to a drive before a file system is mounted
       
   273 // must be present for the mount to be successful (eg. FTL)
       
   274 //
       
   275 	{
       
   276 	test.Next(_L("TestPrimaryExtensions()"));
       
   277 	TInt drive;
       
   278 	TInt err=RFs::CharToDrive(gDriveToTest,drive);
       
   279 	test(err==KErrNone);
       
   280 
       
   281 #if defined(__WINS__)
       
   282 	if(drive==EDriveC)
       
   283 		return;
       
   284 #endif
       
   285 
       
   286 	TPckgBuf<TBool> drvSyncBuf;
       
   287 	err = TheFs.QueryVolumeInfoExt(drive, EIsDriveSync, drvSyncBuf);
       
   288 	test(err==KErrNone);
       
   289     const TBool bDrvSync = drvSyncBuf();
       
   290 
       
   291 	// don't test on ram drive since accesses memory directly
       
   292 	TDriveInfo info;
       
   293 	TInt r=TheFs.Drive(info,drive);
       
   294 	if(info.iMediaAtt&KMediaAttVariableSize)
       
   295 		return;
       
   296 
       
   297 	TFullName fsName;
       
   298 	r=TheFs.FileSystemName(fsName,drive);
       
   299 	test(r==KErrNone);
       
   300 	test.Printf(_L("fsName=%S\n"),&fsName);
       
   301 
       
   302 	test.Next(_L("RFs::AddExtension()"));
       
   303 	r=TheFs.AddExtension(KExtensionLog);
       
   304 	test(r==KErrNone);
       
   305 	r=TheFs.AddExtension(KExtensionEmpty);
       
   306 	test(r==KErrNone);
       
   307 	r=TheFs.AddExtension(KExtensionBit);
       
   308 	test(r==KErrNone);
       
   309 
       
   310 	test.Next(_L("RFs::MountFileSystem()"));
       
   311 	// test with file system that already exists
       
   312 	r=TheFs.MountFileSystem(fsName,KExtensionBitName,drive,bDrvSync);
       
   313 	test(r==KErrAccessDenied);
       
   314 	// unmount drive and mount primary extension along with file system
       
   315 	r=TheFs.DismountFileSystem(fsName,drive);
       
   316 	test(r==KErrNone);
       
   317 
       
   318     //-- !! N.B this extension mangles data read/written ftom/to the media, for some file systems it is OK and mounting succeeds
       
   319     //-- for others - this will result in KErrCorrupt
       
   320 	r=TheFs.MountFileSystem(fsName,KExtensionBitName,drive,bDrvSync);
       
   321 	test(r==KErrNone||r==KErrCorrupt);
       
   322 	
       
   323     // and now format
       
   324 	Format(drive);
       
   325 	TFullName extName;
       
   326 	r=TheFs.ExtensionName(extName,drive,0);
       
   327 	test(r==KErrNone && extName==KExtensionBitName);
       
   328 	r=TheFs.ExtensionName(extName,drive,1);
       
   329 	test(r==KErrNotFound);
       
   330 	
       
   331 	// and now do some file system operations
       
   332 	TBuf8<16> readBuf;
       
   333 	r=TheFs.MkDir(dir1);
       
   334 	test(r==KErrNone||r==KErrAlreadyExists);
       
   335 	RFile file1;
       
   336 	r=file1.Replace(TheFs,file1Name,EFileShareExclusive);
       
   337 	test(r==KErrNone);
       
   338 	r=file1.Write(toWrite);
       
   339 	test(r==KErrNone);
       
   340 	r=file1.Read(0,readBuf);
       
   341 	test(readBuf==toWrite);
       
   342 	r=file1.SetSize(0);
       
   343 	test(r==KErrNone);
       
   344 	file1.Close();
       
   345 	r=TheFs.Delete(file1Name);
       
   346 	test(r==KErrNone);
       
   347 	r=TheFs.RmDir(dir1);
       
   348 	test(r==KErrNone);
       
   349 
       
   350 	// add a secondary extension
       
   351 	test.Printf(_L("RFs::MountExtension()"));
       
   352 	r=TheFs.MountExtension(KExtensionLogName,drive);
       
   353 	test(r==KErrNone);
       
   354 	r=TheFs.ExtensionName(extName,drive,0);
       
   355 	test(r==KErrNone && extName==KExtensionBitName);
       
   356 	r=TheFs.ExtensionName(extName,drive,1);
       
   357 	test(r==KErrNone && extName==KExtensionLogName);
       
   358 	// try to add the same extension
       
   359 	r=TheFs.MountExtension(KExtensionBitName,drive);
       
   360 	test(r==KErrAlreadyExists);
       
   361 	r=TheFs.ExtensionName(extName,drive,0);
       
   362 	test(r==KErrNone && extName==KExtensionBitName);
       
   363 	r=TheFs.ExtensionName(extName,drive,1);
       
   364 	test(r==KErrNone && extName==KExtensionLogName);
       
   365 	// try to add a third extension
       
   366 	r=TheFs.MountExtension(KExtensionEmptyName,drive);
       
   367 	test(r==KErrAccessDenied);
       
   368 	r=TheFs.ExtensionName(extName,drive,0);
       
   369 	test(r==KErrNone && extName==KExtensionBitName);
       
   370 	r=TheFs.ExtensionName(extName,drive,1);
       
   371 	test(r==KErrNone && extName==KExtensionLogName);
       
   372 
       
   373 	// and now do some file system operations
       
   374 	r=TheFs.MkDir(dir1);
       
   375 	test(r==KErrNone||r==KErrAlreadyExists);
       
   376 	r=file1.Replace(TheFs,file1Name,EFileShareExclusive);
       
   377 	test(r==KErrNone);
       
   378 	r=file1.Write(toWrite);
       
   379 	test(r==KErrNone);
       
   380 	r=file1.Read(0,readBuf);
       
   381 	test(readBuf==toWrite);
       
   382 	r=file1.SetSize(0);
       
   383 	test(r==KErrNone);
       
   384 	file1.Close();
       
   385 	r=TheFs.Delete(file1Name);
       
   386 	test(r==KErrNone);
       
   387 	r=TheFs.RmDir(dir1);
       
   388 	test(r==KErrNone);
       
   389 
       
   390 	test.Printf(_L("RFs::DismountExtension()"));
       
   391 	// test that can't dismount a primary extension via this method
       
   392 	r=TheFs.DismountExtension(KExtensionLogName,drive);
       
   393 	test(r==KErrNone);
       
   394 	r=TheFs.ExtensionName(extName,drive,0);
       
   395 	test(r==KErrNone && extName==KExtensionBitName);
       
   396 	r=TheFs.ExtensionName(extName,drive,1);
       
   397 	test(r==KErrNotFound);
       
   398 	r=TheFs.DismountExtension(KExtensionBitName,drive);
       
   399 	test(r==KErrAccessDenied);
       
   400 	r=TheFs.ExtensionName(extName,drive,0);
       
   401 	test(r==KErrNone && extName==KExtensionBitName);
       
   402 	r=TheFs.ExtensionName(extName,drive,1);
       
   403 	test(r==KErrNotFound);
       
   404 	
       
   405 	test.Printf(_L("RFs::DismountFileSystem()"));
       
   406 	r=TheFs.MountExtension(KExtensionLogName,drive);
       
   407 	test(r==KErrNone);
       
   408 	r=TheFs.ExtensionName(extName,drive,0);
       
   409 	test(r==KErrNone && extName==KExtensionBitName);
       
   410 	r=TheFs.ExtensionName(extName,drive,1);
       
   411 	test(r==KErrNone && extName==KExtensionLogName);
       
   412 	// and now dismount
       
   413 	r=TheFs.DismountFileSystem(fsName,drive);
       
   414 	test(r==KErrNone);
       
   415 	r=TheFs.ExtensionName(extName,drive,0);
       
   416 	test(r==KErrNotReady);
       
   417 	r=TheFs.ExtensionName(extName,drive,1);
       
   418 	test(r==KErrNotReady);
       
   419 	// remount the file system
       
   420 	r=TheFs.MountFileSystem(fsName,drive,bDrvSync);
       
   421 	test(r==KErrNone||r==KErrCorrupt);
       
   422 	r=TheFs.ExtensionName(extName,drive,0);
       
   423 	test(r==KErrNotFound);
       
   424 	r=TheFs.ExtensionName(extName,drive,1);
       
   425 	test(r==KErrNotFound);
       
   426 	Format(drive);
       
   427 
       
   428 	test.Next(_L("RFs::RemoveExtension()"));
       
   429 	r=TheFs.RemoveExtension(KExtensionLogName);
       
   430 	test(r==KErrNone);
       
   431 	r=TheFs.RemoveExtension(KExtensionEmptyName);
       
   432 	test(r==KErrNone);
       
   433 	r=TheFs.RemoveExtension(KExtensionBitName);
       
   434 	test(r==KErrNone);
       
   435 	}
       
   436 
       
   437 
       
   438 GLDEF_C void CallTestsL()
       
   439 //
       
   440 // Do tests relative to the session path
       
   441 //
       
   442 	{
       
   443     //-- set up console output 
       
   444     F32_Test_Utils::SetConsole(test.Console()); 
       
   445 	
       
   446     TInt drive;
       
   447 	TInt err=RFs::CharToDrive(gDriveToTest,drive);
       
   448 	test.Start(_L("Starting Test - T_EXT1"));
       
   449 	test(err==KErrNone);
       
   450 
       
   451     PrintDrvInfo(TheFs, drive);
       
   452 
       
   453 //Do not run this test on the NAND drive, as
       
   454 //this has the FTL mounted as a primary extension
       
   455 //which causes the test to fail
       
   456 #if defined(__WINS__)
       
   457 	if (drive==EDriveU)
       
   458 		return;
       
   459 #else
       
   460 	TDriveInfo driveInfo;
       
   461 	TheFs.Drive(driveInfo,drive);
       
   462 	if (driveInfo.iType == EMediaNANDFlash)
       
   463 		{
       
   464 		return;
       
   465 		}
       
   466 #endif
       
   467 	TestSecondaryExtensions();
       
   468 
       
   469     //-- the t_bitext extension mangles data from the media, which may make FS mounting fail because of "corrupted" data. 
       
   470     //-- Then this step formats the media, automounter doesn't support it straightforward way
       
   471     if(!Is_Lffs(TheFs, drive) && !Is_Automounter(TheFs, drive))
       
   472 		{
       
   473 		TestPrimaryExtensions();
       
   474 		}
       
   475 
       
   476 	test.End();
       
   477 	test.Close();
       
   478 	}