[Issue #59] Added more explicit abort messages

This commit is contained in:
Snaipe 2015-09-27 23:49:22 +02:00
parent ee4e811bd0
commit 3fe7b41256
8 changed files with 46 additions and 8 deletions

View file

@ -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);

View file

@ -23,6 +23,7 @@
*/
#include "alloc.h"
#include "internal.h"
#include "criterion/logging.h"
#include <stdlib.h>
#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();
}
}

View file

@ -27,6 +27,7 @@
# include <stdio.h>
# include <stdlib.h>
# 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();
}

View file

@ -23,6 +23,7 @@
*/
#include <assert.h>
#include <string.h>
#include <errno.h>
#include <csptr/smalloc.h>
#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

View file

@ -24,6 +24,7 @@
#define CRITERION_LOGGING_COLORS
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <csptr/smalloc.h>
#include <valgrind/valgrind.h>
#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);

View file

@ -23,6 +23,7 @@
*/
#include <stdlib.h>
#include <stdbool.h>
#include <errno.h>
#include <csptr/smalloc.h>
#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);

View file

@ -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) {

View file

@ -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, ...) {