|
|
50f89d |
commit 35e3fbc4512c880fccb35b8e3abd132d4be18480
|
|
|
50f89d |
Author: Florian Weimer <fweimer@redhat.com>
|
|
|
50f89d |
Date: Mon Nov 19 15:35:03 2018 +0100
|
|
|
50f89d |
|
|
|
50f89d |
support: Print timestamps in timeout handler
|
|
|
50f89d |
|
|
|
50f89d |
This is sometimes useful to determine if a test truly got stuck, or if
|
|
|
50f89d |
it was making progress (logging information to standard output) and
|
|
|
50f89d |
was merely slow to finish.
|
|
|
50f89d |
|
|
|
50f89d |
diff --git a/support/support_test_main.c b/support/support_test_main.c
|
|
|
50f89d |
index 23429779aca85613..fa3c2e06dee5ae0f 100644
|
|
|
50f89d |
--- a/support/support_test_main.c
|
|
|
50f89d |
+++ b/support/support_test_main.c
|
|
|
50f89d |
@@ -30,6 +30,7 @@
|
|
|
50f89d |
#include <string.h>
|
|
|
50f89d |
#include <sys/param.h>
|
|
|
50f89d |
#include <sys/resource.h>
|
|
|
50f89d |
+#include <sys/time.h>
|
|
|
50f89d |
#include <sys/types.h>
|
|
|
50f89d |
#include <sys/wait.h>
|
|
|
50f89d |
#include <time.h>
|
|
|
50f89d |
@@ -86,6 +87,19 @@ static pid_t test_pid;
|
|
|
50f89d |
/* The cleanup handler passed to test_main. */
|
|
|
50f89d |
static void (*cleanup_function) (void);
|
|
|
50f89d |
|
|
|
50f89d |
+static void
|
|
|
50f89d |
+print_timestamp (const char *what, struct timeval tv)
|
|
|
50f89d |
+{
|
|
|
50f89d |
+ struct tm tm;
|
|
|
50f89d |
+ if (gmtime_r (&tv.tv_sec, &tm) == NULL)
|
|
|
50f89d |
+ printf ("%s: %lld.%06d\n",
|
|
|
50f89d |
+ what, (long long int) tv.tv_sec, (int) tv.tv_usec);
|
|
|
50f89d |
+ else
|
|
|
50f89d |
+ printf ("%s: %04d-%02d-%02dT%02d:%02d:%02d.%06d\n",
|
|
|
50f89d |
+ what, 1900 + tm.tm_year, tm.tm_mon + 1, tm.tm_mday,
|
|
|
50f89d |
+ tm.tm_hour, tm.tm_min, tm.tm_sec, (int) tv.tv_usec);
|
|
|
50f89d |
+}
|
|
|
50f89d |
+
|
|
|
50f89d |
/* Timeout handler. We kill the child and exit with an error. */
|
|
|
50f89d |
static void
|
|
|
50f89d |
__attribute__ ((noreturn))
|
|
|
50f89d |
@@ -94,6 +108,13 @@ signal_handler (int sig)
|
|
|
50f89d |
int killed;
|
|
|
50f89d |
int status;
|
|
|
50f89d |
|
|
|
50f89d |
+ /* Do this first to avoid further interference from the
|
|
|
50f89d |
+ subprocess. */
|
|
|
50f89d |
+ struct timeval now;
|
|
|
50f89d |
+ bool now_available = gettimeofday (&now, NULL) == 0;
|
|
|
50f89d |
+ struct stat64 st;
|
|
|
50f89d |
+ bool st_available = fstat64 (STDOUT_FILENO, &st) == 0 && st.st_mtime != 0;
|
|
|
50f89d |
+
|
|
|
50f89d |
assert (test_pid > 1);
|
|
|
50f89d |
/* Kill the whole process group. */
|
|
|
50f89d |
kill (-test_pid, SIGKILL);
|
|
|
50f89d |
@@ -144,6 +165,13 @@ signal_handler (int sig)
|
|
|
50f89d |
printf ("Timed out: killed the child process but it exited %d\n",
|
|
|
50f89d |
WEXITSTATUS (status));
|
|
|
50f89d |
|
|
|
50f89d |
+ if (now_available)
|
|
|
50f89d |
+ print_timestamp ("Termination time", now);
|
|
|
50f89d |
+ if (st_available)
|
|
|
50f89d |
+ print_timestamp ("Last write to standard output",
|
|
|
50f89d |
+ (struct timeval) { st.st_mtim.tv_sec,
|
|
|
50f89d |
+ st.st_mtim.tv_nsec / 1000 });
|
|
|
50f89d |
+
|
|
|
50f89d |
/* Exit with an error. */
|
|
|
50f89d |
exit (1);
|
|
|
50f89d |
}
|