kerneltest/e32test/pccd/t_medch.cpp
branchRCL_3
changeset 257 3e88ff8f41d5
parent 256 c1f20ce4abcf
equal deleted inserted replaced
256:c1f20ce4abcf 257:3e88ff8f41d5
    48 
    48 
    49 #define MMC_PDD_NAME _L("MEDMMC")
    49 #define MMC_PDD_NAME _L("MEDMMC")
    50 
    50 
    51 const TInt KPowerUpTimeOut = 5000000; // Give the card 5 seconds to power up
    51 const TInt KPowerUpTimeOut = 5000000; // Give the card 5 seconds to power up
    52 
    52 
    53 const TUint KDriveAttMask = KDriveAttLocal | KDriveAttRom | KDriveAttRemote;
       
    54 const TUint KMediaAttMask = KMediaAttVariableSize | KMediaAttDualDensity | KMediaAttLockable | KMediaAttLocked | KMediaAttHasPassword  | KMediaAttReadWhileWrite;
       
    55 
       
    56 LOCAL_D	RTest test(_L("Media change test"));
    53 LOCAL_D	RTest test(_L("Media change test"));
    57 
    54 
    58 LOCAL_D	TBusLocalDrive TheDrive;
    55 LOCAL_D	TBusLocalDrive TheDrive;
    59 LOCAL_D	RMedCh TheMediaChange;
    56 LOCAL_D	RMedCh TheMediaChange;
    60 LOCAL_D TRequestStatus TheMediaStatus;
    57 LOCAL_D TRequestStatus TheMediaStatus;
    61 LOCAL_D TBool TheChangedFlag;
    58 LOCAL_D TBool TheChangedFlag;
    62 
       
    63 LOCAL_C TInt FindDataPagingDrive()
       
    64 /** 
       
    65 Find the drive containing the swap partition.
       
    66 
       
    67 @return		Local drive identifier or KErrNotFound if not found
       
    68 */
       
    69 	{
       
    70 	TInt drive = KErrNotFound;
       
    71 	
       
    72 	RLocalDrive	d;
       
    73 	TBool change = EFalse;
       
    74 	TLocalDriveCapsV5 driveCaps;
       
    75 	TPckg<TLocalDriveCapsV5> capsPack(driveCaps);
       
    76 	
       
    77 	for(TInt i = 0; i < KMaxLocalDrives && drive < 0; ++i)
       
    78 		{
       
    79 		if(d.Connect(i, change) == KErrNone)
       
    80 			{
       
    81 			if(d.Caps(capsPack) == KErrNone)
       
    82 				{
       
    83 				if ((driveCaps.iMediaAtt & KMediaAttPageable) &&
       
    84 					(driveCaps.iPartitionType == KPartitionTypePagedData))
       
    85 					{
       
    86 					drive = i;
       
    87 					}
       
    88 				}
       
    89 			d.Close();
       
    90 			}
       
    91 		}
       
    92 		
       
    93 	if(drive == KErrNotFound)
       
    94 		{
       
    95 		test.Printf(_L("No data paging drive found\n"));
       
    96 		}
       
    97 		
       
    98 	return drive;
       
    99 	}
       
   100 	
       
   101 LOCAL_C TInt DataPagingMediaCaps(TLocalDriveCapsV5 &aCaps)
       
   102 /** 
       
   103 Return the caps of the media containing a swap partition.
       
   104 
       
   105 @return		Error code, on success aCaps contains the capabilities of the paging drive
       
   106 */
       
   107 	{
       
   108 	TInt dataPagingDrive = FindDataPagingDrive();
       
   109 	
       
   110 	if (dataPagingDrive == KErrNotFound)
       
   111 		{
       
   112 		return KErrNotFound;
       
   113 		}
       
   114 
       
   115 	RLocalDrive	dpDrive;
       
   116 	TBool change = EFalse;
       
   117 
       
   118 	TInt r = dpDrive.Connect(dataPagingDrive, change);
       
   119 	test(r == KErrNone);
       
   120 	
       
   121 	TLocalDriveCapsV5 dpDriveCaps;
       
   122 	TPckg<TLocalDriveCapsV5> capsPack(dpDriveCaps);
       
   123 	r = dpDrive.Caps(capsPack);
       
   124 	test(r == KErrNone);
       
   125 	
       
   126 	if((dpDriveCaps.iDriveAtt & KDriveAttHidden) == 0)
       
   127 		{
       
   128 		test.Printf(_L("Paging partition is not hidden! Assuming it is correct anyway!\n"));
       
   129 		}
       
   130 	
       
   131 	aCaps = dpDriveCaps;
       
   132 	
       
   133 	return KErrNone;
       
   134 	}
       
   135 	
       
   136 LOCAL_C TBool IsDriveOnPagingMedia(TInt aDrive, TLocalDriveCapsV5 &aPagingMediaCaps)
       
   137 /** 
       
   138 Determines whether a drive is on the same media as the paging media by comparing 
       
   139 media characteristics
       
   140 
       
   141 @return		ETrue if (likely) to be on the same media, EFalse if not.
       
   142 */	{
       
   143 	RLocalDrive	drive;
       
   144 	TBool change = EFalse;
       
   145 
       
   146 	TInt r = drive.Connect(aDrive, change);
       
   147 	test(r == KErrNone);
       
   148 	
       
   149 	TLocalDriveCapsV5 driveCaps;
       
   150 	TPckg<TLocalDriveCapsV5> capsPack(driveCaps);
       
   151 	r = drive.Caps(capsPack);
       
   152 	test(r == KErrNone);
       
   153 	
       
   154 	// Check media serial number
       
   155 	if(aPagingMediaCaps.iSerialNumLength > 0)
       
   156 		{
       
   157 		if((driveCaps.iSerialNumLength > 0) && 
       
   158 		   ((memcompare(driveCaps.iSerialNum, driveCaps.iSerialNumLength, 
       
   159 			aPagingMediaCaps.iSerialNum, aPagingMediaCaps.iSerialNumLength)) == 0))
       
   160 			{
       
   161 			// serial numbers equal, so drive in question is on same media as paging drive
       
   162 			test.Printf(_L("Based on serial number match, drive %d shares the same media as paging drive\n"), aDrive);
       
   163 			return ETrue;
       
   164 			}
       
   165 		}
       
   166 	else
       
   167 		{
       
   168 		// Turn off bits which may be different
       
   169 		aPagingMediaCaps.iDriveAtt &= KDriveAttMask;
       
   170 		aPagingMediaCaps.iMediaAtt &= KMediaAttMask;
       
   171 		driveCaps.iDriveAtt &= KDriveAttMask;
       
   172 		driveCaps.iMediaAtt &= KMediaAttMask;
       
   173 
       
   174 		if ((driveCaps.iType == aPagingMediaCaps.iType) &&
       
   175 			(driveCaps.iDriveAtt == aPagingMediaCaps.iDriveAtt) && 
       
   176 			(driveCaps.iMediaAtt == aPagingMediaCaps.iMediaAtt))
       
   177 			{
       
   178 			test.Printf(_L("Based on media characteristics match, drive %d shares the same media as paging drive\n"), aDrive);
       
   179 			return ETrue;
       
   180 			}
       
   181 		}
       
   182 		
       
   183 	return EFalse;
       
   184 	}
       
   185 
    59 
   186 
    60 
   187 LOCAL_C TBool SetupDrivesForPlatform(TInt& aDrive, TInt& aSocket)
    61 LOCAL_C TBool SetupDrivesForPlatform(TInt& aDrive, TInt& aSocket)
   188 /**
    62 /**
   189  * Finds a suitable drive for the media change test
    63  * Finds a suitable drive for the media change test
   199 	TDriveInfoV1 &di=diBuf();
    73 	TDriveInfoV1 &di=diBuf();
   200 
    74 
   201 	aDrive  = -1;
    75 	aDrive  = -1;
   202 	aSocket = -1;
    76 	aSocket = -1;
   203 	
    77 	
   204 	TLocalDriveCapsV5 pagingMediaCaps;
       
   205 	TBool pagingMediaCheck = EFalse;
       
   206 	if(DataPagingMediaCaps(pagingMediaCaps) == KErrNone)
       
   207 		{
       
   208 		pagingMediaCheck = ETrue;
       
   209 		}
       
   210 	
       
   211 	for(aDrive=0; aDrive < di.iTotalSupportedDrives; aDrive++)
    78 	for(aDrive=0; aDrive < di.iTotalSupportedDrives; aDrive++)
   212 		{
    79 		{
   213 		test.Printf(_L(" Drive %d - %S\r\n"), aDrive, &di.iDriveName[aDrive]);
    80 		test.Printf(_L(" Drive %d - %S\r\n"), aDrive, &di.iDriveName[aDrive]);
   214 		if(di.iDriveName[aDrive].MatchF(_L("MultiMediaCard0")) == KErrNone)
    81 		if(di.iDriveName[aDrive].MatchF(_L("MultiMediaCard0")) == KErrNone)
   215 			{
    82 			break;
   216 			if(pagingMediaCheck)
       
   217 				{
       
   218 				if( ! IsDriveOnPagingMedia(aDrive, pagingMediaCaps))
       
   219 					{
       
   220 					break;
       
   221 					}
       
   222 				}
       
   223 			else
       
   224 				{
       
   225 				break;
       
   226 				}
       
   227 			}
       
   228 		}
    83 		}
   229 
    84 
   230 	if(aDrive == di.iTotalSupportedDrives)
    85 	if(aDrive == di.iTotalSupportedDrives)
   231 		{
    86 		{
   232 		test.Printf(_L(" MMC Drive Not Found\r\n"));
    87 		test.Printf(_L(" MMC Drive Not Found\r\n"));
   315  * @param aTitle  The text to be displayed
   170  * @param aTitle  The text to be displayed
   316  * @param aCycles The current iteration
   171  * @param aCycles The current iteration
   317  */
   172  */
   318 	{
   173 	{
   319 	test.Console()->SetPos(20, 25);
   174 	test.Console()->SetPos(20, 25);
   320 	test.Printf(_L("%S [%d cycles]\n"), &aTitle, aCycles);
   175 	test.Printf(_L("%S [%d cycles]"), &aTitle, aCycles);
   321 #ifdef __MANUAL_TEST__
   176 #ifdef __MANUAL_TEST__
   322 	test.Console()->SetPos(20, 27);
   177 	test.Console()->SetPos(20, 27);
   323 	test.Printf(_L("<press a key>\n"));
   178 	test.Printf(_L("<press a key>"));
   324 	test.Getch();
   179 	test.Getch();
   325 #endif
   180 #endif
   326 	}
   181 	}
   327 
   182 		
   328 GLDEF_C TInt E32Main()
   183 GLDEF_C TInt E32Main()
   329 /**
   184 /**
   330  * Test Entry Point for T_MEDCH.
   185  * Test Entry Point for T_MEDCH.
   331  * 
   186  * 
   332  * This test uses the associated driver (D_MEDCH) to simulate media removal and 
   187  * This test uses the associated driver (D_MEDCH) to simulate media removal and 
   356 	 * Connect to the required local drive.
   211 	 * Connect to the required local drive.
   357 	 * TheChangedFlag is used for detection of media removal.
   212 	 * TheChangedFlag is used for detection of media removal.
   358 	 */
   213 	 */
   359 	TInt drive;
   214 	TInt drive;
   360 	TInt socket;
   215 	TInt socket;
   361 
       
   362 	if(SetupDrivesForPlatform(drive, socket))
   216 	if(SetupDrivesForPlatform(drive, socket))
   363 		{
   217 		{
   364 		b.Format(_L("Connect to local drive %d"), drive);
   218 		b.Format(_L("Connect to local drive %d"), drive);
   365 		test.Next(b);
   219 		test.Next(b);
   366 		TheDrive.Connect(drive, TheChangedFlag);
   220 		TheDrive.Connect(drive, TheChangedFlag);