bool makeCoverageStats() { bool success = false; SharedFile covHeaderFile; OovString covHeaderFn = CoverageHeaderReader::getFn( Project::getCoverageSourceDirectory()); eOpenStatus stat = covHeaderFile.open(covHeaderFn, M_ReadShared, OE_Binary); if(stat == OS_Opened) { CoverageHeaderReader covHeaderReader; OovStatus status = covHeaderReader.read(covHeaderFile); if(status.needReport()) { status.report(ET_Error, "Unable to read coverage header"); } int headerInstrLines = covHeaderReader.getNumInstrumentedLines(); if(headerInstrLines > 0) { success = true; FilePath covCountsFn(Project::getCoverageProjectDirectory(), FP_Dir); covCountsFn.appendDir("out-Debug"); static char const covCountsFnStr[] = "OovCoverageCounts.txt"; covCountsFn.appendFile(covCountsFnStr); CoverageCountsReader covCounts; covCounts.read(covCountsFn); int covInstrLines = covCounts.getNumInstrumentedLines(); if(headerInstrLines == covInstrLines) { makeCoverageStats(covHeaderReader, covCounts); updateCovSourceCounts(covHeaderReader, covCounts); } else { fprintf(stderr, "Number of OovCoverage.h lines %d don't match %s lines %d\n", headerInstrLines, covCountsFnStr, covInstrLines); } } else { fprintf(stderr, "No lines are instrumented in %s\n", covHeaderFn.getStr()); } } else { fprintf(stderr, "Unable to open file %s\n", covHeaderFn.getStr()); } return success; }
bool CppFileContents::write(OovStringRef const fn) { SimpleFile file; eOpenStatus openStat = file.open(fn, M_WriteExclusiveTrunc, OE_Binary); OovStatus status(openStat == OS_Opened, SC_File); if(status.ok()) { OovString includeCov = "#include \"OovCoverage.h\""; appendLineEnding(includeCov); updateMemory(); status = file.write(includeCov.c_str(), includeCov.length()); } if(status.ok()) { status = file.write(mFileContents.data(), mFileContents.size()); } if(!status.ok()) { OovString str = "Unable to write %s "; str += fn; str += "\n"; status.report(ET_Error, str.getStr()); } return status.ok(); }
/// Copy a single source file and make a comment that contains the hit count /// for each instrumented line. static void updateCovSourceCounts(OovStringRef const relSrcFn, std::vector<int> &counts) { FilePath srcFn(Project::getCoverageSourceDirectory(), FP_Dir); srcFn.appendFile(relSrcFn); FilePath dstFn(Project::getCoverageProjectDirectory(), FP_Dir); dstFn.appendFile(relSrcFn); File srcFile; OovStatus status = srcFile.open(srcFn, "r"); if(status.ok()) { status = FileEnsurePathExists(dstFn); if(status.ok()) { File dstFile; status = dstFile.open(dstFn, "w"); if(status.ok()) { char buf[1000]; size_t instrCount = 0; while(srcFile.getString(buf, sizeof(buf), status)) { if(strstr(buf, "COV_IN(")) { if(instrCount < counts.size()) { OovString countStr = " // "; countStr.appendInt(counts[instrCount]); OovString newStr = buf; size_t pos = newStr.find('\n'); newStr.insert(pos, countStr); if(newStr.length() < sizeof(buf)-1) { strcpy(buf, newStr.getStr()); } } instrCount++; } status = dstFile.putString(buf); if(!status.ok()) { break; } } } } } if(status.needReport()) { OovString err = "Unable to transfer coverage "; err += srcFn; err += " "; err += dstFn; status.report(ET_Error, err); } }
bool FileIsFileOnDisk(OovStringRef const path, bool &success) { OovString tempPath = path; FilePathRemovePathSep(tempPath, tempPath.size()-1); struct OovStat32 statval; int statRet = OovStat32(tempPath.getStr(), &statval); // Indicate there is an error only if the error is not ENOENT. success = ((statRet == 0) || (errno == ENOENT)); // Only indicate the file exists if there was no error, and it is a file. return((statRet == 0) && !S_ISDIR(statval.st_mode)); }
void Editor::setStyle() { GtkCssProvider *provider = gtk_css_provider_get_default(); GdkDisplay *display = gdk_display_get_default(); GdkScreen *screen = gdk_display_get_default_screen(display); OovString path = Project::getBinDirectory(); path += "OovEdit.css"; GError *err = 0; gtk_css_provider_load_from_path(provider, path.getStr(), &err); gtk_style_context_add_provider_for_screen (screen, GTK_STYLE_PROVIDER(provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); g_object_unref(provider); }
bool FileEnsurePathExists(OovStringRef const path) { bool success = true; // Walk up the tree to find a base that exists. FilePath fp(path, FP_File); size_t pos = fp.getPosEndDir(); while(pos != 0) { fp.discardTail(pos); bool ignoredSuccess = true; if(fp.isDirOnDisk(ignoredSuccess)) break; else pos = fp.getPosLeftPathSep(pos, RP_RetPosFailure); } while(pos != std::string::npos && pos != 0 && success) { pos = findPathSep(path, pos); if(pos != std::string::npos) { OovString partPath = path; partPath.resize(pos); if(!FileIsDirOnDisk(partPath, success)) { #ifdef __linux__ success = (mkdir(partPath.getStr(), 0x1FF) == 0); // 0777 #else success = (_mkdir(partPath.getStr()) == 0); #endif } pos++; } } return success; }
/// Make a stats file that contains the percentage of instrumented /// lines that have been executed for each source file. static void makeCoverageStats(CoverageHeaderReader const &covHeader, CoverageCountsReader const &covCounts) { FilePath statFn(Project::getCoverageProjectDirectory(), FP_Dir); statFn.appendFile("oovCovStats.txt"); File statFile; OovStatus status = statFile.open(statFn, "w"); if(status.ok()) { size_t countIndex = 0; std::vector<int> const &counts = covCounts.getCounts(); for(auto const &mapItem : covHeader.getMap()) { int count = mapItem.second; int hits = 0; for(int i=0; i<count; i++) { if(countIndex < counts.size()) { if(counts[countIndex++]) { hits++; } } } int percent = 0; if(count > 0) { percent = (hits * 100) / count; } else { percent = 100; } OovString covFn = makeOrigCovFn(mapItem.first); fprintf(statFile.getFp(), "%s %d\n", covFn.getStr(), percent); } } if(status.needReport()) { OovString err = "Unable to open file "; err += statFn; status.report(ET_Error, err); } }
void ComponentTypesFile::coerceParentComponents(OovStringRef const compName) { OovString name = compName; while(1) { size_t pos = name.rfind('/'); if(pos != std::string::npos) { name.erase(pos); } if(compName != name.getStr()) { setComponentType(name, CT_Unknown); } if(pos == std::string::npos) { break; } } }
bool CppFileContents::read(char const *fn) { SimpleFile file; eOpenStatus openStat = file.open(fn, M_ReadWriteExclusive, OE_Binary); OovStatus status(openStat == OS_Opened, SC_File); if(status.ok()) { int size = file.getSize(); mFileContents.resize(size); int actual = 0; status = file.read(mFileContents.data(), size, actual); } if(!status.ok()) { OovString str = "Unable to read %s "; str += fn; str += "\n"; status.report(ET_Error, str.getStr()); } return status.ok(); }