[PATCH v3 1/2] covoar: Fix NOP execution marking

2021-03-12 Thread Alex White
Some NOP instructions were not being marked as executed because they
are located at the end of uncovered ranges. This has been fixed.
---
 tester/covoar/CoverageMapBase.cc  |  10 +++
 tester/covoar/CoverageMapBase.h   |   4 ++
 tester/covoar/DesiredSymbols.cc   |  38 --
 tester/covoar/DesiredSymbols.h|  11 ++-
 tester/covoar/ObjdumpProcessor.cc | 112 +++---
 5 files changed, 140 insertions(+), 35 deletions(-)

diff --git a/tester/covoar/CoverageMapBase.cc b/tester/covoar/CoverageMapBase.cc
index ad0080d..6ca5cf7 100644
--- a/tester/covoar/CoverageMapBase.cc
+++ b/tester/covoar/CoverageMapBase.cc
@@ -142,6 +142,11 @@ namespace Coverage {
 return size;
   }
 
+  uint32_t CoverageMapBase::getSizeOfRange( size_t index ) const
+  {
+return Ranges.at(index).size();
+  }
+
   bool CoverageMapBase::getBeginningOfInstruction(
 uint32_t  address,
 uint32_t* beginning
@@ -178,6 +183,11 @@ namespace Coverage {
 return Ranges.front().lowAddress;
   }
 
+  uint32_t CoverageMapBase::getLowAddressOfRange( size_t index ) const
+  {
+return Ranges.at(index).lowAddress;
+  }
+
   bool CoverageMapBase::getRange( uint32_t address, AddressRange& range ) const
   {
 for ( auto r : Ranges ) {
diff --git a/tester/covoar/CoverageMapBase.h b/tester/covoar/CoverageMapBase.h
index 6ad76d3..a58c696 100644
--- a/tester/covoar/CoverageMapBase.h
+++ b/tester/covoar/CoverageMapBase.h
@@ -156,6 +156,8 @@ namespace Coverage {
  */
 int32_t getFirstLowAddress() const;
 
+uint32_t getLowAddressOfRange( size_t index ) const;
+
 /*!
  *  This method returns true and sets the address range if
  *  the address falls with the bounds of an address range
@@ -177,6 +179,8 @@ namespace Coverage {
  */
 uint32_t getSize() const;
 
+uint32_t getSizeOfRange( size_t index ) const;
+
 /*!
  *  This method returns the address of the beginning of the
  *  instruction that contains the specified address.
diff --git a/tester/covoar/DesiredSymbols.cc b/tester/covoar/DesiredSymbols.cc
index b9a5bb7..c97b25c 100644
--- a/tester/covoar/DesiredSymbols.cc
+++ b/tester/covoar/DesiredSymbols.cc
@@ -142,7 +142,7 @@ namespace Coverage {
   CoverageMapBase* theCoverageMap = s.second.unifiedCoverageMap;
   if (theCoverageMap)
   {
-// Increment the total sizeInBytes byt the bytes in the symbol
+// Increment the total sizeInBytes by the bytes in the symbol
 stats.sizeInBytes += s.second.stats.sizeInBytes;
 
 // Now scan through the coverage map of this symbol.
@@ -202,6 +202,26 @@ namespace Coverage {
 uint32_t count;
 
 // Mark NOPs as executed
+a = s.second.stats.sizeInBytes - 1;
+count = 0;
+while (a > 0) {
+  if (theCoverageMap->isStartOfInstruction( a )) {
+break;
+  }
+
+  count++;
+
+  if (theCoverageMap->isNop( a )) {
+for (la = a; la < (a + count); la++) {
+  theCoverageMap->setWasExecuted( la );
+}
+
+count = 0;
+  }
+
+  a--;
+}
+
 endAddress = s.second.stats.sizeInBytes - 1;
 a = 0;
 while (a < endAddress) {
@@ -223,12 +243,13 @@ namespace Coverage {
   ha++;
   if ( ha >= endAddress )
 break;
-} while ( !theCoverageMap->isStartOfInstruction( ha ) );
+} while ( !theCoverageMap->isStartOfInstruction( ha ) ||
+  theCoverageMap->isNop( ha ) );
   a = ha;
 }
 
 // Now scan through the coverage map of this symbol.
-endAddress = s.second.stats.sizeInBytes - 1;
+endAddress = s.second.stats.sizeInBytesWithoutNops - 1;
 a = 0;
 while (a <= endAddress) {
   // If an address was NOT executed, find consecutive unexecuted
@@ -316,7 +337,8 @@ namespace Coverage {
   void DesiredSymbols::createCoverageMap(
 const std::string& exefileName,
 const std::string& symbolName,
-uint32_t   size
+uint32_t   size,
+uint32_t   sizeWithoutNops
   )
   {
 CoverageMapBase* aCoverageMap;
@@ -354,9 +376,10 @@ namespace Coverage {
   << '/' << size << ')'
   << std::endl;
 
-if ( itr->second.stats.sizeInBytes < size )
+if ( itr->second.stats.sizeInBytes < size ) {
   itr->second.stats.sizeInBytes = size;
-else
+  itr->second.stats.sizeInBytesWithoutNops = sizeWithoutNops;
+} else
   size = itr->second.stats.sizeInBytes;
   }
 }
@@ -376,6 +399,7 @@ namespace Coverage {
 );
   itr->second.unifiedCoverageMap = aCoverageMap;
   itr->second.stats.sizeInBytes = size;
+  itr->second.stats.sizeInBytesWithoutNops = sizeWithoutNops;
 }
   }
 
@@ -479,7 +503,7 @@ namespace Coverage {
 // are the same size.
 // Changed from ERROR msg to INFO, because size mi

Re: [PATCH v3 1/2] covoar: Fix NOP execution marking

2021-03-14 Thread Chris Johns
This v3 set is blocked by the v2 questions I have raised.

Chris

On 13/3/21 2:48 am, Alex White wrote:
> Some NOP instructions were not being marked as executed because they
> are located at the end of uncovered ranges. This has been fixed.
> ---
>  tester/covoar/CoverageMapBase.cc  |  10 +++
>  tester/covoar/CoverageMapBase.h   |   4 ++
>  tester/covoar/DesiredSymbols.cc   |  38 --
>  tester/covoar/DesiredSymbols.h|  11 ++-
>  tester/covoar/ObjdumpProcessor.cc | 112 +++---
>  5 files changed, 140 insertions(+), 35 deletions(-)
> 
> diff --git a/tester/covoar/CoverageMapBase.cc 
> b/tester/covoar/CoverageMapBase.cc
> index ad0080d..6ca5cf7 100644
> --- a/tester/covoar/CoverageMapBase.cc
> +++ b/tester/covoar/CoverageMapBase.cc
> @@ -142,6 +142,11 @@ namespace Coverage {
>  return size;
>}
>  
> +  uint32_t CoverageMapBase::getSizeOfRange( size_t index ) const
> +  {
> +return Ranges.at(index).size();
> +  }
> +
>bool CoverageMapBase::getBeginningOfInstruction(
>  uint32_t  address,
>  uint32_t* beginning
> @@ -178,6 +183,11 @@ namespace Coverage {
>  return Ranges.front().lowAddress;
>}
>  
> +  uint32_t CoverageMapBase::getLowAddressOfRange( size_t index ) const
> +  {
> +return Ranges.at(index).lowAddress;
> +  }
> +
>bool CoverageMapBase::getRange( uint32_t address, AddressRange& range ) 
> const
>{
>  for ( auto r : Ranges ) {
> diff --git a/tester/covoar/CoverageMapBase.h b/tester/covoar/CoverageMapBase.h
> index 6ad76d3..a58c696 100644
> --- a/tester/covoar/CoverageMapBase.h
> +++ b/tester/covoar/CoverageMapBase.h
> @@ -156,6 +156,8 @@ namespace Coverage {
>   */
>  int32_t getFirstLowAddress() const;
>  
> +uint32_t getLowAddressOfRange( size_t index ) const;
> +
>  /*!
>   *  This method returns true and sets the address range if
>   *  the address falls with the bounds of an address range
> @@ -177,6 +179,8 @@ namespace Coverage {
>   */
>  uint32_t getSize() const;
>  
> +uint32_t getSizeOfRange( size_t index ) const;
> +
>  /*!
>   *  This method returns the address of the beginning of the
>   *  instruction that contains the specified address.
> diff --git a/tester/covoar/DesiredSymbols.cc b/tester/covoar/DesiredSymbols.cc
> index b9a5bb7..c97b25c 100644
> --- a/tester/covoar/DesiredSymbols.cc
> +++ b/tester/covoar/DesiredSymbols.cc
> @@ -142,7 +142,7 @@ namespace Coverage {
>CoverageMapBase* theCoverageMap = s.second.unifiedCoverageMap;
>if (theCoverageMap)
>{
> -// Increment the total sizeInBytes byt the bytes in the symbol
> +// Increment the total sizeInBytes by the bytes in the symbol
>  stats.sizeInBytes += s.second.stats.sizeInBytes;
>  
>  // Now scan through the coverage map of this symbol.
> @@ -202,6 +202,26 @@ namespace Coverage {
>  uint32_t count;
>  
>  // Mark NOPs as executed
> +a = s.second.stats.sizeInBytes - 1;
> +count = 0;
> +while (a > 0) {
> +  if (theCoverageMap->isStartOfInstruction( a )) {
> +break;
> +  }
> +
> +  count++;
> +
> +  if (theCoverageMap->isNop( a )) {
> +for (la = a; la < (a + count); la++) {
> +  theCoverageMap->setWasExecuted( la );
> +}
> +
> +count = 0;
> +  }
> +
> +  a--;
> +}
> +
>  endAddress = s.second.stats.sizeInBytes - 1;
>  a = 0;
>  while (a < endAddress) {
> @@ -223,12 +243,13 @@ namespace Coverage {
>ha++;
>if ( ha >= endAddress )
>  break;
> -} while ( !theCoverageMap->isStartOfInstruction( ha ) );
> +} while ( !theCoverageMap->isStartOfInstruction( ha ) ||
> +  theCoverageMap->isNop( ha ) );
>a = ha;
>  }
>  
>  // Now scan through the coverage map of this symbol.
> -endAddress = s.second.stats.sizeInBytes - 1;
> +endAddress = s.second.stats.sizeInBytesWithoutNops - 1;
>  a = 0;
>  while (a <= endAddress) {
>// If an address was NOT executed, find consecutive unexecuted
> @@ -316,7 +337,8 @@ namespace Coverage {
>void DesiredSymbols::createCoverageMap(
>  const std::string& exefileName,
>  const std::string& symbolName,
> -uint32_t   size
> +uint32_t   size,
> +uint32_t   sizeWithoutNops
>)
>{
>  CoverageMapBase* aCoverageMap;
> @@ -354,9 +376,10 @@ namespace Coverage {
><< '/' << size << ')'
><< std::endl;
>  
> -if ( itr->second.stats.sizeInBytes < size )
> +if ( itr->second.stats.sizeInBytes < size ) {
>itr->second.stats.sizeInBytes = size;
> -else
> +  itr->second.stats.sizeInBytesWithoutNops = sizeWithoutNops;
> +} else
>size = itr->second.stats.s