kerneltest/f32test/server/t_wcache.cpp
changeset 247 d8d70de2bd36
parent 109 b3a1d9898418
child 245 647ab20fee2e
--- a/kerneltest/f32test/server/t_wcache.cpp	Tue Jul 06 15:50:07 2010 +0300
+++ b/kerneltest/f32test/server/t_wcache.cpp	Wed Aug 18 11:08:29 2010 +0300
@@ -28,6 +28,8 @@
 #include <f32dbg.h>
 #include "t_server.h"
 #include <e32twin.h>
+#include <hal.h>
+#include "tf32testtimer.h"
 
 const TInt KTotalCacheSize = 32 * 1024 * 1024;
 const TInt KDefaultCacheSize = (128 + 12) * 1024; 	// This size is the default configuration size
@@ -89,7 +91,6 @@
 const TInt KOneMeg = KOneK * 1024;
 const TInt KBlockSize = KOneK;
 const TInt KWaitRequestsTableSize = 256;
-const TInt KMs = 1000; 
 
 TInt gSecondFileSize = 0; 
 TInt gFirstFileSize = 0;
@@ -102,9 +103,6 @@
 TBuf16<25> gCurrentFile;
 
 TInt gNextFile = 0;
-TTime gTime1;
-TTime gTime2;
-
 
 // Concurrent Threads
 RThread gThread1;
@@ -513,25 +511,22 @@
 	
 	@return time taken to perform the operation in uS
 */
-TInt WriteTestFile(RFile& aFile, TDes16& aFileName, TInt aSize, TInt aBlockSize, TInt aMode) 
+TTimeIntervalMicroSeconds WriteTestFile(RFile& aFile, TDes16& aFileName, TInt aSize, TInt aBlockSize, TInt aMode) 
 	{
 	RTest test(_L("T_WCACHE"));
 
-	TTime startTime;
-	TTime endTime;
 	TInt r = 0;
-	
-	startTime.HomeTime();
+
+    TF32TestTimer timer;
+	timer.Start();
 	
 	r = WriteFile(gTheFs,aFile, aFileName , aSize * KOneK, aBlockSize, gBufWritePtr, aMode);
 	test_KErrNone(r);
-	
-	endTime.HomeTime();
-	
-	gTimeTakenBigFile = I64LOW(endTime.MicroSecondsFrom(startTime).Int64());
-	
+
+	timer.Stop();	
+	gTimeTakenBigFile = timer.Time();
 	test.Close();
-	return I64LOW(gTimeTakenBigFile.Int64());
+	return timer.Time();        
 	}
 
 /** Measure the time taken for this file to be read synchronously
@@ -545,18 +540,16 @@
 	@return time taken to perform the operation in uS
 
 */
-TInt ReadTestFile(RFile& aFile, TDes16& aFileName, TInt aSize, TInt aBlockSize, TInt aMode) 
+TTimeIntervalMicroSeconds ReadTestFile(RFile& aFile, TDes16& aFileName, TInt aSize, TInt aBlockSize, TInt aMode) 
 	{
-	TTime startTime;
-	TTime endTime;
+    TF32TestTimer timer;
+	timer.Start();
+	ReadFile(gTheFs,aFile, aFileName, aSize * KOneK, aBlockSize, aMode);
+	timer.Stop();
 	
-	startTime.HomeTime();
-	ReadFile(gTheFs,aFile, aFileName, aSize * KOneK, aBlockSize, aMode);
-	endTime.HomeTime();
-	
-	gTimeTakenBigFile = I64LOW(endTime.MicroSecondsFrom(startTime).Int64());
-	
-	return I64LOW(gTimeTakenBigFile.Int64()) ;
+	gTimeTakenBigFile = timer.Time();
+        	
+	return timer.Time();
 	}
 
 /** Read asynchronously the test file from the disc
@@ -569,22 +562,19 @@
 
 	@return time taken to perform the operation in uS
 */
-TInt ReadAsyncTestFile(RFile& file, TDes16& aFile, TInt aSize, TInt aBlockSize, TInt aMode) 
+TTimeIntervalMicroSeconds ReadAsyncTestFile(RFile& file, TDes16& aFile, TInt aSize, TInt aBlockSize, TInt aMode) 
 	{
-	TTime startTime;
-	TTime endTime;
 	TRequestStatus status[KWaitRequestsTableSize];
-	
-	startTime.HomeTime();
+    TF32TestTimer timer;
+	timer.Start();
 	
 	ReadFileAsync(gTheFs, file, aFile, aSize * KOneK, aBlockSize, status, aMode);
 	WaitForAll(status,  (aSize * KOneK)/KBlockSize);
-	
-	endTime.HomeTime();
+	timer.Stop();	
+		
+	gTimeTakenBigFile = timer.Time();
 	
-	gTimeTakenBigFile = I64LOW(endTime.MicroSecondsFrom(startTime).Int64());
-	
-	return I64LOW(gTimeTakenBigFile.Int64());
+	return timer.Time();
 	}
 
 /** Read asynchronously the test file from the disc
@@ -596,22 +586,19 @@
 
 	@return time taken to perform the operation in uS
 */
-TInt WriteAsyncTestFile(RFile& aFile, TDes16& aFileName, TInt aSize, TInt aMode) 
+TTimeIntervalMicroSeconds WriteAsyncTestFile(RFile& aFile, TDes16& aFileName, TInt aSize, TInt aMode) 
 	{
-	TTime startTime;
-	TTime endTime;
 	TRequestStatus status[KWaitRequestsTableSize];
-	
-	startTime.HomeTime();
+    TF32TestTimer timer;
+    timer.Start();
 	
 	WriteFileAsync(gTheFs, aFile, aFileName, aSize * KOneK, aMode, status );
 	WaitForAll(status, (aSize * KOneK)/KBlockSize);
-	
-	endTime.HomeTime();
+	timer.Stop();	
 	
-	gTimeTakenBigFile = I64LOW(endTime.MicroSecondsFrom(startTime).Int64());
+	gTimeTakenBigFile = timer.Time();
 	
-	return I64LOW(gTimeTakenBigFile.Int64());
+	return timer.Time();
 	}
 
 /**  Test Boundaries
@@ -621,9 +608,9 @@
 void TestBoundaries()
 	{
 	TInt r = 0;
-	TInt time = 0;
-	TInt rtime = 0;
-	TInt tcreate = 0;
+	TTimeIntervalMicroSeconds time = 0;
+	TTimeIntervalMicroSeconds rtime = 0;
+	TTimeIntervalMicroSeconds tcreate = 0;
 	RFile fileWriter;
 	RFile fileWriter2;
 	RFile fileReader;
@@ -641,21 +628,22 @@
 		test.Printf(_L("\nSync: Write from 1 K to %d K \n"), i); 
 
 		tcreate = WriteTestFile(fileWriter, gSecondFile, i, KBlockSize, EFileShareAny|EFileWrite|EFileWriteDirectIO);
-		test.Printf(_L("Time to write %d K without caching: %d mS\n"), i, tcreate/KMs);	
+		test.Printf(_L("Time to write %d K without caching: %d mS\n"), i, TF32TestTimer::TimeInMilliSeconds(tcreate));	
 		fileWriter.Close();
 
 		time =  WriteTestFile(fileWriter2, gFirstFile, i, KBlockSize, EFileShareAny|EFileWrite|EFileWriteBuffered);
-		test.Printf(_L("Time to write %d K WITH caching: %d mS\n"), i, time/KMs);
+		test.Printf(_L("Time to write %d K WITH caching: %d mS\n"), i, TF32TestTimer::TimeInMilliSeconds(time));
 
 		rtime = ReadTestFile(fileReader, gFirstFile, i, KBlockSize, EFileShareAny|EFileRead|EFileReadBuffered);
-		test.Printf(_L("Time to read %d K from the cache: %d mS\n"), i, rtime/KMs);
-
+		test.Printf(_L("Time to read %d K from the cache: %d mS\n"), i, TF32TestTimer::TimeInMilliSeconds(rtime));
 
 		fileReader.Close();	
 		fileWriter2.Close();
 		
 		#if !defined(__WINS__)
-			test((tcreate > time) || (tcreate > rtime)); 
+            test(tcreate > TTimeIntervalMicroSeconds(0));  // test measured time is correct
+			test(tcreate > time);
+            test(tcreate > rtime); 
 		#endif
 
 		r = gTheFs.Delete(gFirstFile);
@@ -676,21 +664,23 @@
 		test.Printf(_L("\nAsync: Write from 1 K to %d K \n"), i); 
 
 		tcreate = WriteAsyncTestFile(fileWriter, gSecondFile, i, EFileShareAny|EFileWrite|EFileWriteDirectIO);
-		test.Printf(_L("Time to write %d K without caching: %d mS\n"), i, tcreate/KMs);	
+		test.Printf(_L("Time to write %d K without caching: %d mS\n"), i, TF32TestTimer::TimeInMilliSeconds(tcreate));
 		fileWriter.Close();
 
 		time =  WriteAsyncTestFile(fileWriter2, gFirstFile, i,EFileShareAny|EFileWrite|EFileWriteBuffered);
-		test.Printf(_L("Time to write %d K WITH caching: %d mS\n"), i, time/KMs);
+		test.Printf(_L("Time to write %d K WITH caching: %d mS\n"), i, TF32TestTimer::TimeInMilliSeconds(time));
 
 
 		rtime = ReadAsyncTestFile(fileReader, gFirstFile, i, KBlockSize, EFileShareAny|EFileRead|EFileReadBuffered);
-		test.Printf(_L("Time to read %d K from the cache: %d mS\n"), i, rtime/KMs);
+		test.Printf(_L("Time to read %d K from the cache: %d mS\n"), i, TF32TestTimer::TimeInMilliSeconds(rtime));
 
 		fileReader.Close();	
 		fileWriter2.Close();
 		
 		#if !defined(__WINS__)
-			test((tcreate > time) || (tcreate > rtime));  
+            test(tcreate > TTimeIntervalMicroSeconds(0));  // test measured time is correct
+			test(tcreate > time);
+            test(tcreate > rtime);
 		#endif
 
 		r = gTheFs.Delete(gFirstFile);
@@ -749,17 +739,16 @@
 	
 	@return returns the time that took to do the verification in mS, fails if the file is not corrupted/modified
 */
-TInt ReadTestFileVerif(TDes16& aFile)
+TTimeIntervalMicroSeconds ReadTestFileVerif(TDes16& aFile)
 	{
-	TTime startTime;
-	TTime endTime;
 	TInt r = 0;
 	TInt size = 0;
 	RFile fileRead;
 	TInt corrupt = 0;
 	TBool isFat=IsFSFAT(gTheFs,gDrive);
-	
-	startTime.HomeTime();
+
+    TF32TestTimer timer;
+	timer.Start();
 	
 	r = fileRead.Open(gTheFs,aFile,EFileShareAny|EFileRead|EFileReadBuffered|EFileReadAheadOff);
 	test_KErrNone(r);
@@ -791,12 +780,11 @@
 	fileRead.Close();
 	
 	test(corrupt>0); // Ensure the cache returns the changed content 
-	
-	endTime.HomeTime();
+	timer.Stop();	
 	
-	gTimeTakenBigFile = I64LOW(endTime.MicroSecondsFrom(startTime).Int64());
+	gTimeTakenBigFile = timer.Time();
 	
-	return I64LOW(gTimeTakenBigFile.Int64()) / KMs;
+	return timer.Time();
 	}
 
 /**  Modifies the second file
@@ -840,8 +828,8 @@
 LOCAL_C void TestIntegrity()
 	{
 	TInt r = 0;
-	TInt time;
-	TInt tcreate = 0;
+	TTimeIntervalMicroSeconds time;
+	TTimeIntervalMicroSeconds tcreate = 0;
 	RFile file;
 	
 	// Modify file in some position 
@@ -850,14 +838,14 @@
 	test.Printf(_L("\nSync: Write from 1 K to %d K \n"), 255); 
 
 	tcreate = WriteTestFile(file, gSecondFile, 255, KBlockSize, EFileShareAny|EFileWrite|EFileWriteBuffered);
-	test.Printf(_L("Time to write %d K with caching: %d mS\n"), 255, tcreate/KMs);	
+	test.Printf(_L("Time to write %d K with caching: %d mS\n"), 255, TF32TestTimer::TimeInMilliSeconds(tcreate));	
 	file.Close();
 
 	test.Printf(_L("Mess the content that is still in the cache\n"));
 	CorruptSecondFile(); 
 	
 	time = ReadTestFileVerif(gSecondFile);	
-	test.Printf(_L("Time taken to verify: %d\n"),time);
+	test.Printf(_L("Time taken to verify: %ld\n"),time.Int64());
 	
 	test.Printf(_L("Integrity verified\n"));
 
@@ -1178,7 +1166,7 @@
 */
 void TestRemoval()
 	{	
-	TInt time = 0, rtime = 0;
+	TTimeIntervalMicroSeconds time = 0, rtime = 0;
 	RFile file1, file2;
 	
 		 	
@@ -1227,7 +1215,7 @@
 	test.Printf(_L("\nSync: Write from 1 K to 254 K \n")); 
 
 	time =  WriteTestFile(file1, gSecondFile, KMinSize, KBlockSize, EFileShareAny|EFileWrite|EFileWriteBuffered);
-	test.Printf(_L("Time to write %d K WITH caching: %d mS\n"), KMinSize, time/KMs);
+	test.Printf(_L("Time to write %d K WITH caching: %d mS\n"), KMinSize, TF32TestTimer::TimeInMilliSeconds(time));
 	test.Printf(_L("Remove MMC card,! and then press a key\n"));
 	test.Getch();
 
@@ -1235,7 +1223,7 @@
 	test.Getch();
 
 	rtime = ReadTestFile(file2, gSecondFile, KMinSize, KBlockSize, EFileShareAny|EFileRead|EFileReadBuffered);
-	test.Printf(_L("Time to read %d K from the cache: %d mS\n"), KMinSize, rtime/KMs);
+	test.Printf(_L("Time to read %d K from the cache: %d mS\n"), KMinSize, TF32TestTimer::TimeInMilliSeconds(rtime));
 
 	test.Printf(_L("Remove MMC card! and then press a key\n"));
 	test.Getch();
@@ -1247,7 +1235,7 @@
 	test.Printf(_L("\nSync: Write from 1 K to 255 K \n")); 
 
 	time =  WriteTestFile(file1, gFirstFile, KMinSize + 1 , KBlockSize, EFileShareAny|EFileWrite|EFileWriteBuffered);
-	test.Printf(_L("Time to write %d K WITH caching: %d mS\n"), KMinSize + 1, time/KMs);
+	test.Printf(_L("Time to write %d K WITH caching: %d mS\n"), KMinSize + 1, TF32TestTimer::TimeInMilliSeconds(time));
 	test.Printf(_L("Remove MMC card and delete the file //F32-TST//FFFFFFF0.TXT and then press a key\n"));
 	test.Getch();
 
@@ -1255,7 +1243,7 @@
 	test.Getch();
 
 	rtime = ReadTestFile(file2, gFirstFile, KMinSize + 1, KBlockSize, EFileShareAny|EFileRead|EFileReadBuffered);
-	test.Printf(_L("Time to read %d K from the cache: %d mS\n"), KMinSize + 1, rtime/KMs);
+	test.Printf(_L("Time to read %d K from the cache: %d mS\n"), KMinSize + 1, TF32TestTimer::TimeInMilliSeconds(rtime));
 
 	test.Printf(_L("Remove MMC card! and then press a key\n"));
 	test.Getch();