diff --git a/include/criterion/logging.h b/include/criterion/logging.h index 17baf4b..d823b9c 100644 --- a/include/criterion/logging.h +++ b/include/criterion/logging.h @@ -47,6 +47,7 @@ enum criterion_logging_prefix { CRITERION_LOGGING_PREFIX_SKIP, CRITERION_LOGGING_PREFIX_PASS, CRITERION_LOGGING_PREFIX_FAIL, + CRITERION_LOGGING_PREFIX_ERR, }; struct criterion_prefix_data { @@ -82,6 +83,7 @@ extern const struct criterion_prefix_data g_criterion_logging_prefixes[]; # define CRITERION_PREFIX_SKIP (&g_criterion_logging_prefixes[CRITERION_LOGGING_PREFIX_SKIP ]) # define CRITERION_PREFIX_PASS (&g_criterion_logging_prefixes[CRITERION_LOGGING_PREFIX_PASS ]) # define CRITERION_PREFIX_FAIL (&g_criterion_logging_prefixes[CRITERION_LOGGING_PREFIX_FAIL ]) +# define CRITERION_PREFIX_ERR (&g_criterion_logging_prefixes[CRITERION_LOGGING_PREFIX_ERR ]) CR_API void criterion_vlog(enum criterion_logging_level level, const char *msg, va_list args); @@ -97,6 +99,8 @@ CR_API void criterion_log(enum criterion_logging_level level, const char *msg, . # define criterion_pinfo(...) criterion_plog(CRITERION_INFO, __VA_ARGS__) # define criterion_pimportant(...) criterion_plog(CRITERION_IMPORTANT, __VA_ARGS__) +# define criterion_perror(...) criterion_plog(CRITERION_IMPORTANT, CRITERION_PREFIX_ERR, __VA_ARGS__) + struct criterion_output_provider { void (*log_pre_all )(struct criterion_test_set *set); void (*log_pre_suite )(struct criterion_suite_set *set); diff --git a/src/compat/alloc.c b/src/compat/alloc.c index 7ae9d6d..48d83f5 100644 --- a/src/compat/alloc.c +++ b/src/compat/alloc.c @@ -23,6 +23,7 @@ */ #include "alloc.h" #include "internal.h" +#include "criterion/logging.h" #include #ifdef VANILLA_WIN32 @@ -51,7 +52,7 @@ void init_inheritable_heap(void) { HeapDestroy(h->handle); if (g_heap == (HANDLE) NULL) { - fputs("Could not create the private inheritable heap.", stderr); + criterion_perror("Could not create the private inheritable heap.\n"); abort(); } } diff --git a/src/compat/pipe.h b/src/compat/pipe.h index 148bb1e..f6a607e 100644 --- a/src/compat/pipe.h +++ b/src/compat/pipe.h @@ -27,6 +27,7 @@ # include # include # include "common.h" +# include "criterion/logging.h" struct pipe_handle; typedef struct pipe_handle s_pipe_handle; @@ -69,6 +70,7 @@ INLINE FILE* get_std_file(enum criterion_std_fd fd_kind) { case CR_STDOUT: return stdout; case CR_STDERR: return stderr; } + criterion_perror("get_std_file: invalid parameter.\n"); abort(); } diff --git a/src/compat/process.c b/src/compat/process.c index 08b6625..4e6c286 100644 --- a/src/compat/process.c +++ b/src/compat/process.c @@ -23,6 +23,7 @@ */ #include #include +#include #include #include "core/worker.h" #include "core/runner.h" @@ -133,8 +134,12 @@ static void handle_sigchld(UNUSED int sig) { memcpy(buf + sizeof (kind), &pid_ull, sizeof (pid_ull)); memcpy(buf + sizeof (kind) + sizeof (pid_ull), &ws, sizeof (ws)); - if (write(fd, &buf, sizeof (buf)) < (ssize_t) sizeof (buf)) + if (write(fd, &buf, sizeof (buf)) < (ssize_t) sizeof (buf)) { + criterion_perror("Could not write the WORKER_TERMINATED event " + "down the event pipe: %s.\n", + strerror(errno)); abort(); + } } } #endif diff --git a/src/core/runner.c b/src/core/runner.c index d12e3f8..ca72f17 100644 --- a/src/core/runner.c +++ b/src/core/runner.c @@ -24,6 +24,7 @@ #define CRITERION_LOGGING_COLORS #include #include +#include #include #include #include "criterion/criterion.h" @@ -437,8 +438,11 @@ static int criterion_run_all_tests_impl(struct criterion_test_set *set) { fflush(NULL); // flush everything before forking g_worker_pipe = stdpipe(); - if (g_worker_pipe == NULL) + if (g_worker_pipe == NULL) { + criterion_perror("Could not initialize the event pipe: %s.\n", + strerror(errno)); abort(); + } struct criterion_global_stats *stats = stats_init(); run_tests_async(set, stats); diff --git a/src/core/worker.c b/src/core/worker.c index bbc26df..3a6240d 100644 --- a/src/core/worker.c +++ b/src/core/worker.c @@ -23,6 +23,7 @@ */ #include #include +#include #include #include "criterion/types.h" @@ -69,6 +70,8 @@ struct event *worker_read_event(struct worker_set *workers, s_pipe_file_handle * return ev; } } + criterion_perror("Could not link back the event PID to the active workers.\n"); + criterion_perror("The event pipe might have been corrupted.\n"); abort(); } return NULL; @@ -102,6 +105,7 @@ struct worker *spawn_test_worker(struct execution_context *ctx, s_proc_handle *proc = fork_process(); if (proc == (void *) -1) { + criterion_perror("Could not fork the current process and start a worker: %s.\n", strerror(errno)); abort(); } else if (proc == NULL) { run_worker(&g_worker_context); diff --git a/src/io/event.c b/src/io/event.c index 3820ba3..2747f63 100644 --- a/src/io/event.c +++ b/src/io/event.c @@ -28,6 +28,7 @@ #include "criterion/stats.h" #include "criterion/common.h" #include "criterion/hooks.h" +#include "criterion/logging.h" #include "core/worker.h" #include "event.h" @@ -50,10 +51,12 @@ void destroy_assert_event(void *ptr, UNUSED void *meta) { # define unlikely(x) (x) #endif -#define ASSERT(Cond) \ - do { \ - if (unlikely(!(Cond))) \ - abort(); \ +#define ASSERT(Cond) \ + do { \ + if (unlikely(!(Cond))){ \ + criterion_perror("Corrupted event IO in the worker pipe.\n"); \ + abort(); \ + } \ } while (0) struct event *read_event(s_pipe_file_handle *f) { diff --git a/src/log/logging.c b/src/log/logging.c index 7ef465b..a09b2d7 100644 --- a/src/log/logging.c +++ b/src/log/logging.c @@ -31,8 +31,10 @@ #ifdef ENABLE_NLS # define LOG_FORMAT "[%1$s%2$s%3$s] %4$s" +# define ERROR_FORMAT "[%1$s%2$s%3$s] %4$s%5$s%6$s%7$s" #else # define LOG_FORMAT "[%s%s%s] %s" +# define ERROR_FORMAT "[%s%s%s] %s%s%s%s" #endif const struct criterion_prefix_data g_criterion_logging_prefixes[] = { @@ -42,6 +44,7 @@ const struct criterion_prefix_data g_criterion_logging_prefixes[] = { [CRITERION_LOGGING_PREFIX_SKIP] = { "SKIP", CRIT_FG_GOLD }, [CRITERION_LOGGING_PREFIX_PASS] = { "PASS", CRIT_FG_GREEN }, [CRITERION_LOGGING_PREFIX_FAIL] = { "FAIL", CRIT_FG_RED }, + [CRITERION_LOGGING_PREFIX_ERR] = { "ERR ", CRIT_FG_RED }, { NULL, NULL } }; @@ -56,11 +59,23 @@ void criterion_plog(enum criterion_logging_level level, const struct criterion_p vsnprintf(formatted_msg, sizeof formatted_msg, msg, args); va_end(args); - fprintf(stderr, _(LOG_FORMAT), + if (prefix == &g_criterion_logging_prefixes[CRITERION_LOGGING_PREFIX_ERR]) { + fprintf(stderr, _(ERROR_FORMAT), + CRIT_COLOR_NORMALIZE(prefix->color), + prefix->prefix, + RESET, + FG_RED, + FG_BOLD, + formatted_msg, + RESET); + } else { + fprintf(stderr, _(LOG_FORMAT), CRIT_COLOR_NORMALIZE(prefix->color), prefix->prefix, RESET, formatted_msg); + } + } void criterion_log(enum criterion_logging_level level, const char *msg, ...) {