This is an archive of the discontinued LLVM Phabricator instance.

tsan: refactor trace tests
ClosedPublic

Authored by dvyukov on Oct 5 2021, 7:41 AM.

Details

Summary

Instead of creating real threads for trace tests
create a new ThreadState in the main thread.
This makes the tests more unit-testy and will also
help with future trace tests that will need
more than 1 thread. Creating more than 1 real thread and
dispatching test actions across multiple threads in the
required deterministic order is painful.

This is resubmit of reverted D110546 with 2 changes:

  1. The previous version patched ImitateTlsWrite to not

expect ThreadState to be allocated in TLS (the CHECK
failed for the fake test threads).
This added an ugly hack into production code and was still
logically wrong because we imitated write to the main
thread TLS/stack when we started the fake test thread
(which has nothing to do with the main thread TLS/stack).
This version uses ThreadType::Fiber instead of ThreadType::Regular
for the fake threads. This naturally makes ThreadStart skip
obtaining stack/tls and imitating writes to them.

  1. This version still skips the tests on Darwin and PowerPC

to be on the safer side. Build bots reported failures for PowerPC
for the previous version.

Diff Detail

Event Timeline

dvyukov created this revision.Oct 5 2021, 7:41 AM
dvyukov requested review of this revision.Oct 5 2021, 7:41 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 5 2021, 7:41 AM
Herald added a subscriber: Restricted Project. · View Herald Transcript
melver accepted this revision.Oct 6 2021, 2:02 AM
melver added inline comments.
compiler-rt/lib/tsan/tests/unit/tsan_trace_test.cpp
24

Does this mean the new trace code is broken on these architectures? Or is it just the test itself?

I currently cannot tell if v3 will be broken on Mac and PPC. If not, a comment reasoning why it won't be broken would help.

This revision is now accepted and ready to land.Oct 6 2021, 2:02 AM
dvyukov updated this revision to Diff 380233.Oct 17 2021, 3:38 AM

extended explanatory comment

dvyukov marked an inline comment as done.Oct 17 2021, 3:38 AM
dvyukov added inline comments.
compiler-rt/lib/tsan/tests/unit/tsan_trace_test.cpp
24

Good point. I extended the comment.

This revision was landed with ongoing or failed builds.Oct 17 2021, 3:39 AM
This revision was automatically updated to reflect the committed changes.
dvyukov marked an inline comment as done.