Skip to content

Commit 1c094a1

Browse files
authored
[TSan][Test-Only] Account for race in cxa_guard_acquire.cpp test (#165853)
It is possible for "Enter potentially blocking region" to come before "Enter constructor" in this test - if the thread that acquires the guard fails to reach its printf before the other thread that enters the blocking region reaches its own printf. Note that for the exit logs this inversion is not possible. This patch addresses this by allowing those two log lines to come in either order. rdar://163375661
1 parent 7c9f137 commit 1c094a1

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

compiler-rt/test/tsan/cxa_guard_acquire.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,17 @@ int main(int argc, char **argv) {
6666
printf("Enter main\n");
6767

6868
// If initialization is contended, the blocked thread should enter a
69-
// potentially blocking region.
69+
// potentially blocking region. Note that we use a DAG check because it is
70+
// possible for Thread 1 to acquire the guard, then Thread 2 fail to acquire
71+
// the guard then call `OnPotentiallyBlockingRegionBegin` and print "Enter
72+
// potentially blocking region\n", before Thread 1 manages to reach "Enter
73+
// constructor\n". This is exceptionally rare, but can be replicated by
74+
// inserting a `sleep(1)` between `LazyInit() {` and `printf("Enter
75+
// constructor\n");`. Due to the barrier it is not possible for the exit logs
76+
// to be inverted.
7077
//
71-
// CHECK-NEXT: Enter constructor
72-
// CHECK-NEXT: Enter potentially blocking region
78+
// CHECK-DAG: Enter constructor
79+
// CHECK-DAG: Enter potentially blocking region
7380
// CHECK-NEXT: Exit constructor
7481
// CHECK-NEXT: Exit potentially blocking region
7582
barrier_init(&barrier, 2);

0 commit comments

Comments
 (0)