Commit 440b08e4 authored by Zsolt Parragi's avatar Zsolt Parragi Committed by Brad King

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.
parent a3ec65c3
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "cmsys/RegularExpression.hxx" #include "cmsys/RegularExpression.hxx"
#include <chrono> #include <chrono>
#include <cmAlgorithms.h> #include <cmAlgorithms.h>
#include <cstdint>
#include <cstring> #include <cstring>
#include <iomanip> #include <iomanip>
#include <ratio> #include <ratio>
...@@ -143,7 +144,7 @@ bool cmCTestRunTest::EndTest(size_t completed, size_t total, bool started) ...@@ -143,7 +144,7 @@ bool cmCTestRunTest::EndTest(size_t completed, size_t total, bool started)
if (res != cmProcess::State::Expired) { if (res != cmProcess::State::Expired) {
this->TimeoutIsForStopTime = false; this->TimeoutIsForStopTime = false;
} }
int retVal = this->TestProcess->GetExitValue(); std::int64_t retVal = this->TestProcess->GetExitValue();
bool forceFail = false; bool forceFail = false;
bool skipped = false; bool skipped = false;
bool outputTestErrorsToConsole = false; bool outputTestErrorsToConsole = false;
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "cmsys/RegularExpression.hxx" #include "cmsys/RegularExpression.hxx"
#include <chrono> #include <chrono>
#include <cstdint>
#include <iosfwd> #include <iosfwd>
#include <map> #include <map>
#include <set> #include <set>
...@@ -153,7 +154,7 @@ public: ...@@ -153,7 +154,7 @@ public:
std::string Reason; std::string Reason;
std::string FullCommandLine; std::string FullCommandLine;
cmDuration ExecutionTime; cmDuration ExecutionTime;
int ReturnValue; std::int64_t ReturnValue;
int Status; int Status;
std::string ExceptionStatus; std::string ExceptionStatus;
bool CompressOutput; bool CompressOutput;
......
...@@ -11,7 +11,9 @@ ...@@ -11,7 +11,9 @@
#include <iostream> #include <iostream>
#include <signal.h> #include <signal.h>
#include <string> #include <string>
#if !defined(_WIN32) #if defined(_WIN32)
# include "cm_kwiml.h"
#else
# include <unistd.h> # include <unistd.h>
#endif #endif
#include <utility> #include <utility>
...@@ -353,7 +355,7 @@ void cmProcess::OnExit(int64_t exit_status, int term_signal) ...@@ -353,7 +355,7 @@ void cmProcess::OnExit(int64_t exit_status, int term_signal)
} }
// Record exit information. // Record exit information.
this->ExitValue = static_cast<int>(exit_status); this->ExitValue = exit_status;
this->Signal = term_signal; this->Signal = term_signal;
this->TotalTime = std::chrono::steady_clock::now() - this->StartTime; this->TotalTime = std::chrono::steady_clock::now() - this->StartTime;
// Because of a processor clock scew the runtime may become slightly // Because of a processor clock scew the runtime may become slightly
...@@ -539,7 +541,8 @@ std::string cmProcess::GetExitExceptionString() ...@@ -539,7 +541,8 @@ std::string cmProcess::GetExitExceptionString()
case STATUS_NO_MEMORY: case STATUS_NO_MEMORY:
default: default:
char buf[1024]; 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); exception_str.assign(buf);
} }
#else #else
......
...@@ -53,7 +53,7 @@ public: ...@@ -53,7 +53,7 @@ public:
State GetProcessStatus(); State GetProcessStatus();
int GetId() { return this->Id; } int GetId() { return this->Id; }
void SetId(int id) { this->Id = id; } void SetId(int id) { this->Id = id; }
int GetExitValue() { return this->ExitValue; } int64_t GetExitValue() { return this->ExitValue; }
cmDuration GetTotalTime() { return this->TotalTime; } cmDuration GetTotalTime() { return this->TotalTime; }
enum class Exception enum class Exception
...@@ -122,7 +122,7 @@ private: ...@@ -122,7 +122,7 @@ private:
std::vector<std::string> Arguments; std::vector<std::string> Arguments;
std::vector<const char*> ProcessArgs; std::vector<const char*> ProcessArgs;
int Id; int Id;
int ExitValue; int64_t ExitValue;
}; };
#endif #endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment