Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'tesh-check-output-on-timeout' into 'master'
[simgrid.git] / tools / tesh / tesh.py
index dc7b629..91084a9 100755 (executable)
@@ -364,11 +364,19 @@ class Cmd(object):
         try:
             (stdout_data, stderr_data) = proc.communicate("\n".join(self.input_pipe), self.timeout)
             pgtokill = None
+            timeout_reached = False
         except subprocess.TimeoutExpired:
+            timeout_reached = True
             print("Test suite `" + FileReader().filename + "': NOK (<" +
                   cmdName + "> timeout after " + str(self.timeout) + " sec)")
             kill_process_group(pgtokill)
-            tesh_exit(3)
+            # Try to get the output of the timeout process, to help in debugging.
+            try:
+                (stdout_data, stderr_data) = proc.communicate(timeout=1)
+            except subprocess.TimeoutExpired:
+                print("[{file}:{number}] Could not retrieve output. Killing the process group failed?".format(
+                    file=FileReader().filename, number=self.linenumber))
+                tesh_exit(3)
 
         if self.output_display:
             print(stdout_data)
@@ -435,6 +443,9 @@ class Cmd(object):
                     print("Obtained output kept as requested: " + os.path.abspath("obtained"))
                 tesh_exit(2)
 
+        if timeout_reached:
+            tesh_exit(3)
+
         #print ((proc.returncode, self.expect_return))
 
         if proc.returncode != self.expect_return:
@@ -469,7 +480,7 @@ if __name__ == '__main__':
     signal.signal(signal.SIGINT, signal_handler)
     signal.signal(signal.SIGTERM, signal_handler)
 
-    parser = argparse.ArgumentParser(description='tesh -- testing shell', add_help=True)
+    parser = argparse.ArgumentParser(description='tesh -- testing shell')
     group1 = parser.add_argument_group('Options')
     group1.add_argument('teshfile', nargs='?', help='Name of teshfile, stdin if omitted')
     group1.add_argument(
@@ -489,10 +500,7 @@ if __name__ == '__main__':
         action='store_true',
         help='Keep the obtained output when it does not match the expected one')
 
-    try:
-        options = parser.parse_args()
-    except SystemExit:
-        tesh_exit(1)
+    options = parser.parse_args()
 
     if options.cd is not None:
         print("[Tesh/INFO] change directory to " + options.cd)