diff options
author | Bryon Bean <bryon.bean@kitware.com> | 2017-12-10 17:06:35 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2018-01-10 15:19:14 (GMT) |
commit | b5e21d7d2ed3168c9efcbc25c67d2c330d76d4d0 (patch) | |
tree | 15610190a02639271ec13ab1610ad398383fdd93 /Source/CTest/cmProcess.h | |
parent | fcebff75f912f50bdc7fd30f4185141255ba4b1f (diff) | |
download | CMake-b5e21d7d2ed3168c9efcbc25c67d2c330d76d4d0.zip CMake-b5e21d7d2ed3168c9efcbc25c67d2c330d76d4d0.tar.gz CMake-b5e21d7d2ed3168c9efcbc25c67d2c330d76d4d0.tar.bz2 |
CTest: Re-implement test process handling using libuv
Co-Author: Brad King <brad.king@kitware.com>
Diffstat (limited to 'Source/CTest/cmProcess.h')
-rw-r--r-- | Source/CTest/cmProcess.h | 50 |
1 files changed, 36 insertions, 14 deletions
diff --git a/Source/CTest/cmProcess.h b/Source/CTest/cmProcess.h index 297cc47..9250896 100644 --- a/Source/CTest/cmProcess.h +++ b/Source/CTest/cmProcess.h @@ -5,11 +5,17 @@ #include "cmConfigure.h" // IWYU pragma: keep -#include "cmsys/Process.h" +#include "cmUVHandlePtr.h" +#include "cm_uv.h" + #include <chrono> +#include <stddef.h> #include <string> +#include <sys/types.h> #include <vector> +class cmCTestRunTest; + /** \class cmProcess * \brief run a process with c++ * @@ -18,7 +24,7 @@ class cmProcess { public: - cmProcess(); + explicit cmProcess(cmCTestRunTest& runner); ~cmProcess(); const char* GetCommand() { return this->Command.c_str(); } void SetCommand(const char* command); @@ -28,7 +34,7 @@ public: void ChangeTimeout(std::chrono::duration<double> t); void ResetStartTime(); // Return true if the process starts - bool StartProcess(); + bool StartProcess(uv_loop_t& loop); enum class State { @@ -61,21 +67,37 @@ public: Exception GetExitException(); std::string GetExitExceptionString(); - /** - * Read one line of output but block for no more than timeout. - * Returns: - * cmsysProcess_Pipe_None = Process terminated and all output read - * cmsysProcess_Pipe_STDOUT = Line came from stdout or stderr - * cmsysProcess_Pipe_Timeout = Timeout expired while waiting - */ - int GetNextOutputLine(std::string& line, - std::chrono::duration<double> timeout); - private: std::chrono::duration<double> Timeout; std::chrono::steady_clock::time_point StartTime; std::chrono::duration<double> TotalTime; - cmsysProcess* Process; + bool ReadHandleClosed = false; + bool ProcessHandleClosed = false; + + cm::uv_process_ptr Process; + cm::uv_pipe_ptr PipeReader; + cm::uv_timer_ptr Timer; + std::vector<char> Buf; + + cmCTestRunTest& Runner; + int Signal = 0; + cmProcess::State ProcessState = cmProcess::State::Starting; + + static void OnExitCB(uv_process_t* process, int64_t exit_status, + int term_signal); + static void OnTimeoutCB(uv_timer_t* timer); + static void OnReadCB(uv_stream_t* stream, ssize_t nread, + const uv_buf_t* buf); + static void OnAllocateCB(uv_handle_t* handle, size_t suggested_size, + uv_buf_t* buf); + + void OnExit(int64_t exit_status, int term_signal); + void OnTimeout(); + void OnRead(ssize_t nread, const uv_buf_t* buf); + void OnAllocate(size_t suggested_size, uv_buf_t* buf); + + void StartTimer(); + class Buffer : public std::vector<char> { // Half-open index range of partial line already scanned. |