From 6936ca44ded8e84b77ae2ff0c00c6769d2b387f7 Mon Sep 17 00:00:00 2001 From: Snaipe Date: Sun, 13 Dec 2015 18:52:56 +0100 Subject: [PATCH] Removed the generic event sending function from the API --- include/criterion/event.h | 2 - src/core/runner.c | 3 +- src/io/event.c | 146 +++----------------------------------- src/io/event.h | 2 - 4 files changed, 11 insertions(+), 142 deletions(-) diff --git a/include/criterion/event.h b/include/criterion/event.h index 9fe2983..4498413 100644 --- a/include/criterion/event.h +++ b/include/criterion/event.h @@ -34,8 +34,6 @@ CR_BEGIN_C_API -CR_API void criterion_send_event(int kind, void *data, size_t size); - CR_API void criterion_send_assert(struct criterion_assert_stats *stats); CR_END_C_API diff --git a/src/core/runner.c b/src/core/runner.c index 66fefe0..3fbe043 100644 --- a/src/core/runner.c +++ b/src/core/runner.c @@ -384,7 +384,8 @@ int criterion_run_all_tests(struct criterion_test_set *set) { void run_single_test_by_name(const char *testname) { struct criterion_test_set *set = criterion_init(); - g_event_pipe = pipe_file_open(NULL); + // FIXME: initialize null sink for pipe system. + abort(); FOREACH_SET(struct criterion_suite_set *s, set->suites) { size_t tests = s->tests ? s->tests->size : 0; diff --git a/src/io/event.c b/src/io/event.c index 4c84d6f..aa7d9b7 100644 --- a/src/io/event.c +++ b/src/io/event.c @@ -22,146 +22,18 @@ * THE SOFTWARE. */ -#include -#include -#include -#include "criterion/stats.h" -#include "criterion/internal/common.h" -#include "criterion/hooks.h" -#include "criterion/logging.h" -#include "core/worker.h" #include "protocol/protocol.h" +#include "protocol/messages.h" #include "event.h" -s_pipe_file_handle *g_event_pipe = NULL; - int g_client_socket = -1; -pb_ostream_t g_event_stream; -void destroy_event(void *ptr, CR_UNUSED void *meta) { - struct event *ev = ptr; - free(ev->data); -} - -void destroy_assert_event(void *ptr, CR_UNUSED void *meta) { - struct event *ev = ptr; - free((void*) ((struct criterion_assert_stats *) ev->data)->message); - free(ev->data); -} - -#ifdef __GNUC__ -# define unlikely(x) __builtin_expect((x),0) -#else -# define unlikely(x) (x) -#endif - -#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) { - unsigned kind; - ASSERT(pipe_read(&kind, sizeof (unsigned), f) == 1); - - unsigned long long pid; - ASSERT(pipe_read(&pid, sizeof (unsigned long long), f) == 1); - - switch (kind) { - case ASSERT: { - const size_t assert_size = sizeof (struct criterion_assert_stats); - struct criterion_assert_stats *buf = NULL; - char *msg = NULL; - - buf = malloc(assert_size); - ASSERT(pipe_read(buf, assert_size, f) == 1); - - size_t len = 0; - ASSERT(pipe_read(&len, sizeof (size_t), f) == 1); - - msg = malloc(len); - ASSERT(pipe_read(msg, len, f) == 1); - - buf->message = msg; - - struct event *ev = smalloc( - .size = sizeof (struct event), - .dtor = destroy_assert_event - ); - *ev = (struct event) { .pid = pid, .kind = kind, .data = buf }; - return ev; - } - case TEST_ABORT: { - char *msg = NULL; - - size_t len = 0; - ASSERT(pipe_read(&len, sizeof (size_t), f) == 1); - - msg = malloc(len); - ASSERT(pipe_read(msg, len, f) == 1); - - struct event *ev = smalloc( - .size = sizeof (struct event), - .dtor = destroy_event - ); - *ev = (struct event) { .pid = pid, .kind = kind, .data = msg }; - return ev; - } - case THEORY_FAIL: { - size_t len = 0; - ASSERT(pipe_read(&len, sizeof (size_t), f) == 1); - - char *buf = malloc(len); - ASSERT(pipe_read(buf, len, f) == 1); - - struct event *ev = smalloc( - .size = sizeof (struct event), - .dtor = destroy_event - ); - *ev = (struct event) { .pid = pid, .kind = kind, .data = buf }; - return ev; - } - case POST_TEST: { - double *elapsed_time = malloc(sizeof (double)); - ASSERT(pipe_read(elapsed_time, sizeof (double), f) == 1); - - struct event *ev = smalloc( - .size = sizeof (struct event), - .dtor = destroy_event - ); - *ev = (struct event) { .pid = pid, .kind = kind, .data = elapsed_time }; - return ev; - } - case WORKER_TERMINATED: { - struct worker_status *status = malloc(sizeof (struct worker_status)); - ASSERT(pipe_read(status, sizeof (struct worker_status), f) == 1); - - struct event *ev = smalloc( - .size = sizeof (struct event), - .dtor = destroy_event - ); - *ev = (struct event) { .pid = pid, .kind = kind, .data = status }; - return ev; - } - default: { - struct event *ev = smalloc(sizeof (struct event)); - *ev = (struct event) { .pid = pid, .kind = kind, .data = NULL }; - return ev; - } - } -} - -void criterion_send_event(int kind, void *data, size_t size) { - unsigned long long pid = get_process_id(); - - unsigned char *buf = malloc(sizeof (int) + sizeof (pid) + size); - memcpy(buf, &kind, sizeof (int)); - memcpy(buf + sizeof (int), &pid, sizeof (pid)); - memcpy(buf + sizeof (int) + sizeof (pid), data, size); - ASSERT(pipe_write(buf, sizeof (int) + sizeof (pid) + size, g_event_pipe) == 1); - - free(buf); +void criterion_send_assert(struct criterion_assert_stats *stats) { + criterion_protocol_msg msg = criterion_message(assert, + .message = stats->message, + .passed = stats->passed, + .file = stats->file, + .line = stats->line, + ); + write_message(g_client_socket, &msg); } diff --git a/src/io/event.h b/src/io/event.h index 07cf391..a42153e 100644 --- a/src/io/event.h +++ b/src/io/event.h @@ -29,8 +29,6 @@ # include # include -extern s_pipe_file_handle *g_event_pipe; -extern pb_ostream_t g_event_stream; extern int g_client_socket; struct event {