From bbc91111375e5ecd2be708fe8c2baea88093eb1a Mon Sep 17 00:00:00 2001 From: JP Appel Date: Fri, 26 Jul 2024 15:25:12 -0400 Subject: FEAT: worker now raises SIGSTOP while waiting for work --- eztester.c | 18 ++++++++++-------- eztester.h | 3 ++- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/eztester.c b/eztester.c index ef6ad94..38d02dc 100644 --- a/eztester.c +++ b/eztester.c @@ -110,7 +110,7 @@ void _ez_worker(volatile struct _ez_shared_mem *mem, while (mem->index < list->length) { // wait for work while (!mem->work_in_queue) { - usleep(1000 * 50); + usleep(50e3); } mem->status = list->tests[mem->index].runner(); @@ -122,6 +122,7 @@ void _ez_worker(volatile struct _ez_shared_mem *mem, } mem->work_in_queue = false; + raise(SIGSTOP); } exit(0); } @@ -129,13 +130,14 @@ void _ez_worker(volatile struct _ez_shared_mem *mem, void _ez_chld_handler(int signum) { int status; pid_t pid; - _ez_child_premature_exit = 1; - while ((pid = waitpid(-1, &status, WNOHANG)) > 0) { + while ((pid = waitpid(-1, &status, WNOHANG | WUNTRACED)) > 0) { if (WIFEXITED(status)) { _ez_child_premature_exit_status = WEXITSTATUS(status); + _ez_child_premature_exit = 1; } else if (WIFSIGNALED(status)) { _ez_child_premature_exit_signal = WTERMSIG(status); + _ez_child_premature_exit = 1; } } } @@ -174,17 +176,17 @@ void eztester_run(eztester_list *test_list, eztester_behavior behavior) { printf("[%03zu/%03zu] Testing: %s\n", results.current, results.total, test.name); fflush(stdout); - if (_ez_child_premature_exit) { - _ez_premature_exit("Worker Process ended prematurely!", pid, mem, - results); - } + + kill(pid, SIGCONT); + while (mem->work_in_queue) { - usleep(1000 * 50); + usleep(50e3); if (_ez_child_premature_exit) { _ez_premature_exit("Worker Process ended prematurely!", pid, mem, results); } } + status = mem->status; switch (status) { diff --git a/eztester.h b/eztester.h index 682d348..c216dd3 100644 --- a/eztester.h +++ b/eztester.h @@ -47,7 +47,8 @@ void eztester_run(eztester_list *test_list, const eztester_behavior behavior); /* Wrapper for `system` function * - * if command is null return the availability of a shell (negated result of system's behavior) + * if command is null return the availability of a shell (negated result of + * system's behavior) * * If command is not null return the exit status of the process */ -- cgit v1.2.3