Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[tesh] check output on timeout
authorMillian Poquet <millian.poquet@inria.fr>
Thu, 13 Jun 2019 15:39:11 +0000 (17:39 +0200)
committerMillian Poquet <millian.poquet@inria.fr>
Thu, 13 Jun 2019 15:39:53 +0000 (17:39 +0200)
Rationale: Help users debug why the process got a timeout.

Fixes https://framagit.org/simgrid/simgrid/issues/23

tools/tesh/CMakeLists.txt
tools/tesh/catch-timeout-output.tesh [new file with mode: 0644]
tools/tesh/catch-timeout.tesh
tools/tesh/tesh.py

index ed44f89..5390d9c 100644 (file)
@@ -3,7 +3,7 @@ configure_file("${CMAKE_HOME_DIRECTORY}/tools/tesh/tesh.py"
 
 
 foreach(x setenv set-output-ignore set-output-sort set-return set-timeout background basic bg-basic bg-set-signal
-          catch-return catch-signal catch-timeout catch-wrong-output cd color ignore-regexp IO-bigsize IO-broken-pipe IO-orders)
+          catch-return catch-signal catch-timeout catch-timeout-output catch-wrong-output cd color ignore-regexp IO-bigsize IO-broken-pipe IO-orders)
   set(tesh_files  ${tesh_files} ${CMAKE_CURRENT_SOURCE_DIR}/${x}.tesh)
   if(NOT enable_memcheck AND NOT WIN32)
     ADD_TESH(tesh-self-${x} --setenv bindir=${CMAKE_BINARY_DIR}/bin ${CMAKE_HOME_DIRECTORY}/tools/tesh/${x}.tesh)
diff --git a/tools/tesh/catch-timeout-output.tesh b/tools/tesh/catch-timeout-output.tesh
new file mode 100644 (file)
index 0000000..227d93c
--- /dev/null
@@ -0,0 +1,19 @@
+#!/usr/bin/env tesh
+
+# Checks that the output of a timeout process can be printed.
+
+! expect return 2
+< ! timeout 1
+< $ sh -c 'echo "I crashed" && sleep 6'
+> Test suite from stdin
+> [(stdin):2] sh -c 'echo "I crashed" && sleep 6'
+> Test suite `(stdin)': NOK (<(stdin):2> timeout after 1 sec)
+> Output of <(stdin):2> mismatch:
+> --- expected
+> +++ obtained
+> @@ -0,0 +1 @@
+> +I crashed
+> Test suite `(stdin)': NOK (<(stdin):2> output mismatch)
+$ ${bindir:=.}/tesh
+
+
index 0bee596..a246c16 100644 (file)
@@ -1,6 +1,6 @@
 #!/usr/bin/env tesh
 
-# This suite must be functional because we changed the timeout value to 10
+# This suite must be functional because we changed the timeout value to 1
 # before sleeping 6 secs.
 
 ! expect return 3
index aa1f65e..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: