From a6f2bbb4c27cac8a2a6f9c052d8dd118bcd86580 Mon Sep 17 00:00:00 2001 From: Snaipe Date: Wed, 23 Sep 2015 01:48:39 +0200 Subject: [PATCH] Boyscouting. --- src/compat/pipe.h | 5 +++-- src/compat/process.c | 10 ---------- src/core/runner.c | 10 +++++----- src/core/worker.c | 17 +++++------------ src/core/worker.h | 8 ++++---- src/io/event.h | 2 +- 6 files changed, 18 insertions(+), 34 deletions(-) diff --git a/src/compat/pipe.h b/src/compat/pipe.h index 83aa63d..c2f7d13 100644 --- a/src/compat/pipe.h +++ b/src/compat/pipe.h @@ -25,6 +25,7 @@ # define PIPE_H_ # include +# include # include "common.h" struct pipe_handle; @@ -53,13 +54,13 @@ FILE *pipe_out(s_pipe_handle *p, enum pipe_opt opts); int stdpipe_options(s_pipe_handle *pipe, int id, int noblock); void pipe_std_redirect(s_pipe_handle *pipe, enum criterion_std_fd fd); -INLINE FILE* get_std_file(int fd_kind) { +INLINE FILE* get_std_file(enum criterion_std_fd fd_kind) { switch (fd_kind) { case CR_STDIN: return stdin; case CR_STDOUT: return stdout; case CR_STDERR: return stderr; } - return NULL; + abort(); } extern s_pipe_handle *stdout_redir; diff --git a/src/compat/process.c b/src/compat/process.c index b107686..08b6625 100644 --- a/src/compat/process.c +++ b/src/compat/process.c @@ -385,16 +385,6 @@ failure: #endif } -void wait_process(s_proc_handle *handle, int *status) { -#ifdef VANILLA_WIN32 - WaitForSingleObject(handle->handle, INFINITE); - *status = get_win_status(handle->handle); - CloseHandle(handle->handle); -#else - waitpid(handle->pid, status, 0); -#endif -} - s_proc_handle *get_current_process() { s_proc_handle *handle = smalloc(sizeof (s_proc_handle)); #ifdef VANILLA_WIN32 diff --git a/src/core/runner.c b/src/core/runner.c index 2fef2f7..abb25c9 100644 --- a/src/core/runner.c +++ b/src/core/runner.c @@ -295,7 +295,7 @@ static void handle_event(struct event *ev) { } } -static struct process *run_test(struct criterion_global_stats *stats, +static struct worker *run_test(struct criterion_global_stats *stats, struct criterion_suite_stats *suite_stats, struct criterion_test_stats *test_stats, struct test_single_param *param) { @@ -345,7 +345,7 @@ void criterion_finalize(struct criterion_test_set *set) { sfree(set); } -static struct process *run_next_test(struct criterion_test_set *p_set, +static struct worker *run_next_test(struct criterion_test_set *p_set, struct criterion_global_stats *p_stats, ccrContParam) { ccrBeginContext; @@ -407,7 +407,7 @@ static struct process *run_next_test(struct criterion_test_set *p_set, (char *) ctx->params.params + ctx->i * ctx->params.size }; - struct process *worker = run_test(ctx->stats, + struct worker *worker = run_test(ctx->stats, ctx->suite_stats, ctx->test_stats, ¶m); @@ -435,7 +435,7 @@ static struct process *run_next_test(struct criterion_test_set *p_set, continue; } - struct process *worker = run_test(ctx->stats, + struct worker *worker = run_test(ctx->stats, ctx->suite_stats, ctx->test_stats, NULL); @@ -468,7 +468,7 @@ static void run_tests_async(struct criterion_test_set *set, size_t nb_workers = DEF(criterion_options.jobs, get_processor_count()); struct worker_set workers = { .max_workers = nb_workers, - .workers = calloc(nb_workers, sizeof (struct process*)), + .workers = calloc(nb_workers, sizeof (struct worker*)), }; size_t active_workers = 0; diff --git a/src/core/worker.c b/src/core/worker.c index e956176..8912b19 100644 --- a/src/core/worker.c +++ b/src/core/worker.c @@ -47,7 +47,7 @@ bool is_runner(void) { } static void close_process(void *ptr, UNUSED void *meta) { - struct process *proc = ptr; + struct worker *proc = ptr; fclose(proc->in); sfree(proc->ctx.suite_stats); sfree(proc->ctx.test_stats); @@ -87,7 +87,7 @@ void run_worker(struct worker_context *ctx) { _Exit(0); } -struct process *spawn_test_worker(struct execution_context *ctx, +struct worker *spawn_test_worker(struct execution_context *ctx, f_worker_func func, s_pipe_handle *pipe) { g_worker_context = (struct worker_context) { @@ -98,7 +98,7 @@ struct process *spawn_test_worker(struct execution_context *ctx, .param = ctx->param, }; - struct process *ptr = NULL; + struct worker *ptr = NULL; s_proc_handle *proc = fork_process(); if (proc == (void *) -1) { @@ -112,11 +112,11 @@ struct process *spawn_test_worker(struct execution_context *ctx, } ptr = smalloc( - .size = sizeof (struct process), + .size = sizeof (struct worker), .kind = SHARED, .dtor = close_process); - *ptr = (struct process) { + *ptr = (struct worker) { .proc = proc, .in = pipe_in(pipe, PIPE_DUP), .ctx = *ctx, @@ -139,10 +139,3 @@ struct process_status get_status(int status) { return (struct process_status) { .kind = STOPPED }; } - -struct process_status wait_proc(struct process *proc) { - int status; - wait_process(proc->proc, &status); - - return get_status(status); -} diff --git a/src/core/worker.h b/src/core/worker.h index e7b2c7a..865ab96 100644 --- a/src/core/worker.h +++ b/src/core/worker.h @@ -46,7 +46,7 @@ struct execution_context { struct test_single_param *param; }; -struct process { +struct worker { int active; s_proc_handle *proc; FILE *in; @@ -70,7 +70,7 @@ struct worker_status { }; struct worker_set { - struct process **workers; + struct worker **workers; size_t max_workers; }; @@ -80,9 +80,9 @@ void run_worker(struct worker_context *ctx); void set_runner_process(void); void unset_runner_process(void); bool is_runner(void); -struct process_status wait_proc(struct process *proc); +struct process_status wait_proc(struct worker *proc); struct process_status get_status(int status); -struct process *spawn_test_worker(struct execution_context *ctx, +struct worker *spawn_test_worker(struct execution_context *ctx, f_worker_func func, s_pipe_handle *pipe); struct event *worker_read_event(struct worker_set *workers, FILE *pipe); diff --git a/src/io/event.h b/src/io/event.h index faa54d3..641c966 100644 --- a/src/io/event.h +++ b/src/io/event.h @@ -35,7 +35,7 @@ struct event { int kind; void *data; - struct process *worker; + struct worker *worker; size_t worker_index; };