[igt-dev] [PATCH i-g-t 1/2] runner/resultgen: Split json generation and file writing
Petri Latvala
petri.latvala at intel.com
Tue Oct 23 12:20:23 UTC 2018
This allows testing to skip the file writing.
Signed-off-by: Petri Latvala <petri.latvala at intel.com>
Cc: Arkadiusz Hiler <arkadiusz.hiler at intel.com>
---
runner/resultgen.c | 36 +++++++++++++++++++++++-------------
runner/resultgen.h | 2 ++
2 files changed, 25 insertions(+), 13 deletions(-)
diff --git a/runner/resultgen.c b/runner/resultgen.c
index e059c65b..a62e400e 100644
--- a/runner/resultgen.c
+++ b/runner/resultgen.c
@@ -988,14 +988,13 @@ static void create_result_root_nodes(struct json_object *root,
json_object_object_add(root, "runtimes", results->runtimes);
}
-bool generate_results(int dirfd)
+struct json_object *generate_results_json(int dirfd)
{
struct settings settings;
struct job_list job_list;
struct json_object *obj, *elapsed;
struct results results;
- int resultsfd, testdirfd, fd;
- const char *json_string;
+ int testdirfd, fd;
size_t i;
init_settings(&settings);
@@ -1003,18 +1002,12 @@ bool generate_results(int dirfd)
if (!read_settings(&settings, dirfd)) {
fprintf(stderr, "resultgen: Cannot parse settings\n");
- return false;
+ return NULL;
}
if (!read_job_list(&job_list, dirfd)) {
fprintf(stderr, "resultgen: Cannot parse job list\n");
- return false;
- }
-
- /* TODO: settings.overwrite */
- if ((resultsfd = openat(dirfd, "results.json", O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0) {
- fprintf(stderr, "resultgen: Cannot create results file\n");
- return false;
+ return NULL;
}
obj = json_object_new_object();
@@ -1079,12 +1072,29 @@ bool generate_results(int dirfd)
if (!parse_test_directory(testdirfd, &job_list.entries[i], &settings, &results)) {
close(testdirfd);
- close(resultsfd);
- return false;
+ return NULL;
}
close(testdirfd);
}
+ return obj;
+}
+
+bool generate_results(int dirfd)
+{
+ struct json_object *obj = generate_results_json(dirfd);
+ const char *json_string;
+ int resultsfd;
+
+ if (obj == NULL)
+ return false;
+
+ /* TODO: settings.overwrite */
+ if ((resultsfd = openat(dirfd, "results.json", O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0) {
+ fprintf(stderr, "resultgen: Cannot create results file\n");
+ return false;
+ }
+
json_string = json_object_to_json_string_ext(obj, JSON_C_TO_STRING_PRETTY);
write(resultsfd, json_string, strlen(json_string));
close(resultsfd);
diff --git a/runner/resultgen.h b/runner/resultgen.h
index 83a0876b..ab0bf108 100644
--- a/runner/resultgen.h
+++ b/runner/resultgen.h
@@ -6,4 +6,6 @@
bool generate_results(int dirfd);
bool generate_results_path(char *resultspath);
+struct json_object *generate_results_json(int dirfd);
+
#endif
--
2.18.0
More information about the igt-dev
mailing list