diff options
Diffstat (limited to 'test/libcxx/thread')
17 files changed, 530 insertions, 0 deletions
diff --git a/test/libcxx/thread/futures/futures.promise/set_exception.pass.cpp b/test/libcxx/thread/futures/futures.promise/set_exception.pass.cpp new file mode 100644 index 000000000000..bf567a30243a --- /dev/null +++ b/test/libcxx/thread/futures/futures.promise/set_exception.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// + +// UNSUPPORTED: libcpp-no-exceptions +// UNSUPPORTED: libcpp-has-no-threads +// UNSUPPORTED: c++98, c++03 + +// <future> + +// class promise<R> + +// void set_exception(exception_ptr p); +// Test that a null exception_ptr is diagnosed. + +#define _LIBCPP_ASSERT(x, m) ((x) ? ((void)0) : throw 42) + +#define _LIBCPP_DEBUG 0 +#include <future> +#include <exception> +#include <cstdlib> +#include <cassert> + + +int main() +{ + { + typedef int T; + std::promise<T> p; + try { + p.set_exception(std::exception_ptr()); + assert(false); + } catch (int const& value) { + assert(value == 42); + } + } + { + typedef int& T; + std::promise<T> p; + try { + p.set_exception(std::exception_ptr()); + assert(false); + } catch (int const& value) { + assert(value == 42); + } + } +} diff --git a/test/libcxx/thread/futures/futures.promise/set_exception_at_thread_exit.pass.cpp b/test/libcxx/thread/futures/futures.promise/set_exception_at_thread_exit.pass.cpp new file mode 100644 index 000000000000..1cb61d9af297 --- /dev/null +++ b/test/libcxx/thread/futures/futures.promise/set_exception_at_thread_exit.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// + +// UNSUPPORTED: libcpp-no-exceptions +// UNSUPPORTED: libcpp-has-no-threads +// UNSUPPORTED: c++98, c++03 + +// <future> + +// class promise<R> + +// void set_exception_on_thread_exit(exception_ptr p); +// Test that a null exception_ptr is diagnosed. + +#define _LIBCPP_ASSERT(x, m) ((x) ? ((void)0) : throw 42) + +#define _LIBCPP_DEBUG 0 +#include <future> +#include <exception> +#include <cstdlib> +#include <cassert> + + +int main() +{ + { + typedef int T; + std::promise<T> p; + try { + p.set_exception_at_thread_exit(std::exception_ptr()); + assert(false); + } catch (int const& value) { + assert(value == 42); + } + } + { + typedef int& T; + std::promise<T> p; + try { + p.set_exception_at_thread_exit(std::exception_ptr()); + assert(false); + } catch (int const& value) { + assert(value == 42); + } + } +} diff --git a/test/libcxx/thread/futures/futures.task/types.pass.cpp b/test/libcxx/thread/futures/futures.task/types.pass.cpp new file mode 100644 index 000000000000..cb0fb803c6ab --- /dev/null +++ b/test/libcxx/thread/futures/futures.task/types.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: libcpp-has-no-threads +// UNSUPPORTED: c++98, c++03 + +// <future> + +// template<class R, class... ArgTypes> +// class packaged_task<R(ArgTypes...)> +// { +// public: +// typedef R result_type; // extension + +// This is a libc++ extension. + +#include <future> +#include <type_traits> + +struct A {}; + +int main() +{ + static_assert((std::is_same<std::packaged_task<A(int, char)>::result_type, A>::value), ""); +} diff --git a/test/libcxx/thread/thread.condition/thread.condition.condvar/native_handle.pass.cpp b/test/libcxx/thread/thread.condition/thread.condition.condvar/native_handle.pass.cpp new file mode 100644 index 000000000000..bf28e01a0e86 --- /dev/null +++ b/test/libcxx/thread/thread.condition/thread.condition.condvar/native_handle.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: libcpp-has-no-threads + +// <condition_variable> + +// class condition_variable; + +// typedef pthread_cond_t* native_handle_type; +// native_handle_type native_handle(); + +#include <condition_variable> +#include <cassert> + +int main() +{ + static_assert((std::is_same<std::condition_variable::native_handle_type, + pthread_cond_t*>::value), ""); + std::condition_variable cv; + std::condition_variable::native_handle_type h = cv.native_handle(); + assert(h != nullptr); +} diff --git a/test/libcxx/thread/thread.condition/version.pass.cpp b/test/libcxx/thread/thread.condition/version.pass.cpp new file mode 100644 index 000000000000..12a775e83398 --- /dev/null +++ b/test/libcxx/thread/thread.condition/version.pass.cpp @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: libcpp-has-no-threads + +// <condition_variable> + +#include <condition_variable> + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} diff --git a/test/libcxx/thread/thread.mutex/thread.lock/thread.lock.guard/variadic_mutex_mangling.pass.cpp b/test/libcxx/thread/thread.mutex/thread.lock/thread.lock.guard/variadic_mutex_mangling.pass.cpp new file mode 100644 index 000000000000..aae0afbffd37 --- /dev/null +++ b/test/libcxx/thread/thread.mutex/thread.lock/thread.lock.guard/variadic_mutex_mangling.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: libcpp-has-no-threads + +// TODO(EricWF) Investigate why typeid(...).name() returns a different string +// on GCC 4.9 but not newer GCCs. +// XFAIL: gcc-4.9 + +// THIS TESTS C++03 EXTENSIONS. + +// <mutex> + +// template <class ...Mutex> class lock_guard; + +// Test that the the variadic lock guard implementation mangles the same in +// C++11 and C++03. This is important since the mangling of `lock_guard` depends +// on it being declared as a variadic template, even in C++03. + +#define _LIBCPP_ABI_VARIADIC_LOCK_GUARD +#include <mutex> +#include <string> +#include <typeinfo> +#include <cassert> + +int main() { + const std::string expect = "NSt3__110lock_guardIJNS_5mutexEEEE"; + assert(typeid(std::lock_guard<std::mutex>).name() == expect); +} diff --git a/test/libcxx/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.class/native_handle.pass.cpp b/test/libcxx/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.class/native_handle.pass.cpp new file mode 100644 index 000000000000..12c80f02c340 --- /dev/null +++ b/test/libcxx/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.class/native_handle.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: libcpp-has-no-threads + +// <mutex> + +// class mutex; + +// typedef pthread_mutex_t* native_handle_type; +// native_handle_type native_handle(); + +#include <mutex> +#include <cassert> + +int main() +{ + std::mutex m; + pthread_mutex_t* h = m.native_handle(); + assert(h); +} diff --git a/test/libcxx/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.recursive/native_handle.pass.cpp b/test/libcxx/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.recursive/native_handle.pass.cpp new file mode 100644 index 000000000000..10626bc4072e --- /dev/null +++ b/test/libcxx/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.recursive/native_handle.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: libcpp-has-no-threads + +// <mutex> + +// class recursive_mutex; + +// typedef pthread_mutex_t* native_handle_type; +// native_handle_type native_handle(); + +#include <mutex> +#include <cassert> + +int main() +{ + std::recursive_mutex m; + pthread_mutex_t* h = m.native_handle(); + assert(h); +} diff --git a/test/libcxx/thread/thread.mutex/thread_safety_annotations_not_enabled.pass.cpp b/test/libcxx/thread/thread.mutex/thread_safety_annotations_not_enabled.pass.cpp new file mode 100644 index 000000000000..d9ac92c270c3 --- /dev/null +++ b/test/libcxx/thread/thread.mutex/thread_safety_annotations_not_enabled.pass.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: libcpp-has-no-threads + +// <mutex> + +// This test does not define _LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS so it +// should compile without any warnings or errors even though this pattern is not +// understood by the thread safety annotations. + +#include <mutex> + +int main() { + std::mutex m; + m.lock(); + { + std::unique_lock<std::mutex> g(m, std::adopt_lock); + } +} diff --git a/test/libcxx/thread/thread.mutex/thread_safety_lock_guard.pass.cpp b/test/libcxx/thread/thread.mutex/thread_safety_lock_guard.pass.cpp new file mode 100644 index 000000000000..4e85a039686a --- /dev/null +++ b/test/libcxx/thread/thread.mutex/thread_safety_lock_guard.pass.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: libcpp-has-no-threads +// REQUIRES: thread-safety + +// <mutex> + +#define _LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS + +#include <mutex> + +std::mutex m; +int foo __attribute__((guarded_by(m))); + +int main() { + std::lock_guard<std::mutex> lock(m); + foo++; +} diff --git a/test/libcxx/thread/thread.mutex/thread_safety_lock_unlock.pass.cpp b/test/libcxx/thread/thread.mutex/thread_safety_lock_unlock.pass.cpp new file mode 100644 index 000000000000..40b97c396ad6 --- /dev/null +++ b/test/libcxx/thread/thread.mutex/thread_safety_lock_unlock.pass.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: libcpp-has-no-threads +// REQUIRES: thread-safety + +// <mutex> + +#define _LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS + +#include <mutex> + +std::mutex m; +int foo __attribute__((guarded_by(m))); + +int main() { + m.lock(); + foo++; + m.unlock(); +} diff --git a/test/libcxx/thread/thread.mutex/thread_safety_missing_unlock.fail.cpp b/test/libcxx/thread/thread.mutex/thread_safety_missing_unlock.fail.cpp new file mode 100644 index 000000000000..c1425c960c00 --- /dev/null +++ b/test/libcxx/thread/thread.mutex/thread_safety_missing_unlock.fail.cpp @@ -0,0 +1,23 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: libcpp-has-no-threads +// REQUIRES: thread-safety + +// <mutex> + +#define _LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS + +#include <mutex> + +std::mutex m; + +int main() { + m.lock(); +} // expected-error {{mutex 'm' is still held at the end of function}} diff --git a/test/libcxx/thread/thread.mutex/thread_safety_requires_capability.pass.cpp b/test/libcxx/thread/thread.mutex/thread_safety_requires_capability.pass.cpp new file mode 100644 index 000000000000..e03f5eabffcf --- /dev/null +++ b/test/libcxx/thread/thread.mutex/thread_safety_requires_capability.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: libcpp-has-no-threads +// REQUIRES: thread-safety + +// <mutex> + +#define _LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS + +#include <mutex> + +std::mutex m; +int foo __attribute__((guarded_by(m))); + +void increment() __attribute__((requires_capability(m))) { + foo++; +} + +int main() { + m.lock(); + increment(); + m.unlock(); +} diff --git a/test/libcxx/thread/thread.mutex/version.pass.cpp b/test/libcxx/thread/thread.mutex/version.pass.cpp new file mode 100644 index 000000000000..81b52c79204b --- /dev/null +++ b/test/libcxx/thread/thread.mutex/version.pass.cpp @@ -0,0 +1,20 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <mutex> + +#include <mutex> + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} diff --git a/test/libcxx/thread/thread.threads/thread.thread.class/thread.thread.member/native_handle.pass.cpp b/test/libcxx/thread/thread.threads/thread.thread.class/thread.thread.member/native_handle.pass.cpp new file mode 100644 index 000000000000..c8807a965c44 --- /dev/null +++ b/test/libcxx/thread/thread.threads/thread.thread.class/thread.thread.member/native_handle.pass.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: libcpp-has-no-threads + +// <thread> + +// class thread + +// native_handle_type native_handle(); + +#include <thread> +#include <new> +#include <cstdlib> +#include <cassert> + +class G +{ + int alive_; +public: + static int n_alive; + static bool op_run; + + G() : alive_(1) {++n_alive;} + G(const G& g) : alive_(g.alive_) {++n_alive;} + ~G() {alive_ = 0; --n_alive;} + + void operator()() + { + assert(alive_ == 1); + assert(n_alive >= 1); + op_run = true; + } +}; + +int G::n_alive = 0; +bool G::op_run = false; + +int main() +{ + { + G g; + std::thread t0(g); + pthread_t pid = t0.native_handle(); + assert(pid != 0); + t0.join(); + } +} diff --git a/test/libcxx/thread/thread.threads/thread.thread.class/types.pass.cpp b/test/libcxx/thread/thread.threads/thread.thread.class/types.pass.cpp new file mode 100644 index 000000000000..a5bf77031cca --- /dev/null +++ b/test/libcxx/thread/thread.threads/thread.thread.class/types.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: libcpp-has-no-threads + +// <thread> + +// class thread +// { +// public: +// typedef pthread_t native_handle_type; +// ... +// }; + +#include <thread> +#include <type_traits> + +int main() +{ + static_assert((std::is_same<std::thread::native_handle_type, pthread_t>::value), ""); +} diff --git a/test/libcxx/thread/thread.threads/version.pass.cpp b/test/libcxx/thread/thread.threads/version.pass.cpp new file mode 100644 index 000000000000..d16b0eb06842 --- /dev/null +++ b/test/libcxx/thread/thread.threads/version.pass.cpp @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: libcpp-has-no-threads + +// <thread> + +#include <thread> + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} |
