123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651 |
- #ifndef cmCTest_h
- #define cmCTest_h
- #include "cmConfigure.h"
- #include "cmDuration.h"
- #include "cmProcessOutput.h"
- #include "cmsys/String.hxx"
- #include <chrono>
- #include <map>
- #include <set>
- #include <sstream>
- #include <string>
- #include <time.h>
- #include <vector>
- class cmCTestGenericHandler;
- class cmCTestStartCommand;
- class cmGeneratedFileStream;
- class cmMakefile;
- class cmXMLWriter;
- class cmCTest
- {
- friend class cmCTestRunTest;
- friend class cmCTestMultiProcessHandler;
- public:
- typedef cmProcessOutput::Encoding Encoding;
-
- enum Part
- {
- PartStart,
- PartUpdate,
- PartConfigure,
- PartBuild,
- PartTest,
- PartCoverage,
- PartMemCheck,
- PartSubmit,
- PartNotes,
- PartExtraFiles,
- PartUpload,
- PartCount
- };
-
- struct PartInfo
- {
- PartInfo()
- : Enabled(false)
- {
- }
- void SetName(const std::string& name) { this->Name = name; }
- const std::string& GetName() const { return this->Name; }
- void Enable() { this->Enabled = true; }
- operator bool() const { return this->Enabled; }
- std::vector<std::string> SubmitFiles;
- private:
- bool Enabled;
- std::string Name;
- };
- #ifdef CMAKE_BUILD_WITH_CMAKE
- enum HTTPMethod
- {
- HTTP_GET,
- HTTP_POST,
- HTTP_PUT
- };
-
- static int HTTPRequest(std::string url, HTTPMethod method,
- std::string& response, std::string const& fields = "",
- std::string const& putFile = "", int timeout = 0);
- #endif
-
- Part GetPartFromName(const char* name);
- typedef std::vector<cmsys::String> VectorOfStrings;
- typedef std::set<std::string> SetOfStrings;
-
- int Run(std::vector<std::string>&, std::string* output = nullptr);
-
- bool InitializeFromCommand(cmCTestStartCommand* command);
- void Finalize();
-
- int ProcessSteps();
-
- struct tm* GetNightlyTime(std::string const& str, bool tomorrowtag);
-
- bool GetTomorrowTag() { return this->TomorrowTag; }
-
- int TestDirectory(bool memcheck);
-
- std::string const& GetConfigType();
- cmDuration GetTimeOut() { return this->TimeOut; }
- void SetTimeOut(cmDuration t) { this->TimeOut = t; }
- cmDuration GetGlobalTimeout() { return this->GlobalTimeout; }
-
- int GetParallelLevel() { return this->ParallelLevel; }
- void SetParallelLevel(int);
- unsigned long GetTestLoad() { return this->TestLoad; }
- void SetTestLoad(unsigned long);
-
- bool CTestFileExists(const std::string& filename);
- bool AddIfExists(Part part, const char* file);
-
- bool SetTest(const char*, bool report = true);
-
- void SetTestModel(int mode);
- int GetTestModel() { return this->TestModel; }
- std::string GetTestModelString();
- static int GetTestModelFromString(const char* str);
- static std::string CleanString(const std::string& str);
- std::string GetCTestConfiguration(const std::string& name);
- void SetCTestConfiguration(const char* name, const char* value,
- bool suppress = false);
- void EmptyCTestConfiguration();
-
- cmCTest();
- ~cmCTest();
-
- void SetNotesFiles(const char* notes);
- void PopulateCustomVector(cmMakefile* mf, const std::string& definition,
- std::vector<std::string>& vec);
- void PopulateCustomInteger(cmMakefile* mf, const std::string& def, int& val);
-
- std::string CurrentTime();
-
- std::string Base64GzipEncodeFile(std::string const& file);
-
- std::string Base64EncodeFile(std::string const& file);
-
- cmDuration GetRemainingTimeAllowed();
- static cmDuration MaxDuration();
-
- bool OpenOutputFile(const std::string& path, const std::string& name,
- cmGeneratedFileStream& stream, bool compress = false);
-
- bool GetShowOnly();
- bool ShouldUseHTTP10() { return this->UseHTTP10; }
- bool ShouldPrintLabels() { return this->PrintLabels; }
- bool ShouldCompressTestOutput();
- bool CompressString(std::string& str);
- std::chrono::system_clock::time_point GetStopTime()
- {
- return this->StopTime;
- }
- void SetStopTime(std::string const& time);
-
- std::string GetScheduleType() { return this->ScheduleType; }
- void SetScheduleType(std::string const& type) { this->ScheduleType = type; }
-
- int GetMaxTestNameWidth() const;
- void SetMaxTestNameWidth(int w) { this->MaxTestNameWidth = w; }
-
- bool RunCommand(std::vector<std::string> const& args, std::string* stdOut,
- std::string* stdErr, int* retVal = nullptr,
- const char* dir = nullptr,
- cmDuration timeout = cmDuration::zero(),
- Encoding encoding = cmProcessOutput::Auto);
-
- static std::string SafeBuildIdField(const std::string& value);
-
- void StartXML(cmXMLWriter& xml, bool append);
-
- void EndXML(cmXMLWriter& xml);
-
- int RunMakeCommand(const char* command, std::string& output, int* retVal,
- const char* dir, cmDuration timeout, std::ostream& ofs,
- Encoding encoding = cmProcessOutput::Auto);
-
- std::string GetCurrentTag();
-
- std::string GetBinaryDir();
-
- std::string GetShortPathToFile(const char* fname);
- enum
- {
- EXPERIMENTAL,
- NIGHTLY,
- CONTINUOUS
- };
-
- enum
- {
- UPDATE_ERRORS = 0x01,
- CONFIGURE_ERRORS = 0x02,
- BUILD_ERRORS = 0x04,
- TEST_ERRORS = 0x08,
- MEMORY_ERRORS = 0x10,
- COVERAGE_ERRORS = 0x20,
- SUBMIT_ERRORS = 0x40
- };
-
- bool GetProduceXML();
- void SetProduceXML(bool v);
-
- int RunTest(std::vector<const char*> args, std::string* output, int* retVal,
- std::ostream* logfile, cmDuration testTimeOut,
- std::vector<std::string>* environment,
- Encoding encoding = cmProcessOutput::Auto);
-
- int ExecuteHandler(const char* handler);
-
- cmCTestGenericHandler* GetHandler(const char* handler);
- cmCTestGenericHandler* GetInitializedHandler(const char* handler);
-
- bool SetCTestConfigurationFromCMakeVariable(cmMakefile* mf,
- const char* dconfig,
- const std::string& cmake_var,
- bool suppress = false);
-
- static std::string MakeURLSafe(const std::string&);
-
- static std::string DecodeURL(const std::string&);
-
- void SetSuppressUpdatingCTestConfiguration(bool val)
- {
- this->SuppressUpdatingCTestConfiguration = val;
- }
-
- void AddCTestConfigurationOverwrite(const std::string& encstr);
-
- int GenerateNotesFile(const VectorOfStrings& files);
-
- bool SubmitExtraFiles(const char* files);
- bool SubmitExtraFiles(const VectorOfStrings& files);
-
- void SetOutputLogFileName(const char* name);
-
- void SetConfigType(const char* ct);
-
- enum
- {
- DEBUG = 0,
- OUTPUT,
- HANDLER_OUTPUT,
- HANDLER_PROGRESS_OUTPUT,
- HANDLER_VERBOSE_OUTPUT,
- WARNING,
- ERROR_MESSAGE,
- OTHER
- };
-
- void Log(int logType, const char* file, int line, const char* msg,
- bool suppress = false);
-
- int GetDartVersion() { return this->DartVersion; }
- int GetDropSiteCDash() { return this->DropSiteCDash; }
-
- void AddSubmitFile(Part part, const char* name);
- std::vector<std::string> const& GetSubmitFiles(Part part)
- {
- return this->Parts[part].SubmitFiles;
- }
- void ClearSubmitFiles(Part part) { this->Parts[part].SubmitFiles.clear(); }
-
- int ReadCustomConfigurationFileTree(const char* dir, cmMakefile* mf);
- std::vector<std::string>& GetInitialCommandLineArguments()
- {
- return this->InitialCommandLineArguments;
- }
-
- void SetSpecificTrack(const char* track);
- const char* GetSpecificTrack();
- void SetFailover(bool failover) { this->Failover = failover; }
- bool GetFailover() { return this->Failover; }
- bool GetVerbose() { return this->Verbose; }
- bool GetExtraVerbose() { return this->ExtraVerbose; }
-
- void SetStreams(std::ostream* out, std::ostream* err)
- {
- this->StreamOut = out;
- this->StreamErr = err;
- }
- void AddSiteProperties(cmXMLWriter& xml);
- bool GetLabelSummary() { return this->LabelSummary; }
- bool GetSubprojectSummary() { return this->SubprojectSummary; }
- std::string GetCostDataFile();
- const std::map<std::string, std::string>& GetDefinitions()
- {
- return this->Definitions;
- }
-
- int GetTestRepeat() { return this->RepeatTests; }
-
- bool GetRepeatUntilFail() { return this->RepeatUntilFail; }
- void GenerateSubprojectsOutput(cmXMLWriter& xml);
- std::vector<std::string> GetLabelsForSubprojects();
- void SetRunCurrentScript(bool value);
- private:
- int RepeatTests;
- bool RepeatUntilFail;
- std::string ConfigType;
- std::string ScheduleType;
- std::chrono::system_clock::time_point StopTime;
- bool Verbose;
- bool ExtraVerbose;
- bool ProduceXML;
- bool LabelSummary;
- bool SubprojectSummary;
- bool UseHTTP10;
- bool PrintLabels;
- bool Failover;
- bool ForceNewCTestProcess;
- bool RunConfigurationScript;
- int GenerateNotesFile(const char* files);
-
- typedef std::map<std::string, cmCTestGenericHandler*> t_TestingHandlers;
- t_TestingHandlers TestingHandlers;
- bool ShowOnly;
-
- typedef std::map<std::string, std::string> CTestConfigurationMap;
-
-
-
-
- CTestConfigurationMap CTestConfiguration;
- CTestConfigurationMap CTestConfigurationOverwrites;
- PartInfo Parts[PartCount];
- typedef std::map<std::string, Part> PartMapType;
- PartMapType PartMap;
- std::string CurrentTag;
- bool TomorrowTag;
- int TestModel;
- std::string SpecificTrack;
- cmDuration TimeOut;
- cmDuration GlobalTimeout;
- int MaxTestNameWidth;
- int ParallelLevel;
- bool ParallelLevelSetInCli;
- unsigned long TestLoad;
- int CompatibilityMode;
-
- std::string BinaryDir;
- std::string NotesFiles;
- bool InteractiveDebugMode;
- bool ShortDateFormat;
- bool CompressXMLFiles;
- bool CompressTestOutput;
- void InitStreams();
- std::ostream* StreamOut;
- std::ostream* StreamErr;
- void BlockTestErrorDiagnostics();
-
- int Initialize(const char* binary_dir, cmCTestStartCommand* command);
-
- bool AddTestsForDashboardType(std::string& targ);
-
- void ErrorMessageUnknownDashDValue(std::string& val);
-
- bool AddVariableDefinition(const std::string& arg);
-
- bool HandleCommandLineArguments(size_t& i, std::vector<std::string>& args,
- std::string& errormsg);
-
- void HandleScriptArguments(size_t& i, std::vector<std::string>& args,
- bool& SRArgumentSpecified);
-
- bool UpdateCTestConfiguration();
-
- int GenerateCTestNotesOutput(cmXMLWriter& xml, const VectorOfStrings& files);
-
- bool CheckArgument(const std::string& arg, const char* varg1,
- const char* varg2 = nullptr);
-
- void OutputTestErrors(std::vector<char> const& process_output);
-
- bool HandleTestActionArgument(const char* ctestExec, size_t& i,
- const std::vector<std::string>& args);
-
- bool HandleTestModelArgument(const char* ctestExec, size_t& i,
- const std::vector<std::string>& args);
- int RunCMakeAndTest(std::string* output);
- int ExecuteTests();
- bool SuppressUpdatingCTestConfiguration;
- bool Debug;
- bool ShowLineNumbers;
- bool Quiet;
- int DartVersion;
- bool DropSiteCDash;
- std::vector<std::string> InitialCommandLineArguments;
- int SubmitIndex;
- cmGeneratedFileStream* OutputLogFile;
- int OutputLogFileLastTag;
- bool OutputTestOutputOnTestFailure;
- std::map<std::string, std::string> Definitions;
- };
- class cmCTestLogWrite
- {
- public:
- cmCTestLogWrite(const char* data, size_t length)
- : Data(data)
- , Length(length)
- {
- }
- const char* Data;
- size_t Length;
- };
- inline std::ostream& operator<<(std::ostream& os, const cmCTestLogWrite& c)
- {
- if (!c.Length) {
- return os;
- }
- os.write(c.Data, c.Length);
- os.flush();
- return os;
- }
- #define cmCTestLog(ctSelf, logType, msg) \
- do { \
- std::ostringstream cmCTestLog_msg; \
- cmCTestLog_msg << msg; \
- (ctSelf)->Log(cmCTest::logType, __FILE__, __LINE__, \
- cmCTestLog_msg.str().c_str()); \
- } while (false)
- #define cmCTestOptionalLog(ctSelf, logType, msg, suppress) \
- do { \
- std::ostringstream cmCTestLog_msg; \
- cmCTestLog_msg << msg; \
- (ctSelf)->Log(cmCTest::logType, __FILE__, __LINE__, \
- cmCTestLog_msg.str().c_str(), suppress); \
- } while (false)
- #endif
|