kerneltest/e32test/pccd/t_medch.cpp
branchRCL_3
changeset 256 c1f20ce4abcf
parent 0 a41df078684a
child 257 3e88ff8f41d5
equal deleted inserted replaced
249:a179b74831c9 256:c1f20ce4abcf
    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 
    53 LOCAL_D	RTest test(_L("Media change test"));
    56 LOCAL_D	RTest test(_L("Media change test"));
    54 
    57 
    55 LOCAL_D	TBusLocalDrive TheDrive;
    58 LOCAL_D	TBusLocalDrive TheDrive;
    56 LOCAL_D	RMedCh TheMediaChange;
    59 LOCAL_D	RMedCh TheMediaChange;
    57 LOCAL_D TRequestStatus TheMediaStatus;
    60 LOCAL_D TRequestStatus TheMediaStatus;
    58 LOCAL_D TBool TheChangedFlag;
    61 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 	}
    59 
   185 
    60 
   186 
    61 LOCAL_C TBool SetupDrivesForPlatform(TInt& aDrive, TInt& aSocket)
   187 LOCAL_C TBool SetupDrivesForPlatform(TInt& aDrive, TInt& aSocket)
    62 /**
   188 /**
    63  * Finds a suitable drive for the media change test
   189  * Finds a suitable drive for the media change test
    73 	TDriveInfoV1 &di=diBuf();
   199 	TDriveInfoV1 &di=diBuf();
    74 
   200 
    75 	aDrive  = -1;
   201 	aDrive  = -1;
    76 	aSocket = -1;
   202 	aSocket = -1;
    77 	
   203 	
       
   204 	TLocalDriveCapsV5 pagingMediaCaps;
       
   205 	TBool pagingMediaCheck = EFalse;
       
   206 	if(DataPagingMediaCaps(pagingMediaCaps) == KErrNone)
       
   207 		{
       
   208 		pagingMediaCheck = ETrue;
       
   209 		}
       
   210 	
    78 	for(aDrive=0; aDrive < di.iTotalSupportedDrives; aDrive++)
   211 	for(aDrive=0; aDrive < di.iTotalSupportedDrives; aDrive++)
    79 		{
   212 		{
    80 		test.Printf(_L(" Drive %d - %S\r\n"), aDrive, &di.iDriveName[aDrive]);
   213 		test.Printf(_L(" Drive %d - %S\r\n"), aDrive, &di.iDriveName[aDrive]);
    81 		if(di.iDriveName[aDrive].MatchF(_L("MultiMediaCard0")) == KErrNone)
   214 		if(di.iDriveName[aDrive].MatchF(_L("MultiMediaCard0")) == KErrNone)
    82 			break;
   215 			{
       
   216 			if(pagingMediaCheck)
       
   217 				{
       
   218 				if( ! IsDriveOnPagingMedia(aDrive, pagingMediaCaps))
       
   219 					{
       
   220 					break;
       
   221 					}
       
   222 				}
       
   223 			else
       
   224 				{
       
   225 				break;
       
   226 				}
       
   227 			}
    83 		}
   228 		}
    84 
   229 
    85 	if(aDrive == di.iTotalSupportedDrives)
   230 	if(aDrive == di.iTotalSupportedDrives)
    86 		{
   231 		{
    87 		test.Printf(_L(" MMC Drive Not Found\r\n"));
   232 		test.Printf(_L(" MMC Drive Not Found\r\n"));
   170  * @param aTitle  The text to be displayed
   315  * @param aTitle  The text to be displayed
   171  * @param aCycles The current iteration
   316  * @param aCycles The current iteration
   172  */
   317  */
   173 	{
   318 	{
   174 	test.Console()->SetPos(20, 25);
   319 	test.Console()->SetPos(20, 25);
   175 	test.Printf(_L("%S [%d cycles]"), &aTitle, aCycles);
   320 	test.Printf(_L("%S [%d cycles]\n"), &aTitle, aCycles);
   176 #ifdef __MANUAL_TEST__
   321 #ifdef __MANUAL_TEST__
   177 	test.Console()->SetPos(20, 27);
   322 	test.Console()->SetPos(20, 27);
   178 	test.Printf(_L("<press a key>"));
   323 	test.Printf(_L("<press a key>\n"));
   179 	test.Getch();
   324 	test.Getch();
   180 #endif
   325 #endif
   181 	}
   326 	}
   182 		
   327 
   183 GLDEF_C TInt E32Main()
   328 GLDEF_C TInt E32Main()
   184 /**
   329 /**
   185  * Test Entry Point for T_MEDCH.
   330  * Test Entry Point for T_MEDCH.
   186  * 
   331  * 
   187  * This test uses the associated driver (D_MEDCH) to simulate media removal and 
   332  * This test uses the associated driver (D_MEDCH) to simulate media removal and 
   211 	 * Connect to the required local drive.
   356 	 * Connect to the required local drive.
   212 	 * TheChangedFlag is used for detection of media removal.
   357 	 * TheChangedFlag is used for detection of media removal.
   213 	 */
   358 	 */
   214 	TInt drive;
   359 	TInt drive;
   215 	TInt socket;
   360 	TInt socket;
       
   361 
   216 	if(SetupDrivesForPlatform(drive, socket))
   362 	if(SetupDrivesForPlatform(drive, socket))
   217 		{
   363 		{
   218 		b.Format(_L("Connect to local drive %d"), drive);
   364 		b.Format(_L("Connect to local drive %d"), drive);
   219 		test.Next(b);
   365 		test.Next(b);
   220 		TheDrive.Connect(drive, TheChangedFlag);
   366 		TheDrive.Connect(drive, TheChangedFlag);