diff options
author | Ryan Long <ryan.long@oarcorp.com> | 2021-07-13 14:05:02 -0400 |
---|---|---|
committer | Joel Sherrill <joel@rtems.org> | 2021-07-19 09:41:34 -0500 |
commit | f0f7b8b051c57e208700e0fa567681008de65af7 (patch) | |
tree | a2a8237bd1d6f0c8978050c9627eecda84c96473 | |
parent | Reports: Convert to C++ (diff) | |
download | rtems-tools-f0f7b8b051c57e208700e0fa567681008de65af7.tar.bz2 |
ReportsBase.cc: Fix formatting
-rw-r--r-- | tester/covoar/ReportsBase.cc | 305 |
1 files changed, 156 insertions, 149 deletions
diff --git a/tester/covoar/ReportsBase.cc b/tester/covoar/ReportsBase.cc index cc3810b..cd65c53 100644 --- a/tester/covoar/ReportsBase.cc +++ b/tester/covoar/ReportsBase.cc @@ -24,8 +24,8 @@ namespace Coverage { ReportsBase::ReportsBase( time_t timestamp, const std::string& symbolSetName ): - reportExtension_m(""), - symbolSetName_m(symbolSetName), + reportExtension_m( "" ), + symbolSetName_m( symbolSetName ), timestamp_m( timestamp ) { } @@ -40,8 +40,8 @@ void ReportsBase::OpenFile( std::ofstream& aFile ) { - int sc; - std::string file; + int sc; + std::string file; std::string symbolSetOutputDirectory; rld::path::path_join( @@ -54,9 +54,9 @@ void ReportsBase::OpenFile( #ifdef _WIN32 sc = _mkdir( symbolSetOutputDirectory ); #else - sc = mkdir( symbolSetOutputDirectory.c_str(),0755 ); + sc = mkdir( symbolSetOutputDirectory.c_str(), 0755 ); #endif - if ( (sc == -1) && (errno != EEXIST) ) { + if ( ( sc == -1 ) && ( errno != EEXIST ) ) { throw rld::error( "Unable to create output directory", "ReportsBase::OpenFile" @@ -65,7 +65,7 @@ void ReportsBase::OpenFile( } file = symbolSetOutputDirectory; - rld::path::path_join(file, fileName, file); + rld::path::path_join( file, fileName, file ); // Open the file. aFile.open( file ); @@ -74,9 +74,7 @@ void ReportsBase::OpenFile( } } -void ReportsBase::WriteIndex( - const std::string& fileName -) +void ReportsBase::WriteIndex( const std::string& fileName ) { } @@ -130,64 +128,49 @@ void ReportsBase::OpenSymbolSummaryFile( OpenFile(fileName, symbolSetName_m, aFile); } -void ReportsBase::CloseFile( - std::ofstream& aFile -) +void ReportsBase::CloseFile( std::ofstream& aFile ) { aFile.close(); } -void ReportsBase::CloseAnnotatedFile( - std::ofstream& aFile -) +void ReportsBase::CloseAnnotatedFile( std::ofstream& aFile ) { CloseFile( aFile ); } -void ReportsBase::CloseBranchFile( - std::ofstream& aFile, - bool hasBranches -) +void ReportsBase::CloseBranchFile( std::ofstream& aFile, bool hasBranches ) { CloseFile( aFile ); } -void ReportsBase::CloseCoverageFile( - std::ofstream& aFile -) +void ReportsBase::CloseCoverageFile( std::ofstream& aFile ) { CloseFile( aFile ); } -void ReportsBase::CloseNoRangeFile( - std::ofstream& aFile -) +void ReportsBase::CloseNoRangeFile( std::ofstream& aFile ) { CloseFile( aFile ); } -void ReportsBase::CloseSizeFile( - std::ofstream& aFile -) +void ReportsBase::CloseSizeFile( std::ofstream& aFile ) { CloseFile( aFile ); } -void ReportsBase::CloseSymbolSummaryFile( - std::ofstream& aFile -) +void ReportsBase::CloseSymbolSummaryFile( std::ofstream& aFile ) { CloseFile( aFile ); } -std::string expand_tabs(const std::string& in) { +std::string expand_tabs( const std::string& in ) { std::string expanded = ""; int i = 0; - for (char c : in) { - if (c == '\t') { - int num_tabs = 4 - (i % 4); - expanded.append(num_tabs, ' '); + for ( char c : in ) { + if ( c == '\t' ) { + int num_tabs = 4 - ( i % 4 ); + expanded.append( num_tabs, ' ' ); i += num_tabs; } else { expanded += c; @@ -201,9 +184,8 @@ std::string expand_tabs(const std::string& in) { /* * Write annotated report */ -void ReportsBase::WriteAnnotatedReport( - const std::string& fileName -) { +void ReportsBase::WriteAnnotatedReport( const std::string& fileName ) +{ std::ofstream aFile; Coverage::CoverageRanges* theBranches; Coverage::CoverageRanges* theRanges; @@ -211,8 +193,8 @@ void ReportsBase::WriteAnnotatedReport( uint32_t bAddress = 0; AnnotatedLineState_t state; - OpenAnnotatedFile(fileName, aFile); - if (!aFile.is_open()) { + OpenAnnotatedFile( fileName, aFile ); + if ( !aFile.is_open() ) { throw rld::error( "Unable to open " + fileName, "ReportsBase::WriteAnnotatedReport" @@ -221,48 +203,60 @@ void ReportsBase::WriteAnnotatedReport( } // Process uncovered branches for each symbol. - const std::vector<std::string>& symbols = SymbolsToAnalyze->getSymbolsForSet(symbolSetName_m); + const std::vector<std::string>& symbols = + SymbolsToAnalyze->getSymbolsForSet( symbolSetName_m ); - for (const auto& symbol : symbols) { - const SymbolInformation& info = SymbolsToAnalyze->allSymbols().at(symbol); + for ( const auto& symbol : symbols ) { + const SymbolInformation& info = + SymbolsToAnalyze->allSymbols().at( symbol ); // If uncoveredRanges and uncoveredBranches don't exist, then the // symbol was never referenced by any executable. Just skip it. - if ((info.uncoveredRanges == NULL) && - (info.uncoveredBranches == NULL)) + if ( + ( info.uncoveredRanges == NULL ) && + ( info.uncoveredBranches == NULL ) + ) { continue; + } // If uncoveredRanges and uncoveredBranches are empty, then everything // must have been covered for this symbol. Just skip it. - if ((info.uncoveredRanges->set.empty()) && - (info.uncoveredBranches->set.empty())) + if ( + ( info.uncoveredRanges->set.empty() ) && + ( info.uncoveredBranches->set.empty() ) + ) { continue; + } theCoverageMap = info.unifiedCoverageMap; - bAddress = info.baseAddress; - theRanges = info.uncoveredRanges; - theBranches = info.uncoveredBranches; + bAddress = info.baseAddress; + theRanges = info.uncoveredRanges; + theBranches = info.uncoveredBranches; // Add annotations to each line where necessary AnnotatedStart( aFile ); - for (const auto& instruction : info.instructions) { - uint32_t id = 0; - std::string annotation = ""; - std::string line; - const std::size_t LINE_LENGTH = 150; - std::string textLine = ""; - std::stringstream ss; + for ( const auto& instruction : info.instructions ) { + uint32_t id = 0; + std::string annotation = ""; + std::string line; + const std::size_t LINE_LENGTH = 150; + std::string textLine = ""; + std::stringstream ss; state = A_SOURCE; if ( instruction.isInstruction ) { - if (!theCoverageMap->wasExecuted( instruction.address - bAddress )){ + if ( !theCoverageMap->wasExecuted( instruction.address - bAddress ) ) { annotation = "<== NOT EXECUTED"; state = A_NEVER_EXECUTED; id = theRanges->getId( instruction.address ); - } else if (theCoverageMap->isBranch( instruction.address - bAddress )) { + } else if ( + theCoverageMap->isBranch( instruction.address - bAddress ) + ) { id = theBranches->getId( instruction.address ); - if (theCoverageMap->wasAlwaysTaken( instruction.address - bAddress )){ + if ( + theCoverageMap->wasAlwaysTaken( instruction.address - bAddress ) + ){ annotation = "<== ALWAYS TAKEN"; state = A_BRANCH_TAKEN; } else if ( @@ -276,7 +270,7 @@ void ReportsBase::WriteAnnotatedReport( } } - std::string textLineWithoutTabs = expand_tabs(instruction.line); + std::string textLineWithoutTabs = expand_tabs( instruction.line ); ss << std::left << std::setw( 90 ) << textLineWithoutTabs.c_str(); @@ -285,7 +279,7 @@ void ReportsBase::WriteAnnotatedReport( line = textLine + annotation; - PutAnnotatedLine( aFile, state, line, id); + PutAnnotatedLine( aFile, state, line, id ); } AnnotatedEnd( aFile ); @@ -297,37 +291,44 @@ void ReportsBase::WriteAnnotatedReport( /* * Write branch report */ -void ReportsBase::WriteBranchReport( - const std::string& fileName -) { +void ReportsBase::WriteBranchReport( const std::string& fileName ) +{ std::ofstream report; Coverage::CoverageRanges* theBranches; unsigned int count; bool hasBranches = true; - if ((SymbolsToAnalyze->getNumberBranchesFound(symbolSetName_m) == 0) || - (BranchInfoAvailable == false) ) + if ( + ( SymbolsToAnalyze->getNumberBranchesFound( symbolSetName_m ) == 0 ) || + ( BranchInfoAvailable == false ) + ) { hasBranches = false; + } // Open the branch report file OpenBranchFile( fileName, hasBranches, report ); - if (!report.is_open()) + if ( !report.is_open() ) { return; + } // If no branches were found then branch coverage is not supported - if ((SymbolsToAnalyze->getNumberBranchesFound(symbolSetName_m) != 0) && - (BranchInfoAvailable == true) ) { + if ( + ( SymbolsToAnalyze->getNumberBranchesFound( symbolSetName_m ) != 0 ) && + ( BranchInfoAvailable == true ) + ) { // Process uncovered branches for each symbol in the set. - const std::vector<std::string>& symbols = SymbolsToAnalyze->getSymbolsForSet(symbolSetName_m); + const std::vector<std::string>& symbols = + SymbolsToAnalyze->getSymbolsForSet( symbolSetName_m ); count = 0; - for (const auto& symbol : symbols) { - const SymbolInformation& info = SymbolsToAnalyze->allSymbols().at(symbol); + for ( const auto& symbol : symbols ) { + const SymbolInformation& info = + SymbolsToAnalyze->allSymbols().at( symbol ); theBranches = info.uncoveredBranches; - if (theBranches && !theBranches->set.empty()) { - for (const auto& range : theBranches->set) { + if ( theBranches && !theBranches->set.empty() ) { + for ( const auto& range : theBranches->set ) { count++; PutBranchEntry( report, count, symbol, info, range ); } @@ -341,9 +342,7 @@ void ReportsBase::WriteBranchReport( /* * Write coverage report */ -void ReportsBase::WriteCoverageReport( - const std::string& fileName -) +void ReportsBase::WriteCoverageReport( const std::string& fileName ) { std::ofstream report; Coverage::CoverageRanges* theRanges; @@ -353,7 +352,7 @@ void ReportsBase::WriteCoverageReport( // Open special file that captures NoRange informaiton NoRangeName = "no_range_"; - NoRangeName += fileName; + NoRangeName += fileName; OpenNoRangeFile( NoRangeName, NoRangeFile ); if ( !NoRangeFile.is_open() ) { return; @@ -366,11 +365,13 @@ void ReportsBase::WriteCoverageReport( } // Process uncovered ranges for each symbol. - const std::vector<std::string>& symbols = SymbolsToAnalyze->getSymbolsForSet(symbolSetName_m); + const std::vector<std::string>& symbols = + SymbolsToAnalyze->getSymbolsForSet( symbolSetName_m ); count = 0; - for (const auto& symbol : symbols) { - const SymbolInformation& info = SymbolsToAnalyze->allSymbols().at(symbol); + for ( const auto& symbol : symbols ) { + const SymbolInformation& info = + SymbolsToAnalyze->allSymbols().at( symbol ); theRanges = info.uncoveredRanges; @@ -378,11 +379,11 @@ void ReportsBase::WriteCoverageReport( // referenced by any executable. There may be a problem with the // desired symbols list or with the executables so put something // in the report. - if (theRanges == NULL) { + if ( theRanges == NULL ) { putCoverageNoRange( report, NoRangeFile, count, symbol ); count++; - } else if (!theRanges->set.empty()) { - for (const auto& range : theRanges->set) { + } else if ( !theRanges->set.empty() ) { + for ( const auto& range : theRanges->set ) { PutCoverageLine( report, count, symbol, info, range ); count++; } @@ -391,15 +392,12 @@ void ReportsBase::WriteCoverageReport( CloseNoRangeFile( NoRangeFile ); CloseCoverageFile( report ); - } /* * Write size report */ -void ReportsBase::WriteSizeReport( - const std::string& fileName -) +void ReportsBase::WriteSizeReport( const std::string& fileName ) { std::ofstream report; Coverage::CoverageRanges* theRanges; @@ -412,16 +410,18 @@ void ReportsBase::WriteSizeReport( } // Process uncovered ranges for each symbol. - const std::vector<std::string>& symbols = SymbolsToAnalyze->getSymbolsForSet(symbolSetName_m); + const std::vector<std::string>& symbols = + SymbolsToAnalyze->getSymbolsForSet( symbolSetName_m ); count = 0; - for (const auto& symbol : symbols) { - const SymbolInformation& info = SymbolsToAnalyze->allSymbols().at(symbol); + for ( const auto& symbol : symbols ) { + const SymbolInformation& info = + SymbolsToAnalyze->allSymbols().at( symbol ); theRanges = info.uncoveredRanges; - if (theRanges && !theRanges->set.empty()) { - for (const auto& range : theRanges->set) { + if ( theRanges && !theRanges->set.empty() ) { + for ( const auto& range : theRanges->set ) { PutSizeLine( report, count, symbol, range ); count++; } @@ -431,12 +431,10 @@ void ReportsBase::WriteSizeReport( CloseSizeFile( report ); } -void ReportsBase::WriteSymbolSummaryReport( - const std::string& fileName -) +void ReportsBase::WriteSymbolSummaryReport( const std::string& fileName ) { - std::ofstream report; - unsigned int count; + std::ofstream report; + unsigned int count; // Open the report file. OpenSymbolSummaryFile( fileName , report ); @@ -445,11 +443,13 @@ void ReportsBase::WriteSymbolSummaryReport( } // Process each symbol. - const std::vector<std::string>& symbols = SymbolsToAnalyze->getSymbolsForSet(symbolSetName_m); + const std::vector<std::string>& symbols = + SymbolsToAnalyze->getSymbolsForSet( symbolSetName_m ); count = 0; - for (const auto& symbol : symbols) { - const SymbolInformation& info = SymbolsToAnalyze->allSymbols().at(symbol); + for ( const auto& symbol : symbols ) { + const SymbolInformation& info = + SymbolsToAnalyze->allSymbols().at( symbol ); PutSymbolSummaryLine( report, count, symbol, info ); count++; @@ -464,14 +464,14 @@ void ReportsBase::WriteSummaryReport( ) { // Calculate coverage statistics and output results. - uint32_t a; - uint32_t endAddress; - uint32_t notExecuted = 0; - double percentage; - double percentageBranches; - Coverage::CoverageMapBase* theCoverageMap; - uint32_t totalBytes = 0; - std::ofstream report; + uint32_t a; + uint32_t endAddress; + uint32_t notExecuted = 0; + double percentage; + double percentageBranches; + Coverage::CoverageMapBase* theCoverageMap; + uint32_t totalBytes = 0; + std::ofstream report; // Open the report file. OpenFile( fileName, symbolSetName, report ); @@ -480,21 +480,22 @@ void ReportsBase::WriteSummaryReport( } // Look at each symbol. - const std::vector<std::string>& symbols = SymbolsToAnalyze->getSymbolsForSet(symbolSetName); + const std::vector<std::string>& symbols = + SymbolsToAnalyze->getSymbolsForSet( symbolSetName ); - for (const auto& symbol : symbols) { - SymbolInformation info = SymbolsToAnalyze->allSymbols().at(symbol); + for ( const auto& symbol : symbols ) { + SymbolInformation info = SymbolsToAnalyze->allSymbols().at( symbol ); // If the symbol's unified coverage map exists, scan through it // and count bytes. theCoverageMap = info.unifiedCoverageMap; - if (theCoverageMap) { + if ( theCoverageMap ) { endAddress = info.stats.sizeInBytes - 1; - for (a = 0; a <= endAddress; a++) { + for ( a = 0; a <= endAddress; a++ ) { totalBytes++; - if (!theCoverageMap->wasExecuted( a )) + if ( !theCoverageMap->wasExecuted( a ) ) notExecuted++; } } @@ -507,12 +508,12 @@ void ReportsBase::WriteSummaryReport( } percentageBranches = (double) ( - SymbolsToAnalyze->getNumberBranchesAlwaysTaken(symbolSetName) + - SymbolsToAnalyze->getNumberBranchesNeverTaken(symbolSetName) + - (SymbolsToAnalyze->getNumberBranchesNotExecuted(symbolSetName) * 2) + SymbolsToAnalyze->getNumberBranchesAlwaysTaken( symbolSetName ) + + SymbolsToAnalyze->getNumberBranchesNeverTaken( symbolSetName ) + + ( SymbolsToAnalyze->getNumberBranchesNotExecuted( symbolSetName ) * 2 ) ); percentageBranches /= - (double) SymbolsToAnalyze->getNumberBranchesFound(symbolSetName) * 2; + (double) SymbolsToAnalyze->getNumberBranchesFound( symbolSetName ) * 2; percentageBranches *= 100.0; report << "Bytes Analyzed : " << totalBytes << std::endl @@ -527,28 +528,29 @@ void ReportsBase::WriteSummaryReport( << SymbolsToAnalyze->getNumberUncoveredRanges( symbolSetName ) << std::endl << std::endl; - if ((SymbolsToAnalyze->getNumberBranchesFound(symbolSetName) == 0) || - (BranchInfoAvailable == false) ) { + if ( + ( SymbolsToAnalyze->getNumberBranchesFound( symbolSetName ) == 0 ) || + ( BranchInfoAvailable == false ) + ) { report << "No branch information available" << std::endl; } else { - report << "Total conditional branches found : " << SymbolsToAnalyze->getNumberBranchesFound( symbolSetName ) << std::endl << "Total branch paths found : " << SymbolsToAnalyze->getNumberBranchesFound( symbolSetName ) * 2 << std::endl << "Uncovered branch paths found : " - << SymbolsToAnalyze->getNumberBranchesAlwaysTaken(symbolSetName) + - SymbolsToAnalyze->getNumberBranchesNeverTaken(symbolSetName) + - (SymbolsToAnalyze->getNumberBranchesNotExecuted(symbolSetName) * 2) + << SymbolsToAnalyze->getNumberBranchesAlwaysTaken( symbolSetName ) + + SymbolsToAnalyze->getNumberBranchesNeverTaken( symbolSetName ) + + ( SymbolsToAnalyze->getNumberBranchesNotExecuted( symbolSetName ) * 2 ) << std::endl << " " - << SymbolsToAnalyze->getNumberBranchesAlwaysTaken(symbolSetName) + << SymbolsToAnalyze->getNumberBranchesAlwaysTaken( symbolSetName ) << " branches always taken" << std::endl << " " - << SymbolsToAnalyze->getNumberBranchesNeverTaken(symbolSetName) + << SymbolsToAnalyze->getNumberBranchesNeverTaken( symbolSetName ) << " branches never taken" << std::endl << " " - << SymbolsToAnalyze->getNumberBranchesNotExecuted(symbolSetName) * 2 + << SymbolsToAnalyze->getNumberBranchesNotExecuted( symbolSetName ) * 2 << " branch paths not executed" << std::endl << "Percentage branch paths covered : " - << std::fixed << std::setprecision(2) << std::setw(4) + << std::fixed << std::setprecision( 2 ) << std::setw( 4 ) << 100.0 - percentageBranches << std::endl; } @@ -556,7 +558,7 @@ void ReportsBase::WriteSummaryReport( CloseFile( report ); } -void GenerateReports(const std::string& symbolSetName) +void GenerateReports( const std::string& symbolSetName ) { typedef std::list<ReportsBase *> reportList_t; @@ -564,51 +566,56 @@ void GenerateReports(const std::string& symbolSetName) reportList_t::iterator ritr; std::string reportName; ReportsBase* reports; - - time_t timestamp; + time_t timestamp; - timestamp = time(NULL); /* get current cal time */ - reports = new ReportsText(timestamp, symbolSetName); - reportList.push_back(reports); - reports = new ReportsHtml(timestamp, symbolSetName); - reportList.push_back(reports); + timestamp = time( NULL ); /* get current cal time */ + reports = new ReportsText( timestamp, symbolSetName ); + reportList.push_back( reports ); + reports = new ReportsHtml( timestamp, symbolSetName ); + reportList.push_back( reports ); - for (ritr = reportList.begin(); ritr != reportList.end(); ritr++ ) { + for ( ritr = reportList.begin(); ritr != reportList.end(); ritr++ ) { reports = *ritr; reportName = "index" + reports->ReportExtension(); - if (Verbose) + if ( Verbose ) { std::cerr << "Generate " << reportName << std::endl; + } reports->WriteIndex( reportName ); reportName = "annotated" + reports->ReportExtension(); - if (Verbose) + if ( Verbose ) { std::cerr << "Generate " << reportName << std::endl; + } reports->WriteAnnotatedReport( reportName ); reportName = "branch" + reports->ReportExtension(); - if (Verbose) + if ( Verbose ) { std::cerr << "Generate " << reportName << std::endl; + } reports->WriteBranchReport( reportName ); reportName = "uncovered" + reports->ReportExtension(); - if (Verbose) + if ( Verbose ) { std::cerr << "Generate " << reportName << std::endl; + } reports->WriteCoverageReport( reportName ); reportName = "sizes" + reports->ReportExtension(); - if (Verbose) - std::cerr << "Generate " << reportName << std::endl; + if ( Verbose ) { + std::cerr << "Generate " << reportName << std::endl; + } reports->WriteSizeReport( reportName ); reportName = "symbolSummary" + reports->ReportExtension(); - if (Verbose) + if ( Verbose ) { std::cerr << "Generate " << reportName << std::endl; + } reports->WriteSymbolSummaryReport( reportName ); } - for (ritr = reportList.begin(); ritr != reportList.end(); ritr++ ) { + for ( ritr = reportList.begin(); ritr != reportList.end(); ritr++ ) { reports = *ritr; delete reports; } |