diff options
author | Kyle Edwards <kyle.edwards@kitware.com> | 2023-06-06 12:41:43 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2023-06-06 12:41:58 (GMT) |
commit | 0eada9266370223479c8127d448085f5971a1062 (patch) | |
tree | 9f021bfc93697ef3f06715b340ad226950818540 /Tests | |
parent | 722c801da774a45a3245fd7abe5f87eb5066632f (diff) | |
parent | 154fe00ca56710d6fced4ab5c51f7edb162ea991 (diff) | |
download | CMake-0eada9266370223479c8127d448085f5971a1062.zip CMake-0eada9266370223479c8127d448085f5971a1062.tar.gz CMake-0eada9266370223479c8127d448085f5971a1062.tar.bz2 |
Merge topic 'cmuvprocesschain-status-getexception'
154fe00ca5 cmUVProcessChain: Add Status::GetException() method
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !8528
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/CMakeLib/testUVProcessChain.cxx | 70 | ||||
-rw-r--r-- | Tests/CMakeLib/testUVProcessChainHelper.cxx | 9 |
2 files changed, 65 insertions, 14 deletions
diff --git a/Tests/CMakeLib/testUVProcessChain.cxx b/Tests/CMakeLib/testUVProcessChain.cxx index ce6cd6d..7027689 100644 --- a/Tests/CMakeLib/testUVProcessChain.cxx +++ b/Tests/CMakeLib/testUVProcessChain.cxx @@ -4,6 +4,8 @@ #include <iostream> #include <sstream> #include <string> +#include <type_traits> +#include <utility> #include <vector> #include <cm/memory> @@ -22,30 +24,62 @@ struct ExpectedStatus bool MatchExitStatus; bool MatchTermSignal; cmUVProcessChain::Status Status; + cmUVProcessChain::ExceptionCode ExceptionCode; + std::string ExceptionString; }; static const std::vector<ExpectedStatus> status1 = { - { false, false, false, { 0, 0 } }, - { false, false, false, { 0, 0 } }, - { false, false, false, { 0, 0 } }, + { false, false, false, { 0, 0 }, cmUVProcessChain::ExceptionCode::None, "" }, + { false, false, false, { 0, 0 }, cmUVProcessChain::ExceptionCode::None, "" }, + { false, false, false, { 0, 0 }, cmUVProcessChain::ExceptionCode::None, "" }, }; static const std::vector<ExpectedStatus> status2 = { - { true, true, true, { 0, 0 } }, - { false, false, false, { 0, 0 } }, - { false, false, false, { 0, 0 } }, + { true, true, true, { 0, 0 }, cmUVProcessChain::ExceptionCode::None, "" }, + { false, false, false, { 0, 0 }, cmUVProcessChain::ExceptionCode::None, "" }, + { false, false, false, { 0, 0 }, cmUVProcessChain::ExceptionCode::None, "" }, }; static const std::vector<ExpectedStatus> status3 = { - { true, true, true, { 0, 0 } }, - { true, true, true, { 1, 0 } }, + { true, true, true, { 0, 0 }, cmUVProcessChain::ExceptionCode::None, "" }, + { true, true, true, { 1, 0 }, cmUVProcessChain::ExceptionCode::None, "" }, #ifdef _WIN32 - { true, true, true, { 2, 0 } }, + { true, + true, + true, + { STATUS_ACCESS_VIOLATION, 0 }, + cmUVProcessChain::ExceptionCode::Fault, + "Access violation" }, #else - { true, false, true, { 0, SIGABRT } }, + { true, + false, + true, + { 0, SIGABRT }, + cmUVProcessChain::ExceptionCode::Other, + "Subprocess aborted" }, #endif }; +static const char* ExceptionCodeToString(cmUVProcessChain::ExceptionCode code) +{ + switch (code) { + case cmUVProcessChain::ExceptionCode::None: + return "None"; + case cmUVProcessChain::ExceptionCode::Fault: + return "Fault"; + case cmUVProcessChain::ExceptionCode::Illegal: + return "Illegal"; + case cmUVProcessChain::ExceptionCode::Interrupt: + return "Interrupt"; + case cmUVProcessChain::ExceptionCode::Numerical: + return "Numerical"; + case cmUVProcessChain::ExceptionCode::Other: + return "Other"; + default: + return ""; + } +} + bool operator==(const cmUVProcessChain::Status* actual, const ExpectedStatus& expected) { @@ -62,6 +96,11 @@ bool operator==(const cmUVProcessChain::Status* actual, expected.Status.TermSignal != actual->TermSignal) { return false; } + if (expected.Finished && + std::make_pair(expected.ExceptionCode, expected.ExceptionString) != + actual->GetException()) { + return false; + } return true; } @@ -116,6 +155,11 @@ static void printResults( << printExpected(e.MatchExitStatus, e.Status.ExitStatus) << ", TermSignal: " << printExpected(e.MatchTermSignal, e.Status.TermSignal) + << ", ExceptionCode: " + << printExpected(e.Finished, + ExceptionCodeToString(e.ExceptionCode)) + << ", ExceptionString: \"" + << printExpected(e.Finished, e.ExceptionString) << '"' << std::endl; } else { std::cout << " null" << std::endl; @@ -124,8 +168,12 @@ static void printResults( std::cout << "Actual:" << std::endl; for (auto const& a : actual) { if (a) { + auto exception = a->GetException(); std::cout << " ExitStatus: " << a->ExitStatus - << ", TermSignal: " << a->TermSignal << std::endl; + << ", TermSignal: " << a->TermSignal << ", ExceptionCode: " + << ExceptionCodeToString(exception.first) + << ", ExceptionString: \"" << exception.second << '"' + << std::endl; } else { std::cout << " null" << std::endl; } diff --git a/Tests/CMakeLib/testUVProcessChainHelper.cxx b/Tests/CMakeLib/testUVProcessChainHelper.cxx index 82dafd2..99743e7 100644 --- a/Tests/CMakeLib/testUVProcessChainHelper.cxx +++ b/Tests/CMakeLib/testUVProcessChainHelper.cxx @@ -7,6 +7,10 @@ #include <string> #include <thread> +#ifdef _WIN32 +# include <windows.h> +#endif + #include "cmSystemTools.h" static std::string getStdin() @@ -61,10 +65,9 @@ int main(int argc, char** argv) } // On Windows, the exit code of abort() is different between debug and - // release builds, and does not yield a term_signal in libuv in either - // case. For the sake of simplicity, we just return another non-zero code. + // release builds. Instead, simulate an access violation. #ifdef _WIN32 - return 2; + return STATUS_ACCESS_VIOLATION; #else std::abort(); #endif |