From d2aad446f83709a2b3135407af873c6eb7532043 Mon Sep 17 00:00:00 2001 From: David Steele Date: Wed, 18 Jan 2023 15:21:23 +0000 Subject: [PATCH] Updating Test Harness to show wait channel If, during parallel execution, a child test case is pending for a minute, then display the wait channel symbol, and kill the process. Signed-off-by: David Steele Change-Id: Idf5d287211464672c82232ff6e6c84c92fe341c6 --- .../dali-toolkit-test-utils/test-harness.cpp | 32 ++++++++++++++++++---- .../dali-toolkit-test-utils/test-harness.h | 5 ++-- 2 files changed, 29 insertions(+), 8 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 86874fd..31080a4 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 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -122,6 +122,18 @@ std::string TestModuleName(const char* processName) return oss.str(); } +std::string GetWChan(int pid) +{ + std::ostringstream procwchan; + procwchan << "/proc/" << pid << "/wchan"; + std::ifstream ifs; + ifs.open(procwchan.str(), std::ifstream::in); + std::string line; + std::getline(ifs, line); + ifs.close(); + return line; +} + std::string ReadAndEscape(std::string filename) { std::ostringstream os; @@ -496,11 +508,17 @@ int32_t RunAllInParallel(const char* processName, ::testcase tc_array[], std::st 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) + double seconds = double(timeSpan.count()) * std::chrono::steady_clock::period::num / std::chrono::steady_clock::period::den; + + if(seconds > MAXIMUM_CHILD_LIFETIME) { // Kill the child process. A subsequent call to waitpid will process signal result below. - kill(tc.first, SIGKILL); + if(!tc.second.finished) + { + printf("Child process %s WCHAN:%s\n", tc.second.name, GetWChan(tc.first).c_str()); + kill(tc.first, SIGKILL); + tc.second.finished = true; // Only send kill signal once. + } } } } @@ -513,8 +531,9 @@ int32_t RunAllInParallel(const char* processName, ::testcase tc_array[], std::st { if(WIFEXITED(status)) { - auto& testCase = children[childPid]; - testCase.result = WEXITSTATUS(status); + auto& testCase = children[childPid]; + testCase.result = WEXITSTATUS(status); + testCase.finished = true; if(testCase.result) { printf("Test case %s failed: %d\n", testCase.name, testCase.result); @@ -535,6 +554,7 @@ int32_t RunAllInParallel(const char* processName, ::testcase tc_array[], std::st RunningTestCases::iterator iter = children.find(childPid); if(iter != children.end()) { + iter->second.finished = true; printf("Test case %s exited with signal %s\n", iter->second.name, strsignal(status)); iter->second.result = 1; failedTestCases.push_back(iter->second.testCase); 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 554846f..e884c64 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 @@ -2,7 +2,7 @@ #define TEST_HARNESS_H /* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,9 +44,10 @@ struct TestCase const char* name; std::chrono::steady_clock::time_point startTime; std::chrono::system_clock::time_point startSystemTime; - int32_t result; + int32_t result{0}; pid_t childPid{0}; testcase* tctPtr; + bool finished{false}; TestCase(int32_t index, testcase* testCase) : testCase(index), -- 2.7.4