From 620fa335f1282a61369a4109345d26707c481037 Mon Sep 17 00:00:00 2001 From: David Steele Date: Mon, 2 Nov 2020 13:39:09 +0000 Subject: [PATCH] Added test-harness timeout check Change-Id: Iec480185de70bd63c23211074abb6148f8ffd39a --- .../dali-toolkit-test-utils/test-harness.cpp | 45 +++++++++++++++------- .../dali-toolkit-test-utils/test-harness.h | 16 +++++--- 2 files changed, 43 insertions(+), 18 deletions(-) diff --git a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-harness.cpp b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-harness.cpp index 0b814e7..b53630d 100644 --- a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-harness.cpp +++ b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-harness.cpp @@ -21,8 +21,11 @@ #include #include #include + +#include #include +#include #include #include #include @@ -31,6 +34,8 @@ namespace TestHarness { typedef std::map RunningTestCases; +const double MAXIMUM_CHILD_LIFETIME(60.0f); // 1 minute + const char* basename(const char* path) { const char* ptr = path; @@ -247,25 +252,42 @@ int32_t RunAllInParallel(const char* processName, ::testcase tc_array[], bool re else // Parent process { TestCase tc(nextTestCase, tc_array[nextTestCase].name); + tc.startTime = std::chrono::steady_clock::now(); + children[pid] = tc; nextTestCase++; numRunningChildren++; } } - // Wait for the next child to finish - + // Check to see if any children have finished yet int32_t status = 0; - int32_t childPid = waitpid(-1, &status, 0); - if(childPid == -1) + int32_t childPid = waitpid(-1, &status, WNOHANG); + if(childPid == 0) + { + // No children have finished. + // Check if any have exceeded execution time + auto endTime = std::chrono::steady_clock::now(); + + for(auto& tc : children) + { + std::chrono::steady_clock::duration timeSpan = endTime - tc.second.startTime; + std::chrono::duration seconds = std::chrono::duration_cast>(timeSpan); + if(seconds.count() > MAXIMUM_CHILD_LIFETIME) + { + // Kill the child process. A subsequent call to waitpid will process signal result below. + kill(tc.first, SIGKILL); + } + } + } + else if(childPid == -1) // waitpid errored { perror("waitpid"); exit(EXIT_STATUS_WAITPID_FAILED); } - - if(WIFEXITED(status)) + else // a child has finished { - if(childPid > 0) + if(WIFEXITED(status)) { int32_t testResult = WEXITSTATUS(status); if(testResult) @@ -280,14 +302,11 @@ int32_t RunAllInParallel(const char* processName, ::testcase tc_array[], bool re } numRunningChildren--; } - } - - else if(WIFSIGNALED(status) || WIFSTOPPED(status)) - { - status = WIFSIGNALED(status) ? WTERMSIG(status) : WSTOPSIG(status); - if(childPid > 0) + else if(WIFSIGNALED(status) || WIFSTOPPED(status)) { + status = WIFSIGNALED(status) ? WTERMSIG(status) : WSTOPSIG(status); + RunningTestCases::iterator iter = children.find(childPid); if(iter != children.end()) { diff --git a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-harness.h b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-harness.h index c4b5e03..b210918 100644 --- a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-harness.h +++ b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-harness.h @@ -20,6 +20,7 @@ #include #include +#include #include namespace TestHarness @@ -39,29 +40,34 @@ const int32_t MAX_NUM_CHILDREN(16); struct TestCase { - int32_t testCase; - const char* testCaseName; + int32_t testCase; + const char* testCaseName; + std::chrono::steady_clock::time_point startTime; TestCase() : testCase(0), - testCaseName(NULL) + testCaseName(NULL), + startTime() { } TestCase(int32_t tc, const char* name) : testCase(tc), - testCaseName(name) + testCaseName(name), + startTime() { } TestCase(const TestCase& rhs) : testCase(rhs.testCase), - testCaseName(rhs.testCaseName) + testCaseName(rhs.testCaseName), + startTime(rhs.startTime) { } TestCase& operator=(const TestCase& rhs) { testCase = rhs.testCase; testCaseName = rhs.testCaseName; + startTime = rhs.startTime; return *this; } }; -- 2.7.4