Changeset 14c7f25 in rtems-tools


Ignore:
Timestamp:
Apr 28, 2018, 8:12:46 AM (13 months ago)
Author:
Chris Johns <chrisj@…>
Branches:
master
Children:
feafa6f
Parents:
3e187ba
git-author:
Chris Johns <chrisj@…> (04/28/18 08:12:46)
git-committer:
Chris Johns <chrisj@…> (04/30/18 23:00:35)
Message:

tester/covoar: Remove the C part of main and convert to C++

This is a clean up.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tester/covoar/covoar.cc

    r3e187ba r14c7f25  
    117117void usage(const std::string& progname)
    118118{
    119   fprintf(
    120     stderr,
    121     "Usage: %s [-v] -T TARGET -f FORMAT [-E EXPLANATIONS] -1 EXECUTABLE coverage1 ... coverageN\n"
    122     "--OR--\n"
    123     "Usage: %s [-v] -T TARGET -f FORMAT [-E EXPLANATIONS] -e EXE_EXTENSION -c COVERAGEFILE_EXTENSION EXECUTABLE1 ... EXECUTABLE2\n"
    124     "\n"
    125     "  -v                        - verbose at initialization\n"
    126     "  -T TARGET                 - target name\n"
    127     "  -f FORMAT                 - coverage file format "
    128            "(RTEMS, QEMU, TSIM or Skyeye)\n"
    129     "  -E EXPLANATIONS           - name of file with explanations\n"
    130     "  -s SYMBOL_SET_FILE        - path to the INI format symbol sets\n"
    131     "  -1 EXECUTABLE             - name of executable to get symbols from\n"
    132     "  -e EXE_EXTENSION          - extension of the executables to analyze\n"
    133     "  -c COVERAGEFILE_EXTENSION - extension of the coverage files to analyze\n"
    134     "  -g GCNOS_LIST             - name of file with list of *.gcno files\n"
    135     "  -p PROJECT_NAME           - name of the project\n"
    136     "  -C ConfigurationFileName  - name of configuration file\n"
    137     "  -O Output_Directory       - name of output directory (default=.\n"
    138     "  -d debug                  - disable cleaning of tempfiles."
    139     "\n",
    140     progname.c_str(),
    141     progname.c_str()
    142   );
     119  std::cerr <<"Usage: " << progname
     120            <<" [-v] -T TARGET -f FORMAT [-E EXPLANATIONS] -1 EXECUTABLE coverage1 ... coverageN" << std::endl
     121            << "--OR--" << std::endl
     122            << "Usage: " << progname
     123            << " [-v] -T TARGET -f FORMAT [-E EXPLANATIONS] -e EXE_EXTENSION -c COVERAGEFILE_EXTENSION EXECUTABLE1 ... EXECUTABLE2" << std::endl
     124            << std::endl
     125            << "  -v                        - verbose at initialization" << std::endl
     126            << "  -T TARGET                 - target name" << std::endl
     127            << "  -f FORMAT                 - coverage file format (RTEMS, QEMU, TSIM or Skyeye)" << std::endl
     128            << "  -E EXPLANATIONS           - name of file with explanations" << std::endl
     129            << "  -s SYMBOL_SET_FILE        - path to the INI format symbol sets" << std::endl
     130            << "  -1 EXECUTABLE             - name of executable to get symbols from" << std::endl
     131            << "  -e EXE_EXTENSION          - extension of the executables to analyze" << std::endl
     132            << "  -c COVERAGEFILE_EXTENSION - extension of the coverage files to analyze" << std::endl
     133            << "  -g GCNOS_LIST             - name of file with list of *.gcno files" << std::endl
     134            << "  -p PROJECT_NAME           - name of the project" << std::endl
     135            << "  -C ConfigurationFileName  - name of configuration file" << std::endl
     136            << "  -O Output_Directory       - name of output directory (default=." << std::endl
     137            << "  -d debug                  - disable cleaning of tempfile" << std::endl
     138            << std::endl;
    143139}
    144140
     
    283279    // Ensure that the executable is readable.
    284280    if (!FileIsReadable( singleExecutable )) {
    285       fprintf(
    286         stderr,
    287         "WARNING: Unable to read executable %s\n",
    288         singleExecutable
    289       );
     281      std::cerr << "warning: Unable to read executable: " << singleExecutable
     282                << std::endl;
    290283    } else {
    291284
     
    293286        // Ensure that the coverage file is readable.
    294287        if (!FileIsReadable( argv[i] )) {
    295           fprintf(
    296             stderr,
    297             "WARNING: Unable to read coverage file %s\n",
    298             argv[i]
    299           );
     288          std::cerr << "warning: Unable to read coverage file: " << argv[i]
     289                    << std::endl;
    300290        } else {
    301291          coverageFileNames.push_back( argv[i] );
     
    322312    // arguments as executables and derive the coverage file names.
    323313    for (int i = optind; i < argc; i++) {
    324 
    325314      // Ensure that the executable is readable.
    326315      if (!FileIsReadable( argv[i] )) {
    327         fprintf(
    328           stderr,
    329           "WARNING: Unable to read executable %s\n",
    330           argv[i]
    331         );
     316        std::cerr << "warning: Unable to read executable: " << argv[i] << std::endl;
    332317      } else {
    333318        coverageFileName = argv[i];
     
    339324
    340325        if (!FileIsReadable( coverageFileName.c_str() )) {
    341           fprintf(
    342             stderr,
    343             "WARNING: Unable to read coverage file %s\n",
    344             coverageFileName.c_str()
    345           );
     326          std::cerr << "warning: Unable to read coverage file: " << coverageFileName
     327                    << std::endl;
    346328        } else {
    347329          executableInfo = new Coverage::ExecutableInfo( argv[i] );
     
    355337  // Ensure that there is at least one executable to process.
    356338  if (executablesToAnalyze.empty()) {
    357     fprintf(
    358       stderr, "ERROR: No information to analyze\n"
    359     );
     339    std::cerr << "error: No information to analyze" << std::endl;
    360340    exit(EXIT_FAILURE);
    361341  }
     
    390370  if (Verbose) {
    391371    if (singleExecutable) {
    392       fprintf(
    393         stderr,
    394         "Processing a single executable and multiple coverage files\n"
    395       );
     372      std::cerr << "Processing a single executable and multiple coverage files"
     373                << std::endl;
    396374    } else {
    397       fprintf(
    398         stderr,
    399         "Processing multiple executable/coverage file pairs\n"
    400       );
    401     }
    402     fprintf( stderr, "Coverage Format : %s\n", format );
    403     fprintf( stderr, "Target          : %s\n", buildTarget.c_str() );
    404     fprintf( stderr, "\n" );
     375      std::cerr << "Processing multiple executable/coverage file pairs" << std::endl;
     376    }
     377    std::cerr << "Coverage Format : " << format << std::endl
     378              << "Target          : " << buildTarget.c_str() << std::endl
     379              << std::endl;
    405380
    406381    // Process each executable/coverage file pair.
    407382    Executables::iterator eitr = executablesToAnalyze.begin();
    408     for (CoverageNames::iterator citr = coverageFileNames.begin();
    409          citr != coverageFileNames.end();
    410          citr++) {
    411 
    412       fprintf(
    413         stderr,
    414         "Coverage file %s for executable %s\n",
    415         (*citr).c_str(),
    416         ((*eitr)->getFileName()).c_str()
    417       );
    418 
     383    for (const auto& cname : coverageFileNames) {
     384      std::cerr << "Coverage file " << cname
     385                << " for executable: " << (*eitr)->getFileName() << std::endl;
    419386      if (!singleExecutable)
    420387        eitr++;
     
    440407
    441408  if ( Verbose )
    442     std::cout << "Analyzing " << SymbolsToAnalyze->set.size()
     409    std::cerr << "Analyzing " << SymbolsToAnalyze->set.size()
    443410              << " symbols" << std::endl;
    444411
     
    451418  coverageReader = Coverage::CreateCoverageReader(coverageFormat);
    452419  if (!coverageReader) {
    453     fprintf( stderr, "ERROR: Unable to create coverage file reader\n" );
     420    std::cerr << "error: Unable to create coverage file reader" << std::endl;
    454421    exit(EXIT_FAILURE);
    455422  }
     
    459426
    460427  // Prepare each executable for analysis.
    461   for (Executables::iterator eitr = executablesToAnalyze.begin();
    462        eitr != executablesToAnalyze.end();
    463        eitr++) {
    464 
    465     if (Verbose) {
    466       fprintf(
    467         stderr,
    468         "Extracting information from %s\n",
    469         ((*eitr)->getFileName()).c_str()
    470       );
    471     }
     428  for (auto& exe : executablesToAnalyze) {
     429    if (Verbose)
     430      std::cerr << "Extracting information from: " << exe->getFileName()
     431                << std::endl;
    472432
    473433    // If a dynamic library was specified, determine the load address.
    474434    if (dynamicLibrary) {
    475       (*eitr)->setLoadAddress(
    476         objdumpProcessor->determineLoadAddress( *eitr )
    477       );
     435      exe->setLoadAddress( objdumpProcessor->determineLoadAddress( exe ) );
    478436    }
    479437
    480438    // Load the objdump for the symbols in this executable.
    481     objdumpProcessor->load( *eitr, objdumpFile, err );
     439    objdumpProcessor->load( exe, objdumpFile, err );
    482440  }
    483441
     
    489447  Executables::iterator eitr = executablesToAnalyze.begin();
    490448  for (const auto& cname : coverageFileNames) {
    491     if (Verbose) {
    492       fprintf(
    493         stderr,
    494         "Processing coverage file %s for executable %s\n",
    495         cname.c_str(),
    496         ((*eitr)->getFileName()).c_str()
    497       );
    498     }
     449    Coverage::ExecutableInfo* exe = *eitr;
     450    if (Verbose)
     451      std::cerr << "Processing coverage file " << cname
     452                << " for executable " << exe->getFileName()
     453                << std::endl;
    499454
    500455    // Process its coverage file.
    501     coverageReader->processFile( cname.c_str(), *eitr );
     456    coverageReader->processFile( cname.c_str(), exe );
    502457
    503458    // Merge each symbols coverage map into a unified coverage map.
    504     (*eitr)->mergeCoverage();
     459    exe->mergeCoverage();
    505460
    506461    // DEBUG Print ExecutableInfo content
    507     //(*eitr)->dumpExecutableInfo();
     462    //exe->dumpExecutableInfo();
    508463
    509464    if (!singleExecutable) {
     
    513468
    514469  // Do necessary preprocessing of uncovered ranges and branches
    515   if (Verbose) {
    516     fprintf( stderr, "Preprocess uncovered ranges and branches\n" );
    517   }
     470  if (Verbose)
     471    std::cerr << "Preprocess uncovered ranges and branches" << std::endl;
     472
    518473  SymbolsToAnalyze->preprocess();
    519474
     
    521476  // Generate Gcov reports
    522477  //
    523   if (Verbose) {
    524     fprintf( stderr, "Generating Gcov reports...\n");
    525   }
    526   gcnosFile = fopen ( gcnosFileName , "r" );
    527 
    528   if ( !gcnosFile ) {
    529     fprintf( stderr, "Unable to open %s\n", gcnosFileName );
    530   }
    531   else {
    532     while ( fscanf( gcnosFile, "%s", inputBuffer ) != EOF) {
    533       gcovFile = new Gcov::GcovData();
    534       strcpy( gcnoFileName, inputBuffer );
    535 
    536       if ( Verbose ) {
    537         fprintf( stderr, "Processing file: %s\n", gcnoFileName );
     478  if (gcnosFileName) {
     479    if (Verbose)
     480      std::cerr << "Generating Gcov reports..." << std::endl;
     481
     482    gcnosFile = fopen ( gcnosFileName , "r" );
     483
     484    if ( !gcnosFile )
     485      std::cerr << "Unable to open " << gcnosFileName << std::endl;
     486    else {
     487      while ( fscanf( gcnosFile, "%s", inputBuffer ) != EOF) {
     488        gcovFile = new Gcov::GcovData();
     489        strcpy( gcnoFileName, inputBuffer );
     490
     491        if ( Verbose )
     492          std::cerr << "Processing file: " << gcnoFileName << std::endl;
     493
     494        if ( gcovFile->readGcnoFile( gcnoFileName ) ) {
     495          // Those need to be in this order
     496          gcovFile->processCounters();
     497          gcovFile->writeReportFile();
     498          gcovFile->writeGcdaFile();
     499          gcovFile->writeGcovFile();
     500        }
     501
     502        delete gcovFile;
    538503      }
    539 
    540       if ( gcovFile->readGcnoFile( gcnoFileName ) ) {
    541         // Those need to be in this order
    542         gcovFile->processCounters();
    543         gcovFile->writeReportFile();
    544         gcovFile->writeGcdaFile();
    545         gcovFile->writeGcovFile();
    546       }
    547 
    548       delete gcovFile;
    549     }
    550     fclose( gcnosFile );
     504      fclose( gcnosFile );
     505    }
    551506  }
    552507
    553508  // Determine the uncovered ranges and branches.
    554   if (Verbose) {
    555     fprintf( stderr, "Computing uncovered ranges and branches\n" );
    556   }
     509  if (Verbose)
     510    std::cerr << "Computing uncovered ranges and branches" << std::endl;
     511
    557512  SymbolsToAnalyze->computeUncovered();
    558513
    559514  // Calculate remainder of statistics.
    560   if (Verbose) {
    561     fprintf( stderr, "Calculate statistics\n" );
    562   }
     515  if (Verbose)
     516    std::cerr << "Calculate statistics" << std::endl;
     517
    563518  SymbolsToAnalyze->calculateStatistics();
    564519
    565520  // Look up the source lines for any uncovered ranges and branches.
    566   if (Verbose) {
    567     fprintf(
    568       stderr, "Looking up source lines for uncovered ranges and branches\n"
    569     );
    570   }
     521  if (Verbose)
     522    std::cerr << "Looking up source lines for uncovered ranges and branches"
     523              << std::endl;
     524
    571525  SymbolsToAnalyze->findSourceForUncovered();
    572526
     
    574528  // Report the coverage data.
    575529  //
    576   if (Verbose) {
    577     fprintf(
    578       stderr, "Generate Reports\n"
    579     );
    580   }
     530  if (Verbose)
     531    std::cerr << "Generate Reports" << std::endl;
     532
    581533  Coverage::GenerateReports();
    582534
     
    589541    notFound += "ExplanationsNotFound.txt";
    590542
    591     if (Verbose) {
    592       fprintf( stderr, "Writing Not Found Report (%s)\n", notFound.c_str() );
    593     }
     543    if (Verbose)
     544      std::cerr << "Writing Not Found Report (" << notFound<< ')' << std::endl;
     545
    594546    AllExplanations->writeNotFound( notFound.c_str() );
    595547  }
     
    604556    syms.keep();
    605557  }
     558
    606559  return 0;
    607560}
Note: See TracChangeset for help on using the changeset viewer.