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

This is a clean up.
This commit is contained in:
Chris Johns 2018-04-28 18:12:46 +10:00
parent 3e187baeb9
commit 14c7f256c3

View File

@ -116,30 +116,26 @@ static void createBuildPath(Executables& executablesToAnalyze,
*/ */
void usage(const std::string& progname) void usage(const std::string& progname)
{ {
fprintf( std::cerr <<"Usage: " << progname
stderr, <<" [-v] -T TARGET -f FORMAT [-E EXPLANATIONS] -1 EXECUTABLE coverage1 ... coverageN" << std::endl
"Usage: %s [-v] -T TARGET -f FORMAT [-E EXPLANATIONS] -1 EXECUTABLE coverage1 ... coverageN\n" << "--OR--" << std::endl
"--OR--\n" << "Usage: " << progname
"Usage: %s [-v] -T TARGET -f FORMAT [-E EXPLANATIONS] -e EXE_EXTENSION -c COVERAGEFILE_EXTENSION EXECUTABLE1 ... EXECUTABLE2\n" << " [-v] -T TARGET -f FORMAT [-E EXPLANATIONS] -e EXE_EXTENSION -c COVERAGEFILE_EXTENSION EXECUTABLE1 ... EXECUTABLE2" << std::endl
"\n" << std::endl
" -v - verbose at initialization\n" << " -v - verbose at initialization" << std::endl
" -T TARGET - target name\n" << " -T TARGET - target name" << std::endl
" -f FORMAT - coverage file format " << " -f FORMAT - coverage file format (RTEMS, QEMU, TSIM or Skyeye)" << std::endl
"(RTEMS, QEMU, TSIM or Skyeye)\n" << " -E EXPLANATIONS - name of file with explanations" << std::endl
" -E EXPLANATIONS - name of file with explanations\n" << " -s SYMBOL_SET_FILE - path to the INI format symbol sets" << std::endl
" -s SYMBOL_SET_FILE - path to the INI format symbol sets\n" << " -1 EXECUTABLE - name of executable to get symbols from" << std::endl
" -1 EXECUTABLE - name of executable to get symbols from\n" << " -e EXE_EXTENSION - extension of the executables to analyze" << std::endl
" -e EXE_EXTENSION - extension of the executables to analyze\n" << " -c COVERAGEFILE_EXTENSION - extension of the coverage files to analyze" << std::endl
" -c COVERAGEFILE_EXTENSION - extension of the coverage files to analyze\n" << " -g GCNOS_LIST - name of file with list of *.gcno files" << std::endl
" -g GCNOS_LIST - name of file with list of *.gcno files\n" << " -p PROJECT_NAME - name of the project" << std::endl
" -p PROJECT_NAME - name of the project\n" << " -C ConfigurationFileName - name of configuration file" << std::endl
" -C ConfigurationFileName - name of configuration file\n" << " -O Output_Directory - name of output directory (default=." << std::endl
" -O Output_Directory - name of output directory (default=.\n" << " -d debug - disable cleaning of tempfile" << std::endl
" -d debug - disable cleaning of tempfiles." << std::endl;
"\n",
progname.c_str(),
progname.c_str()
);
} }
#define PrintableString(_s) \ #define PrintableString(_s) \
@ -282,21 +278,15 @@ int main(
// Ensure that the executable is readable. // Ensure that the executable is readable.
if (!FileIsReadable( singleExecutable )) { if (!FileIsReadable( singleExecutable )) {
fprintf( std::cerr << "warning: Unable to read executable: " << singleExecutable
stderr, << std::endl;
"WARNING: Unable to read executable %s\n",
singleExecutable
);
} else { } else {
for (int i = optind; i < argc; i++) { for (int i = optind; i < argc; i++) {
// Ensure that the coverage file is readable. // Ensure that the coverage file is readable.
if (!FileIsReadable( argv[i] )) { if (!FileIsReadable( argv[i] )) {
fprintf( std::cerr << "warning: Unable to read coverage file: " << argv[i]
stderr, << std::endl;
"WARNING: Unable to read coverage file %s\n",
argv[i]
);
} else { } else {
coverageFileNames.push_back( argv[i] ); coverageFileNames.push_back( argv[i] );
} }
@ -321,14 +311,9 @@ int main(
// If not invoked with a single executable, process the remaining // If not invoked with a single executable, process the remaining
// arguments as executables and derive the coverage file names. // 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. // Ensure that the executable is readable.
if (!FileIsReadable( argv[i] )) { if (!FileIsReadable( argv[i] )) {
fprintf( std::cerr << "warning: Unable to read executable: " << argv[i] << std::endl;
stderr,
"WARNING: Unable to read executable %s\n",
argv[i]
);
} else { } else {
coverageFileName = argv[i]; coverageFileName = argv[i];
coverageFileName.replace( coverageFileName.replace(
@ -338,11 +323,8 @@ int main(
); );
if (!FileIsReadable( coverageFileName.c_str() )) { if (!FileIsReadable( coverageFileName.c_str() )) {
fprintf( std::cerr << "warning: Unable to read coverage file: " << coverageFileName
stderr, << std::endl;
"WARNING: Unable to read coverage file %s\n",
coverageFileName.c_str()
);
} else { } else {
executableInfo = new Coverage::ExecutableInfo( argv[i] ); executableInfo = new Coverage::ExecutableInfo( argv[i] );
executablesToAnalyze.push_back( executableInfo ); executablesToAnalyze.push_back( executableInfo );
@ -354,9 +336,7 @@ int main(
// Ensure that there is at least one executable to process. // Ensure that there is at least one executable to process.
if (executablesToAnalyze.empty()) { if (executablesToAnalyze.empty()) {
fprintf( std::cerr << "error: No information to analyze" << std::endl;
stderr, "ERROR: No information to analyze\n"
);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@ -389,33 +369,20 @@ int main(
if (Verbose) { if (Verbose) {
if (singleExecutable) { if (singleExecutable) {
fprintf( std::cerr << "Processing a single executable and multiple coverage files"
stderr, << std::endl;
"Processing a single executable and multiple coverage files\n"
);
} else { } else {
fprintf( std::cerr << "Processing multiple executable/coverage file pairs" << std::endl;
stderr,
"Processing multiple executable/coverage file pairs\n"
);
} }
fprintf( stderr, "Coverage Format : %s\n", format ); std::cerr << "Coverage Format : " << format << std::endl
fprintf( stderr, "Target : %s\n", buildTarget.c_str() ); << "Target : " << buildTarget.c_str() << std::endl
fprintf( stderr, "\n" ); << std::endl;
// Process each executable/coverage file pair. // Process each executable/coverage file pair.
Executables::iterator eitr = executablesToAnalyze.begin(); Executables::iterator eitr = executablesToAnalyze.begin();
for (CoverageNames::iterator citr = coverageFileNames.begin(); for (const auto& cname : coverageFileNames) {
citr != coverageFileNames.end(); std::cerr << "Coverage file " << cname
citr++) { << " for executable: " << (*eitr)->getFileName() << std::endl;
fprintf(
stderr,
"Coverage file %s for executable %s\n",
(*citr).c_str(),
((*eitr)->getFileName()).c_str()
);
if (!singleExecutable) if (!singleExecutable)
eitr++; eitr++;
} }
@ -439,7 +406,7 @@ int main(
} }
if ( Verbose ) if ( Verbose )
std::cout << "Analyzing " << SymbolsToAnalyze->set.size() std::cerr << "Analyzing " << SymbolsToAnalyze->set.size()
<< " symbols" << std::endl; << " symbols" << std::endl;
// Create explanations. // Create explanations.
@ -450,7 +417,7 @@ int main(
// Create coverage map reader. // Create coverage map reader.
coverageReader = Coverage::CreateCoverageReader(coverageFormat); coverageReader = Coverage::CreateCoverageReader(coverageFormat);
if (!coverageReader) { if (!coverageReader) {
fprintf( stderr, "ERROR: Unable to create coverage file reader\n" ); std::cerr << "error: Unable to create coverage file reader" << std::endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@ -458,27 +425,18 @@ int main(
objdumpProcessor = new Coverage::ObjdumpProcessor(); objdumpProcessor = new Coverage::ObjdumpProcessor();
// Prepare each executable for analysis. // Prepare each executable for analysis.
for (Executables::iterator eitr = executablesToAnalyze.begin(); for (auto& exe : executablesToAnalyze) {
eitr != executablesToAnalyze.end(); if (Verbose)
eitr++) { std::cerr << "Extracting information from: " << exe->getFileName()
<< std::endl;
if (Verbose) {
fprintf(
stderr,
"Extracting information from %s\n",
((*eitr)->getFileName()).c_str()
);
}
// If a dynamic library was specified, determine the load address. // If a dynamic library was specified, determine the load address.
if (dynamicLibrary) { if (dynamicLibrary) {
(*eitr)->setLoadAddress( exe->setLoadAddress( objdumpProcessor->determineLoadAddress( exe ) );
objdumpProcessor->determineLoadAddress( *eitr )
);
} }
// Load the objdump for the symbols in this executable. // Load the objdump for the symbols in this executable.
objdumpProcessor->load( *eitr, objdumpFile, err ); objdumpProcessor->load( exe, objdumpFile, err );
} }
// //
@ -488,23 +446,20 @@ int main(
// Process each executable/coverage file pair. // Process each executable/coverage file pair.
Executables::iterator eitr = executablesToAnalyze.begin(); Executables::iterator eitr = executablesToAnalyze.begin();
for (const auto& cname : coverageFileNames) { for (const auto& cname : coverageFileNames) {
if (Verbose) { Coverage::ExecutableInfo* exe = *eitr;
fprintf( if (Verbose)
stderr, std::cerr << "Processing coverage file " << cname
"Processing coverage file %s for executable %s\n", << " for executable " << exe->getFileName()
cname.c_str(), << std::endl;
((*eitr)->getFileName()).c_str()
);
}
// Process its coverage file. // Process its coverage file.
coverageReader->processFile( cname.c_str(), *eitr ); coverageReader->processFile( cname.c_str(), exe );
// Merge each symbols coverage map into a unified coverage map. // Merge each symbols coverage map into a unified coverage map.
(*eitr)->mergeCoverage(); exe->mergeCoverage();
// DEBUG Print ExecutableInfo content // DEBUG Print ExecutableInfo content
//(*eitr)->dumpExecutableInfo(); //exe->dumpExecutableInfo();
if (!singleExecutable) { if (!singleExecutable) {
eitr++; eitr++;
@ -512,72 +467,69 @@ int main(
} }
// Do necessary preprocessing of uncovered ranges and branches // Do necessary preprocessing of uncovered ranges and branches
if (Verbose) { if (Verbose)
fprintf( stderr, "Preprocess uncovered ranges and branches\n" ); std::cerr << "Preprocess uncovered ranges and branches" << std::endl;
}
SymbolsToAnalyze->preprocess(); SymbolsToAnalyze->preprocess();
// //
// Generate Gcov reports // Generate Gcov reports
// //
if (Verbose) { if (gcnosFileName) {
fprintf( stderr, "Generating Gcov reports...\n"); if (Verbose)
} std::cerr << "Generating Gcov reports..." << std::endl;
gcnosFile = fopen ( gcnosFileName , "r" );
if ( !gcnosFile ) { gcnosFile = fopen ( gcnosFileName , "r" );
fprintf( stderr, "Unable to open %s\n", gcnosFileName );
}
else {
while ( fscanf( gcnosFile, "%s", inputBuffer ) != EOF) {
gcovFile = new Gcov::GcovData();
strcpy( gcnoFileName, inputBuffer );
if ( Verbose ) { if ( !gcnosFile )
fprintf( stderr, "Processing file: %s\n", gcnoFileName ); std::cerr << "Unable to open " << gcnosFileName << std::endl;
else {
while ( fscanf( gcnosFile, "%s", inputBuffer ) != EOF) {
gcovFile = new Gcov::GcovData();
strcpy( gcnoFileName, inputBuffer );
if ( Verbose )
std::cerr << "Processing file: " << gcnoFileName << std::endl;
if ( gcovFile->readGcnoFile( gcnoFileName ) ) {
// Those need to be in this order
gcovFile->processCounters();
gcovFile->writeReportFile();
gcovFile->writeGcdaFile();
gcovFile->writeGcovFile();
}
delete gcovFile;
} }
fclose( gcnosFile );
if ( gcovFile->readGcnoFile( gcnoFileName ) ) {
// Those need to be in this order
gcovFile->processCounters();
gcovFile->writeReportFile();
gcovFile->writeGcdaFile();
gcovFile->writeGcovFile();
}
delete gcovFile;
} }
fclose( gcnosFile );
} }
// Determine the uncovered ranges and branches. // Determine the uncovered ranges and branches.
if (Verbose) { if (Verbose)
fprintf( stderr, "Computing uncovered ranges and branches\n" ); std::cerr << "Computing uncovered ranges and branches" << std::endl;
}
SymbolsToAnalyze->computeUncovered(); SymbolsToAnalyze->computeUncovered();
// Calculate remainder of statistics. // Calculate remainder of statistics.
if (Verbose) { if (Verbose)
fprintf( stderr, "Calculate statistics\n" ); std::cerr << "Calculate statistics" << std::endl;
}
SymbolsToAnalyze->calculateStatistics(); SymbolsToAnalyze->calculateStatistics();
// Look up the source lines for any uncovered ranges and branches. // Look up the source lines for any uncovered ranges and branches.
if (Verbose) { if (Verbose)
fprintf( std::cerr << "Looking up source lines for uncovered ranges and branches"
stderr, "Looking up source lines for uncovered ranges and branches\n" << std::endl;
);
}
SymbolsToAnalyze->findSourceForUncovered(); SymbolsToAnalyze->findSourceForUncovered();
// //
// Report the coverage data. // Report the coverage data.
// //
if (Verbose) { if (Verbose)
fprintf( std::cerr << "Generate Reports" << std::endl;
stderr, "Generate Reports\n"
);
}
Coverage::GenerateReports(); Coverage::GenerateReports();
// Write explanations that were not found. // Write explanations that were not found.
@ -588,9 +540,9 @@ int main(
notFound += "/"; notFound += "/";
notFound += "ExplanationsNotFound.txt"; notFound += "ExplanationsNotFound.txt";
if (Verbose) { if (Verbose)
fprintf( stderr, "Writing Not Found Report (%s)\n", notFound.c_str() ); std::cerr << "Writing Not Found Report (" << notFound<< ')' << std::endl;
}
AllExplanations->writeNotFound( notFound.c_str() ); AllExplanations->writeNotFound( notFound.c_str() );
} }
@ -603,5 +555,6 @@ int main(
syms.override( "symbols_list" ); syms.override( "symbols_list" );
syms.keep(); syms.keep();
} }
return 0; return 0;
} }