Skip to content

Commit de42b36

Browse files
committed
Fix: On 32-bit machines avoid exhausting stack in tests
1 parent b3df7e1 commit de42b36

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

scripts/test.cpp

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -530,30 +530,38 @@ int main(void) {
530530
// Start stress-testing the implementation
531531
std::printf("Starting stress tests...\n");
532532
std::size_t const max_cores = std::thread::hardware_concurrency();
533+
534+
// On 32-bit architectures, limit thread counts to avoid resource exhaustion
535+
// Each thread needs ~8MB stack, and 255 threads would consume 2GB+ address space
536+
constexpr bool is_32bit = sizeof(void *) == 4;
537+
constexpr std::size_t max_stress_threads = is_32bit ? 23 : 255;
538+
533539
using stress_test_func_t = bool(std::size_t, std::size_t) /* noexcept */;
534540
struct {
535-
char const *name;
541+
char const *pool_name;
536542
stress_test_func_t *function;
537543
std::size_t count_threads;
538544
std::size_t count_tasks;
539545
} const stress_tests[] = {
540-
{"`fu8` with 3 threads & 3 inputs", &stress_test_composite<fu8_t>, 3, 3},
541-
{"`fu8` with 3 threads & 2 inputs", &stress_test_composite<fu8_t>, 3, 2},
542-
{"`fu8` with 3 threads & 4 inputs", &stress_test_composite<fu8_t>, 3, 4},
543-
{"`fu8` with 3 threads & 5 inputs", &stress_test_composite<fu8_t>, 3, 5},
544-
{"`fu8` with 7 threads & 255 inputs", &stress_test_composite<fu8_t>, 7, 255},
545-
{"`fu8` with 255 threads & 7 inputs", &stress_test_composite<fu8_t>, 255, 7},
546-
{"`fu8` with 253 threads & 254 inputs", &stress_test_composite<fu8_t>, 253, 254},
547-
{"`fu8` with 253 threads & 255 inputs", &stress_test_composite<fu8_t>, 253, 255},
548-
{"`fu8` with 255 threads & 255 inputs", &stress_test_composite<fu8_t>, 255, 255},
549-
{"`fu16` with thread/core & 65K inputs", &stress_test_composite<fu16_t>, max_cores, UINT16_MAX},
550-
{"`fu16` with 333 threads & 65K inputs", &stress_test_composite<fu16_t>, 333, UINT16_MAX},
546+
{"fu8", &stress_test_composite<fu8_t>, 3, 3},
547+
{"fu8", &stress_test_composite<fu8_t>, 3, 2},
548+
{"fu8", &stress_test_composite<fu8_t>, 3, 4},
549+
{"fu8", &stress_test_composite<fu8_t>, 3, 5},
550+
{"fu8", &stress_test_composite<fu8_t>, 7, max_stress_threads},
551+
{"fu8", &stress_test_composite<fu8_t>, max_stress_threads, 7},
552+
{"fu8", &stress_test_composite<fu8_t>, max_stress_threads - 2, max_stress_threads - 1},
553+
{"fu8", &stress_test_composite<fu8_t>, max_stress_threads - 2, max_stress_threads},
554+
{"fu8", &stress_test_composite<fu8_t>, max_stress_threads, max_stress_threads},
555+
{"fu16", &stress_test_composite<fu16_t>, max_cores, UINT16_MAX},
556+
{"fu16", &stress_test_composite<fu16_t>, max_stress_threads, UINT16_MAX},
551557
};
552558

553559
std::size_t const total_stress_tests = sizeof(stress_tests) / sizeof(stress_tests[0]);
554560
std::size_t failed_stress_tests = 0;
555561
for (std::size_t i = 0; i < total_stress_tests; ++i) {
556-
std::printf("Running %s... ", stress_tests[i].name);
562+
std::printf( //
563+
"Running `%s` with %zu threads & %zu inputs... ", //
564+
stress_tests[i].pool_name, stress_tests[i].count_threads, stress_tests[i].count_tasks);
557565
bool const ok = stress_tests[i].function(stress_tests[i].count_threads, stress_tests[i].count_tasks);
558566
if (ok) { std::printf("PASS\n"); }
559567
else { std::printf("FAIL\n"); }

0 commit comments

Comments
 (0)