Skip to content

Commit 9ea7cd4

Browse files
authored
Merge pull request #59561 from kateinoigakukun/katei/repair-none-threading-tests
[Threading][test] Repair none threading tests
2 parents cff02f8 + 356156d commit 9ea7cd4

File tree

7 files changed

+50
-0
lines changed

7 files changed

+50
-0
lines changed

test/Concurrency/async_task_base_priority.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// REQUIRES: concurrency_runtime
99
// UNSUPPORTED: back_deployment_runtime
1010
// UNSUPPORTED: back_deploy_concurrency
11+
// UNSUPPORTED: threading_none
1112

1213
import StdlibUnittest
1314
import Dispatch

test/Runtime/associated_witness_concurrency.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// RUN: %target-run %t
44
// REQUIRES: libdispatch
55
// REQUIRES: executable_test
6+
// UNSUPPORTED: threading_none
67

78
import Dispatch
89

test/Sanitizers/tsan/mainactor.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// REQUIRES: libdispatch
66
// REQUIRES: tsan_runtime
77
// UNSUPPORTED: use_os_stdlib
8+
// UNSUPPORTED: threading_none
89

910
import Dispatch
1011

test/Sanitizers/tsan/tsan.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// REQUIRES: tsan_runtime
66
// UNSUPPORTED: OS=tvos
77
// UNSUPPORTED: CPU=powerpc64le
8+
// UNSUPPORTED: threading_none
89

910
// FIXME: This should be covered by "tsan_runtime"; older versions of Apple OSs
1011
// don't support TSan.

unittests/Threading/LockingHelpers.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@ void tryLockable(M &mutex) {
3636

3737
// We cannot lock a locked lock
3838
ret = mutex.try_lock();
39+
#if SWIFT_THREADING_NONE
40+
// Noop since none threading mode always succeeds getting lock
41+
(void)ret;
42+
#else
3943
ASSERT_FALSE(ret);
44+
#endif
4045

4146
mutex.unlock();
4247
}
@@ -61,6 +66,12 @@ void basicLockableThreaded(M &mutex) {
6166
ASSERT_EQ(count2, 500);
6267
}
6368

69+
#if SWIFT_THREADING_NONE
70+
template <typename M>
71+
void lockableThreaded(M &mutex) {
72+
// Noop since none threading mode always succeeds getting lock
73+
}
74+
#else
6475
// More extensive tests
6576
template <typename M>
6677
void lockableThreaded(M &mutex) {
@@ -90,6 +101,7 @@ void lockableThreaded(M &mutex) {
90101
ASSERT_EQ(count1, 500);
91102
ASSERT_EQ(count2, 500);
92103
}
104+
#endif
93105

94106
// Test a scoped lock implementation
95107
template <typename SL, typename M>

unittests/Threading/ThreadingHelpers.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,37 @@
1313
#ifndef THREADING_HELPERS_H
1414
#define THREADING_HELPERS_H
1515

16+
#if SWIFT_THREADING_NONE
17+
18+
template <typename ThreadBody, typename AfterSpinRelease>
19+
void threadedExecute(int threadCount, ThreadBody threadBody,
20+
AfterSpinRelease afterSpinRelease) {
21+
for (int i = 0; i < threadCount; ++i) {
22+
threadBody(i);
23+
}
24+
}
25+
26+
template <typename ThreadBody>
27+
void threadedExecute(int threadCount, ThreadBody threadBody) {
28+
threadedExecute(threadCount, threadBody, [] {});
29+
}
30+
31+
template <typename M, typename C, typename ConsumerBody, typename ProducerBody>
32+
void threadedExecute(M &mutex, C &condition, bool &doneCondition,
33+
ConsumerBody consumerBody, ProducerBody producerBody) {
34+
for (int i = 1; i <= 5; ++i) {
35+
producerBody(i);
36+
}
37+
mutex.withLockThenNotifyAll(condition, [&] {
38+
doneCondition = true;
39+
});
40+
for (int i = 1; i <= 8; ++i) {
41+
consumerBody(i);
42+
}
43+
}
44+
45+
#else // !SWIFT_THREADING_NONE
46+
1647
#include <thread>
1748

1849
// When true many of the threaded tests log activity to help triage issues.
@@ -131,4 +162,6 @@ void threadedExecute(M &mutex, C &condition, bool &doneCondition,
131162
}
132163
}
133164

165+
#endif // !SWIFT_THREADING_NONE
166+
134167
#endif

validation-test/Runtime/ConcurrentMetadata.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// RUN: %target-run-simple-swift
22
// REQUIRES: executable_test
33
// UNSUPPORTED: single_threaded_runtime
4+
// UNSUPPORTED: threading_none
45

56
// Exercise the metadata cache from multiple threads to shake out any
67
// concurrency bugs.

0 commit comments

Comments
 (0)