From 5caab92d0b9c8516b7ea02809608fcd835af19d4 Mon Sep 17 00:00:00 2001 From: Petri Latvala Date: Thu, 27 Sep 2018 16:11:42 +0300 Subject: runner: Add time_elapsed field to results When starting a test run, drop a timestamp file. Do the same when ending a run. Slap those timestamps directly into the time_elapsed field in results.json. Using timestamps instead of measuring actual elapsed time goes against the naming of the field, but the name is chosen by piglit. Even though piglit itself uses timestamps. Corner cases: On incomplete test runs, the end timestamp will be missing. The time_elapsed field will only have the start timestamp. This matches piglit behaviour exactly. On incomplete but resumed test runs, the end timestamp will be the time when the resume finishes. Piglit doesn't do this, and instead leaves the end timestamp missing. Discussing which behaviour is better is left as an exercise to the readers. Signed-off-by: Petri Latvala Cc: Arkadiusz Hiler Cc: Tomi Sarvela Reviewed-by: Arkadiusz Hiler --- runner/resultgen.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'runner/resultgen.c') diff --git a/runner/resultgen.c b/runner/resultgen.c index e8a60083..11eff9d3 100644 --- a/runner/resultgen.c +++ b/runner/resultgen.c @@ -987,9 +987,9 @@ bool generate_results(int dirfd) { struct settings settings; struct job_list job_list; - struct json_object *obj; + struct json_object *obj, *elapsed; struct results results; - int resultsfd, testdirfd, unamefd; + int resultsfd, testdirfd, fd; const char *json_string; size_t i; @@ -1020,17 +1020,33 @@ bool generate_results(int dirfd) json_object_new_string(settings.name) : json_object_new_string("")); - if ((unamefd = openat(dirfd, "uname.txt", O_RDONLY)) >= 0) { + if ((fd = openat(dirfd, "uname.txt", O_RDONLY)) >= 0) { char buf[128]; - ssize_t r = read(unamefd, buf, 128); + ssize_t r = read(fd, buf, sizeof(buf)); if (r > 0 && buf[r - 1] == '\n') r--; json_object_object_add(obj, "uname", json_object_new_string_len(buf, r)); - close(unamefd); + close(fd); + } + + elapsed = json_object_new_object(); + json_object_object_add(elapsed, "__type__", json_object_new_string("TimeAttribute")); + if ((fd = openat(dirfd, "starttime.txt", O_RDONLY)) >= 0) { + char buf[128] = {}; + read(fd, buf, sizeof(buf)); + json_object_object_add(elapsed, "start", json_object_new_double(atof(buf))); + close(fd); + } + if ((fd = openat(dirfd, "endtime.txt", O_RDONLY)) >= 0) { + char buf[128] = {}; + read(fd, buf, sizeof(buf)); + json_object_object_add(elapsed, "end", json_object_new_double(atof(buf))); + close(fd); } + json_object_object_add(obj, "time_elapsed", elapsed); create_result_root_nodes(obj, &results); @@ -1045,7 +1061,6 @@ bool generate_results(int dirfd) * * - lspci * - options - * - time_elapsed */ for (i = 0; i < job_list.size; i++) { -- cgit v1.2.3