baseintegtests/baseintegrationtest/testsuites/fat32/src/basetestfat32readraw.cpp
branchanywhere
changeset 20 d63d727ee0a6
parent 19 f6d3d9676ee4
parent 16 6d8ad5bee44b
child 21 af091391d962
equal deleted inserted replaced
19:f6d3d9676ee4 20:d63d727ee0a6
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of the License "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Performs various operations to read the raw disk and ensure that results 
       
    15 // returned are what is expected. 
       
    16 // 
       
    17 //
       
    18 
       
    19 
       
    20 #include "basetestfat32readraw.h"
       
    21 
       
    22 static RRawDisk TheDisk;
       
    23 
       
    24 /**
       
    25 Class Constructor
       
    26 */		    
       
    27 CBaseTestFat32ReadRaw::CBaseTestFat32ReadRaw() 
       
    28 	{
       
    29 	SetTestStepName(KTestStepReadRaw);
       
    30 	}
       
    31 	
       
    32 /**
       
    33 Class Destructor
       
    34 */
       
    35 CBaseTestFat32ReadRaw::~CBaseTestFat32ReadRaw() 
       
    36 	{
       
    37 	}
       
    38 
       
    39 
       
    40 /** 
       
    41 This function performs the following actions:
       
    42 1. Gets the position to read on the raw disk from the ini file
       
    43 	-> if a cluster is specified then get the position from GetCluster(). 
       
    44 2. Get the number of bytes to read starting from the obtained position 
       
    45 3. Read the disk byte by byte and place into an array. 
       
    46 	-> If a mask is specified then compare the mask with the read value. 
       
    47 	-> If the correct results are specified in the ini file then compare 
       
    48 	   the array contain the read values with the array containing the 
       
    49 	   correct results.
       
    50 
       
    51 @return EPass if test passes and EFail if test fails
       
    52 */ 
       
    53 TVerdict CBaseTestFat32ReadRaw::doTestStepL()
       
    54 	{
       
    55 	SetTestStepResult(EFail);
       
    56 
       
    57 	TInt ascivalue[20];
       
    58 	TInt correctresults[20];
       
    59 	TInt r; 
       
    60 	
       
    61 	_LIT(KPosition,"ReadPosition");
       
    62 	TInt position; 
       
    63 	TBool alright = GetHexFromConfig(ConfigSection(), KPosition, position);
       
    64 	if(alright)
       
    65 		{
       
    66 		if (iMedia == 1 && position >= 16384)
       
    67 			{
       
    68 			INFO_PRINTF2(_L("Position = %d"), position);
       
    69 			INFO_PRINTF2(_L("iBPB_ResvdSecCnt = %d"), iBPB_ResvdSecCnt);
       
    70 			position = (iBPB_ResvdSecCnt * 512) + (position - 0x4000);
       
    71 			INFO_PRINTF2(_L("New Position = %d"), position);
       
    72 			}
       
    73 		_LIT(KCluster,"ClusterNumber");
       
    74 		TInt64 clusterPosition;
       
    75 		TInt cluster; 
       
    76 		TBool alright2 = GetIntFromConfig(ConfigSection(), KCluster, cluster);
       
    77 		if (alright2)
       
    78 			{
       
    79 			r = GetCluster(cluster, clusterPosition);
       
    80 			if (r != KErrNone)
       
    81 				{
       
    82 				SetTestStepResult(EFail);
       
    83 				INFO_PRINTF1(_L("Could not get disk position"));
       
    84 				return TestStepResult();
       
    85 				}
       
    86 			else
       
    87 				{
       
    88 				position = clusterPosition;
       
    89 				} 
       
    90 			}
       
    91 			
       
    92 		_LIT(KReadPosition, "The position on the disk being read is %d");
       
    93 		INFO_PRINTF2(KReadPosition,position);
       
    94 
       
    95 		_LIT(KNumOfBytes,"NumberOfBytes");
       
    96 		TInt numbyte;
       
    97 		TBool alright3 = GetHexFromConfig(ConfigSection(), KNumOfBytes, numbyte);
       
    98 		if (alright3)
       
    99 			{
       
   100 			r = ReadRaw(position, numbyte, ascivalue);
       
   101 			if(r != KErrNone)
       
   102 				{
       
   103 				_LIT(KErrorRead, "Cannot read the raw disk at position %d and length %d - error = %d");
       
   104 				INFO_PRINTF4(KErrorRead,position, numbyte, r);
       
   105 				SetTestStepResult(EFail);
       
   106 				return TestStepResult();
       
   107 				}
       
   108 			_LIT(KMask,"Mask");
       
   109 			TInt mask;
       
   110 			TBool alright4 = GetHexFromConfig(ConfigSection(), KMask, mask);
       
   111 			if (alright4)
       
   112 				{
       
   113 				r = CheckMask(mask,numbyte, ascivalue, position);
       
   114 				if (r == KErrNone)
       
   115 				{
       
   116 				_LIT(KValueCorrect, "Result Correct");
       
   117 					INFO_PRINTF1(KValueCorrect);
       
   118 					SetTestStepResult(EPass);
       
   119 					_LIT(KReadPass, "Read Passed");
       
   120 					INFO_PRINTF1(KReadPass);
       
   121 					return TestStepResult();
       
   122 					}
       
   123 				else
       
   124 					{
       
   125 					_LIT(KValueWrong, "Result Incorrect, value is %X but should be %X");
       
   126 					INFO_PRINTF3(KValueWrong, ascivalue[0], mask);
       
   127 					SetTestStepResult(EFail);
       
   128 					_LIT(KReadFail, "Read Failed");							
       
   129 					INFO_PRINTF1(KReadFail);
       
   130 					return TestStepResult();
       
   131 					}
       
   132 				}
       
   133 			else
       
   134 				{
       
   135 				r = GetCorrectResult(numbyte,correctresults);
       
   136 				TInt i;
       
   137 				for (i = 0; i < numbyte; i++)
       
   138 					{
       
   139 					if (ascivalue[i] != correctresults[i])
       
   140 						{
       
   141 						if ((ascivalue[i] == 0xFF) && (correctresults[i] == 0x00))
       
   142 							{
       
   143 							_LIT(KValueCorrect, "Result Correct");
       
   144 							INFO_PRINTF1(KValueCorrect);
       
   145 							SetTestStepResult(EPass);
       
   146 							_LIT(KReadPass, "Read Passed");
       
   147 							INFO_PRINTF1(KReadPass);
       
   148 							return TestStepResult();
       
   149 							}
       
   150 						else
       
   151 							{
       
   152 							_LIT(KValueWrong, "Result Incorrect, value is %X but should be %X");
       
   153 							INFO_PRINTF3(KValueWrong, ascivalue[i], correctresults[i]);
       
   154 							SetTestStepResult(EFail);
       
   155 							_LIT(KReadFail, "Read Failed");
       
   156 							INFO_PRINTF1(KReadFail);
       
   157 							return TestStepResult();
       
   158 							}
       
   159 						}
       
   160 					else
       
   161 						{
       
   162 						_LIT(KValueCorrect, "Result Correct");
       
   163 						INFO_PRINTF1(KValueCorrect);
       
   164 						SetTestStepResult(EPass);
       
   165 						_LIT(KReadPass, "Read Passed");
       
   166 						INFO_PRINTF1(KReadPass);
       
   167 						return TestStepResult();
       
   168 						}
       
   169 					}
       
   170 				}
       
   171 			}
       
   172 			else
       
   173 			{
       
   174 			_LIT(KErrorRead, "Cannot read the ini file Number of Bytes ");
       
   175 			INFO_PRINTF3(KErrorRead,position, numbyte);
       
   176 			SetTestStepResult(EFail);
       
   177 			return TestStepResult();
       
   178 			}
       
   179 		}
       
   180 	else
       
   181 		{
       
   182 		_LIT(KErrorRead, "Cannot read the ini file Read Position ");
       
   183 		INFO_PRINTF1(KErrorRead);
       
   184 		SetTestStepResult(EFail);
       
   185 		return TestStepResult();	
       
   186 		}
       
   187 	return TestStepResult();
       
   188 	}
       
   189 
       
   190 
       
   191 /** 
       
   192 Read from the raw disk byte by byte and place the results into an array
       
   193 
       
   194 @param aPos The position from which to start reading the raw disk
       
   195 @param aNumberOfBytes The number of bytes to read from the raw disk
       
   196 @param aAsciiValue Array containing the values that are read from the raw disk
       
   197 
       
   198 @return KErrNone if successfull
       
   199 */
       
   200 TInt CBaseTestFat32ReadRaw::ReadRaw(TInt64 aPos,TInt aNumberOfBytes,TInt *aAsciiValue)
       
   201 	{
       
   202 	TInt r;
       
   203 	r = TheDisk.Open(iTheFs, CurrentDrive());
       
   204 		if (r != KErrNone)
       
   205 		{
       
   206 		_LIT(KErrorRead, "Cannot open the raw disk - r=%d");
       
   207 		INFO_PRINTF2(KErrorRead, r);
       
   208 		return r;
       
   209 		}
       
   210 	
       
   211 	TUint8 data[20];
       
   212 	TPtr8 buf(&data[0], 20);
       
   213 	r = TheDisk.Read(aPos, buf);
       
   214 	if (r != KErrNone)
       
   215 		{
       
   216 		_LIT(KErrorRead, "Cannot read the raw disk - r=%d");
       
   217 		INFO_PRINTF2(KErrorRead, r);
       
   218 		return r;
       
   219 		}
       
   220 	TInt i;	
       
   221 	for (i = 0; i < aNumberOfBytes; i++)
       
   222 		{
       
   223 		aAsciiValue[i] = data[i];
       
   224 		}
       
   225 	TheDisk.Close();	
       
   226 	return r; 
       
   227 	}
       
   228 
       
   229 /** 
       
   230 Get the correct result value byte by byte and place into an array
       
   231 
       
   232 @param aNumberOfBytes The number of bytes to read from the raw disk
       
   233 @param aCorrectResultArray Array containing the values that are expected
       
   234 
       
   235 @return KErrNone if successful
       
   236 */
       
   237 
       
   238 TInt CBaseTestFat32ReadRaw::GetCorrectResult(TInt aNumOfBytes,TInt* aCorrectResultArray)
       
   239 	{
       
   240 	TInt result;
       
   241 	TInt i;
       
   242 	_LIT(KCorrectResult,"CorrectResult%d");
       
   243 	for (i=1; i<aNumOfBytes+1; i++)
       
   244 		{
       
   245 		TBuf<20> a;
       
   246 		a.Format(KCorrectResult, i);
       
   247 		TBool alright3 = GetHexFromConfig(ConfigSection(), a, result);
       
   248 		if (alright3)
       
   249 			{
       
   250 			aCorrectResultArray[i-1] = result;
       
   251 			}
       
   252 		else
       
   253 			{
       
   254 			INFO_PRINTF1(_L("Could not get correct result from ini file"));
       
   255 			return KErrGeneral;
       
   256 			}
       
   257 		}
       
   258 	return KErrNone;
       
   259 	}
       
   260 
       
   261 /** 
       
   262 Get the position by calulating from the entry and position in the entry 
       
   263 specified in the ini file 
       
   264 
       
   265 
       
   266 @param aClusterNumber The cluster number on the raw disk
       
   267 @param aPosition The position from which to start reading the raw disk
       
   268 
       
   269 @return KErrNone if successful
       
   270 */	
       
   271 TInt CBaseTestFat32ReadRaw::GetCluster(TInt aClusterNumber,TInt64 &aPosition)
       
   272 	{
       
   273 	TInt entry;
       
   274 	_LIT(KEntry,"Entry");
       
   275 	TInt entryposition;
       
   276 	_LIT(KPositionInEntry,"PositionInEntry");
       
   277 	TBool alright = GetIntFromConfig(ConfigSection(), KEntry, entry);
       
   278 	if (alright)
       
   279 		{
       
   280 		TBool alright2 = GetIntFromConfig(ConfigSection(), KPositionInEntry, entryposition);
       
   281 		if (alright2)
       
   282 			{
       
   283 			// Calculating the byte number on the disk when given the 
       
   284 			// cluster number, the entry number and the position in the entry
       
   285 			TInt sizeOfEntry = 96;
       
   286 			aPosition = (iBPB_ResvdSecCnt + (iBPB_FATSz32 * 2) + (iBPB_SecPerClus * (aClusterNumber - 2))) * 512;
       
   287 			aPosition = aPosition + ((entry - 1) * sizeOfEntry) + entryposition;
       
   288 			return KErrNone;
       
   289 			}
       
   290 		else
       
   291 			{
       
   292 			INFO_PRINTF1(_L("Could not read position in entry from ini file"));
       
   293 			return KErrGeneral;
       
   294 			}
       
   295 		}
       
   296 	else 
       
   297 		{
       
   298 		INFO_PRINTF1(_L("Could not read entry number from ini file"));
       
   299 		return KErrGeneral;
       
   300 		}
       
   301 	}
       
   302 
       
   303 /** 
       
   304 Check if the mask value is correct with the mask obtained from the ini file
       
   305 
       
   306 @param aMask Value of the mask
       
   307 @param aNumberOfBytes The number of bytes to read from the raw disk
       
   308 @param aAsciiValue Array containing the values that are read from the raw disk
       
   309 @param aPos The position on the raw disk
       
   310 
       
   311 @reutrn KErrNone is successfull
       
   312 */
       
   313 TInt CBaseTestFat32ReadRaw::CheckMask(TInt aMask, TInt aNumOfBytes, TInt *aAsciiValue, TInt64 aPos)
       
   314 	{
       
   315 	TUint32 readValue;
       
   316 	TInt maskreturn;
       
   317 	_LIT(KMaskReturn,"MaskReturn");
       
   318 	TInt i;
       
   319 	
       
   320 	readValue = 0;
       
   321 	for (i=aNumOfBytes-1; i>=0; i--)
       
   322 		{
       
   323 
       
   324 		readValue = readValue << 8;
       
   325 		readValue = readValue + aAsciiValue[i];
       
   326 		}
       
   327 	// Special case for the extension flag field. Checks whether mirroring is
       
   328 	// enabled or disabled and whether is contains the correct value. Position
       
   329 	// on the disk for this fiels is 0x29
       
   330 	if ((aPos == 0x29) && (aMask == 0))
       
   331 		{
       
   332 		if(readValue != 0)
       
   333 			{
       
   334 			aMask = 0x80;
       
   335 			if ((readValue&aMask) == aMask)
       
   336 				{
       
   337 				aMask = 0x0D;
       
   338 				if ((aMask&readValue) == 0)
       
   339 					{
       
   340 					INFO_PRINTF1(_L("Mirroring is DISABLED and the active FAT is correct"));
       
   341 					return KErrNone;
       
   342 					}
       
   343 				else 
       
   344 					{
       
   345 					INFO_PRINTF1(_L("Mirroring is DISABLED and the active FAT is incorrect"));
       
   346 					return KErrGeneral;
       
   347 					}
       
   348 				}
       
   349 			}
       
   350 		else 
       
   351 			{
       
   352 			INFO_PRINTF1(_L("Mirroring is ENABLED and the field is 0"));
       
   353 			return KErrNone;
       
   354 			}
       
   355 		}
       
   356 	else
       
   357 		{
       
   358 		TBool alright = GetIntFromConfig(ConfigSection(), KMaskReturn, maskreturn);
       
   359 		if (alright)
       
   360 			{
       
   361 			if (maskreturn == 0)
       
   362 				{
       
   363 				if ((readValue&aMask) == 0)
       
   364 					{
       
   365 					return KErrNone;
       
   366 					}
       
   367 				else 
       
   368 					{
       
   369 					return KErrGeneral;
       
   370 					}
       
   371 				}
       
   372 			else
       
   373 				{
       
   374 				if ((readValue&aMask) == aMask)
       
   375 					{
       
   376 					return KErrNone;
       
   377 					}
       
   378 				else 
       
   379 					{
       
   380 					return KErrGeneral;
       
   381 					}
       
   382 				}
       
   383 			}
       
   384 		}
       
   385 	return KErrNone;
       
   386 	}