1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmCTestCoverageHandler.h,v $
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
37 cmTypeMacro(cmCTestCoverageHandler
, cmCTestGenericHandler
);
40 * The main entry point for this class
44 cmCTestCoverageHandler();
46 virtual void Initialize();
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
);
57 bool ShouldIDoCoverage(const char* file
, const char* srcDir
,
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
,
78 std::string
& outputFile
);
79 bool ParseBullsEyeCovsrcLine(
80 std::string
const& inputLine
,
81 std::string
& sourceFile
,
88 bool GetNextInt(std::string
const& inputLine
,
89 std::string::size_type
& pos
,
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
103 this->AbsolutePath
= "";
105 this->Covered
= false;
111 cmCTestCoverage(const cmCTestCoverage
& rhs
) :
112 AbsolutePath(rhs
.AbsolutePath
),
113 FullPath(rhs
.FullPath
),
114 Covered(rhs
.Covered
),
116 UnTested(rhs
.UnTested
),
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
;
132 std::string AbsolutePath
;
133 std::string FullPath
;
137 std::vector
<int> Lines
;
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.
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
);