diff options
Diffstat (limited to 'test/libcxx')
8 files changed, 415 insertions, 0 deletions
diff --git a/test/libcxx/input.output/file.streams/c.files/no.global.filesystem.namespace/fopen.fail.cpp b/test/libcxx/input.output/file.streams/c.files/no.global.filesystem.namespace/fopen.fail.cpp new file mode 100644 index 000000000000..31a37229bf0c --- /dev/null +++ b/test/libcxx/input.output/file.streams/c.files/no.global.filesystem.namespace/fopen.fail.cpp @@ -0,0 +1,17 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// REQUIRES: libcpp-has-no-global-filesystem-namespace + +#include <cstdio> + +int main() { + // fopen is not available on systems without a global filesystem namespace. + std::fopen("", ""); +} diff --git a/test/libcxx/input.output/file.streams/c.files/no.global.filesystem.namespace/rename.fail.cpp b/test/libcxx/input.output/file.streams/c.files/no.global.filesystem.namespace/rename.fail.cpp new file mode 100644 index 000000000000..248ab4d67210 --- /dev/null +++ b/test/libcxx/input.output/file.streams/c.files/no.global.filesystem.namespace/rename.fail.cpp @@ -0,0 +1,17 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// REQUIRES: libcpp-has-no-global-filesystem-namespace + +#include <cstdio> + +int main() { + // rename is not available on systems without a global filesystem namespace. + std::rename("", ""); +} diff --git a/test/libcxx/thread/thread.condition/PR30202_notify_from_pthread_created_thread.pass.cpp b/test/libcxx/thread/thread.condition/PR30202_notify_from_pthread_created_thread.pass.cpp new file mode 100644 index 000000000000..de225fe78384 --- /dev/null +++ b/test/libcxx/thread/thread.condition/PR30202_notify_from_pthread_created_thread.pass.cpp @@ -0,0 +1,76 @@ +//===----------------------------------------------------------------------===// +// +// 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: libcpp-has-thread-api-pthread + +// notify_all_at_thread_exit(...) requires move semantics to transfer the +// unique_lock. +// UNSUPPORTED: c++98, c++03 + +// <condition_variable> + +// void +// notify_all_at_thread_exit(condition_variable& cond, unique_lock<mutex> lk); + +// Test that this function works with threads that were not created by +// std::thread. See http://llvm.org/PR30202. + + +#include <condition_variable> +#include <mutex> +#include <thread> +#include <chrono> +#include <cassert> +#include <pthread.h> + +std::condition_variable cv; +std::mutex mut; +bool exited = false; + +typedef std::chrono::milliseconds ms; +typedef std::chrono::high_resolution_clock Clock; + +void* func(void*) +{ + std::unique_lock<std::mutex> lk(mut); + std::notify_all_at_thread_exit(cv, std::move(lk)); + std::this_thread::sleep_for(ms(300)); + exited = true; + return nullptr; +} + +int main() +{ + { + std::unique_lock<std::mutex> lk(mut); + pthread_t id; + int res = pthread_create(&id, 0, &func, nullptr); + assert(res == 0); + Clock::time_point t0 = Clock::now(); + assert(exited == false); + cv.wait(lk); + Clock::time_point t1 = Clock::now(); + assert(exited); + assert(t1-t0 > ms(250)); + pthread_join(id, 0); + } + exited = false; + { + std::unique_lock<std::mutex> lk(mut); + std::thread t(&func, nullptr); + Clock::time_point t0 = Clock::now(); + assert(exited == false); + cv.wait(lk); + Clock::time_point t1 = Clock::now(); + assert(exited); + assert(t1-t0 > ms(250)); + t.join(); + } +} diff --git a/test/libcxx/thread/thread.threads/thread.thread.this/sleep_for.pass.cpp b/test/libcxx/thread/thread.threads/thread.thread.this/sleep_for.pass.cpp new file mode 100644 index 000000000000..b46c2cdec6cb --- /dev/null +++ b/test/libcxx/thread/thread.threads/thread.thread.this/sleep_for.pass.cpp @@ -0,0 +1,69 @@ +//===----------------------------------------------------------------------===// +// +// 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 + +// This test uses the POSIX header <sys/time.h> which Windows doesn't provide +// UNSUPPORTED: windows + +// This test depends on signal behaviour until r210210, so some system libs +// don't pass. +// +// XFAIL: with_system_cxx_lib=macosx10.11 +// XFAIL: with_system_cxx_lib=macosx10.10 +// XFAIL: with_system_cxx_lib=macosx10.9 +// XFAIL: with_system_cxx_lib=macosx10.8 +// XFAIL: with_system_cxx_lib=macosx10.7 + +// <thread> + +// template <class Rep, class Period> +// void sleep_for(const chrono::duration<Rep, Period>& rel_time); + +#include <thread> +#include <cstdlib> +#include <cassert> +#include <cstring> +#include <signal.h> +#include <sys/time.h> + +void sig_action(int) {} + +int main() +{ + int ec; + struct sigaction action; + action.sa_handler = &sig_action; + sigemptyset(&action.sa_mask); + action.sa_flags = 0; + + ec = sigaction(SIGALRM, &action, nullptr); + assert(!ec); + + struct itimerval it; + std::memset(&it, 0, sizeof(itimerval)); + it.it_value.tv_sec = 0; + it.it_value.tv_usec = 250000; + // This will result in a SIGALRM getting fired resulting in the nanosleep + // inside sleep_for getting EINTR. + ec = setitimer(ITIMER_REAL, &it, nullptr); + assert(!ec); + + typedef std::chrono::system_clock Clock; + typedef Clock::time_point time_point; + typedef Clock::duration duration; + std::chrono::milliseconds ms(500); + time_point t0 = Clock::now(); + std::this_thread::sleep_for(ms); + time_point t1 = Clock::now(); + std::chrono::nanoseconds ns = (t1 - t0) - ms; + std::chrono::nanoseconds err = 5 * ms / 100; + // The time slept is within 5% of 500ms + assert(std::abs(ns.count()) < err.count()); +} diff --git a/test/libcxx/utilities/function.objects/refwrap/binary.pass.cpp b/test/libcxx/utilities/function.objects/refwrap/binary.pass.cpp new file mode 100644 index 000000000000..579e81fe69e6 --- /dev/null +++ b/test/libcxx/utilities/function.objects/refwrap/binary.pass.cpp @@ -0,0 +1,80 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// reference_wrapper + +// check for deriving from binary_function + +#include <functional> +#include <type_traits> + +class functor1 + : public std::unary_function<int, char> +{ +}; + +class functor2 + : public std::binary_function<char, int, double> +{ +}; + +class functor3 + : public std::unary_function<int, int>, + public std::binary_function<char, int, double> +{ +public: + typedef float result_type; +}; + +class functor4 + : public std::unary_function<int, int>, + public std::binary_function<char, int, double> +{ +public: +}; + +struct C +{ + typedef int argument_type; + typedef int result_type; +}; + +int main() +{ + static_assert((!std::is_base_of<std::binary_function<int, char, int>, + std::reference_wrapper<functor1> >::value), ""); + static_assert((std::is_base_of<std::binary_function<char, int, double>, + std::reference_wrapper<functor2> >::value), ""); + static_assert((std::is_base_of<std::binary_function<char, int, double>, + std::reference_wrapper<functor3> >::value), ""); + static_assert((std::is_base_of<std::binary_function<char, int, double>, + std::reference_wrapper<functor4> >::value), ""); + static_assert((!std::is_base_of<std::binary_function<int, int, int>, + std::reference_wrapper<C> >::value), ""); + static_assert((!std::is_base_of<std::binary_function<int, int, float>, + std::reference_wrapper<float ()> >::value), ""); + static_assert((!std::is_base_of<std::binary_function<int, int, float>, + std::reference_wrapper<float (int)> >::value), ""); + static_assert((std::is_base_of<std::binary_function<int, int, float>, + std::reference_wrapper<float (int, int)> >::value), ""); + static_assert((!std::is_base_of<std::binary_function<int, int, float>, + std::reference_wrapper<float(*)()> >::value), ""); + static_assert((!std::is_base_of<std::binary_function<int, int, float>, + std::reference_wrapper<float(*)(int)> >::value), ""); + static_assert((std::is_base_of<std::binary_function<int, int, float>, + std::reference_wrapper<float(*)(int, int)> >::value), ""); + static_assert((!std::is_base_of<std::binary_function<C*, int, float>, + std::reference_wrapper<float(C::*)()> >::value), ""); + static_assert((std::is_base_of<std::binary_function<C*, int, float>, + std::reference_wrapper<float(C::*)(int)> >::value), ""); + static_assert((std::is_base_of<std::binary_function<const volatile C*, int, float>, + std::reference_wrapper<float(C::*)(int) const volatile> >::value), ""); +} diff --git a/test/libcxx/utilities/function.objects/refwrap/unary.pass.cpp b/test/libcxx/utilities/function.objects/refwrap/unary.pass.cpp new file mode 100644 index 000000000000..528a8f327d96 --- /dev/null +++ b/test/libcxx/utilities/function.objects/refwrap/unary.pass.cpp @@ -0,0 +1,78 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// reference_wrapper + +// check for deriving from unary_function + +#include <functional> +#include <type_traits> + +class functor1 + : public std::unary_function<int, char> +{ +}; + +class functor2 + : public std::binary_function<char, int, double> +{ +}; + +class functor3 + : public std::unary_function<int, int>, + public std::binary_function<char, int, double> +{ +public: + typedef float result_type; +}; + +class functor4 + : public std::unary_function<int, int>, + public std::binary_function<char, int, double> +{ +public: +}; + +struct C +{ + typedef int argument_type; + typedef int result_type; +}; + +int main() +{ + static_assert((std::is_base_of<std::unary_function<int, char>, + std::reference_wrapper<functor1> >::value), ""); + static_assert((!std::is_base_of<std::unary_function<char, int>, + std::reference_wrapper<functor2> >::value), ""); + static_assert((std::is_base_of<std::unary_function<int, int>, + std::reference_wrapper<functor3> >::value), ""); + static_assert((std::is_base_of<std::unary_function<int, int>, + std::reference_wrapper<functor4> >::value), ""); + static_assert((!std::is_base_of<std::unary_function<int, int>, + std::reference_wrapper<C> >::value), ""); + static_assert((!std::is_base_of<std::unary_function<int, float>, + std::reference_wrapper<float(*)()> >::value), ""); + static_assert((std::is_base_of<std::unary_function<int, float>, + std::reference_wrapper<float (int)> >::value), ""); + static_assert((!std::is_base_of<std::unary_function<int, float>, + std::reference_wrapper<float (int, int)> >::value), ""); + static_assert((std::is_base_of<std::unary_function<int, float>, + std::reference_wrapper<float(*)(int)> >::value), ""); + static_assert((!std::is_base_of<std::unary_function<int, float>, + std::reference_wrapper<float(*)(int, int)> >::value), ""); + static_assert((std::is_base_of<std::unary_function<C*, float>, + std::reference_wrapper<float(C::*)()> >::value), ""); + static_assert((std::is_base_of<std::unary_function<const volatile C*, float>, + std::reference_wrapper<float(C::*)() const volatile> >::value), ""); + static_assert((!std::is_base_of<std::unary_function<C*, float>, + std::reference_wrapper<float(C::*)(int)> >::value), ""); +} diff --git a/test/libcxx/utilities/template.bitset/includes.pass.cpp b/test/libcxx/utilities/template.bitset/includes.pass.cpp new file mode 100644 index 000000000000..2e3c2812e441 --- /dev/null +++ b/test/libcxx/utilities/template.bitset/includes.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// test that <bitset> includes <cstddef>, <string>, <stdexcept> and <iosfwd> + +#include <bitset> + +#ifndef _LIBCPP_CSTDDEF +#error <cstddef> has not been included +#endif + +#ifndef _LIBCPP_STRING +#error <string> has not been included +#endif + +#ifndef _LIBCPP_STDEXCEPT +#error <stdexcept> has not been included +#endif + +#ifndef _LIBCPP_IOSFWD +#error <iosfwd> has not been included +#endif + +int main() +{ +} diff --git a/test/libcxx/utilities/tuple/tuple.tuple/empty_member.pass.cpp b/test/libcxx/utilities/tuple/tuple.tuple/empty_member.pass.cpp new file mode 100644 index 000000000000..1e7243b5f501 --- /dev/null +++ b/test/libcxx/utilities/tuple/tuple.tuple/empty_member.pass.cpp @@ -0,0 +1,46 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// template <class... Types> class tuple; + +// UNSUPPORTED: c++98, c++03 + +// This is not a portable test + +#include <tuple> + +struct A {}; + +struct B {}; + +int main() +{ + { + typedef std::tuple<int, A> T; + static_assert((sizeof(T) == sizeof(int)), ""); + } + { + typedef std::tuple<A, int> T; + static_assert((sizeof(T) == sizeof(int)), ""); + } + { + typedef std::tuple<A, int, B> T; + static_assert((sizeof(T) == sizeof(int)), ""); + } + { + typedef std::tuple<A, B, int> T; + static_assert((sizeof(T) == sizeof(int)), ""); + } + { + typedef std::tuple<int, A, B> T; + static_assert((sizeof(T) == sizeof(int)), ""); + } +} |
