kerneltest/e32test/pccd/t_mmcdrv.cpp
changeset 287 ddfd5aa0d58f
parent 33 0173bcd7697c
equal deleted inserted replaced
286:48e57fb1237e 287:ddfd5aa0d58f
     1 // Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 1996-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     4 // under the terms of the License "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    11 // Contributors:
    11 // Contributors:
    12 //
    12 //
    13 // Description:
    13 // Description:
    14 // e32test\pccd\t_mmcdrv.cpp
    14 // e32test\pccd\t_mmcdrv.cpp
    15 // Test the MultiMediaCard (MMC) media driver
    15 // Test the MultiMediaCard (MMC) media driver
    16 // Spare Test case Numbers 0513-0519
    16 // Spare Test case Numbers 0515-0519
    17 // 
    17 // 
    18 //
    18 //
       
    19 
       
    20 #define __E32TEST_EXTENSION__
    19 
    21 
    20 #include "../mmu/d_sharedchunk.h"
    22 #include "../mmu/d_sharedchunk.h"
    21 #include <e32test.h>
    23 #include <e32test.h>
    22 #include <e32svr.h>
    24 #include <e32svr.h>
    23 #include <e32hal.h>
    25 #include <e32hal.h>
  1858 //	UserSvr::ForceRemountMedia(ERemovableMedia0); // Generate media change	
  1860 //	UserSvr::ForceRemountMedia(ERemovableMedia0); // Generate media change	
  1859 	test(ChangeFlag!=EFalse);
  1861 	test(ChangeFlag!=EFalse);
  1860 	test(SecThreadChangeFlag==EFalse); // Closed 2nd thread so shouldn't have been updated
  1862 	test(SecThreadChangeFlag==EFalse); // Closed 2nd thread so shouldn't have been updated
  1861 	}
  1863 	}
  1862 	
  1864 	
       
  1865 // Helper function for eMMC partition switching test - writes test data
       
  1866 TInt EMmcPartitionWriteTestData(const TInt aDriveNumber, const TChar aDataPattern)
       
  1867 	{
       
  1868 	TBusLocalDrive drv;
       
  1869 	TBool chg(EFalse);
       
  1870 
       
  1871 	TInt r = drv.Connect(aDriveNumber, chg);
       
  1872 	test(r == KErrNone);
       
  1873 
       
  1874 	TBuf8<KDiskSectorSize> buffer;
       
  1875 
       
  1876 	// write pattern to sector 0
       
  1877 	buffer.Fill(aDataPattern, KDiskSectorSize);
       
  1878 	r = drv.Write((TInt64) 0, buffer);
       
  1879 	
       
  1880 	return r;
       
  1881 	}
       
  1882 	
       
  1883 // Helper function for eMMC partition switching test - reads test data
       
  1884 TInt EMmcPartitionReadTestData(const TInt aDriveNumber, TDes8& aData)
       
  1885 	{
       
  1886 	// read pattern from sector 0
       
  1887 	TBusLocalDrive drv;
       
  1888 	TBool chg(EFalse);
       
  1889 	
       
  1890 	TInt r = drv.Connect(aDriveNumber, chg);	
       
  1891 	test(r == KErrNone);
       
  1892 	
       
  1893 	aData.Fill(0x00, aData.MaxSize());
       
  1894 	r = drv.Read((TInt64) 0, aData.MaxSize(), aData);
       
  1895 
       
  1896     drv.Disconnect();
       
  1897     return r;
       
  1898 	}
       
  1899 	
       
  1900 // Helper function for eMMC partition switching test - compares data to expected pattern
       
  1901 TInt EMmcPartitionReadAndCompareTestData(const TInt aDriveNumber, const TChar aExpectedPattern)
       
  1902 	{	
       
  1903 	TBuf8<KDiskSectorSize> actual;
       
  1904 	TBuf8<KDiskSectorSize> expected;
       
  1905 	TInt r = EMmcPartitionReadTestData(aDriveNumber, actual);
       
  1906 	test(r == KErrNone);
       
  1907 	
       
  1908 	expected.Fill(aExpectedPattern, KDiskSectorSize);
       
  1909 	
       
  1910 	if(expected.Compare(actual) != 0)
       
  1911 		{
       
  1912 		test.Printf(_L("ERROR: Comparison failed. Expected:\n"));
       
  1913 		DumpBuffer(expected);			
       
  1914 		test.Printf(_L("\nActual:\n"));
       
  1915 		DumpBuffer(actual);
       
  1916 		r = KErrGeneral;
       
  1917 		}
       
  1918 		
       
  1919 	return r;
       
  1920 	}
       
  1921 	
       
  1922 
       
  1923 		
       
  1924 /**
       
  1925 @SYMTestCaseID 0514 (taken from spare test case IDs)
       
  1926 @SYMTestCaseDesc Test low-level partition switching capability
       
  1927 @SYMTestPriority normal
       
  1928 
       
  1929 @SYMTestActions
       
  1930 	a) Precondition: Valid partitions have been flashed to BOOT 1 and BOOT 2, 
       
  1931 	   these have to be mapped correctly in variantmediadef.h
       
  1932 	b) Write Data Pattern 1 to BOOT 1
       
  1933 	c) Write Data Pattern 2 to BOOT 2
       
  1934 	d) Read data from BOOT 1 and compare to DP1 - test passes if data matches
       
  1935 	e) Write Data Pattern 3 to BOOT 1, at the same offset as in b)
       
  1936 	f) Read data from BOOT 2 and compare to DP2 - test passes if data matches
       
  1937 
       
  1938 @SYMTestExpectedResults All tests must pass	
       
  1939 */
       
  1940 void TestPartitionSwitching()
       
  1941 	{
       
  1942 	const TInt  KDriveBoot1      = 4; // see variantmediadef.h
       
  1943 	const TInt  KDriveBoot2      = 5;
       
  1944 	const TChar KDataPattern1    = 0xD1;
       
  1945 	const TChar KDataPattern2    = 0xD2;
       
  1946 	const TChar KDataPattern3    = 0xD3;
       
  1947 	
       
  1948 	test.Start(_L("eMMC partition switching"));
       
  1949 
       
  1950 	// Write data data pattern 1 to boot1
       
  1951 	test.Printf(_L("Writing Data Pattern 1 to BOOT 1\n"));
       
  1952 	TInt r = EMmcPartitionWriteTestData(KDriveBoot1, KDataPattern1);
       
  1953 	test(r == KErrNone);
       
  1954 
       
  1955 	// Write data data pattern 2 to boot2
       
  1956 	test.Printf(_L("Writing Data Pattern 2 to BOOT 2\n"));
       
  1957 	r = EMmcPartitionWriteTestData(KDriveBoot2, KDataPattern2);
       
  1958 	test(r == KErrNone);
       
  1959 
       
  1960 	// Read back data from boot 1 and compare it to previously written pattern
       
  1961 	test.Printf(_L("Reading from BOOT 1\n"));
       
  1962 	r = EMmcPartitionReadAndCompareTestData(KDriveBoot1, KDataPattern1);
       
  1963 	test(r == KErrNone);
       
  1964 
       
  1965 	// Write data data pattern 3 to boot1
       
  1966 	test.Printf(_L("Writing Data Pattern 3 to BOOT 1\n"));
       
  1967 	r = EMmcPartitionWriteTestData(KDriveBoot1, KDataPattern3);
       
  1968 	test(r == KErrNone);
       
  1969 	
       
  1970 	// Read back data from boot 2 and compare it to previously written pattern
       
  1971 	test.Printf(_L("Reading from BOOT 2\n"));
       
  1972 	r = EMmcPartitionReadAndCompareTestData(KDriveBoot2, KDataPattern2);
       
  1973 	test(r == KErrNone);
       
  1974 	
       
  1975 	test.End();
       
  1976 	}
  1863 
  1977 
  1864 //// End of Test 
  1978 //// End of Test 
       
  1979 
       
  1980 
  1865 void Format()
  1981 void Format()
  1866 //
  1982 //
  1867 // Format current drive
  1983 // Format current drive
  1868 //
  1984 //
  1869 	{
  1985 	{
  2201 
  2317 
  2202 #if TEST_DOOR_CLOSE
  2318 #if TEST_DOOR_CLOSE
  2203 	goto doorTest;
  2319 	goto doorTest;
  2204 #endif
  2320 #endif
  2205 	
  2321 	
       
  2322 	if(ManualMode)
       
  2323 		{
       
  2324 		// Only test in manual mode, as the rom needs special prep anyway (drive registration 
       
  2325 		// in variantmediadef.h and flashing of BB5 partition info structures using mmcloader)
       
  2326 		// It is possible that as a result of the changes to variantmediadef.h the 
       
  2327 		// drive-number-to-letter mapping in the appropriate estart.txt may have to be adjusted 
       
  2328 		// as well
       
  2329 		TestPartitionSwitching();
       
  2330 		}
       
  2331 	
  2206 	for(TInt pass = 0; pass < TMMCDrive::EMaxTestModes; pass++) 
  2332 	for(TInt pass = 0; pass < TMMCDrive::EMaxTestModes; pass++) 
  2207 		{
  2333 		{
  2208 		TInt r = KErrNone;
  2334 		TInt r = KErrNone;
       
  2335 		
  2209 		switch (pass)
  2336 		switch (pass)
  2210 			{			
  2337 			{			
  2211 			case 0 : r = TheMmcDrive.SetTestMode(TMMCDrive::ETestPartition); break;
  2338 			case TMMCDrive::ETestPartition : 
  2212 			case 1 : 
  2339 				r = TheMmcDrive.SetTestMode(TMMCDrive::ETestPartition); 
       
  2340 				break;
       
  2341 				
       
  2342 			case TMMCDrive::ETestWholeMedia : 
  2213 				// don't trash partition table in automated mode because...
  2343 				// don't trash partition table in automated mode because...
  2214 				// cards in test rigs have often got deliberately small partition sizes to testing (!)
  2344 				// cards in test rigs have often got deliberately small partition sizes to testing (!)
  2215 				if (!ManualMode)
  2345 				if (!ManualMode)
  2216 					continue;
  2346 					continue;
  2217 				r = TheMmcDrive.SetTestMode(TMMCDrive::ETestWholeMedia); 
  2347 				r = TheMmcDrive.SetTestMode(TMMCDrive::ETestWholeMedia); 
  2218 				break; 
  2348 				break; 
  2219 			case 2 : {
  2349 				
  2220 						r = TheMmcDrive.SetTestMode(TMMCDrive::ETestSharedMemory);
  2350 			case TMMCDrive::ETestSharedMemory :
  2221 						AllocateSharedBuffers(EFalse,EFalse);
  2351 				r = TheMmcDrive.SetTestMode(TMMCDrive::ETestSharedMemory);
  2222 						break;
  2352 				AllocateSharedBuffers(EFalse,EFalse);
  2223 					 }
  2353 				break;
  2224 			case 3 : {
  2354 				
  2225 						r = TheMmcDrive.SetTestMode(TMMCDrive::ETestSharedMemoryCache); 
  2355 			case TMMCDrive::ETestSharedMemoryCache :
  2226 						AllocateSharedBuffers(EFalse, ETrue);
  2356 				r = TheMmcDrive.SetTestMode(TMMCDrive::ETestSharedMemoryCache); 
  2227 						break;
  2357 				AllocateSharedBuffers(EFalse, ETrue);
  2228 					 }
  2358 				break;
  2229 			case 4 : {
  2359 				
  2230 						r = TheMmcDrive.SetTestMode(TMMCDrive::ETestSharedMemoryFrag);
  2360 			case TMMCDrive::ETestSharedMemoryFrag :
  2231 						AllocateSharedBuffers(ETrue, EFalse);
  2361 				r = TheMmcDrive.SetTestMode(TMMCDrive::ETestSharedMemoryFrag);
  2232 						break;
  2362 				AllocateSharedBuffers(ETrue, EFalse);
  2233 			         }
  2363 				break;
  2234 			default: {
  2364 				
  2235 						r = TheMmcDrive.SetTestMode(TMMCDrive::ETestSharedMemoryFragCache);
  2365 			default:
  2236 						AllocateSharedBuffers(ETrue, ETrue);
  2366 				r = TheMmcDrive.SetTestMode(TMMCDrive::ETestSharedMemoryFragCache);
  2237 						break;
  2367 				AllocateSharedBuffers(ETrue, ETrue);
  2238 			         }
  2368 				break;
  2239 			}
  2369 			}
  2240 
  2370 
  2241 
  2371 
  2242 		if(r == KErrNone)
  2372 		if(r == KErrNone)
  2243 			{
  2373 			{