Boyscouting.

This commit is contained in:
Snaipe 2015-09-23 01:48:39 +02:00
parent 525e69a5ab
commit a6f2bbb4c2
6 changed files with 18 additions and 34 deletions

View file

@ -25,6 +25,7 @@
# define PIPE_H_
# include <stdio.h>
# include <stdlib.h>
# 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;

View file

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

View file

@ -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,
&param);
@ -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;

View file

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

View file

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

View file

@ -35,7 +35,7 @@ struct event {
int kind;
void *data;
struct process *worker;
struct worker *worker;
size_t worker_index;
};