diff options
author | Kyle Edwards <kyle.edwards@kitware.com> | 2019-06-27 20:38:19 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2019-10-02 13:33:54 (GMT) |
commit | bb4a1410592342a824b1dd755b7ca8897deac65c (patch) | |
tree | 9131b8f3b5e531a9fb5471a0b77e9d0b121f5f00 /Source/CTest | |
parent | a1f78a481c8cbda1f0c8503c4d661c3c3ddf00a6 (diff) | |
download | CMake-bb4a1410592342a824b1dd755b7ca8897deac65c.zip CMake-bb4a1410592342a824b1dd755b7ca8897deac65c.tar.gz CMake-bb4a1410592342a824b1dd755b7ca8897deac65c.tar.bz2 |
CTest: Add lexer for PROCESSES property
Diffstat (limited to 'Source/CTest')
-rw-r--r-- | Source/CTest/cmCTestProcessesLexerHelper.cxx | 55 | ||||
-rw-r--r-- | Source/CTest/cmCTestProcessesLexerHelper.h | 44 | ||||
-rw-r--r-- | Source/CTest/cmCTestTestHandler.cxx | 28 | ||||
-rw-r--r-- | Source/CTest/cmCTestTestHandler.h | 15 |
4 files changed, 142 insertions, 0 deletions
diff --git a/Source/CTest/cmCTestProcessesLexerHelper.cxx b/Source/CTest/cmCTestProcessesLexerHelper.cxx new file mode 100644 index 0000000..797164b --- /dev/null +++ b/Source/CTest/cmCTestProcessesLexerHelper.cxx @@ -0,0 +1,55 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#include "cmCTestProcessesLexerHelper.h" + +#include "cmCTestProcessesLexer.h" +#include "cmCTestTestHandler.h" + +cmCTestProcessesLexerHelper::cmCTestProcessesLexerHelper( + std::vector<std::vector<cmCTestTestHandler::cmCTestTestResourceRequirement>>& + output) + : Output(output) +{ +} + +bool cmCTestProcessesLexerHelper::ParseString(const std::string& value) +{ + yyscan_t lexer; + cmCTestProcesses_yylex_init_extra(this, &lexer); + + auto state = cmCTestProcesses_yy_scan_string(value.c_str(), lexer); + int retval = cmCTestProcesses_yylex(lexer); + cmCTestProcesses_yy_delete_buffer(state, lexer); + + cmCTestProcesses_yylex_destroy(lexer); + return retval == 0; +} + +void cmCTestProcessesLexerHelper::SetProcessCount(unsigned int count) +{ + this->ProcessCount = count; +} + +void cmCTestProcessesLexerHelper::SetResourceType(const std::string& type) +{ + this->ResourceType = type; +} + +void cmCTestProcessesLexerHelper::SetNeededSlots(int count) +{ + this->NeededSlots = count; +} + +void cmCTestProcessesLexerHelper::WriteRequirement() +{ + this->Process.push_back({ this->ResourceType, this->NeededSlots, 1 }); +} + +void cmCTestProcessesLexerHelper::WriteProcess() +{ + for (unsigned int i = 0; i < this->ProcessCount; ++i) { + this->Output.push_back(this->Process); + } + this->Process.clear(); + this->ProcessCount = 1; +} diff --git a/Source/CTest/cmCTestProcessesLexerHelper.h b/Source/CTest/cmCTestProcessesLexerHelper.h new file mode 100644 index 0000000..6c9289f --- /dev/null +++ b/Source/CTest/cmCTestProcessesLexerHelper.h @@ -0,0 +1,44 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#ifndef cmCTestProcessesLexerHelper_h +#define cmCTestProcessesLexerHelper_h + +#include <string> +#include <vector> + +#include "cmCTestTestHandler.h" + +class cmCTestProcessesLexerHelper +{ +public: + struct ParserType + { + }; + + cmCTestProcessesLexerHelper( + std::vector< + std::vector<cmCTestTestHandler::cmCTestTestResourceRequirement>>& + output); + ~cmCTestProcessesLexerHelper() = default; + + bool ParseString(const std::string& value); + + void SetProcessCount(unsigned int count); + void SetResourceType(const std::string& type); + void SetNeededSlots(int count); + void WriteRequirement(); + void WriteProcess(); + +private: + std::vector<std::vector<cmCTestTestHandler::cmCTestTestResourceRequirement>>& + Output; + + unsigned int ProcessCount = 1; + std::string ResourceType; + int NeededSlots; + std::vector<cmCTestTestHandler::cmCTestTestResourceRequirement> Process; +}; + +#define YY_EXTRA_TYPE cmCTestProcessesLexerHelper* + +#endif diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx index 67d16af..927e086 100644 --- a/Source/CTest/cmCTestTestHandler.cxx +++ b/Source/CTest/cmCTestTestHandler.cxx @@ -29,6 +29,7 @@ #include "cmAlgorithms.h" #include "cmCTest.h" #include "cmCTestMultiProcessHandler.h" +#include "cmCTestProcessesLexerHelper.h" #include "cmDuration.h" #include "cmExecutionStatus.h" #include "cmGeneratedFileStream.h" @@ -1610,6 +1611,14 @@ std::string cmCTestTestHandler::FindExecutable( return fullPath; } +bool cmCTestTestHandler::ParseProcessesProperty( + const std::string& val, + std::vector<std::vector<cmCTestTestResourceRequirement>>& processes) +{ + cmCTestProcessesLexerHelper lexer(processes); + return lexer.ParseString(val); +} + void cmCTestTestHandler::GetListOfTests() { if (!this->IncludeLabelRegExp.empty()) { @@ -2179,6 +2188,11 @@ bool cmCTestTestHandler::SetTestsProperties( if (key == "PROCESSOR_AFFINITY") { rt.WantAffinity = cmIsOn(val); } + if (key == "PROCESSES") { + if (!ParseProcessesProperty(val, rt.Processes)) { + return false; + } + } if (key == "SKIP_RETURN_CODE") { rt.SkipReturnCode = atoi(val.c_str()); if (rt.SkipReturnCode < 0 || rt.SkipReturnCode > 255) { @@ -2356,3 +2370,17 @@ bool cmCTestTestHandler::AddTest(const std::vector<std::string>& args) this->TestList.push_back(test); return true; } + +bool cmCTestTestHandler::cmCTestTestResourceRequirement::operator==( + const cmCTestTestResourceRequirement& other) const +{ + return this->ResourceType == other.ResourceType && + this->SlotsNeeded == other.SlotsNeeded && + this->UnitsNeeded == other.UnitsNeeded; +} + +bool cmCTestTestHandler::cmCTestTestResourceRequirement::operator!=( + const cmCTestTestResourceRequirement& other) const +{ + return !(*this == other); +} diff --git a/Source/CTest/cmCTestTestHandler.h b/Source/CTest/cmCTestTestHandler.h index 1807a5c..2602c30 100644 --- a/Source/CTest/cmCTestTestHandler.h +++ b/Source/CTest/cmCTestTestHandler.h @@ -102,6 +102,16 @@ public: void Initialize() override; + struct cmCTestTestResourceRequirement + { + std::string ResourceType; + int SlotsNeeded; + int UnitsNeeded; + + bool operator==(const cmCTestTestResourceRequirement& other) const; + bool operator!=(const cmCTestTestResourceRequirement& other) const; + }; + // NOTE: This struct is Saved/Restored // in cmCTestTestHandler, if you add to this class // then you must add the new members to that code or @@ -147,6 +157,7 @@ public: std::set<std::string> FixturesCleanup; std::set<std::string> FixturesRequired; std::set<std::string> RequireSuccessDepends; + std::vector<std::vector<cmCTestTestResourceRequirement>> Processes; // Private test generator properties used to track backtraces cmListFileBacktrace Backtrace; }; @@ -190,6 +201,10 @@ public: std::vector<std::string>& extraPaths, std::vector<std::string>& failed); + static bool ParseProcessesProperty( + const std::string& val, + std::vector<std::vector<cmCTestTestResourceRequirement>>& processes); + using ListOfTests = std::vector<cmCTestTestProperties>; protected: |