--- tester/covoar/GcovData.cc | 198 +++++++++++++++++++++++++--------------------- 1 file changed, 106 insertions(+), 92 deletions(-)
diff --git a/tester/covoar/GcovData.cc b/tester/covoar/GcovData.cc index 59963b6..6b18fa3 100644 --- a/tester/covoar/GcovData.cc +++ b/tester/covoar/GcovData.cc @@ -77,44 +77,45 @@ namespace Gcov { return false; } - // Read and validate the gcnoPreamble (magic, version, timestamp) from the file + // Read and validate the gcnoPreamble (magic, version, timestamp) + // from the file status = readFilePreamble( &gcnoPreamble, gcovFile, GCNO_MAGIC ); - if ( status <= 0 ){ + if ( status <= 0 ) { std::cerr << "Unable to read " << gcnoFileName << std::endl; return false; } //Read all remaining frames from file - while( readFrame(gcovFile) ){} + while( readFrame( gcovFile ) ) {} return true; } - bool GcovData::writeGcdaFile () + bool GcovData::writeGcdaFile() { - gcov_preamble preamble; - gcov_frame_header header; - std::ofstream gcdaFile; - functions_iterator_t currentFunction; - arcs_iterator_t currentArc; - uint32_t buffer; - uint32_t countersFound; - uint32_t countersFoundSum; - uint64_t countersSum; - uint64_t countersMax; - uint64_t llBuffer[4096]; // TODO: Use common buffer - gcov_statistics objectStats; - gcov_statistics programStats; - long int bytes_before; + gcov_preamble preamble; + gcov_frame_header header; + std::ofstream gcdaFile; + functions_iterator_t currentFunction; + arcs_iterator_t currentArc; + uint32_t buffer; + uint32_t countersFound; + uint32_t countersFoundSum; + uint64_t countersSum; + uint64_t countersMax; + uint64_t llBuffer[4096]; // TODO: Use common buffer + gcov_statistics objectStats; + gcov_statistics programStats; + long int bytes_before; // Debug message //std::cerr << "Writing file: " << gcdaFileName << std::endl; // Lets clear counters sumators - countersSum = 0; - countersMax = 0; - countersFoundSum = 0; + countersSum = 0; + countersMax = 0; + countersFoundSum = 0; // Open the data file. gcdaFile.open( gcdaFileName ); @@ -124,9 +125,9 @@ namespace Gcov { } //Form preamble - preamble.magic = GCDA_MAGIC; - preamble.version = gcnoPreamble.version; - preamble.timestamp = gcnoPreamble.timestamp; + preamble.magic = GCDA_MAGIC; + preamble.version = gcnoPreamble.version; + preamble.timestamp = gcnoPreamble.timestamp; //Write preamble gcdaFile.write( (char *) &preamble , 4 * sizeof( preamble ) ); @@ -140,8 +141,7 @@ namespace Gcov { currentFunction = functions.begin(); currentFunction != functions.end(); currentFunction++ - ) - { + ) { //Write function announcement frame header (length always equals 2) header.tag = GCOV_TAG_FUNCTION; header.length = 2; @@ -170,7 +170,12 @@ namespace Gcov { // Determine how many counters there are // and store their counts in buffer countersFound = 0; - (*currentFunction).getCounters( llBuffer, countersFound, countersSum, countersMax ); + (*currentFunction).getCounters( + llBuffer, + countersFound, + countersSum, + countersMax + ); countersFoundSum += countersFound; //Write info about counters @@ -192,14 +197,14 @@ namespace Gcov { } // Prepare frame with object file statistics - header.tag = GCOV_TAG_OBJECT_SUMMARY; - header.length = 9; - objectStats.checksum = 0; // TODO: have no idea hov to calculates it :) + header.tag = GCOV_TAG_OBJECT_SUMMARY; + header.length = 9; + objectStats.checksum = 0; // TODO: have no idea hov to calculates it :) objectStats.counters = countersFoundSum; - objectStats.runs = 1; // We are lying for now, we have no means of figuring this out - objectStats.sum = countersSum; // Sum of all counters - objectStats.max = countersMax; // max value for counter on last run, we have no clue - objectStats.sumMax = countersMax; // we have no clue + objectStats.runs = 1; // // We are lying for now, we have no clue + objectStats.sum = countersSum; // Sum of all counters + objectStats.max = countersMax; // max value for counter on last run, we have no clue + objectStats.sumMax = countersMax; // we have no clue // Write data gcdaFile.write( (char *) &header, sizeof( header ) ); @@ -216,14 +221,14 @@ namespace Gcov { // Prepare frame with program statistics - header.tag = GCOV_TAG_PROGRAM_SUMMARY; - header.length = 9; - programStats.checksum = 0; // TODO: have no idea hov to calculate it :) + header.tag = GCOV_TAG_PROGRAM_SUMMARY; + header.length = 9; + programStats.checksum = 0; // TODO: have no idea hov to calculate it :) programStats.counters = countersFoundSum; - programStats.runs = 1; // We are lying for now, we have no clue - programStats.sum = countersSum; // Sum of all counters - programStats.max = countersMax; // max value for counter on last run, we have no clue - programStats.sumMax = countersMax; // we have no clue + programStats.runs = 1; // We are lying for now, we have no clue + programStats.sum = countersSum; // Sum of all counters + programStats.max = countersMax; // max value for counter on last run, we have no clue + programStats.sumMax = countersMax; // we have no clue // Write data gcdaFile.write( (char *) &header, sizeof( header ) ); @@ -243,22 +248,21 @@ namespace Gcov { bool GcovData::readFrame( std::ifstream& gcovFile ) { - gcov_frame_header header; - char buffer[512]; - char intBuffer[16384]; - uint32_t tempBlockId; - blocks_iterator_t tempBlockIterator; - int status; - - status = readFrameHeader( &header, gcovFile); - + gcov_frame_header header; + char buffer[512]; + char intBuffer[16384]; + uint32_t tempBlockId; + blocks_iterator_t tempBlockIterator; + int status; + + status = readFrameHeader( &header, gcovFile ); if ( status <= 0 ) { // Not printing error message because this // happenns at the end of each file return false; } - switch (header.tag){ + switch ( header.tag ) { case GCOV_TAG_FUNCTION: @@ -266,13 +270,13 @@ namespace Gcov { numberOfFunctions++; GcovFunctionData newFunction; - if ( !readFunctionFrame(header, gcovFile, &newFunction) ){ + if ( !readFunctionFrame( header, gcovFile, &newFunction ) ) { std::cerr << "Error while reading FUNCTION from gcov file..." << std::endl; return false; } - functions.push_back(newFunction); + functions.push_back( newFunction ); } break; @@ -289,8 +293,9 @@ namespace Gcov { return false; } - for( uint32_t i = 0; i < header.length; i++ ) - functions.back().addBlock(i, intBuffer[i], ""); + for( uint32_t i = 0; i < header.length; i++ ) { + functions.back().addBlock( i, intBuffer[i], "" ); + } break; @@ -301,8 +306,13 @@ namespace Gcov { return false; } - for ( int i = 1; i < (int) header.length; i += 2 ) - functions.back().addArc(intBuffer[0], intBuffer[i], intBuffer[i+1]); + for ( int i = 1; i < (int) header.length; i += 2 ) { + functions.back().addArc( + intBuffer[0], + intBuffer[i], + intBuffer[i+1] + ); + } break; @@ -318,9 +328,9 @@ namespace Gcov { header.length -= 2; // Find the right block - tempBlockIterator =functions.back().findBlockById(tempBlockId); + tempBlockIterator = functions.back().findBlockById( tempBlockId ); - header.length -= readString(buffer, gcovFile); + header.length -= readString( buffer, gcovFile ); functions.back().setBlockFileName( tempBlockIterator, buffer ); gcovFile.read( intBuffer, header.length ); @@ -328,11 +338,11 @@ namespace Gcov { std::cerr << "Error while reading LINES from gcov file..." << std::endl; return false; - } - - else - for (int i = 0; i < (int) (header.length - 2); i++) + } else { + for ( int i = 0; i < (int) (header.length - 2); i++ ) { functions.back().addBlockLine( tempBlockIterator, intBuffer[i] ); + } + } break; @@ -349,7 +359,7 @@ namespace Gcov { int GcovData::readString( char* buffer, std::ifstream& gcovFile ) { - int length; + int length; gcovFile.read( (char *) &length, sizeof( int ) ); if ( gcovFile.gcount() != sizeof( int ) ) { @@ -371,13 +381,13 @@ namespace Gcov { } int GcovData::readFrameHeader( - gcov_frame_header* header, - std::ifstream& gcovFile + gcov_frame_header* header, + std::ifstream& gcovFile ) { - int length; + int length; - length = sizeof(gcov_frame_header); + length = sizeof( gcov_frame_header ); gcovFile.read( (char *) header, length ); if ( gcovFile.gcount() != length ) { std::cerr << "ERROR: Unable to read frame header from gcov file" @@ -389,12 +399,12 @@ namespace Gcov { } int GcovData::readFilePreamble( - gcov_preamble* preamble, - std::ifstream& gcovFile, - uint32_t desiredMagic + gcov_preamble* preamble, + std::ifstream& gcovFile, + uint32_t desiredMagic ) { - int length; + int length; length = sizeof( gcov_preamble ); gcovFile.read( (char *) &preamble, 4 * sizeof( gcov_preamble ) ); @@ -414,33 +424,37 @@ namespace Gcov { } bool GcovData::readFunctionFrame( - gcov_frame_header header, - std::ifstream& gcovFile, - GcovFunctionData* function + gcov_frame_header header, + std::ifstream& gcovFile, + GcovFunctionData* function ) { - char buffer[512]; //TODO: use common buffers - char intBuffer[16384]; + char buffer[512]; + char intBuffer[16384]; gcovFile.read( (char *) &intBuffer, 8 ); if ( gcovFile.gcount() != 8 ) { std::cerr << "ERROR: Unable to read Function ID & checksum" << std::endl; return false; } + header.length -= 2; function->setId( intBuffer[0] ); function->setChecksum( intBuffer[1] ); header.length -= readString( buffer, gcovFile ); function->setFunctionName( buffer, symbolsToAnalyze_m ); + header.length -= readString( buffer, gcovFile ); function->setFileName( buffer ); + gcovFile.read( (char*) &intBuffer, 4 * header.length ); if (gcovFile.gcount() != 4 * header.length ) { std::cerr << "ERROR: Unable to read Function starting line number" << std::endl; return false; } + function->setFirstLineNumber( intBuffer[0] ); return true; @@ -448,9 +462,9 @@ namespace Gcov { bool GcovData::writeReportFile() { - functions_iterator_t currentFunction; - uint32_t i = 1; //iterator - std::ofstream textFile; + functions_iterator_t currentFunction; + uint32_t i = 1; //iterator + std::ofstream textFile; // Debug message // std::cerr << "Writing file: " << textFileName << std::endl; @@ -468,8 +482,7 @@ namespace Gcov { currentFunction = functions.begin(); currentFunction != functions.end(); currentFunction++ - ) - { + ) { (*currentFunction).printFunctionInfo( textFile, i ); (*currentFunction).printCoverageInfo( textFile, i ); i++; @@ -491,30 +504,31 @@ namespace Gcov { << std::endl << std::endl; } - void GcovData::writeGcovFile( ) + void GcovData::writeGcovFile() { //std::cerr << "Attempting to run gcov for: " << cFileName << std::endl; std::ostringstream command; - command << "( cd " << rld::path::dirname (cFileName) - << " && gcov " << rld::path::basename (cFileName) + + command << "( cd " << rld::path::dirname( cFileName ) + << " && gcov " << rld::path::basename( cFileName ) << " &>> gcov.log)"; //std::cerr << "> " << command << std::endl; - system( command.str ().c_str () ); + system( command.str().c_str() ); } - bool GcovData::processCounters( ) + bool GcovData::processCounters() { - functions_iterator_t currentFunction; - bool status = true; + functions_iterator_t currentFunction; + bool status = true; for ( currentFunction = functions.begin(); currentFunction != functions.end(); currentFunction++ - ) - { - if ( !(*currentFunction).processFunctionCounters( ) ) + ) { + if ( !(*currentFunction).processFunctionCounters() ) { status = false; + } } return status; -- 1.8.3.1 _______________________________________________ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel