chiark / gitweb /
server/tests.at (WITH_STRACE): Factor out the strace(1) machinery.
[tripe] / server / tests.at
index 5fcf06015778eafef58a0353014e75f0089d1dab..af94847d2a2f4f2d38cfd927ddaee96503368ea8 100644 (file)
@@ -42,6 +42,27 @@ m4_define([PKSTREAM],
   [$abs_top_builddir/pkstream/pkstream -b127.0.0.1 -p127.0.0.1])
 m4_define([MITM], [$abs_top_builddir/proxy/tripe-mitm])
 
+## WITH_STRACE(tag, cmd)
+##
+## There's an awful hack here.  If a process running under strace exits with
+## a signal, then strace will kill itself with the same signal -- and
+## therefore clobber the original process's core file.  So we arrange to run
+## strace in one directory and have the child process run in another.
+m4_define([WITH_STRACE],
+[case "${TRIPE_TEST_STRACE-nil}" in
+  nil)
+    $2
+    ;;
+  *)
+    mkdir -p strace-hack.$1/
+    (ulimit -c hard >/dev/null 2>&1
+     sh -c 'cd strace-hack.$1; exec "$[]@"' - \
+       strace -f -o../$1.trace \
+       sh -c 'cd ..; exec "$[]@"' - \
+       $2)
+    ;;
+ esac])
+
 ## Sequences.  (These are used for testing the replay protection machinery.)
 m4_define([R32], [ 0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15   dnl
                  16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31])
@@ -84,26 +105,11 @@ mv stdout $1/port
 ## Test body...
 $3
 
-## End of the test, now run the server.  There's an awful hack here.  If a
-## process running under strace exits with a signal, then strace will kill
-## itself with the same signal -- and therefore clobber the original
-## process's core file.  So we arrange to run strace in one directory and
-## have the child process run in another.
+## End of the test, now run the server.
 ) && :; } | {
   cd $1
   echo TRIPE $2 >&2
-  case "${TRIPE_TEST_STRACE-nil}" in
-    nil)
-      TRIPE -d. $2 >server-output.full 2>server-errors
-      ;;
-    *)
-      mkdir -p strace-hack/
-      (cd strace-hack/
-       ulimit -c hard >/dev/null 2>&1
-       strace -f -o ../tripe.trace \
-        TRIPE -d.. $2 >../server-output.full 2>../server-errors)
-      ;;
-  esac
+  WITH_STRACE([tripe], [TRIPE $2 >server-output.full 2>server-errors])
   stat=$?
   echo $stat >server-status
   if test $stat -ne 0; then