Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / CTest / cmCTestCoverageHandler.h
blob4db092d30e9bda0cec5a744129c1380df4849df1
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmCTestCoverageHandler.h,v $
5 Language: C++
6 Date: $Date: 2009-03-11 16:03:47 $
7 Version: $Revision: 1.22 $
9 Copyright (c) 2002 Kitware, Inc. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
18 #ifndef cmCTestCoverageHandler_h
19 #define cmCTestCoverageHandler_h
22 #include "cmCTestGenericHandler.h"
23 #include "cmListFileCache.h"
25 #include <cmsys/RegularExpression.hxx>
27 class cmGeneratedFileStream;
28 class cmCTestCoverageHandlerContainer;
30 /** \class cmCTestCoverageHandler
31 * \brief A class that handles coverage computaiton for ctest
34 class cmCTestCoverageHandler : public cmCTestGenericHandler
36 public:
37 cmTypeMacro(cmCTestCoverageHandler, cmCTestGenericHandler);
40 * The main entry point for this class
42 int ProcessHandler();
44 cmCTestCoverageHandler();
46 virtual void Initialize();
48 /**
49 * This method is called when reading CTest custom file
51 void PopulateCustomVectors(cmMakefile *mf);
53 /** Report coverage only for sources with these labels. */
54 void SetLabelFilter(std::set<cmStdString> const& labels);
56 private:
57 bool ShouldIDoCoverage(const char* file, const char* srcDir,
58 const char* binDir);
59 void CleanCoverageLogFiles(std::ostream& log);
60 bool StartCoverageLogFile(cmGeneratedFileStream& ostr, int logFileCount);
61 void EndCoverageLogFile(cmGeneratedFileStream& ostr, int logFileCount);
63 //! Handle coverage using GCC's GCov
64 int HandleGCovCoverage(cmCTestCoverageHandlerContainer* cont);
65 void FindGCovFiles(std::vector<std::string>& files);
67 //! Handle coverage using Bullseye
68 int HandleBullseyeCoverage(cmCTestCoverageHandlerContainer* cont);
69 int RunBullseyeSourceSummary(cmCTestCoverageHandlerContainer* cont);
70 int RunBullseyeCoverageBranch(cmCTestCoverageHandlerContainer* cont,
71 std::set<cmStdString>& coveredFileNames,
72 std::vector<std::string>& files,
73 std::vector<std::string>& filesFullPath);
74 int RunBullseyeCommand(
75 cmCTestCoverageHandlerContainer* cont,
76 const char* cmd,
77 const char* arg,
78 std::string& outputFile);
79 bool ParseBullsEyeCovsrcLine(
80 std::string const& inputLine,
81 std::string& sourceFile,
82 int& functionsCalled,
83 int& totalFunctions,
84 int& percentFunction,
85 int& branchCovered,
86 int& totalBranches,
87 int& percentBranch);
88 bool GetNextInt(std::string const& inputLine,
89 std::string::size_type& pos,
90 int& value);
91 //! Handle Python coverage using Python's Trace.py
92 int HandleTracePyCoverage(cmCTestCoverageHandlerContainer* cont);
94 // Find the source file based on the source and build tree. This is used for
95 // Trace.py mode, since that one does not tell us where the source file is.
96 std::string FindFile(cmCTestCoverageHandlerContainer* cont,
97 std::string fileName);
99 struct cmCTestCoverage
101 cmCTestCoverage()
103 this->AbsolutePath = "";
104 this->FullPath = "";
105 this->Covered = false;
106 this->Tested = 0;
107 this->UnTested = 0;
108 this->Lines.clear();
109 this->Show = false;
111 cmCTestCoverage(const cmCTestCoverage& rhs) :
112 AbsolutePath(rhs.AbsolutePath),
113 FullPath(rhs.FullPath),
114 Covered(rhs.Covered),
115 Tested(rhs.Tested),
116 UnTested(rhs.UnTested),
117 Lines(rhs.Lines),
118 Show(rhs.Show)
121 cmCTestCoverage& operator=(const cmCTestCoverage& rhs)
123 this->AbsolutePath = rhs.AbsolutePath;
124 this->FullPath = rhs.FullPath;
125 this->Covered = rhs.Covered;
126 this->Tested = rhs.Tested;
127 this->UnTested = rhs.UnTested;
128 this->Lines = rhs.Lines;
129 this->Show = rhs.Show;
130 return *this;
132 std::string AbsolutePath;
133 std::string FullPath;
134 bool Covered;
135 int Tested;
136 int UnTested;
137 std::vector<int> Lines;
138 bool Show;
141 std::vector<cmStdString> CustomCoverageExclude;
142 std::vector<cmsys::RegularExpression> CustomCoverageExcludeRegex;
144 typedef std::map<std::string, cmCTestCoverage> CoverageMap;
146 // Map from source file to label ids.
147 class LabelSet: public std::set<int> {};
148 typedef std::map<cmStdString, LabelSet> LabelMapType;
149 LabelMapType SourceLabels;
150 LabelMapType TargetDirs;
152 // Map from label name to label id.
153 typedef std::map<cmStdString, int> LabelIdMapType;
154 LabelIdMapType LabelIdMap;
155 std::vector<std::string> Labels;
156 int GetLabelId(std::string const& label);
158 // Label reading and writing methods.
159 void LoadLabels();
160 void LoadLabels(const char* dir);
161 void WriteXMLLabels(std::ofstream& os, std::string const& source);
163 // Label-based filtering.
164 std::set<int> LabelFilter;
165 bool IntersectsFilter(LabelSet const& labels);
166 bool IsFilteredOut(std::string const& source);
169 #endif