kerneltest/f32test/concur/t_cfsbench.cpp
changeset 149 d9f1e5bfe28c
parent 0 a41df078684a
child 257 3e88ff8f41d5
equal deleted inserted replaced
135:5e441a173c63 149:d9f1e5bfe28c
    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"
   116 	r=TheFs.CharToDrive(c, drv);
   117 	r=TheFs.CharToDrive(c, drv);
   117 	if (r != KErrNone)
   118 	if (r != KErrNone)
   118 		return EFalse;
   119 		return EFalse;
   119 	TDriveInfo info;
   120 	TDriveInfo info;
   120 	r=TheFs.Drive(info,drv);
   121 	r=TheFs.Drive(info,drv);
   121 	test(r==KErrNone);
   122 	test_KErrNone(r);
   122 	return (info.iDriveAtt != 0 && !(info.iDriveAtt & KDriveAttRom));
   123 	return (info.iDriveAtt != 0 && !(info.iDriveAtt & KDriveAttRom));
   123 	}
   124 	}
   124 
   125 
   125 LOCAL_C TChar MountTestFileSystem(TInt aDrive)
   126 LOCAL_C TChar MountTestFileSystem(TInt aDrive)
   126 //
   127 //
   129 	{
   130 	{
   130 	TInt r;
   131 	TInt r;
   131 	TBuf<64> b;
   132 	TBuf<64> b;
   132 	TChar c;
   133 	TChar c;
   133 	r=TheFs.DriveToChar(aDrive,c);
   134 	r=TheFs.DriveToChar(aDrive,c);
   134 	test(r==KErrNone);
   135 	test_KErrNone(r);
   135 	b.Format(_L("Mount test file system on %c:"),(TUint)c);
   136 	b.Format(_L("Mount test file system on %c:"),(TUint)c);
   136 	test.Next(b);
   137 	test.Next(b);
   137 
   138 
   138 	r=TheFs.AddFileSystem(KFsFile);
   139 	r=TheFs.AddFileSystem(KFsFile);
   139 	test(r==KErrNone || r==KErrAlreadyExists);
   140 	test_Value(r, r == KErrNone || r==KErrAlreadyExists);
   140 
   141 
   141 	r=TheFs.FileSystemName(gOldFsName,aDrive);
   142 	r=TheFs.FileSystemName(gOldFsName,aDrive);
   142 	test(r==KErrNone || r==KErrNotFound);
   143 	test_Value(r, r == KErrNone || r==KErrNotFound);
   143 
   144 
   144 	TDriveInfo drv;
   145 	TDriveInfo drv;
   145 	r = TheFs.Drive(drv, aDrive);
   146 	r = TheFs.Drive(drv, aDrive);
   146 	test(r == KErrNone);
   147 	test_KErrNone(r);
   147 
   148 
   148 	gNoMedia = (drv.iType == EMediaUnknown || drv.iType == EMediaNotPresent);
   149 	gNoMedia = (drv.iType == EMediaUnknown || drv.iType == EMediaNotPresent);
   149 
   150 
   150 	if (gOldFsName.Length() > 0)
   151 	if (gOldFsName.Length() > 0)
   151 		{
   152 		{
   152 		TTest::Printf(_L("Dismount %C: %S"), (TUint)c, &gOldFsName);
   153 		TTest::Printf(_L("Dismount %C: %S"), (TUint)c, &gOldFsName);
   153 		r=TheFs.DismountFileSystem(gOldFsName,aDrive);
   154 		r=TheFs.DismountFileSystem(gOldFsName,aDrive);
   154 		test(r==KErrNone);
   155 		test_KErrNone(r);
   155 		}
   156 		}
   156 
   157 
   157 	r=TheFs.MountFileSystem(KFsName,aDrive);
   158 	r=TheFs.MountFileSystem(KFsName,aDrive);
   158 	test(r==KErrNone);
   159 	test_KErrNone(r);
   159 
   160 
   160 	r=TheFs.FileSystemName(gNewFsName,aDrive);
   161 	r=TheFs.FileSystemName(gNewFsName,aDrive);
   161 	test(r==KErrNone);
   162 	test_KErrNone(r);
   162 	test(gNewFsName.CompareF(KFsName)==0);
   163 	test(gNewFsName.CompareF(KFsName)==0);
   163 	return c;
   164 	return c;
   164 	}
   165 	}
   165 
   166 
   166 LOCAL_C void UnmountFileSystem(TInt aDrive)
   167 LOCAL_C void UnmountFileSystem(TInt aDrive)
   167 /// Unmount a test filesystem and mount the old one.
   168 /// Unmount a test filesystem and mount the old one.
   168 	{
   169 	{
   169 	TChar c;
   170 	TChar c;
   170 	TInt r=TheFs.DriveToChar(aDrive,c);
   171 	TInt r=TheFs.DriveToChar(aDrive,c);
   171 	test(r==KErrNone);
   172 	test_KErrNone(r);
   172 	r=TheFs.DismountFileSystem(gNewFsName,aDrive);
   173 	r=TheFs.DismountFileSystem(gNewFsName,aDrive);
   173 	test(r==KErrNone);
   174 	test_KErrNone(r);
   174 	// if there's no media present, don't try to mount it
   175 	// if there's no media present, don't try to mount it
   175 	if (gNoMedia)
   176 	if (gNoMedia)
   176 		{
   177 		{
   177 		test.Printf(_L("No media on %C: so don't remount it"), (TUint)c);
   178 		test.Printf(_L("No media on %C: so don't remount it"), (TUint)c);
   178 		}
   179 		}
   179 	else if (gOldFsName.Length() > 0)
   180 	else if (gOldFsName.Length() > 0)
   180 		{
   181 		{
   181 		test.Printf(_L("Mount    %C: %S"), (TUint)c, &gOldFsName);
   182 		test.Printf(_L("Mount    %C: %S"), (TUint)c, &gOldFsName);
   182 		r=TheFs.MountFileSystem(gOldFsName,aDrive);
   183 		r=TheFs.MountFileSystem(gOldFsName,aDrive);
   183 		test(r==KErrNone);
   184 		test_KErrNone(r);
   184 		}
   185 		}
   185 	if (r != KErrNone)
   186 	if (r != KErrNone)
   186 		test.Printf(_L("Error %d remounting %S on %C\n"), r, &gOldFsName, (TUint)c);
   187 		test.Printf(_L("Error %d remounting %S on %C\n"), r, &gOldFsName, (TUint)c);
   187 	}
   188 	}
   188 
   189 
   193 /// @param aSync  Mount synchronous if true, asynchronous if not.
   194 /// @param aSync  Mount synchronous if true, asynchronous if not.
   194 	{
   195 	{
   195 	TChar c;
   196 	TChar c;
   196 	TInt r=TheFs.DriveToChar(aDrive,c);
   197 	TInt r=TheFs.DriveToChar(aDrive,c);
   197 	r=TheFs.FileSystemName(gFsName, aDrive);
   198 	r=TheFs.FileSystemName(gFsName, aDrive);
   198 	test(r==KErrNone || r==KErrNotFound);
   199 	test_Value(r, r == KErrNone || r==KErrNotFound);
   199 
   200 
   200 	if (gFsName.Length() > 0)
   201 	if (gFsName.Length() > 0)
   201 		{
   202 		{
   202 		r=TheFs.DismountFileSystem(gFsName, aDrive);
   203 		r=TheFs.DismountFileSystem(gFsName, aDrive);
   203 		if(r!=KErrNone)
   204 		test_KErrNone(r);
   204 			{
       
   205 			test.Printf(_L("Error = %d"),r);
       
   206 			test(EFalse);
       
   207 			}
       
   208 		}
   205 		}
   209 
   206 
   210 	TBufC<16> type = _L("asynchronous");
   207 	TBufC<16> type = _L("asynchronous");
   211 	if (aSync)
   208 	if (aSync)
   212 		type = _L("synchronous");
   209 		type = _L("synchronous");
   216 	r=TheFs.MountFileSystem(gFsName, aDrive, aSync);
   213 	r=TheFs.MountFileSystem(gFsName, aDrive, aSync);
   217 #else
   214 #else
   218 	r=TheFs.MountFileSystem(gFsName, aDrive);
   215 	r=TheFs.MountFileSystem(gFsName, aDrive);
   219 #endif
   216 #endif
   220 
   217 
   221 	test(r==KErrNone);
   218 	test_KErrNone(r);
   222 	}
   219 	}
   223 
   220 
   224 enum TOper
   221 enum TOper
   225 	{
   222 	{
   226 	ERead,
   223 	ERead,
   865 //
   862 //
   866 // Do all tests
   863 // Do all tests
   867 //
   864 //
   868 	{
   865 	{
   869 	TInt r = TTest::Init();
   866 	TInt r = TTest::Init();
   870 	test(r == KErrNone);
   867 	test_KErrNone(r);
   871 
   868 
   872 	TChar drvch0 = TTest::DefaultDriveChar();
   869 	TChar drvch0 = TTest::DefaultDriveChar();
   873 	TChar drvch1 = 0;
   870 	TChar drvch1 = 0;
   874 	TChar drvch2 = 0;
   871 	TChar drvch2 = 0;
   875 	TInt  drive0;
   872 	TInt  drive0;
   885 		drvch1 = User::UpperCase(argv[2][0]);
   882 		drvch1 = User::UpperCase(argv[2][0]);
   886 	if (argc > 3)
   883 	if (argc > 3)
   887 		drvch2 = User::UpperCase(argv[3][0]);
   884 		drvch2 = User::UpperCase(argv[3][0]);
   888 
   885 
   889 	r = TheFs.CharToDrive(drvch0, drive0);
   886 	r = TheFs.CharToDrive(drvch0, drive0);
   890 	test(r == KErrNone);
   887 	test_KErrNone(r);
   891 
   888 
   892 	if (TheFs.IsValidDrive(drive0))
   889 	if (TheFs.IsValidDrive(drive0))
   893 		MountTestFileSystem(drive0);
   890 		MountTestFileSystem(drive0);
   894 	else
   891 	else
   895 		test.Printf(_L("Unable to mount test file system\n"));
   892 		test.Printf(_L("Unable to mount test file system\n"));
   900 		UnmountFileSystem(drive0);
   897 		UnmountFileSystem(drive0);
   901 		User::Panic(_L("USER ABORT"), 0);
   898 		User::Panic(_L("USER ABORT"), 0);
   902 		}
   899 		}
   903 
   900 
   904 	r = TheFs.CharToDrive(drvch1, drive1);
   901 	r = TheFs.CharToDrive(drvch1, drive1);
   905 	test(r == KErrNone);
   902 	test_KErrNone(r);
   906 	r = TheFs.CharToDrive(drvch2, drive2);
   903 	r = TheFs.CharToDrive(drvch2, drive2);
   907 	test(r == KErrNone);
   904 	test_KErrNone(r);
   908 
   905 
   909 	r = TheFs.FileSystemName(gFsName1, drive1);
   906 	r = TheFs.FileSystemName(gFsName1, drive1);
   910 	test(r == KErrNone || r == KErrNotFound);
   907 	test_Value(r, r == KErrNone || r == KErrNotFound);
   911 	r = TheFs.FileSystemName(gFsName2, drive2);
   908 	r = TheFs.FileSystemName(gFsName2, drive2);
   912 	test(r == KErrNone || r == KErrNotFound);
   909 	test_Value(r, r == KErrNone || r == KErrNotFound);
   913 
   910 
   914 	gDataLock.CreateLocal();
   911 	gDataLock.CreateLocal();
   915 
   912 
   916 	if (drive1 == drive2)
   913 	if (drive1 == drive2)
   917 		{
   914 		{
  1037 		}
  1034 		}
  1038 
  1035 
  1039 	gDataLock.Close();
  1036 	gDataLock.Close();
  1040 
  1037 
  1041 	UnmountFileSystem(drive0);
  1038 	UnmountFileSystem(drive0);
  1042 	test(r == 0);
  1039 	test_Value(r, r == 0);
  1043 	}
  1040 	}
  1044 
  1041 
  1045 
  1042 
  1046 GLDEF_C TInt E32Main()
  1043 GLDEF_C TInt E32Main()
  1047 //
  1044 //
  1056 
  1053 
  1057     test.Title();
  1054     test.Title();
  1058     test.Start(_L("Starting tests..."));
  1055     test.Start(_L("Starting tests..."));
  1059 
  1056 
  1060     r=TheFs.Connect();
  1057     r=TheFs.Connect();
  1061     test(r==KErrNone);
  1058     test_KErrNone(r);
  1062 
  1059 
  1063     // TheFs.SetAllocFailure(gAllocFailOn);
  1060     // TheFs.SetAllocFailure(gAllocFailOn);
  1064     TTime timerC;
  1061     TTime timerC;
  1065     timerC.HomeTime();
  1062     timerC.HomeTime();
  1066 
  1063 
  1072 
  1069 
  1073     TTime endTimeC;
  1070     TTime endTimeC;
  1074     endTimeC.HomeTime();
  1071     endTimeC.HomeTime();
  1075     TTimeIntervalSeconds timeTakenC;
  1072     TTimeIntervalSeconds timeTakenC;
  1076     r=endTimeC.SecondsFrom(timerC,timeTakenC);
  1073     r=endTimeC.SecondsFrom(timerC,timeTakenC);
  1077     test(r==KErrNone);
  1074     test_KErrNone(r);
  1078     test.Printf(_L("Time taken for test = %d seconds\n"),timeTakenC.Int());
  1075     test.Printf(_L("Time taken for test = %d seconds\n"),timeTakenC.Int());
  1079     // TheFs.SetAllocFailure(gAllocFailOff);
  1076     // TheFs.SetAllocFailure(gAllocFailOff);
  1080     TheFs.Close();
  1077     TheFs.Close();
  1081     test.End();
  1078     test.End();
  1082     test.Close();
  1079     test.Close();