From 440b08e4f0f59f47b53eb8310832bd4a1b1eb912 Mon Sep 17 00:00:00 2001 From: Zsolt Parragi Date: Tue, 6 Nov 2018 20:40:18 +0100 Subject: CTest: Represent process exit codes as 64-bit signed integer Exit code constants on Windows, such as `STATUS_NO_MEMORY` do not fit in a 32-bit signed integer type. They do fit in an unsigned 32-bit type, but for compatibility with UNIX semantics we treat exit codes as signed. Use a 64-bit signed integer to handle both. --- Source/CTest/cmCTestRunTest.cxx | 3 ++- Source/CTest/cmCTestTestHandler.h | 3 ++- Source/CTest/cmProcess.cxx | 9 ++++++--- Source/CTest/cmProcess.h | 4 ++-- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Source/CTest/cmCTestRunTest.cxx b/Source/CTest/cmCTestRunTest.cxx index 7f081ef..5183c6f 100644 --- a/Source/CTest/cmCTestRunTest.cxx +++ b/Source/CTest/cmCTestRunTest.cxx @@ -14,6 +14,7 @@ #include "cmsys/RegularExpression.hxx" #include #include +#include #include #include #include @@ -143,7 +144,7 @@ bool cmCTestRunTest::EndTest(size_t completed, size_t total, bool started) if (res != cmProcess::State::Expired) { this->TimeoutIsForStopTime = false; } - int retVal = this->TestProcess->GetExitValue(); + std::int64_t retVal = this->TestProcess->GetExitValue(); bool forceFail = false; bool skipped = false; bool outputTestErrorsToConsole = false; diff --git a/Source/CTest/cmCTestTestHandler.h b/Source/CTest/cmCTestTestHandler.h index 0b557db..17d5f3f 100644 --- a/Source/CTest/cmCTestTestHandler.h +++ b/Source/CTest/cmCTestTestHandler.h @@ -11,6 +11,7 @@ #include "cmsys/RegularExpression.hxx" #include +#include #include #include #include @@ -153,7 +154,7 @@ public: std::string Reason; std::string FullCommandLine; cmDuration ExecutionTime; - int ReturnValue; + std::int64_t ReturnValue; int Status; std::string ExceptionStatus; bool CompressOutput; diff --git a/Source/CTest/cmProcess.cxx b/Source/CTest/cmProcess.cxx index c03d004..cd2e2f7 100644 --- a/Source/CTest/cmProcess.cxx +++ b/Source/CTest/cmProcess.cxx @@ -11,7 +11,9 @@ #include #include #include -#if !defined(_WIN32) +#if defined(_WIN32) +# include "cm_kwiml.h" +#else # include #endif #include @@ -353,7 +355,7 @@ void cmProcess::OnExit(int64_t exit_status, int term_signal) } // Record exit information. - this->ExitValue = static_cast(exit_status); + this->ExitValue = exit_status; this->Signal = term_signal; this->TotalTime = std::chrono::steady_clock::now() - this->StartTime; // Because of a processor clock scew the runtime may become slightly @@ -539,7 +541,8 @@ std::string cmProcess::GetExitExceptionString() case STATUS_NO_MEMORY: default: char buf[1024]; - _snprintf(buf, 1024, "Exit code 0x%x\n", this->ExitValue); + const char* fmt = "Exit code 0x%" KWIML_INT_PRIx64 "\n"; + _snprintf(buf, 1024, fmt, this->ExitValue); exception_str.assign(buf); } #else diff --git a/Source/CTest/cmProcess.h b/Source/CTest/cmProcess.h index b2d87fa..e5ca17f 100644 --- a/Source/CTest/cmProcess.h +++ b/Source/CTest/cmProcess.h @@ -53,7 +53,7 @@ public: State GetProcessStatus(); int GetId() { return this->Id; } void SetId(int id) { this->Id = id; } - int GetExitValue() { return this->ExitValue; } + int64_t GetExitValue() { return this->ExitValue; } cmDuration GetTotalTime() { return this->TotalTime; } enum class Exception @@ -122,7 +122,7 @@ private: std::vector Arguments; std::vector ProcessArgs; int Id; - int ExitValue; + int64_t ExitValue; }; #endif -- cgit v0.12