Skip to content

[Threading][test] Repair none threading tests #59561

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions test/Concurrency/async_task_base_priority.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// REQUIRES: concurrency_runtime
// UNSUPPORTED: back_deployment_runtime
// UNSUPPORTED: back_deploy_concurrency
// UNSUPPORTED: threading_none

import StdlibUnittest
import Dispatch
Expand Down
1 change: 1 addition & 0 deletions test/Runtime/associated_witness_concurrency.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// RUN: %target-run %t
// REQUIRES: libdispatch
// REQUIRES: executable_test
// UNSUPPORTED: threading_none

import Dispatch

Expand Down
1 change: 1 addition & 0 deletions test/Sanitizers/tsan/mainactor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// REQUIRES: libdispatch
// REQUIRES: tsan_runtime
// UNSUPPORTED: use_os_stdlib
// UNSUPPORTED: threading_none

import Dispatch

Expand Down
1 change: 1 addition & 0 deletions test/Sanitizers/tsan/tsan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// REQUIRES: tsan_runtime
// UNSUPPORTED: OS=tvos
// UNSUPPORTED: CPU=powerpc64le
// UNSUPPORTED: threading_none

// FIXME: This should be covered by "tsan_runtime"; older versions of Apple OSs
// don't support TSan.
Expand Down
12 changes: 12 additions & 0 deletions unittests/Threading/LockingHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ void tryLockable(M &mutex) {

// We cannot lock a locked lock
ret = mutex.try_lock();
#if SWIFT_THREADING_NONE
// Noop since none threading mode always succeeds getting lock
(void)ret;
#else
ASSERT_FALSE(ret);
#endif

mutex.unlock();
}
Expand All @@ -61,6 +66,12 @@ void basicLockableThreaded(M &mutex) {
ASSERT_EQ(count2, 500);
}

#if SWIFT_THREADING_NONE
template <typename M>
void lockableThreaded(M &mutex) {
// Noop since none threading mode always succeeds getting lock
}
#else
// More extensive tests
template <typename M>
void lockableThreaded(M &mutex) {
Expand Down Expand Up @@ -90,6 +101,7 @@ void lockableThreaded(M &mutex) {
ASSERT_EQ(count1, 500);
ASSERT_EQ(count2, 500);
}
#endif

// Test a scoped lock implementation
template <typename SL, typename M>
Expand Down
33 changes: 33 additions & 0 deletions unittests/Threading/ThreadingHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,37 @@
#ifndef THREADING_HELPERS_H
#define THREADING_HELPERS_H

#if SWIFT_THREADING_NONE

template <typename ThreadBody, typename AfterSpinRelease>
void threadedExecute(int threadCount, ThreadBody threadBody,
AfterSpinRelease afterSpinRelease) {
for (int i = 0; i < threadCount; ++i) {
threadBody(i);
}
}

template <typename ThreadBody>
void threadedExecute(int threadCount, ThreadBody threadBody) {
threadedExecute(threadCount, threadBody, [] {});
}

template <typename M, typename C, typename ConsumerBody, typename ProducerBody>
void threadedExecute(M &mutex, C &condition, bool &doneCondition,
ConsumerBody consumerBody, ProducerBody producerBody) {
for (int i = 1; i <= 5; ++i) {
producerBody(i);
}
mutex.withLockThenNotifyAll(condition, [&] {
doneCondition = true;
});
for (int i = 1; i <= 8; ++i) {
consumerBody(i);
}
}

#else // !SWIFT_THREADING_NONE

#include <thread>

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

#endif // !SWIFT_THREADING_NONE

#endif
1 change: 1 addition & 0 deletions validation-test/Runtime/ConcurrentMetadata.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// RUN: %target-run-simple-swift
// REQUIRES: executable_test
// UNSUPPORTED: single_threaded_runtime
// UNSUPPORTED: threading_none

// Exercise the metadata cache from multiple threads to shake out any
// concurrency bugs.
Expand Down