cmake/Source/CTest/cmCTestCoverageHandler.h

151 lines
5.1 KiB
C
Raw Normal View History

2016-10-30 18:24:19 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
2021-09-14 00:13:48 +02:00
#pragma once
2018-01-26 17:06:56 +01:00
#include "cmConfigure.h" // IWYU pragma: keep
2016-07-09 11:21:54 +02:00
2016-10-30 18:24:19 +01:00
#include <iosfwd>
#include <map>
#include <set>
#include <string>
#include <vector>
2020-02-01 23:06:01 +01:00
#include "cmsys/RegularExpression.hxx"
#include "cmCTestGenericHandler.h"
class cmGeneratedFileStream;
2016-10-30 18:24:19 +01:00
class cmMakefile;
2015-08-17 11:37:30 +02:00
class cmXMLWriter;
2016-10-30 18:24:19 +01:00
2010-06-23 01:18:35 +03:00
class cmCTestCoverageHandlerContainer
{
public:
int Error;
std::string SourceDir;
std::string BinaryDir;
2020-02-01 23:06:01 +01:00
using SingleFileCoverageVector = std::vector<int>;
using TotalCoverageMap = std::map<std::string, SingleFileCoverageVector>;
2010-06-23 01:18:35 +03:00
TotalCoverageMap TotalCoverage;
std::ostream* OFS;
2015-08-17 11:37:30 +02:00
bool Quiet;
2010-06-23 01:18:35 +03:00
};
/** \class cmCTestCoverageHandler
2015-08-17 11:37:30 +02:00
* \brief A class that handles coverage computation for ctest
*
*/
class cmCTestCoverageHandler : public cmCTestGenericHandler
{
public:
2020-02-01 23:06:01 +01:00
using Superclass = cmCTestGenericHandler;
/*
* The main entry point for this class
*/
2018-01-26 17:06:56 +01:00
int ProcessHandler() override;
cmCTestCoverageHandler();
2018-01-26 17:06:56 +01:00
void Initialize() override;
/**
* This method is called when reading CTest custom file
*/
2018-01-26 17:06:56 +01:00
void PopulateCustomVectors(cmMakefile* mf) override;
2009-10-04 10:30:41 +03:00
/** Report coverage only for sources with these labels. */
2015-04-27 22:25:09 +02:00
void SetLabelFilter(std::set<std::string> const& labels);
2009-10-04 10:30:41 +03:00
private:
2018-01-26 17:06:56 +01:00
bool ShouldIDoCoverage(std::string const& file, std::string const& srcDir,
std::string const& binDir);
2009-10-04 10:30:41 +03:00
void CleanCoverageLogFiles(std::ostream& log);
bool StartCoverageLogFile(cmGeneratedFileStream& ostr, int logFileCount);
void EndCoverageLogFile(cmGeneratedFileStream& ostr, int logFileCount);
2015-08-17 11:37:30 +02:00
void StartCoverageLogXML(cmXMLWriter& xml);
void EndCoverageLogXML(cmXMLWriter& xml);
//! Handle coverage using GCC's GCov
int HandleGCovCoverage(cmCTestCoverageHandlerContainer* cont);
2009-10-04 10:30:41 +03:00
void FindGCovFiles(std::vector<std::string>& files);
2015-04-27 22:25:09 +02:00
//! Handle coverage using Intel's LCov
int HandleLCovCoverage(cmCTestCoverageHandlerContainer* cont);
2015-11-17 17:22:37 +01:00
bool FindLCovFiles(std::vector<std::string>& files);
2015-04-27 22:25:09 +02:00
2010-06-23 01:18:35 +03:00
//! Handle coverage using xdebug php coverage
int HandlePHPCoverage(cmCTestCoverageHandlerContainer* cont);
2014-08-03 19:52:23 +02:00
//! Handle coverage for Python with coverage.py
2015-04-27 22:25:09 +02:00
int HandleCoberturaCoverage(cmCTestCoverageHandlerContainer* cont);
2014-08-03 19:52:23 +02:00
2012-06-27 20:52:58 +03:00
//! Handle coverage for mumps
int HandleMumpsCoverage(cmCTestCoverageHandlerContainer* cont);
2010-06-23 01:18:35 +03:00
2015-04-27 22:25:09 +02:00
//! Handle coverage for Jacoco
int HandleJacocoCoverage(cmCTestCoverageHandlerContainer* cont);
//! Handle coverage for Delphi (Pascal)
int HandleDelphiCoverage(cmCTestCoverageHandlerContainer* cont);
//! Handle coverage for Jacoco
int HandleBlanketJSCoverage(cmCTestCoverageHandlerContainer* cont);
2016-07-09 11:21:54 +02:00
//! Handle coverage using Bullseye
int HandleBullseyeCoverage(cmCTestCoverageHandlerContainer* cont);
int RunBullseyeSourceSummary(cmCTestCoverageHandlerContainer* cont);
int RunBullseyeCoverageBranch(cmCTestCoverageHandlerContainer* cont,
2015-04-27 22:25:09 +02:00
std::set<std::string>& coveredFileNames,
std::vector<std::string>& files,
std::vector<std::string>& filesFullPath);
2010-06-23 01:18:35 +03:00
2016-07-09 11:21:54 +02:00
int RunBullseyeCommand(cmCTestCoverageHandlerContainer* cont,
const char* cmd, const char* arg,
std::string& outputFile);
bool ParseBullsEyeCovsrcLine(std::string const& inputLine,
std::string& sourceFile, int& functionsCalled,
int& totalFunctions, int& percentFunction,
int& branchCovered, int& totalBranches,
int& percentBranch);
bool GetNextInt(std::string const& inputLine, std::string::size_type& pos,
int& value);
//! Handle Python coverage using Python's Trace.py
int HandleTracePyCoverage(cmCTestCoverageHandlerContainer* cont);
// Find the source file based on the source and build tree. This is used for
// Trace.py mode, since that one does not tell us where the source file is.
std::string FindFile(cmCTestCoverageHandlerContainer* cont,
2016-07-09 11:21:54 +02:00
std::string const& fileName);
2010-06-23 01:18:35 +03:00
std::set<std::string> FindUncoveredFiles(
cmCTestCoverageHandlerContainer* cont);
2015-04-27 22:25:09 +02:00
std::vector<std::string> CustomCoverageExclude;
std::vector<cmsys::RegularExpression> CustomCoverageExcludeRegex;
2015-04-27 22:25:09 +02:00
std::vector<std::string> ExtraCoverageGlobs;
2009-10-04 10:30:41 +03:00
// Map from source file to label ids.
2016-07-09 11:21:54 +02:00
class LabelSet : public std::set<int>
{
};
2020-02-01 23:06:01 +01:00
using LabelMapType = std::map<std::string, LabelSet>;
2009-10-04 10:30:41 +03:00
LabelMapType SourceLabels;
LabelMapType TargetDirs;
// Map from label name to label id.
2020-02-01 23:06:01 +01:00
using LabelIdMapType = std::map<std::string, int>;
2009-10-04 10:30:41 +03:00
LabelIdMapType LabelIdMap;
std::vector<std::string> Labels;
int GetLabelId(std::string const& label);
// Label reading and writing methods.
void LoadLabels();
void LoadLabels(const char* dir);
2015-08-17 11:37:30 +02:00
void WriteXMLLabels(cmXMLWriter& xml, std::string const& source);
2009-10-04 10:30:41 +03:00
// Label-based filtering.
std::set<int> LabelFilter;
bool IntersectsFilter(LabelSet const& labels);
bool IsFilteredOut(std::string const& source);
};