diff options
author | Mika Isojärvi <misojarvi@google.com> | 2015-05-19 13:44:08 -0700 |
---|---|---|
committer | Mika Isojärvi <misojarvi@google.com> | 2015-06-02 15:30:41 -0700 |
commit | 5717785063a5db999d8f5a1cc067eba5fcc7409a (patch) | |
tree | ef4df83dd6d8d025323ee4703a2c76e4fd5f9fe4 /executor | |
parent | e16b0f52b4af5e934670dfc778cece6b3a4eb9b0 (diff) | |
download | VK-GL-CTS-5717785063a5db999d8f5a1cc067eba5fcc7409a.tar.gz VK-GL-CTS-5717785063a5db999d8f5a1cc067eba5fcc7409a.tar.bz2 VK-GL-CTS-5717785063a5db999d8f5a1cc067eba5fcc7409a.zip |
Handle SIGINT in command line executor.
Command line executor now cleanly writes out test log when Ctrl-C is pressed
instead of losing all progress.
Bug: 21161902
Change-Id: I646ceb0b9669d4969a38fd38b3bb1d1e6dbdef98
Diffstat (limited to 'executor')
-rw-r--r-- | executor/tools/xeCommandLineExecutor.cpp | 108 | ||||
-rw-r--r-- | executor/xeBatchExecutor.cpp | 6 | ||||
-rw-r--r-- | executor/xeCallQueue.cpp | 12 | ||||
-rw-r--r-- | executor/xeCallQueue.hpp | 2 |
4 files changed, 125 insertions, 3 deletions
diff --git a/executor/tools/xeCommandLineExecutor.cpp b/executor/tools/xeCommandLineExecutor.cpp index cbe3e7b90..cc7788b48 100644 --- a/executor/tools/xeCommandLineExecutor.cpp +++ b/executor/tools/xeCommandLineExecutor.cpp @@ -44,6 +44,10 @@ #include <string> #include <vector> +#if (DE_OS == DE_OS_UNIX) || (DE_OS == DE_OS_ANDROID) || (DE_OS == DE_OS_WIN32) +# include <signal.h> +#endif + using std::vector; using std::string; @@ -502,6 +506,74 @@ xe::CommLink* createCommLink (const CommandLine& cmdLine) } } +#if (DE_OS == DE_OS_UNIX) || (DE_OS == DE_OS_ANDROID) + +static xe::BatchExecutor* s_executor = DE_NULL; + +void signalHandler (int, siginfo_t*, void*) +{ + if (s_executor) + s_executor->cancel(); +} + +void setupSignalHandler (xe::BatchExecutor* executor) +{ + s_executor = executor; + struct sigaction sa; + + sa.sa_sigaction = signalHandler; + sa.sa_flags = SA_SIGINFO | SA_RESTART; + sigfillset(&sa.sa_mask); + + sigaction(SIGINT, &sa, DE_NULL); +} + +void resetSignalHandler (void) +{ + struct sigaction sa; + + sa.sa_handler = SIG_DFL; + sa.sa_flags = SA_RESTART; + sigfillset(&sa.sa_mask); + + sigaction(SIGINT, &sa, DE_NULL); + s_executor = DE_NULL; +} + +#elif (DE_OS == DE_OS_WIN32) + +static xe::BatchExecutor* s_executor = DE_NULL; + +void signalHandler (int) +{ + if (s_executor) + s_executor->cancel(); +} + +void setupSignalHandler (xe::BatchExecutor* executor) +{ + s_executor = executor; + signal(SIGINT, signalHandler); +} + +void resetSignalHandler (void) +{ + signal(SIGINT, SIG_DFL); + s_executor = DE_NULL; +} + +#else + +void setupSignalHandler (xe::BatchExecutor*) +{ +} + +void resetSignalHandler (void) +{ +} + +#endif + void runExecutor (const CommandLine& cmdLine) { xe::TestRoot root; @@ -535,9 +607,34 @@ void runExecutor (const CommandLine& cmdLine) std::auto_ptr<xe::CommLink> commLink(createCommLink(cmdLine)); xe::BatchExecutor executor(cmdLine.targetCfg, commLink.get(), &root, testSet, &batchResult, &infoLog); - executor.run(); - commLink.reset(); + try + { + setupSignalHandler(&executor); + executor.run(); + resetSignalHandler(); + } + catch (...) + { + resetSignalHandler(); + + if (!cmdLine.outFile.empty()) + { + xe::writeBatchResultToFile(batchResult, cmdLine.outFile.c_str()); + printf("Test log written to %s\n", cmdLine.outFile.c_str()); + } + + if (!cmdLine.infoFile.empty()) + { + writeInfoLog(infoLog, cmdLine.infoFile.c_str()); + printf("Info log written to %s\n", cmdLine.infoFile.c_str()); + } + + if (cmdLine.summary) + printBatchResultSummary(&root, testSet, batchResult); + + throw; + } if (!cmdLine.outFile.empty()) { @@ -553,6 +650,13 @@ void runExecutor (const CommandLine& cmdLine) if (cmdLine.summary) printBatchResultSummary(&root, testSet, batchResult); + + { + string err; + + if (commLink->getState(err) == xe::COMMLINKSTATE_ERROR) + throw xe::Error(err); + } } } // anonymous diff --git a/executor/xeBatchExecutor.cpp b/executor/xeBatchExecutor.cpp index 9e8b7b77f..bd7a2510e 100644 --- a/executor/xeBatchExecutor.cpp +++ b/executor/xeBatchExecutor.cpp @@ -224,6 +224,12 @@ void BatchExecutor::run (void) m_commLink->setCallbacks(DE_NULL, DE_NULL, DE_NULL, DE_NULL); } +void BatchExecutor::cancel (void) +{ + m_state = STATE_FINISHED; + m_dispatcher.cancel(); +} + void BatchExecutor::onStateChanged (CommLinkState state, const char* message) { switch (state) diff --git a/executor/xeCallQueue.cpp b/executor/xeCallQueue.cpp index 5c30318b6..ae6800082 100644 --- a/executor/xeCallQueue.cpp +++ b/executor/xeCallQueue.cpp @@ -38,7 +38,8 @@ namespace xe // CallQueue CallQueue::CallQueue (void) - : m_callSem (0) + : m_canceled (false) + , m_callSem (0) , m_callQueue (64) { } @@ -50,6 +51,12 @@ CallQueue::~CallQueue (void) delete *i; } +void CallQueue::cancel (void) +{ + m_canceled = true; + m_callSem.increment(); +} + void CallQueue::callNext (void) { Call* call = DE_NULL; @@ -57,6 +64,9 @@ void CallQueue::callNext (void) // Wait for a call. m_callSem.decrement(); + if (m_canceled) + return; + // Acquire call from buffer. { de::ScopedLock lock(m_lock); diff --git a/executor/xeCallQueue.hpp b/executor/xeCallQueue.hpp index 94217e418..c88e66938 100644 --- a/executor/xeCallQueue.hpp +++ b/executor/xeCallQueue.hpp @@ -113,11 +113,13 @@ public: Call* getEmptyCall (void); void enqueue (Call* call); void freeCall (Call* call); + void cancel (void); private: CallQueue (const CallQueue& other); CallQueue& operator= (const CallQueue& other); + bool m_canceled; de::Semaphore m_callSem; de::Mutex m_lock; |