kerneltest/f32test/fileutils/src/f32_test_utils.cpp
changeset 244 a77889bee936
parent 175 5af6c74cd793
equal deleted inserted replaced
243:c7a0ce20c48c 244:a77889bee936
    34 //-- Thus it needs to be thrown away by preprocessing in such a case.
    34 //-- Thus it needs to be thrown away by preprocessing in such a case.
    35 
    35 
    36 static CConsoleBase* pConsole = NULL;   //-- pointer to the text console for printing out data
    36 static CConsoleBase* pConsole = NULL;   //-- pointer to the text console for printing out data
    37 static TBool  bPrintOutEnabled = ETrue; //-- global flag, if EFalse, all printing out is disabled
    37 static TBool  bPrintOutEnabled = ETrue; //-- global flag, if EFalse, all printing out is disabled
    38 
    38 
       
    39 
       
    40 
       
    41 //-------------------------------------------------------------------------------------------------------------------
       
    42 
       
    43 /**
       
    44     Prints out a hex dump of a descriptor contents
       
    45     @param  aBuf data descriptor to dump
       
    46 */
       
    47 void  F32_Test_Utils::HexDump(const TDesC8& aBuf)
       
    48 {
       
    49     HexDump(aBuf.Ptr(), aBuf.Size());
       
    50 }
       
    51 
       
    52 //-------------------------------------------------------------------------------------------------------------------
       
    53 /**
       
    54     Prints out a hex dump of a buffer
       
    55     @param  apBuf   pointer to the data to dump
       
    56     @param  aBufLen buffer length
       
    57 */
       
    58 void  F32_Test_Utils::HexDump(const TAny* apBuf, TUint aBufLen)
       
    59 {
       
    60     DoPrintf(_L("~ F32_Test_Utils::HexDump() size:%u\n"), aBufLen);
       
    61   
       
    62     ASSERT(apBuf);
       
    63     
       
    64     if(!aBufLen)
       
    65         return;
       
    66 
       
    67     const TUint colDmpWidth = 16;
       
    68     const TUint8* pBuf = (const TUint8*)apBuf;
       
    69     TBuf<256> buf1;
       
    70     TBuf<64>  buf2;
       
    71 
       
    72     TUint dumpPos;
       
    73     
       
    74     for(dumpPos=0; dumpPos < aBufLen-1; )
       
    75     {
       
    76         buf1.Format(_L("%06X: "), dumpPos);
       
    77         buf2.Zero();
       
    78 
       
    79         for(TUint i=0; i<colDmpWidth; ++i)
       
    80         {
       
    81             buf1.AppendFormat(_L("%02x "), pBuf[dumpPos+i]);
       
    82         
       
    83             const TChar ch = pBuf[dumpPos+i];
       
    84             if(ch.IsPrint())
       
    85                 buf2.Append(ch);
       
    86             else    
       
    87                 buf2.Append(_L("."));
       
    88             
       
    89 
       
    90             if(++dumpPos >= aBufLen)
       
    91             {    
       
    92                 while(++i < colDmpWidth)
       
    93                 {
       
    94                     buf1.Append(_L("   "));
       
    95                     buf2.Append(_L(" "));
       
    96                 }
       
    97 
       
    98                 break;
       
    99             }
       
   100         }
       
   101 
       
   102         buf1.Append(buf2);
       
   103         DoPrintf(buf1);
       
   104     
       
   105     }
       
   106 
       
   107     DoPrintf(_L("\n"));
       
   108 
       
   109 }
       
   110 
       
   111 
       
   112 //-------------------------------------------------------------------------------------------------------------------
       
   113 /**
       
   114     Compare 2 buffers and print out the difference if there is any.
       
   115     Buffer sizes must be the same and non-0
       
   116 
       
   117     @param  aBuf1   buffer 1 descriptor
       
   118     @param  aBuf2   buffer 2 descriptor
       
   119     
       
   120     @return ETrue if buffers are the same, EFalse otherwise
       
   121 */
       
   122 TBool F32_Test_Utils::CompareBuffers(const TDesC8& aBuf1, const TDesC8& aBuf2)
       
   123 {
       
   124     return CompareBuffers(aBuf1.Ptr(), aBuf1.Size(), aBuf2.Ptr(), aBuf2.Size());
       
   125 }
       
   126 
       
   127 //-------------------------------------------------------------------------------------------------------------------
       
   128 /**
       
   129     Compare 2 buffers and print out the difference if there is any.
       
   130     Buffer sizes must be the same and non-0
       
   131 
       
   132     @param  apBuf1   pointer to the buffer 1 
       
   133     @param  aBuf1Len buffer1 length
       
   134     @param  apBuf2   pointer to the buffer 2 
       
   135     @param  aBuf2Len buffer2 length
       
   136 
       
   137     @return ETrue if buffers are the same, EFalse otherwise
       
   138 */
       
   139 TBool F32_Test_Utils::CompareBuffers(const TAny* apBuf1, TUint aBuf1Len, const TAny* apBuf2, TUint aBuf2Len)
       
   140 {
       
   141     ASSERT(apBuf1 && apBuf2);
       
   142     
       
   143     if(aBuf1Len != aBuf2Len)
       
   144     {
       
   145         DoPrintf(_L("~ F32_Test_Utils::CompareBuffers() different sizes! %u:%u\n"), aBuf1Len, aBuf2Len);
       
   146         ASSERT(0);
       
   147         return EFalse;
       
   148     }
       
   149 
       
   150     if(!aBuf1Len)
       
   151     {//-- empty buffers to compare
       
   152         return ETrue;
       
   153     }
       
   154 
       
   155 
       
   156     const TUint8* pBuf1 = (const TUint8*)apBuf1;
       
   157     const TUint8* pBuf2 = (const TUint8*)apBuf2;   
       
   158         
       
   159     if(!Mem::Compare(pBuf1, aBuf1Len, pBuf2, aBuf2Len))
       
   160         return ETrue; //-- buffers are the same. 
       
   161 
       
   162 
       
   163     //-- the buffers' contents are different
       
   164     TUint diffpos;
       
   165     TBuf<256> buf1;
       
   166     TBuf<100> buf2;
       
   167 
       
   168     const TUint colDmpWidth = 16;
       
   169     TBool bBannerPrinted = EFalse;
       
   170 
       
   171     //-- dump chunks of the buffer with differences only
       
   172     for(diffpos=0; diffpos<aBuf1Len-1; )
       
   173     {
       
   174         if(pBuf1[diffpos] == pBuf2[diffpos])
       
   175             {
       
   176             ++diffpos;
       
   177             continue;
       
   178             }
       
   179 
       
   180         if(!bBannerPrinted)
       
   181         {
       
   182             bBannerPrinted = ETrue;
       
   183             DoPrintf(_L("~ F32_Test_Utils::CompareBuffers() buffers' contents are different starting at pos:%u (0x%x). Hexdump:\n"), diffpos, diffpos);
       
   184 
       
   185         }
       
   186 
       
   187         //-- difference found, dump chunks of the buffer with differences only
       
   188         TUint dumpPos = (diffpos >> 4) << 4; //-- round down to 16
       
   189 
       
   190         buf1.Format(_L("%06X: "), dumpPos);
       
   191         buf2.Format(_L("|"));
       
   192         
       
   193         for(TUint i=0; i<colDmpWidth; ++i)
       
   194         {
       
   195             buf1.AppendFormat(_L("%02x"), pBuf1[dumpPos+i]);
       
   196             buf2.AppendFormat(_L("%02x"), pBuf2[dumpPos+i]);
       
   197 
       
   198             if(i < colDmpWidth-1)
       
   199             {
       
   200                 buf1.Append(_L(" "));
       
   201                 buf2.Append(_L(" "));
       
   202             }
       
   203 
       
   204         
       
   205             if(++diffpos >= aBuf1Len)
       
   206             {//-- pad the dump with spaces
       
   207                 while(++i < colDmpWidth)
       
   208                 {
       
   209                     buf1.Append(_L("   "));
       
   210                     buf2.Append(_L("   "));
       
   211                 }
       
   212             
       
   213                 break;
       
   214             }
       
   215 
       
   216         }
       
   217 
       
   218         buf1.Append(buf2);
       
   219         DoPrintf(buf1);
       
   220     }
       
   221     
       
   222     DoPrintf(_L("\n"));
       
   223 
       
   224     return EFalse;
       
   225 }
       
   226 
       
   227 
       
   228 //-------------------------------------------------------------------------------------------------------------------
    39 /**
   229 /**
    40     Set the console where the ouput will go.
   230     Set the console where the ouput will go.
    41     @param  apConsole pointer to the console. if NULL, the print out will be debug port only.
   231     @param  apConsole pointer to the console. if NULL, the print out will be debug port only.
    42 */
   232 */
    43 void F32_Test_Utils::SetConsole(CConsoleBase* apConsole)
   233 void F32_Test_Utils::SetConsole(CConsoleBase* apConsole)