summaryrefslogtreecommitdiff
path: root/runner
diff options
context:
space:
mode:
authorPetri Latvala <petri.latvala@intel.com>2018-10-23 15:20:23 +0300
committerPetri Latvala <petri.latvala@intel.com>2018-11-06 11:52:46 +0200
commit6d19a3b4bddb4d8716cf6b763ee784ba9bc9f440 (patch)
treeaa1adf07df6a386da5a3849336b41fd346d2ef16 /runner
parent737241d621cc1a7ff6ae4278bde234439ab61799 (diff)
runner/resultgen: Split json generation and file writing
This allows testing to skip the file writing. Signed-off-by: Petri Latvala <petri.latvala@intel.com> Cc: Arkadiusz Hiler <arkadiusz.hiler@intel.com> Reviewed-by: Arkadiusz Hiler <arkadiusz.hiler@intel.com>
Diffstat (limited to 'runner')
-rw-r--r--runner/resultgen.c36
-rw-r--r--runner/resultgen.h2
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