tests: allow disabling threading when debugging tests

with `-threads 1`
This commit is contained in:
Eric Wasylishen 2023-02-25 23:50:35 -07:00
parent 88a9cb6bb4
commit c5efefd4b7
2 changed files with 16 additions and 0 deletions

View File

@ -13,6 +13,13 @@ static std::unique_ptr<tbb::global_control> tbbGlobalControl;
void configureTBB(int maxthreads, bool lowPriority) 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<tbb::global_control>(); tbbGlobalControl = std::unique_ptr<tbb::global_control>();
if (maxthreads > 0) { if (maxthreads > 0) {

View File

@ -2,6 +2,7 @@
#include <doctest/doctest.h> #include <doctest/doctest.h>
#include <common/log.hh> #include <common/log.hh>
#include <common/threads.hh>
int main(int argc, char **argv) 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 // writing console colors within test case output breaks doctest/CLion integration
logging::enable_color_codes = false; 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; doctest::Context context;
context.applyCommandLine(argc, argv); context.applyCommandLine(argc, argv);