kerneltest/f32test/concur/t_cfsperform.cpp
changeset 109 b3a1d9898418
parent 0 a41df078684a
child 257 3e88ff8f41d5
equal deleted inserted replaced
102:ef2a444a7410 109:b3a1d9898418
    15 // 
    15 // 
    16 //
    16 //
    17 
    17 
    18 //! @file f32test\concur\t_cfsbench.cpp
    18 //! @file f32test\concur\t_cfsbench.cpp
    19 
    19 
       
    20 #define	__E32TEST_EXTENSION__
    20 #include <f32file.h>
    21 #include <f32file.h>
    21 #include <e32test.h>
    22 #include <e32test.h>
    22 #include <f32dbg.h>
    23 #include <f32dbg.h>
    23 #include "t_server.h"
    24 #include "t_server.h"
    24 #include "t_tdebug.h"
    25 #include "t_tdebug.h"
    80 	r=TheFs.CharToDrive(c, drv);
    81 	r=TheFs.CharToDrive(c, drv);
    81 	if (r != KErrNone)
    82 	if (r != KErrNone)
    82 		return EFalse;
    83 		return EFalse;
    83 	TDriveInfo info;
    84 	TDriveInfo info;
    84 	r=TheFs.Drive(info,drv);
    85 	r=TheFs.Drive(info,drv);
    85 	test(r==KErrNone);
    86 	test_KErrNone(r);
    86 	return (info.iDriveAtt != 0 && !(info.iDriveAtt & KDriveAttRom));
    87 	return (info.iDriveAtt != 0 && !(info.iDriveAtt & KDriveAttRom));
    87 	}
    88 	}
    88 
    89 
    89 LOCAL_C TChar MountTestFileSystem(TInt aDrive)
    90 LOCAL_C TChar MountTestFileSystem(TInt aDrive)
    90 //
    91 //
    93 	{
    94 	{
    94 	TInt r;
    95 	TInt r;
    95 	TBuf<64> b;
    96 	TBuf<64> b;
    96 	TChar c;
    97 	TChar c;
    97 	r=TheFs.DriveToChar(aDrive,c);
    98 	r=TheFs.DriveToChar(aDrive,c);
    98 	test(r==KErrNone);
    99 	test_KErrNone(r);
    99 	b.Format(_L("Mount test file system on %c:"),(TUint)c);
   100 	b.Format(_L("Mount test file system on %c:"),(TUint)c);
   100 	test.Next(b);
   101 	test.Next(b);
   101 
   102 
   102 	r=TheFs.AddFileSystem(KFsFile);
   103 	r=TheFs.AddFileSystem(KFsFile);
   103 	test(r==KErrNone || r==KErrAlreadyExists);
   104 	test_Value(r, r == KErrNone || r==KErrAlreadyExists);
   104 	
   105 	
   105 	r=TheFs.FileSystemName(gOldFsName,aDrive);
   106 	r=TheFs.FileSystemName(gOldFsName,aDrive);
   106 	test(r==KErrNone || r==KErrNotFound);
   107 	test_Value(r, r == KErrNone || r==KErrNotFound);
   107 
   108 
   108 	TDriveInfo drv;
   109 	TDriveInfo drv;
   109 	r = TheFs.Drive(drv, aDrive);
   110 	r = TheFs.Drive(drv, aDrive);
   110 	test(r == KErrNone);
   111 	test_KErrNone(r);
   111 
   112 
   112 	gNoMedia = (drv.iType == EMediaUnknown || drv.iType == EMediaNotPresent);
   113 	gNoMedia = (drv.iType == EMediaUnknown || drv.iType == EMediaNotPresent);
   113 
   114 
   114 	if (gOldFsName.Length() > 0)
   115 	if (gOldFsName.Length() > 0)
   115 		{
   116 		{
   116 		TTest::Printf(_L("Dismount %C: %S"), (TUint)c, &gOldFsName);
   117 		TTest::Printf(_L("Dismount %C: %S"), (TUint)c, &gOldFsName);
   117 		r=TheFs.DismountFileSystem(gOldFsName,aDrive);
   118 		r=TheFs.DismountFileSystem(gOldFsName,aDrive);
   118 		test(r==KErrNone);
   119 		test_KErrNone(r);
   119 		}
   120 		}
   120 
   121 
   121 	r=TheFs.MountFileSystem(KFsName,aDrive);
   122 	r=TheFs.MountFileSystem(KFsName,aDrive);
   122 	test(r==KErrNone);
   123 	test_KErrNone(r);
   123 
   124 
   124 	r=TheFs.FileSystemName(gNewFsName,aDrive);
   125 	r=TheFs.FileSystemName(gNewFsName,aDrive);
   125 	test(r==KErrNone);
   126 	test_KErrNone(r);
   126 	test(gNewFsName.CompareF(KFsName)==0);
   127 	test(gNewFsName.CompareF(KFsName)==0);
   127 	return c;
   128 	return c;
   128 	}
   129 	}
   129 
   130 
   130 LOCAL_C void UnmountFileSystem(TInt aDrive)
   131 LOCAL_C void UnmountFileSystem(TInt aDrive)
   131 /// Unmount a test filesystem and mount the old one.
   132 /// Unmount a test filesystem and mount the old one.
   132 	{
   133 	{
   133 	TChar c;
   134 	TChar c;
   134 	TInt r=TheFs.DriveToChar(aDrive,c);
   135 	TInt r=TheFs.DriveToChar(aDrive,c);
   135 	test(r==KErrNone);
   136 	test_KErrNone(r);
   136 	r=TheFs.DismountFileSystem(gNewFsName,aDrive);
   137 	r=TheFs.DismountFileSystem(gNewFsName,aDrive);
   137 	test(r==KErrNone);
   138 	test_KErrNone(r);
   138 	// if there's no media present, don't try to mount it
   139 	// if there's no media present, don't try to mount it
   139 	if (gNoMedia)
   140 	if (gNoMedia)
   140 		{
   141 		{
   141 		test.Printf(_L("No media on %C: so don't remount it"), (TUint)c);
   142 		test.Printf(_L("No media on %C: so don't remount it"), (TUint)c);
   142 		}
   143 		}
   143 	else if (gOldFsName.Length() > 0)
   144 	else if (gOldFsName.Length() > 0)
   144 		{
   145 		{
   145 		test.Printf(_L("Mount    %C: %S"), (TUint)c, &gOldFsName);
   146 		test.Printf(_L("Mount    %C: %S"), (TUint)c, &gOldFsName);
   146 		r=TheFs.MountFileSystem(gOldFsName,aDrive);
   147 		r=TheFs.MountFileSystem(gOldFsName,aDrive);
   147 		test(r==KErrNone);
   148 		test_KErrNone(r);
   148 		}
   149 		}
   149 	if (r != KErrNone)
   150 	if (r != KErrNone)
   150 		test.Printf(_L("Error %d remounting %S on %C\n"), r, &gOldFsName, (TUint)c);
   151 		test.Printf(_L("Error %d remounting %S on %C\n"), r, &gOldFsName, (TUint)c);
   151 	}
   152 	}
   152 
   153 
   157 /// @param aSync  Mount synchronous if true, asynchronous if not.
   158 /// @param aSync  Mount synchronous if true, asynchronous if not.
   158 	{
   159 	{
   159 	TChar c;
   160 	TChar c;
   160 	TInt r=TheFs.DriveToChar(aDrive,c);
   161 	TInt r=TheFs.DriveToChar(aDrive,c);
   161 	r=TheFs.FileSystemName(gFsName, aDrive);
   162 	r=TheFs.FileSystemName(gFsName, aDrive);
   162 	test(r==KErrNone || r==KErrNotFound);
   163 	test_Value(r, r == KErrNone || r==KErrNotFound);
   163 
   164 
   164 	if (gFsName.Length() > 0)
   165 	if (gFsName.Length() > 0)
   165 		{
   166 		{
   166 		r=TheFs.DismountFileSystem(gFsName, aDrive);
   167 		r=TheFs.DismountFileSystem(gFsName, aDrive);
   167 		if(r!=KErrNone)
   168 		if(r!=KErrNone)
   181 	r=TheFs.MountFileSystem(gFsName, aDrive, aSync);
   182 	r=TheFs.MountFileSystem(gFsName, aDrive, aSync);
   182 #else
   183 #else
   183 	r=TheFs.MountFileSystem(gFsName, aDrive);
   184 	r=TheFs.MountFileSystem(gFsName, aDrive);
   184 #endif
   185 #endif
   185 
   186 
   186 	test(r==KErrNone);
   187 	test_KErrNone(r);
   187 	}
   188 	}
   188 
   189 
   189 enum TOper
   190 enum TOper
   190 	{
   191 	{
   191 	ERead,
   192 	ERead,
   355 		if (r != KErrNone)
   356 		if (r != KErrNone)
   356 			return r;
   357 			return r;
   357 
   358 
   358 		TInt sizeFile = 0;
   359 		TInt sizeFile = 0;
   359 		r = iF.Size(sizeFile);
   360 		r = iF.Size(sizeFile);
   360 		test(r == KErrNone);
   361 		test_KErrNone(r);
   361         if (gVerbose)
   362         if (gVerbose)
   362 			{
   363 			{
   363 			test.Printf(_L("File Size = %d, %d buffers of size %d\n"), sizeFile, iMax, iBufSize);
   364 			test.Printf(_L("File Size = %d, %d buffers of size %d\n"), sizeFile, iMax, iBufSize);
   364 			}
   365 			}
   365 		iMax = sizeFile / iBufSize;
   366 		iMax = sizeFile / iBufSize;
   466 
   467 
   467 	test(buf != NULL);
   468 	test(buf != NULL);
   468 	for (TInt pos=0; pos<iFileSize; pos+= buf->Length())
   469 	for (TInt pos=0; pos<iFileSize; pos+= buf->Length())
   469 		{
   470 		{
   470 		r = iF.Write(pos, bufptr);
   471 		r = iF.Write(pos, bufptr);
   471 		if (r != KErrNone)
   472 		test_KErrNone(r);
   472 			test.Printf(_L("Write() returned %d\n"), r);
       
   473 
       
   474 		test(r == KErrNone);
       
   475 		}
   473 		}
   476 	delete buf; buf = NULL;
   474 	delete buf; buf = NULL;
   477 
   475 
   478 	//	if (gVerbose)
   476 	//	if (gVerbose)
   479 		test.Printf(_L("Done.\n"));
   477 		test.Printf(_L("Done.\n"));
   650 
   648 
   651 	timer.CreateLocal();
   649 	timer.CreateLocal();
   652 
   650 
   653 
   651 
   654 	r = TheFs.DriveToChar(aDrive1, dc1);
   652 	r = TheFs.DriveToChar(aDrive1, dc1);
   655 	test(r == KErrNone);
   653 	test_KErrNone(r);
   656 	r = TheFs.DriveToChar(aDrive2, dc2);
   654 	r = TheFs.DriveToChar(aDrive2, dc2);
   657 	test(r == KErrNone);
   655 	test_KErrNone(r);
   658 
   656 
   659 	// allocate buffers
   657 	// allocate buffers
   660 	r = f1.Init(dc1, aBufSize1);
   658 	r = f1.Init(dc1, aBufSize1);
   661 		test(r == KErrNone);
   659 	test_KErrNone(r);
   662 	r = f2.Init(dc2, aBufSize2);
   660 	r = f2.Init(dc2, aBufSize2);
   663 	test(r == KErrNone);
   661 	test_KErrNone(r);
   664 
   662 
   665 	
   663 	
   666 	_LIT(KSync, " sync");
   664 	_LIT(KSync, " sync");
   667 	_LIT(KAsync, "async");
   665 	_LIT(KAsync, "async");
   668 	if (gVerbose)
   666 	if (gVerbose)
   684 		//********************************************************************
   682 		//********************************************************************
   685 
   683 
   686 		if (aBufSize1 > 0)
   684 		if (aBufSize1 > 0)
   687 			{
   685 			{
   688 			r = f1.CreateReadFile();
   686 			r = f1.CreateReadFile();
   689 			test(r == KErrNone);
   687 			test_KErrNone(r);
   690 			}
   688 			}
   691 		if (aBufSize2 > 0)
   689 		if (aBufSize2 > 0)
   692 			{
   690 			{
   693 			r = f2.CreateReadFile();
   691 			r = f2.CreateReadFile();
   694 			test(r == KErrNone);
   692 			test_KErrNone(r);
   695 			}
   693 			}
   696 
   694 
   697 		if (aBufSize1 > 0)
   695 		if (aBufSize1 > 0)
   698 			r = f1.Open(RFileOps::ERead);
   696 			r = f1.Open(RFileOps::ERead);
   699 		test(r == KErrNone);
   697 		test_KErrNone(r);
   700 		
   698 		
   701 		if (aBufSize2 > 0)
   699 		if (aBufSize2 > 0)
   702 			r = f2.Open(RFileOps::ERead);
   700 			r = f2.Open(RFileOps::ERead);
   703 		test(r == KErrNone);
   701 		test_KErrNone(r);
   704 
   702 
   705 
   703 
   706 		timer.After(tstat, KTimeBM * KSecond);
   704 		timer.After(tstat, KTimeBM * KSecond);
   707 
   705 
   708 		startTime.HomeTime();
   706 		startTime.HomeTime();
   738 		// write test
   736 		// write test
   739 		//********************************************************************
   737 		//********************************************************************
   740 		if (aBufSize1 > 0)
   738 		if (aBufSize1 > 0)
   741 			{
   739 			{
   742 			r = f1.Open(RFileOps::EWrite);
   740 			r = f1.Open(RFileOps::EWrite);
   743 			test(r == KErrNone);
   741 			test_KErrNone(r);
   744 			}
   742 			}
   745 	
   743 	
   746 		if (aBufSize2 > 0)
   744 		if (aBufSize2 > 0)
   747 			{
   745 			{
   748 			r = f2.Open(RFileOps::EWrite);
   746 			r = f2.Open(RFileOps::EWrite);
   749 			test(r == KErrNone);
   747 			test_KErrNone(r);
   750 			}
   748 			}
   751 
   749 
   752 		timer.After(tstat, KTimeBM * KSecond);
   750 		timer.After(tstat, KTimeBM * KSecond);
   753 
   751 
   754 		startTime.HomeTime();
   752 		startTime.HomeTime();
   902 // Do all tests
   900 // Do all tests
   903 //
   901 //
   904 GLDEF_C void CallTestsL()
   902 GLDEF_C void CallTestsL()
   905 	{
   903 	{
   906 	TInt r = TTest::Init();
   904 	TInt r = TTest::Init();
   907 	test(r == KErrNone);
   905 	test_KErrNone(r);
   908 
   906 
   909 	TChar drvch1 = 0;
   907 	TChar drvch1 = 0;
   910 	TChar drvch2 = 0;
   908 	TChar drvch2 = 0;
   911 	TInt  drive1;
   909 	TInt  drive1;
   912 	TInt  drive2;
   910 	TInt  drive2;
   961 		{
   959 		{
   962 		User::Panic(_L("USER ABORT"), 0);
   960 		User::Panic(_L("USER ABORT"), 0);
   963 		}
   961 		}
   964 
   962 
   965 	r = TheFs.CharToDrive(drvch1, drive1);
   963 	r = TheFs.CharToDrive(drvch1, drive1);
   966 	test(r == KErrNone);
   964 	test_KErrNone(r);
   967 	r = TheFs.CharToDrive(drvch2, drive2);
   965 	r = TheFs.CharToDrive(drvch2, drive2);
   968 	test(r == KErrNone);
   966 	test_KErrNone(r);
   969 	
   967 	
   970 	r = TheFs.FileSystemName(gFsName1, drive1);
   968 	r = TheFs.FileSystemName(gFsName1, drive1);
   971 	test(r == KErrNone || r == KErrNotFound);
   969 	test_Value(r, r == KErrNone || r == KErrNotFound);
   972 	r = TheFs.FileSystemName(gFsName2, drive2);
   970 	r = TheFs.FileSystemName(gFsName2, drive2);
   973 	test(r == KErrNone || r == KErrNotFound);
   971 	test_Value(r, r == KErrNone || r == KErrNotFound);
   974 
   972 
   975 	if (testFs)
   973 	if (testFs)
   976 		{
   974 		{
   977 		MountTestFileSystem(drive1);
   975 		MountTestFileSystem(drive1);
   978 		MountTestFileSystem(drive2);
   976 		MountTestFileSystem(drive2);
  1049 	if (testFs)
  1047 	if (testFs)
  1050 		{
  1048 		{
  1051 		UnmountFileSystem(drive1);
  1049 		UnmountFileSystem(drive1);
  1052 		UnmountFileSystem(drive2);
  1050 		UnmountFileSystem(drive2);
  1053 		}
  1051 		}
  1054 	test(r == 0);
  1052 	test_Value(r, r == 0);
  1055 	}
  1053 	}
  1056 
  1054 
  1057 
  1055 
  1058 GLDEF_C TInt E32Main()
  1056 GLDEF_C TInt E32Main()
  1059 // 
  1057 // 
  1067 
  1065 
  1068     test.Title();
  1066     test.Title();
  1069     test.Start(_L("Starting tests..."));
  1067     test.Start(_L("Starting tests..."));
  1070 
  1068 
  1071     r=TheFs.Connect();
  1069     r=TheFs.Connect();
  1072     test(r==KErrNone);
  1070     test_KErrNone(r);
  1073 
  1071 
  1074     // TheFs.SetAllocFailure(gAllocFailOn);
  1072     // TheFs.SetAllocFailure(gAllocFailOn);
  1075     TTime timerC;
  1073     TTime timerC;
  1076     timerC.HomeTime();
  1074     timerC.HomeTime();
  1077 	// Do the tests
  1075 	// Do the tests
  1082 
  1080 
  1083     TTime endTimeC;
  1081     TTime endTimeC;
  1084     endTimeC.HomeTime();
  1082     endTimeC.HomeTime();
  1085     TTimeIntervalSeconds timeTakenC;
  1083     TTimeIntervalSeconds timeTakenC;
  1086     r=endTimeC.SecondsFrom(timerC,timeTakenC);
  1084     r=endTimeC.SecondsFrom(timerC,timeTakenC);
  1087     test(r==KErrNone);
  1085     test_KErrNone(r);
  1088     test.Printf(_L("Time taken for test = %d seconds\n"),timeTakenC.Int());
  1086     test.Printf(_L("Time taken for test = %d seconds\n"),timeTakenC.Int());
  1089     // TheFs.SetAllocFailure(gAllocFailOff);
  1087     // TheFs.SetAllocFailure(gAllocFailOff);
  1090     TheFs.Close();
  1088     TheFs.Close();
  1091     test.End();
  1089     test.End();
  1092     test.Close();
  1090     test.Close();