summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPetri Latvala <petri.latvala@intel.com>2018-04-25 14:55:32 +0300
committerPetri Latvala <petri.latvala@intel.com>2018-04-25 14:55:32 +0300
commit7039806ca2c0dc1297793631e92730c77191d85f (patch)
treefed186b5cd28a489253d1f350658fa78bcfaf8e0
parent4dcec7ecd6d75cf12a2c3fa842075a683eac7145 (diff)
Runtimes handling
-rw-r--r--runner/executor.c65
-rw-r--r--runner/resultgen.c12
2 files changed, 75 insertions, 2 deletions
diff --git a/runner/executor.c b/runner/executor.c
index 19f5e1e4..d199e32e 100644
--- a/runner/executor.c
+++ b/runner/executor.c
@@ -10,10 +10,60 @@
#include <sys/types.h>
#include <sys/utsname.h>
#include <sys/wait.h>
+#include <time.h>
#include <unistd.h>
#include "executor.h"
+/* Clock handling copied from igt_core.c */
+
+static clockid_t igt_clock;
+
+#define time_valid(ts) ((ts)->tv_sec || (ts)->tv_nsec)
+
+static double
+time_elapsed(struct timespec *then,
+ struct timespec *now)
+{
+ double elapsed = -1.;
+
+ if (time_valid(then) && time_valid(now)) {
+ elapsed = now->tv_sec - then->tv_sec;
+ elapsed += (now->tv_nsec - then->tv_nsec) * 1e-9;
+ }
+
+ return elapsed;
+}
+
+static int gettime(struct timespec *ts)
+{
+ memset(ts, 0, sizeof(*ts));
+ errno = 0;
+
+ /* Stay on the same clock for consistency. */
+ if (igt_clock != (clockid_t)-1) {
+ if (clock_gettime(igt_clock, ts))
+ goto error;
+ return 0;
+ }
+
+#ifdef CLOCK_MONOTONIC_RAW
+ if (!clock_gettime(igt_clock = CLOCK_MONOTONIC_RAW, ts))
+ return 0;
+#endif
+#ifdef CLOCK_MONOTONIC_COARSE
+ if (!clock_gettime(igt_clock = CLOCK_MONOTONIC_COARSE, ts))
+ return 0;
+#endif
+ if (!clock_gettime(igt_clock = CLOCK_MONOTONIC, ts))
+ return 0;
+error:
+ fprintf(stderr, "Warning: Could not read monotonic time: %s\n",
+ strerror(errno));
+
+ return -errno;
+}
+
static void prune_subtest(struct job_list_entry *entry, char *subtest)
{
char *excl;
@@ -219,6 +269,9 @@ static int monitor_output(pid_t child,
int nfds = outfd;
int timeout = settings->inactivity_timeout;
int killed = 0; /* 1 = sigterm sent, 2 = sigkill sent */
+ struct timespec time_beg, time_end;
+
+ gettime(&time_beg);
if (errfd > nfds)
nfds = errfd;
@@ -399,6 +452,8 @@ static int monitor_output(pid_t child,
}
if (sigfd >= 0 && FD_ISSET(sigfd, &set)) {
+ double time;
+
s = read(sigfd, &siginfo, sizeof(siginfo));
if (s < 0) {
fprintf(stderr, "Error reading from signalfd: %s\n",
@@ -417,9 +472,15 @@ static int monitor_output(pid_t child,
status = 9999;
}
- dprintf(outputs[_F_JOURNAL], "%s:%d\n",
+ gettime(&time_end);
+
+ time = time_elapsed(&time_beg, &time_end);
+ if (time < 0.0)
+ time = 0.0;
+
+ dprintf(outputs[_F_JOURNAL], "%s:%d (%.3fs)\n",
killed ? "timeout" : "exit",
- status);
+ status, time);
if (settings->sync) {
fdatasync(outputs[_F_JOURNAL]);
}
diff --git a/runner/resultgen.c b/runner/resultgen.c
index 49b7bb68..be3fc687 100644
--- a/runner/resultgen.c
+++ b/runner/resultgen.c
@@ -683,12 +683,24 @@ static bool fill_from_journal(int fd, char *binary,
while ((read = getline(&line, &linelen, f)) > 0) {
if (read >= exitlen && !memcmp(line, exitline, exitlen)) {
+ char *p = strchr(line, '(');
+ char *igt_name = gen_igt_name(binary, NULL);
+ double time = 0.0;
+ struct json_object *obj = get_or_create_json_object(tests, igt_name);
+
exitcode = atoi(line + exitlen);
+
+ if (p++) {
+ time = strtod(p, NULL);
+ }
+
+ add_runtime(obj, time);
} else if (read >= timeoutlen && !memcmp(line, timeoutline, timeoutlen)) {
if (subtests->size) {
char *last_subtest = subtests->names[subtests->size - 1];
char *igt_name = gen_igt_name(binary, last_subtest);
struct json_object *obj = get_or_create_json_object(tests, igt_name);
+
json_object_object_add(obj, "result",
json_object_new_string("timeout"));
}