[PATCH rtems-tools v1 04/10] covoar.cc: Fix formatting

Ryan Long ryan.long at oarcorp.com
Wed Sep 8 16:44:34 UTC 2021


---
 tester/covoar/covoar.cc | 300 +++++++++++++++++++++++++++---------------------
 1 file changed, 167 insertions(+), 133 deletions(-)

diff --git a/tester/covoar/covoar.cc b/tester/covoar/covoar.cc
index 746add1..e8fb430 100644
--- a/tester/covoar/covoar.cc
+++ b/tester/covoar/covoar.cc
@@ -35,25 +35,27 @@
 #define STAT stat
 #endif
 
-#if defined(_WIN32) || defined(__CYGWIN__)
-  #define kill(p,s) raise(s)
+#if defined( _WIN32 ) || defined( __CYGWIN__ )
+  #define kill( p,s ) raise( s )
 #endif
 
 #define MAX_LINE_LENGTH 512
 
-typedef std::list<std::string> CoverageNames;
+typedef std::list<std::string>               CoverageNames;
 typedef std::list<Coverage::ExecutableInfo*> Executables;
-typedef std::string option_error;
+typedef std::string                          OptionError;
 
 bool FileIsReadable( const std::string& f1 )
 {
   struct STAT buf1;
 
-  if (STAT( f1.c_str(), &buf1 ) == -1)
+  if ( STAT( f1.c_str(), &buf1 ) == -1 ) {
     return false;
+  }
 
-  if (buf1.st_size == 0)
+  if ( buf1.st_size == 0 ) {
     return false;
+  }
 
   // XXX check permission ??
   return true;
@@ -63,75 +65,92 @@ bool FileIsReadable( const std::string& f1 )
  * Create a build path from the executable paths. Also extract the build prefix
  * and BSP names.
  */
-static void createBuildPath(Executables& executablesToAnalyze,
-                            std::string& buildPath,
-                            std::string& buildPrefix,
-                            std::string& buildBSP)
+static void createBuildPath(
+  Executables& executablesToAnalyze,
+  std::string& buildPath,
+  std::string& buildPrefix,
+  std::string& buildBSP
+)
 {
-  for (const auto& exe : executablesToAnalyze) {
+  for ( const auto& exe : executablesToAnalyze ) {
     rld::strings eparts;
-    rld::split(eparts, rld::path::path_abs(exe->getFileName()), RLD_PATH_SEPARATOR);
+    rld::split(
+      eparts,
+      rld::path::path_abs( exe->getFileName() ),
+      RLD_PATH_SEPARATOR
+    );
     std::string fail; // empty means all is OK else an error string
-    for (rld::path::paths::reverse_iterator pri = eparts.rbegin();
-         pri != eparts.rend();
-         ++pri) {
-      if (*pri == "testsuites") {
+    for (
+      rld::path::paths::reverse_iterator pri = eparts.rbegin();
+      pri != eparts.rend();
+      ++pri
+    ) {
+      if ( *pri == "testsuites" ) {
         ++pri;
-        if (pri == eparts.rend()) {
+        if ( pri == eparts.rend() ) {
           fail = "invalid executable path, no BSP";
           break;
         }
-        if (buildBSP.empty()) {
+
+        if ( buildBSP.empty() ) {
           buildBSP = *pri;
         } else {
-          if (buildBSP != *pri) {
+          if ( buildBSP != *pri ) {
             fail = "executable BSP does not match: " + buildBSP;
             break;
           }
         }
+
         ++pri;
-        if (pri == eparts.rend() || *pri != "c") {
+        if ( pri == eparts.rend() || *pri != "c" ) {
           fail = "invalid executable path, no 'c'";
           break;
         }
+
         ++pri;
-        if (pri == eparts.rend()) {
+        if ( pri == eparts.rend() ) {
           fail = "invalid executable path, no arch prefix";
           break;
         }
-        if (buildPrefix.empty()) {
+
+        if ( buildPrefix.empty() ) {
           buildPrefix = *pri;
         } else {
-          if (buildPrefix != *pri) {
+          if ( buildPrefix != *pri ) {
             fail = "executable build prefix does not match: " + buildPrefix;
             break;
           }
         }
+
         ++pri;
-        if (pri == eparts.rend()) {
+        if ( pri == eparts.rend() ) {
           fail = "invalid executable path, no build top";
           break;
         }
+
         //
         // The remaining parts of the path is the build path. Iterator over them
         // and collect into a new paths variable to join to make a path.
         //
         rld::path::paths bparts;
-        for (; pri != eparts.rend(); ++pri)
+        for ( ; pri != eparts.rend(); ++pri )
           bparts.insert(bparts.begin(), *pri);
+
         std::string thisBuildPath;
-        rld::path::path_join(thisBuildPath, bparts, thisBuildPath);
-        if (buildPath.empty()) {
+        rld::path::path_join( thisBuildPath, bparts, thisBuildPath );
+        if ( buildPath.empty() ) {
           buildPath = thisBuildPath;
         } else {
-          if (buildPath != thisBuildPath) {
+          if ( buildPath != thisBuildPath ) {
             fail = "executable build path does not match: " + buildPath;
           }
         }
+
         break;
       }
     }
-    if (!fail.empty()) {
+
+    if ( !fail.empty() ) {
       throw rld::error( fail, "createBuildPath" );
     }
   }
@@ -140,10 +159,10 @@ static void createBuildPath(Executables& executablesToAnalyze,
 /*
  *  Print program usage message
  */
-void usage(const std::string& progname)
+void usage( const std::string& progname )
 {
-  std::cerr <<"Usage: " << progname
-            <<" [-v] -T TARGET -f FORMAT [-E EXPLANATIONS] -1 EXECUTABLE coverage1 ... coverageN" << std::endl
+  std::cerr << "Usage: " << progname
+            << " [-v] -T TARGET -f FORMAT [-E EXPLANATIONS] -1 EXECUTABLE coverage1 ... coverageN" << std::endl
             << "--OR--" << std::endl
             << "Usage: " << progname
             << " [-v] -T TARGET -f FORMAT [-E EXPLANATIONS] -e EXE_EXTENSION -c COVERAGEFILE_EXTENSION EXECUTABLE1 ... EXECUTABLE2" << std::endl
@@ -164,10 +183,7 @@ void usage(const std::string& progname)
             << std::endl;
 }
 
-int covoar(
-  int    argc,
-  char** argv
-)
+int covoar( int argc, char** argv )
 {
   CoverageNames                 coverageFileNames;
   std::string                   coverageFileName;
@@ -183,7 +199,6 @@ int covoar(
   std::string                   target;
   std::string                   format = "QEMU";
   std::ifstream                 gcnosFile;
-  Gcov::GcovData*               gcovFile;
   std::string                   singleExecutable;
   rld::process::tempfile        objdumpFile( ".dmp" );
   rld::process::tempfile        err( ".err" );
@@ -205,8 +220,8 @@ int covoar(
   // Process command line options.
   //
 
-  while ((opt = getopt(argc, argv, "1:L:e:c:g:E:f:s:S:T:O:p:vd")) != -1) {
-    switch (opt) {
+  while ( (opt = getopt( argc, argv, "1:L:e:c:g:E:f:s:S:T:O:p:vd" )) != -1 ) {
+    switch ( opt ) {
       case '1': singleExecutable    = optarg; break;
       case 'L': dynamicLibrary      = optarg; break;
       case 'e': executableExtension = optarg; break;
@@ -222,7 +237,7 @@ int covoar(
       case 'p': projectName         = optarg; break;
       case 'd': debug               = true;   break;
       default: /* '?' */
-        throw option_error( "unknown option" );
+        throw OptionError( "unknown option" );
     }
   }
 
@@ -233,20 +248,23 @@ int covoar(
   /*
    * Validate that we have a symbols of interest file.
    */
-  if ( symbolSet.empty() )
-    throw option_error( "symbol set file -S" );
+  if ( symbolSet.empty() ) {
+    throw OptionError( "symbol set file -S" );
+  }
 
   /*
    * Has path to explanations.txt been specified.
    */
-  if ( explanations.empty() )
-    throw option_error( "explanations -E" );
+  if ( explanations.empty() ) {
+    throw OptionError( "explanations -E" );
+  }
 
   /*
    * Check for project name.
    */
-  if ( projectName.empty() )
-    throw option_error( "project name -p" );
+  if ( projectName.empty() ) {
+    throw OptionError( "project name -p" );
+  }
 
   //
   // Find the top of the BSP's build tree and if we have found the top
@@ -255,36 +273,41 @@ int covoar(
   std::string buildPath;
   std::string buildTarget;
   std::string buildBSP;
-  createBuildPath(executablesToAnalyze,
-                  buildPath,
-                  buildTarget,
-                  buildBSP);
+  createBuildPath(
+    executablesToAnalyze,
+    buildPath,
+    buildTarget,
+    buildBSP
+  );
 
   //
   // Use a command line target if provided.
   //
-  if (!target.empty()) {
+  if ( !target.empty() ) {
     buildTarget = target;
   }
 
-  if (verbose) {
-    if (!singleExecutable.empty()) {
+  if ( verbose ) {
+    if ( !singleExecutable.empty() ) {
       std::cerr << "Processing a single executable and multiple coverage files"
                 << std::endl;
     } else {
-      std::cerr << "Processing multiple executable/coverage file pairs" << std::endl;
+      std::cerr << "Processing multiple executable/coverage file pairs"
+                << std::endl;
     }
+
     std::cerr << "Coverage Format : " << format << std::endl
               << "Target          : " << buildTarget.c_str() << std::endl
               << std::endl;
 
     // Process each executable/coverage file pair.
     Executables::iterator eitr = executablesToAnalyze.begin();
-    for (const auto& cname : coverageFileNames) {
+    for ( const auto& cname : coverageFileNames ) {
       std::cerr << "Coverage file " << cname
                 << " for executable: " << (*eitr)->getFileName() << std::endl;
-      if (singleExecutable.empty())
+      if ( singleExecutable.empty() ) {
         eitr++;
+      }
     }
   }
 
@@ -305,17 +328,15 @@ int covoar(
 
   // If a single executable was specified, process the remaining
   // arguments as coverage file names.
-  if (!singleExecutable.empty()) {
-
+  if ( !singleExecutable.empty() ) {
     // Ensure that the executable is readable.
-    if (!FileIsReadable( singleExecutable )) {
+    if ( !FileIsReadable( singleExecutable ) ) {
       std::cerr << "warning: Unable to read executable: " << singleExecutable
                 << std::endl;
     } else {
-
-      for (int i = optind; i < argc; i++) {
+      for ( int i = optind; i < argc; i++ ) {
         // Ensure that the coverage file is readable.
-        if (!FileIsReadable( argv[i] )) {
+        if ( !FileIsReadable( argv[i] ) ) {
           std::cerr << "warning: Unable to read coverage file: " << argv[i]
                     << std::endl;
         } else {
@@ -325,7 +346,7 @@ int covoar(
 
       // If there was at least one coverage file, create the
       // executable information.
-      if (!coverageFileNames.empty()) {
+      if ( !coverageFileNames.empty() ) {
         if ( !dynamicLibrary.empty() ) {
           executableInfo = new Coverage::ExecutableInfo(
             singleExecutable.c_str(),
@@ -345,21 +366,21 @@ int covoar(
         executablesToAnalyze.push_back( executableInfo );
       }
     }
-  }
-  else {
+  } else {
     // If not invoked with a single executable, process the remaining
     // arguments as executables and derive the coverage file names.
-    for (int i = optind; i < argc; i++) {
+    for ( int i = optind; i < argc; i++ ) {
       // Ensure that the executable is readable.
-      if (!FileIsReadable( argv[i] )) {
-        std::cerr << "warning: Unable to read executable: " << argv[i] << std::endl;
+      if ( !FileIsReadable( argv[i] ) ) {
+        std::cerr << "warning: Unable to read executable: " << argv[i]
+                  << std::endl;
       } else {
         coverageFileName = argv[i];
         coverageFileName.append( "." + coverageExtension );
 
-        if (!FileIsReadable( coverageFileName.c_str() )) {
-          std::cerr << "warning: Unable to read coverage file: " << coverageFileName
-                    << std::endl;
+        if ( !FileIsReadable( coverageFileName.c_str() ) ) {
+          std::cerr << "warning: Unable to read coverage file: "
+                    << coverageFileName << std::endl;
         } else {
           executableInfo = new Coverage::ExecutableInfo(
             argv[i],
@@ -375,36 +396,45 @@ int covoar(
   }
 
   // Ensure that there is at least one executable to process.
-  if (executablesToAnalyze.empty())
+  if ( executablesToAnalyze.empty() ) {
     throw rld::error( "No information to analyze", "covoar" );
+  }
 
   // The executablesToAnalyze and coverageFileNames containers need
   // to be the name size of some of the code below breaks. Lets
   // check and make sure.
-  if (executablesToAnalyze.size() != coverageFileNames.size())
-    throw rld::error( "executables and coverage name size mismatch", "covoar" );
+  if ( executablesToAnalyze.size() != coverageFileNames.size() ) {
+    throw rld::error(
+      "executables and coverage name size mismatch",
+      "covoar"
+    );
+  }
 
-  if ( verbose )
+  if ( verbose ) {
     std::cerr << "Analyzing " << symbolsToAnalyze.allSymbols().size()
               << " symbols" << std::endl;
+  }
 
   // Create explanations.
-  if ( !explanations.empty() )
+  if ( !explanations.empty() ) {
     allExplanations.load( explanations.c_str() );
+  }
 
   // Create coverage map reader.
-  coverageFormat = Coverage::CoverageFormatToEnum(format.c_str());
-  coverageReader = Coverage::CreateCoverageReader(coverageFormat);
-  if (!coverageReader)
+  coverageFormat = Coverage::CoverageFormatToEnum( format.c_str() );
+  coverageReader = Coverage::CreateCoverageReader( coverageFormat );
+  if ( !coverageReader ) {
     throw rld::error( "Unable to create coverage file reader", "covoar" );
+  }
 
   coverageReader->targetInfo_m = targetInfo;
 
   // Prepare each executable for analysis.
-  for (auto& exe : executablesToAnalyze) {
-    if (verbose)
+  for ( auto& exe : executablesToAnalyze ) {
+    if ( verbose ) {
       std::cerr << "Extracting information from: " << exe->getFileName()
                 << std::endl;
+    }
 
     // If a dynamic library was specified, determine the load address.
     if ( !dynamicLibrary.empty() ) {
@@ -421,12 +451,13 @@ int covoar(
 
   // Process each executable/coverage file pair.
   Executables::iterator eitr = executablesToAnalyze.begin();
-  for (const auto& cname : coverageFileNames) {
+  for ( const auto& cname : coverageFileNames ) {
     Coverage::ExecutableInfo* exe = *eitr;
-    if (verbose)
+    if ( verbose ) {
       std::cerr << "Processing coverage file " << cname
                 << " for executable " << exe->getFileName()
                 << std::endl;
+    }
 
     // Process its coverage file.
     coverageReader->processFile( cname.c_str(), exe );
@@ -437,76 +468,83 @@ int covoar(
     // DEBUG Print ExecutableInfo content
     //exe->dumpExecutableInfo();
 
-    if (singleExecutable.empty()) {
+    if ( singleExecutable.empty() ) {
       eitr++;
     }
   }
 
   // Do necessary preprocessing of uncovered ranges and branches
-  if (verbose)
+  if ( verbose ) {
     std::cerr << "Preprocess uncovered ranges and branches" << std::endl;
+  }
 
   symbolsToAnalyze.preprocess( symbolsToAnalyze );
 
   //
   // Generate Gcov reports
   //
-  if (!gcnosFileName.empty()) {
-    if (verbose)
+  if ( !gcnosFileName.empty() ) {
+    if ( verbose ) {
       std::cerr << "Generating Gcov reports..." << std::endl;
+    }
 
     gcnosFile.open( gcnosFileName );
 
-    if ( !gcnosFile )
+    if ( !gcnosFile ) {
       std::cerr << "Unable to open " << gcnosFileName << std::endl;
-    else {
+    } else {
       while ( gcnosFile >> inputBuffer ) {
-        gcovFile = new Gcov::GcovData( symbolsToAnalyze );
+        Gcov::GcovData gcovFile( symbolsToAnalyze );
+        //gcovFile = new Gcov::GcovData( symbolsToAnalyze );
         gcnoFileName = inputBuffer;
 
-        if ( verbose )
+        if ( verbose ) {
           std::cerr << "Processing file: " << gcnoFileName << std::endl;
+        }
 
-        if ( gcovFile->readGcnoFile( gcnoFileName ) ) {
+        if ( gcovFile.readGcnoFile( gcnoFileName ) ) {
           // Those need to be in this order
-          gcovFile->processCounters();
-          gcovFile->writeReportFile();
-          gcovFile->writeGcdaFile();
-          gcovFile->writeGcovFile();
+          gcovFile.processCounters();
+          gcovFile.writeReportFile();
+          gcovFile.writeGcdaFile();
+          gcovFile.writeGcovFile();
         }
-
-        delete gcovFile;
       }
+
       gcnosFile.close();
     }
   }
 
   // Determine the uncovered ranges and branches.
-  if (verbose)
+  if ( verbose ) {
     std::cerr << "Computing uncovered ranges and branches" << std::endl;
+  }
 
   symbolsToAnalyze.computeUncovered( verbose );
 
   // Calculate remainder of statistics.
-  if (verbose)
+  if ( verbose ) {
     std::cerr << "Calculate statistics" << std::endl;
+  }
 
   symbolsToAnalyze.calculateStatistics();
 
   // Look up the source lines for any uncovered ranges and branches.
-  if (verbose)
+  if ( verbose ) {
     std::cerr << "Looking up source lines for uncovered ranges and branches"
               << std::endl;
+  }
 
   symbolsToAnalyze.findSourceForUncovered( verbose, symbolsToAnalyze );
 
   //
   // Report the coverage data.
   //
-  if (verbose)
+  if ( verbose ) {
     std::cerr << "Generate Reports" << std::endl;
+  }
 
-  for (const auto& setName : symbolsToAnalyze.getSetNames()) {
+  for ( const auto& setName : symbolsToAnalyze.getSetNames() ) {
     branchInfoAvailable = coverageReader->getBranchInfoAvailable();
 
     Coverage::GenerateReports(
@@ -524,12 +562,10 @@ int covoar(
   if ( !explanations.empty() ) {
     std::string notFound;
 
-    notFound = outputDirectory;
-    notFound += "/";
-    notFound += "ExplanationsNotFound.txt";
-
-    if (verbose)
+    notFound = outputDirectory + "/ExplanationsNotFound.txt";
+    if ( verbose ) {
       std::cerr << "Writing Not Found Report (" << notFound<< ')' << std::endl;
+    }
 
     allExplanations.writeNotFound( notFound.c_str() );
   }
@@ -547,11 +583,10 @@ int covoar(
   return 0;
 }
 
-#define PrintableString(_s) \
-((!(_s)) ? "NOT SET" : (_s))
+#define PrintableString( _s ) \
+( ( !(_s) ) ? "NOT SET" : (_s) )
 
-static void
-fatal_signal( int signum )
+static void fatal_signal( int signum )
 {
   signal( signum, SIG_DFL );
 
@@ -564,69 +599,68 @@ fatal_signal( int signum )
   kill( getpid(), signum );
 }
 
-static void
-setup_signals( void )
+static void setup_signals()
 {
-  if ( signal( SIGINT, SIG_IGN ) != SIG_IGN )
+  if ( signal( SIGINT, SIG_IGN ) != SIG_IGN ) {
     signal( SIGINT, fatal_signal );
+  }
 #ifdef SIGHUP
-  if ( signal( SIGHUP, SIG_IGN ) != SIG_IGN )
+  if ( signal( SIGHUP, SIG_IGN ) != SIG_IGN ) {
     signal( SIGHUP, fatal_signal );
+  }
 #endif
-  if ( signal( SIGTERM, SIG_IGN ) != SIG_IGN )
+  if ( signal( SIGTERM, SIG_IGN ) != SIG_IGN ) {
     signal( SIGTERM, fatal_signal );
+  }
 #ifdef SIGPIPE
-  if ( signal( SIGPIPE, SIG_IGN ) != SIG_IGN )
+  if ( signal( SIGPIPE, SIG_IGN ) != SIG_IGN ) {
     signal( SIGPIPE, fatal_signal );
+  }
 #endif
 #ifdef SIGCHLD
   signal( SIGCHLD, SIG_DFL );
 #endif
 }
 
-void
-unhandled_exception (void)
+void unhandled_exception()
 {
   std::cerr << "error: exception handling error, please report" << std::endl;
-  exit (1);
+  exit( 1 );
 }
 
-int main(
-  int    argc,
-  char** argv
-)
+int main( int argc, char** argv )
 {
   std::string progname( argv[0] );
   int         ec = 0;
 
   setup_signals();
 
-  std::set_terminate(unhandled_exception);
+  std::set_terminate( unhandled_exception );
 
   try
   {
-    progname = rld::path::basename(argv[0]);
+    progname = rld::path::basename( argv[0] );
     covoar( argc, argv );
   }
-  catch ( option_error oe )
+  catch ( OptionError oe )
   {
     std::cerr << "error: missing option: " + oe << std::endl;
-    usage(progname);
+    usage( progname );
     ec = EXIT_FAILURE;
   }
-  catch (rld::error re)
+  catch ( rld::error re )
   {
     std::cerr << "error: "
               << re.where << ": " << re.what
               << std::endl;
     ec = 10;
   }
-  catch (std::exception e)
+  catch ( std::exception e )
   {
-    rld::output_std_exception(e, std::cerr);
+    rld::output_std_exception( e, std::cerr );
     ec = 11;
   }
-  catch (...)
+  catch ( ... )
   {
     /*
      * Helps to know if this happens.
-- 
1.8.3.1



More information about the devel mailing list