From 18b29bd58d1daa1752e981488445e0fcb100f2a7 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Tue, 30 Dec 2025 11:28:36 -0500 Subject: Implement task timeout * Add argument: --task-timeout=1[s,m,h] * Timed out tasks are SIGKILL'd * If killing a task fails, the entire program ends --- tests/test_multiprocessing.c | 1 + 1 file changed, 1 insertion(+) (limited to 'tests') diff --git a/tests/test_multiprocessing.c b/tests/test_multiprocessing.c index 7c9d695..b10f530 100644 --- a/tests/test_multiprocessing.c +++ b/tests/test_multiprocessing.c @@ -214,6 +214,7 @@ int main(int argc, char *argv[]) { test_mp_fail_fast, test_mp_stop_continue }; + globals.task_timeout = 60; STASIS_TEST_RUN(tests); STASIS_TEST_END_MAIN(); } -- cgit From 11e4e32a37e61d7e3168adbdfaf507aa58cb43f0 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Fri, 2 Jan 2026 16:29:45 -0500 Subject: Add tests * test_mp_timeout() * test_mp_seconds_to_human_readable() --- tests/test_multiprocessing.c | 54 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/test_multiprocessing.c b/tests/test_multiprocessing.c index b10f530..4a68688 100644 --- a/tests/test_multiprocessing.c +++ b/tests/test_multiprocessing.c @@ -171,6 +171,42 @@ void test_mp_fail_fast() { mp_pool_free(&p); } +static void test_mp_timeout() { + struct MultiProcessingPool *p = NULL; + p = mp_pool_init("timeout", "timeoutlogs"); + p->status_interval = 1; + struct MultiProcessingTask *task = mp_pool_task(p, "timeout", NULL, "sleep 5"); + int timeout = 3; + task->timeout = timeout; + mp_pool_join(p, 1, 0); + STASIS_ASSERT((task->time_data.duration >= (double) timeout && task->time_data.duration < (double) timeout + 1), "Timeout occurred out of desired range"); + mp_pool_show_summary(p); + mp_pool_free(&p); +} + +static void test_mp_seconds_to_human_readable() { + struct testcase { + int seconds; + const char *expected; + } tc[] = { + {.seconds = -1, "-1s"}, + {.seconds = 0, "0s"}, + {.seconds = 10, "10s"}, + {.seconds = 20, "20s"}, + {.seconds = 30, "30s"}, + {.seconds = 60, "1m 0s"}, + {.seconds = 125, "2m 5s"}, + {.seconds = 3600, "1h 0m 0s"}, + {.seconds = 86399, "23h 59m 59s"}, + {.seconds = 86400, "24h 0m 0s"}, + }; + for (size_t i = 0; i < sizeof(tc) / sizeof(tc[0]); i++) { + char *result = seconds_to_human_readable(tc[i].seconds); + printf("seconds=%d, expected: %s, got: %s\n", tc[i].seconds, tc[i].expected, result); + STASIS_ASSERT(strcmp(result, tc[i].expected) == 0, "bad output"); + } +} + pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; static void *pool_container(void *data) { char *commands_sc[] = { @@ -206,15 +242,19 @@ void test_mp_stop_continue() { int main(int argc, char *argv[]) { STASIS_TEST_BEGIN_MAIN(); STASIS_TEST_FUNC *tests[] = { - test_mp_pool_init, - test_mp_task, - test_mp_pool_join, - test_mp_pool_free, - test_mp_pool_workflow, - test_mp_fail_fast, - test_mp_stop_continue + //test_mp_pool_init, + //test_mp_task, + //test_mp_pool_join, + //test_mp_pool_free, + //test_mp_pool_workflow, + //test_mp_fail_fast, + test_mp_timeout, + test_mp_seconds_to_human_readable, + //test_mp_stop_continue }; + globals.task_timeout = 60; + STASIS_TEST_RUN(tests); STASIS_TEST_END_MAIN(); } -- cgit From 5c1f18bf3a98ad71d3674f4fd935feae73e0963a Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Sat, 3 Jan 2026 02:01:22 -0500 Subject: Trying to fix a buffer overflow reported by the CI * Locally ASAN wasn't complaining. --- tests/test_multiprocessing.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/test_multiprocessing.c b/tests/test_multiprocessing.c index 4a68688..1db8716 100644 --- a/tests/test_multiprocessing.c +++ b/tests/test_multiprocessing.c @@ -185,7 +185,7 @@ static void test_mp_timeout() { } static void test_mp_seconds_to_human_readable() { - struct testcase { + const struct testcase { int seconds; const char *expected; } tc[] = { @@ -201,7 +201,8 @@ static void test_mp_seconds_to_human_readable() { {.seconds = 86400, "24h 0m 0s"}, }; for (size_t i = 0; i < sizeof(tc) / sizeof(tc[0]); i++) { - char *result = seconds_to_human_readable(tc[i].seconds); + char result[255] = {0}; + seconds_to_human_readable(tc[i].seconds, result, sizeof(result)); printf("seconds=%d, expected: %s, got: %s\n", tc[i].seconds, tc[i].expected, result); STASIS_ASSERT(strcmp(result, tc[i].expected) == 0, "bad output"); } -- cgit From b840c9737effa4b9c5e6550efab468c53e86cf11 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Sat, 3 Jan 2026 08:56:31 -0500 Subject: Enable tests --- tests/test_multiprocessing.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/test_multiprocessing.c b/tests/test_multiprocessing.c index 1db8716..60aa4f6 100644 --- a/tests/test_multiprocessing.c +++ b/tests/test_multiprocessing.c @@ -243,15 +243,15 @@ void test_mp_stop_continue() { int main(int argc, char *argv[]) { STASIS_TEST_BEGIN_MAIN(); STASIS_TEST_FUNC *tests[] = { - //test_mp_pool_init, - //test_mp_task, - //test_mp_pool_join, - //test_mp_pool_free, - //test_mp_pool_workflow, - //test_mp_fail_fast, + test_mp_pool_init, + test_mp_task, + test_mp_pool_join, + test_mp_pool_free, + test_mp_pool_workflow, + test_mp_fail_fast, test_mp_timeout, test_mp_seconds_to_human_readable, - //test_mp_stop_continue + test_mp_stop_continue }; globals.task_timeout = 60; -- cgit From 272231cf29b8ce348d53b6950247fd7faec2d372 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Sat, 3 Jan 2026 11:41:47 -0500 Subject: Add TESTS_VERBOSE cmake option * Defines STASIS_TEST_VERBOSE --- tests/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tests') diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 2b09e9e..08ef833 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -30,6 +30,9 @@ foreach(source_file ${source_files}) elseif (CMAKE_C_COMPILER_ID STREQUAL "MSVC") target_compile_options(${test_executable} PRIVATE ${win_cflags} ${win_msvc_cflags}) endif() + if (TESTS_VERBOSE) + target_compile_definitions(${test_executable} PRIVATE STASIS_TEST_VERBOSE=1) + endif () target_include_directories(${test_executable} PRIVATE ${core_INCLUDE} ${delivery_INCLUDE} -- cgit From c948d5020091cc40fe8eb7f0a21e51a2c1dc3ef5 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Sat, 3 Jan 2026 11:42:24 -0500 Subject: Add STASIS_TEST_MSG macro --- tests/include/testing.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'tests') diff --git a/tests/include/testing.h b/tests/include/testing.h index ab24115..6fa5ca6 100644 --- a/tests/include/testing.h +++ b/tests/include/testing.h @@ -9,6 +9,15 @@ #define __FILE_NAME__ __FILE__ #endif +#ifdef STASIS_TEST_VERBOSE +#define STASIS_TEST_MSG(MSG, ...) do { \ +fprintf(stderr, "%s:%d:%s(): ", path_basename(__FILE__), __LINE__, __FUNCTION__); \ +fprintf(stderr, MSG LINE_SEP, __VA_ARGS__); \ +} while (0) +#else +#define STASIS_TEST_MSG(MSG, ...) do {} while (0) +#endif + typedef void(STASIS_TEST_FUNC)(); struct stasis_test_result_t { const char *filename; -- cgit From ba5a5fda9c3fcc5490c97ddb6b1beef41da7c8e2 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Sat, 3 Jan 2026 11:42:41 -0500 Subject: First use of STASIS_TEST_MSG --- tests/test_multiprocessing.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/test_multiprocessing.c b/tests/test_multiprocessing.c index 60aa4f6..3a462f1 100644 --- a/tests/test_multiprocessing.c +++ b/tests/test_multiprocessing.c @@ -161,7 +161,7 @@ void test_mp_fail_fast() { if (task->status == 0) result.total_status_success++; if (task->pid == MP_POOL_PID_UNUSED && task->status == MP_POOL_TASK_STATUS_INITIAL) result.total_unused++; } - fprintf(stderr, "total_status_fail = %d\ntotal_status_success = %d\ntotal_signaled = %d\ntotal_unused = %d\n", + STASIS_TEST_MSG("\ntotal_status_fail = %d\ntotal_status_success = %d\ntotal_signaled = %d\ntotal_unused = %d", result.total_status_fail, result.total_status_success, result.total_signaled, result.total_unused); STASIS_ASSERT(result.total_status_fail, "Should have failures"); STASIS_ASSERT(result.total_status_success, "Should have successes"); @@ -203,7 +203,7 @@ static void test_mp_seconds_to_human_readable() { for (size_t i = 0; i < sizeof(tc) / sizeof(tc[0]); i++) { char result[255] = {0}; seconds_to_human_readable(tc[i].seconds, result, sizeof(result)); - printf("seconds=%d, expected: %s, got: %s\n", tc[i].seconds, tc[i].expected, result); + STASIS_TEST_MSG("seconds=%d, expected: %s, got: %s", tc[i].seconds, tc[i].expected, result); STASIS_ASSERT(strcmp(result, tc[i].expected) == 0, "bad output"); } } -- cgit