Updating Test Harness to show wait channel 24/287024/3
authorDavid Steele <david.steele@samsung.com>
Wed, 18 Jan 2023 15:19:04 +0000 (15:19 +0000)
committerDavid Steele <david.steele@samsung.com>
Wed, 18 Jan 2023 17:11:42 +0000 (17:11 +0000)
If, during parallel execution, a child test case is pending for a
minute, then display the wait channel symbol, and kill the process.

Change-Id: I5605cc563729ac4d65a16be9354faeed2788bf42
Signed-off-by: David Steele <david.steele@samsung.com>
automated-tests/src/dali/dali-test-suite-utils/test-harness.cpp
automated-tests/src/dali/dali-test-suite-utils/test-harness.h

index 86874fd..31080a4 100644 (file)
@@ -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<double>       seconds  = std::chrono::duration_cast<std::chrono::duration<double>>(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);
index 554846f..e884c64 100644 (file)
@@ -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),