From da66a5704ed884ee3a6e1b498a8a08d2cea9e9b3 Mon Sep 17 00:00:00 2001 From: Snaipe Date: Thu, 22 Oct 2015 18:13:29 +0100 Subject: [PATCH] Integrated new report system into core --- src/core/runner.c | 5 +++++ src/entry/main.c | 1 + src/log/output.c | 50 ++++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 51 insertions(+), 5 deletions(-) diff --git a/src/core/runner.c b/src/core/runner.c index bbe870a..be6ff1e 100644 --- a/src/core/runner.c +++ b/src/core/runner.c @@ -37,6 +37,7 @@ #include "wrappers/wrap.h" #include "string/i18n.h" #include "io/event.h" +#include "log/output.h" #include "runner_coroutine.h" #include "stats.h" #include "runner.h" @@ -347,6 +348,8 @@ struct criterion_test_set *criterion_initialize(void) { if (resume_child()) // (windows only) resume from the fork exit(0); + criterion_init_output(); + return criterion_init(); } @@ -451,6 +454,8 @@ static int criterion_run_all_tests_impl(struct criterion_test_set *set) { report(POST_ALL, stats); log(post_all, stats); + process_all_output(stats); + cleanup: sfree(g_worker_pipe); sfree(stats); diff --git a/src/entry/main.c b/src/entry/main.c index f711c8b..eaad074 100644 --- a/src/entry/main.c +++ b/src/entry/main.c @@ -30,6 +30,7 @@ #include "criterion/options.h" #include "criterion/ordered-set.h" #include "core/runner.h" +#include "log/output.h" #include "config.h" #include "common.h" diff --git a/src/log/output.c b/src/log/output.c index f23aa1d..b7893ff 100644 --- a/src/log/output.c +++ b/src/log/output.c @@ -1,10 +1,13 @@ #include #include #include +#include #include "criterion/output.h" +typedef kvec_t(const char *) str_vec; + KHASH_MAP_INIT_STR(ht_str, criterion_reporter*) -KHASH_MAP_INIT_STR(ht_path, const char *) +KHASH_MAP_INIT_STR(ht_path, str_vec*) static khash_t(ht_str) *reporters; static khash_t(ht_path) *outputs; @@ -22,13 +25,50 @@ int criterion_register_output_provider(const char *name, criterion_reporter *rep } int criterion_add_output(const char *provider, const char *path) { - int absent; - khint_t k = kh_put(ht_path, outputs, provider, &absent); - kh_value(outputs, k) = path; - return absent; + khint_t k = kh_get(ht_path, outputs, provider); + + if (k == kh_end(outputs)) { + int absent; + k = kh_put(ht_path, outputs, provider, &absent); + if (absent == -1) + return -1; + + str_vec *vec = malloc(sizeof (str_vec)); + kv_init(*vec); + kh_value(outputs, k) = vec; + } + str_vec *vec = kh_value(outputs, k); + + kv_push(const char *, *vec, path); + return 1; } void criterion_free_output(void) { kh_destroy(ht_str, reporters); kh_destroy(ht_path, outputs); } + +void process_all_output(struct criterion_global_stats *stats) { + for (khint_t k = kh_begin(reporters); k != kh_end(reporters); ++k) { + if (!kh_exist(reporters, k)) + continue; + + criterion_reporter *report = kh_value(reporters, k); + khint_t ko = kh_get(ht_path, outputs, kh_key(reporters, k)); + if (ko == kh_end(outputs)) + continue; + + str_vec *vec = kh_value(outputs, ko); + for (size_t i = 0; i < kv_size(*vec); ++i) { + const char *path = kv_A(*vec, i); + + FILE *f; + if (path[0] == '-' && !path[1]) + f = stderr; + else + f = fopen(path, "w"); + + report(f, stats); + } + } +}