From c5efefd4b70fee71ede4322b9ba96e1de10d4347 Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Sat, 25 Feb 2023 23:50:35 -0700 Subject: [PATCH] tests: allow disabling threading when debugging tests with `-threads 1` --- common/threads.cc | 7 +++++++ tests/test_main.cc | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/common/threads.cc b/common/threads.cc index eb04fea7..e481c3aa 100644 --- a/common/threads.cc +++ b/common/threads.cc @@ -13,6 +13,13 @@ static std::unique_ptr tbbGlobalControl; void configureTBB(int maxthreads, bool lowPriority) { + if (tbbGlobalControl) { + logging::print("ignoring multiple configureTBB calls\n"); + // only allow calling once per process, so we can disable threading in test_main.cc + // and further attempts to re-enable it will be ignored + return; + } + tbbGlobalControl = std::unique_ptr(); if (maxthreads > 0) { diff --git a/tests/test_main.cc b/tests/test_main.cc index 4687c9ba..b72e2db1 100644 --- a/tests/test_main.cc +++ b/tests/test_main.cc @@ -2,6 +2,7 @@ #include #include +#include int main(int argc, char **argv) { @@ -10,6 +11,14 @@ int main(int argc, char **argv) // writing console colors within test case output breaks doctest/CLion integration logging::enable_color_codes = false; + // parse "-threads 1" + for (int i = 1; i < argc - 1; ++i) { + if (!strcmp("-threads", argv[i])) { + configureTBB(atoi(argv[i + 1]), false); + break; + } + } + doctest::Context context; context.applyCommandLine(argc, argv);