Removed the generic event sending function from the API
This commit is contained in:
parent
f8965214e3
commit
6936ca44de
4 changed files with 11 additions and 142 deletions
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
146
src/io/event.c
146
src/io/event.c
|
@ -22,146 +22,18 @@
|
|||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <csptr/smalloc.h>
|
||||
#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);
|
||||
}
|
||||
|
|
|
@ -29,8 +29,6 @@
|
|||
# include <stdio.h>
|
||||
# include <pb.h>
|
||||
|
||||
extern s_pipe_file_handle *g_event_pipe;
|
||||
extern pb_ostream_t g_event_stream;
|
||||
extern int g_client_socket;
|
||||
|
||||
struct event {
|
||||
|
|
Loading…
Add table
Reference in a new issue