Fix multithreaded test harness teardown races - #376
Merged
Conversation
Co-authored-by: Ihar Yermalayeu <ermig1979@gmail.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aims to harden the multithreaded test harness teardown path by making logging state mutations/output thread-safe and by reducing races around Linux signal handler installation/restoration during parallel test execution.
Changes:
- Added a mutex to serialize
Test::Logconfiguration mutations andWrite()output/state tracking across threads. - Replaced per-worker Linux signal handler install/restore with a shared, ref-counted
SignalScope, plus a thread-local “valid jump” guard forsetjmp/longjmpusage.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/Test/TestLog.cpp |
Serializes log configuration changes and Write() output/state with a mutex. |
src/Test/Test.cpp |
Introduces shared Linux signal handler scope and a thread-local validity guard for setjmp/longjmp to avoid teardown races. |
Comment on lines
47
to
52
| void Log::SetLogFile(String name) | ||
| { | ||
| std::lock_guard<std::mutex> lock(_mutex); | ||
| CreatePathIfNotExist(name, true); | ||
| _file.open(name); | ||
| } |
Comment on lines
563
to
+566
| #if defined(__linux__) | ||
| static __thread jmp_buf s_threadData; | ||
| static __thread bool s_threadDataValid; | ||
| static std::mutex s_signalMutex; |
Comment on lines
759
to
+762
| #if defined(__linux__) | ||
| __thread jmp_buf Task::s_threadData; | ||
| __thread bool Task::s_threadDataValid = false; | ||
| std::mutex Task::s_signalMutex; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Test::Logstate mutations and output so skipped messages, thread names, and file/stdout writes are safe under threaded tests.Testing
cmake ./prj/cmake -B build-debug-ci -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=g++ -DCMAKE_C_COMPILER=gcc -DSIMD_TOOLCHAIN="g++" -DSIMD_TARGET="" -DSIMD_AVX512VNNI=ON -DSIMD_AVX512BF16=ON -DSIMD_AMXBF16=ON -DSIMD_TEST_FLAGS="-march=native" -DSIMD_SHARED=ON && cmake --build build-debug-ci --parallel$(nproc)LD_LIBRARY_PATH="/workspace/build-debug-ci:$LD_LIBRARY_PATH" ./Test "-r=.." -m=a -tt=4 "-ot=log_Debug_sobel_verify.txt" -ts=1 -mt=1 -w=640 -h=480 -c=256 -fi=SobelLD_LIBRARY_PATH="/workspace/build-debug-ci:$LD_LIBRARY_PATH" ./Test "-r=.." -m=a -tt=$(nproc) "-ot=log_Debug_broad_verify.txt" -ts=5 -mt=1 -w=640 -h=480 -c=256 -fe=SynetConvolution8i -fe=SynetQuantizedConvolutionSIGILLinSynetConvolution8iForwardAutoTest, so local validation used the broad filtered run above to reach the reported post-success teardown path.