kerneltest/f32test/server/t_main.cpp
changeset 90 947f0dc9f7a8
parent 0 a41df078684a
child 109 b3a1d9898418
child 175 5af6c74cd793
--- a/kerneltest/f32test/server/t_main.cpp	Tue Feb 02 01:24:03 2010 +0200
+++ b/kerneltest/f32test/server/t_main.cpp	Fri Apr 16 16:24:37 2010 +0300
@@ -662,16 +662,26 @@
 	test.Printf(_L("DriveCacheFlags = %08X\n"), gDriveCacheFlags);
 
 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
+	test.Printf(_L("\n"));
+
+	TInt orgSessionCount;
+	r = controlIo(TheFs,theDrive, KControlIoSessionCount, orgSessionCount);
+	test(r==KErrNone);
+	test.Printf(_L("Session count start=%d\n"),orgSessionCount);
+
+	TInt orgObjectCount;
+	r = controlIo(TheFs,theDrive, KControlIoObjectCount, orgObjectCount);
+	test(r==KErrNone);
+	test.Printf(_L("Object count start=%d\n"),orgObjectCount);
+
+
 	TPckgBuf<TIOCacheValues> pkgOrgValues;
 	TIOCacheValues& orgValues=pkgOrgValues();
 	r = controlIo(TheFs,theDrive, KControlIoCacheCount, orgValues);
 	test_KErrNone(r);
 
-	test.Printf(_L("\n"));
-	test.Printf(_L("Requests on close queue at start=%d\n"),orgValues.iCloseCount);
-	test.Printf(_L("Requests on free queue at start=%d\n"),orgValues.iFreeCount);
-	test.Printf(_L("Requests dynamically allocated at start=%d\n"),orgValues.iAllocated);
-	test.Printf(_L("Requests in total at start=%d\n"),orgValues.iTotalCount);
+	test.Printf(_L("Requests at start: CloseQ %d FreeQ %d total %d peak %d\n"), 
+		orgValues.iCloseCount, orgValues.iFreeCount, orgValues.iTotalCount, orgValues.iRequestCountPeak);
 
 	// File cache
 
@@ -702,15 +712,89 @@
 	TheFs.SetAllocFailure(gAllocFailOff);
 	
 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
+	// Close and then re-open the main file server session to force the closure of
+	// any sub-sessions which may have been left open....
+	// NB: This won't help if the test has opened another session & left sub-sessions open.
+	TheFs.Close();
+	r=TheFs.Connect();
+	test(r==KErrNone);
+
+	// Display the file cache stats before closing the file queue
+	TFileCacheStats endFileCacheStats;
+	r = controlIo(TheFs,theDrive, KControlIoFileCacheStats, endFileCacheStats);
+	test_Value(r, r == KErrNone || r == KErrNotSupported);
+	test.Printf(_L("File cache: Cachelines (free %d, used %d), Segments(allocated %d locked %d). Closed files(%d)\n"),
+		endFileCacheStats.iFreeCount, 
+		endFileCacheStats.iUsedCount, 
+		endFileCacheStats.iAllocatedSegmentCount,
+		endFileCacheStats.iLockedSegmentCount,
+		endFileCacheStats.iFilesOnClosedQueue);
+
+
+	// Wait up to 3 seconds for all file server sessions & objects to close
+	// and then test session & object counts haven't changed
+	TInt endSessionCount = 0;
+	TInt endObjectCount = 0;
+	for (TInt n=0; n<3; n++)
+		{
+		// Flush the closed files queue as a file-cache object on the closed queue is counted as an open object
+		test.Printf(_L("Flushing close queue...\n"));
+		r = TheFs.ControlIo(theDrive, KControlIoFlushClosedFiles);
+		test_KErrNone(r);
+
+		r = controlIo(TheFs,theDrive, KControlIoSessionCount, endSessionCount);
+		test(r==KErrNone);
+		test.Printf(_L("Session count end=%d\n"),endSessionCount);
+
+		r = controlIo(TheFs,theDrive, KControlIoObjectCount, endObjectCount);
+		test(r==KErrNone);
+		test.Printf(_L("Object count end=%d\n"),endObjectCount);
+
+		if (endSessionCount == orgSessionCount && endObjectCount == orgObjectCount)
+			break;
+		
+		test.Printf(_L("Warning: Session/object count leak\n"));
+		User::After(1000000);
+		}
+
+	// some tests don't close their sessions, so this test won't work until 
+	// all the tests are fixed :
+//	test(endSessionCount == orgSessionCount);
+//	test(endObjectCount == orgObjectCount);
+
+
+	// Test that the File cache hasn't leaked ....
+	r = controlIo(TheFs,theDrive, KControlIoFileCacheStats, endFileCacheStats);
+	test_Value(r, r == KErrNone || r == KErrNotSupported);
+	test.Printf(_L("File cache: Cachelines (free %d, used %d), Segments(allocated %d locked %d). Closed files(%d)\n"),
+		endFileCacheStats.iFreeCount, 
+		endFileCacheStats.iUsedCount, 
+		endFileCacheStats.iAllocatedSegmentCount,
+		endFileCacheStats.iLockedSegmentCount,
+		endFileCacheStats.iFilesOnClosedQueue);
+	if (r == KErrNone)
+		{
+		test(startFileCacheStats.iFreeCount == endFileCacheStats.iFreeCount);
+		test(startFileCacheStats.iUsedCount == endFileCacheStats.iUsedCount);
+		test(startFileCacheStats.iAllocatedSegmentCount == endFileCacheStats.iAllocatedSegmentCount);
+		test(startFileCacheStats.iLockedSegmentCount == endFileCacheStats.iLockedSegmentCount);
+		test(startFileCacheStats.iFileCount == endFileCacheStats.iFileCount);
+		}
+#endif
+
+
+	
+#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
+	// Test that the request allocator hasn't leaked...
 	TPckgBuf<TIOCacheValues> pkgValues;
 	TIOCacheValues& values=pkgValues();
 	r = controlIo(TheFs,theDrive, KControlIoCacheCount, values);
 	test_KErrNone(r);
 	
-	test.Printf(_L("Requests on close queue at end=%d\n"),values.iCloseCount);
-	test.Printf(_L("Requests on free queue at end=%d\n"),values.iFreeCount);
-	test.Printf(_L("Requests dynamically allocated at end=%d\n"),values.iAllocated);
-	test.Printf(_L("Requests in total at end=%d\n"),values.iTotalCount);
+	test.Printf(_L("Requests at end: CloseQ %d FreeQ %d total %d peak %d\n"), 
+		values.iCloseCount, values.iFreeCount, values.iTotalCount, values.iRequestCountPeak);
+	test.Printf(_L("Operations at end: FreeQ %d total %d peak=%d\n"),
+		values.iOpFreeCount, values.iOpRequestCount, values.iOpRequestCountPeak);
 	
 	test(orgValues.iCloseCount==values.iCloseCount);
 	test(orgValues.iAllocated == values.iAllocated);
@@ -723,42 +807,6 @@
 	// + 1 (because we used one request to issue KControlIoCacheCount)
 	// If this doesn't equate then this implies a request leak
 	test(values.iTotalCount == values.iCloseCount + values.iFreeCount + 1);
-
-	// File cache
-	TFileCacheStats endFileCacheStats;
-	r = controlIo(TheFs,theDrive, KControlIoFileCacheStats, endFileCacheStats);
-	test_Value(r, r == KErrNone || r == KErrNotSupported);
-
-	test.Printf(_L("File cache: Cachelines (free %d, used %d), Segments(allocated %d locked %d). Closed files(%d)\n"),
-		endFileCacheStats.iFreeCount, 
-		endFileCacheStats.iUsedCount, 
-		endFileCacheStats.iAllocatedSegmentCount,
-		endFileCacheStats.iLockedSegmentCount,
-		endFileCacheStats.iFilesOnClosedQueue);
-
-	// flush closed files queue
-	test.Printf(_L("Flushing close queue..."));
-	r = TheFs.ControlIo(theDrive, KControlIoFlushClosedFiles);
-	test_KErrNone(r);
-
-	r = controlIo(TheFs,theDrive, KControlIoFileCacheStats, endFileCacheStats);
-	test_Value(r, r == KErrNone || r == KErrNotSupported);
-	test.Printf(_L("File cache: Cachelines (free %d, used %d), Segments(allocated %d locked %d). Closed files(%d)\n"),
-		endFileCacheStats.iFreeCount, 
-		endFileCacheStats.iUsedCount, 
-		endFileCacheStats.iAllocatedSegmentCount,
-		endFileCacheStats.iLockedSegmentCount,
-		endFileCacheStats.iFilesOnClosedQueue);
-
-
-	if (r == KErrNone)
-		{
-		test(startFileCacheStats.iFreeCount == endFileCacheStats.iFreeCount);
-		test(startFileCacheStats.iUsedCount == endFileCacheStats.iUsedCount);
-		test(startFileCacheStats.iAllocatedSegmentCount == endFileCacheStats.iAllocatedSegmentCount);
-		test(startFileCacheStats.iLockedSegmentCount == endFileCacheStats.iLockedSegmentCount);
-		test(startFileCacheStats.iFileCount == endFileCacheStats.iFileCount);
-		}
 #endif
 
 	TheFs.Close();