Fix or move various non-standard tests.
This patch does the following: * Remove <__config> includes from some container tests. * Guards uses of std::launch::any in async tests because it's an extension. * Move "test/std/extensions" to "test/libcxx/extensions" * Moves various non-standard tests including those in "sequences/vector", "std/localization" and "utilities/meta". git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@267981 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -7,6 +7,8 @@
|
|||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
// UNSUPPORTED: c++98, c++03
|
||||||
|
|
||||||
// <vector>
|
// <vector>
|
||||||
|
|
||||||
// vector<const int> v; // an extension
|
// vector<const int> v; // an extension
|
||||||
@@ -16,7 +18,5 @@
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
|
|
||||||
std::vector<const int> v = {1, 2, 3};
|
std::vector<const int> v = {1, 2, 3};
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
@@ -22,7 +22,6 @@
|
|||||||
// template <class M>
|
// template <class M>
|
||||||
// iterator insert_or_assign(const_iterator hint, key_type&& k, M&& obj); // C++17
|
// iterator insert_or_assign(const_iterator hint, key_type&& k, M&& obj); // C++17
|
||||||
|
|
||||||
#include <__config>
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
@@ -60,9 +59,6 @@ public:
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
|
||||||
#ifndef _LIBCPP_HAS_NO_VARIADICS
|
|
||||||
|
|
||||||
{ // pair<iterator, bool> insert_or_assign(const key_type& k, M&& obj);
|
{ // pair<iterator, bool> insert_or_assign(const key_type& k, M&& obj);
|
||||||
typedef std::map<int, Moveable> M;
|
typedef std::map<int, Moveable> M;
|
||||||
typedef std::pair<M::iterator, bool> R;
|
typedef std::pair<M::iterator, bool> R;
|
||||||
@@ -186,7 +182,4 @@ int main()
|
|||||||
assert(r->first.get() == 3); // key
|
assert(r->first.get() == 3); // key
|
||||||
assert(r->second.get() == 5); // value
|
assert(r->second.get() == 5); // value
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // _LIBCPP_HAS_NO_VARIADICS
|
|
||||||
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
|
||||||
}
|
}
|
||||||
@@ -22,7 +22,6 @@
|
|||||||
// template <class... Args>
|
// template <class... Args>
|
||||||
// iterator try_emplace(const_iterator hint, key_type&& k, Args&&... args); // C++17
|
// iterator try_emplace(const_iterator hint, key_type&& k, Args&&... args); // C++17
|
||||||
|
|
||||||
#include <__config>
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
@@ -58,9 +57,6 @@ public:
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
|
||||||
#ifndef _LIBCPP_HAS_NO_VARIADICS
|
|
||||||
|
|
||||||
{ // pair<iterator, bool> try_emplace(const key_type& k, Args&&... args);
|
{ // pair<iterator, bool> try_emplace(const key_type& k, Args&&... args);
|
||||||
typedef std::map<int, Moveable> M;
|
typedef std::map<int, Moveable> M;
|
||||||
typedef std::pair<M::iterator, bool> R;
|
typedef std::pair<M::iterator, bool> R;
|
||||||
@@ -183,7 +179,4 @@ int main()
|
|||||||
assert(r->first.get() == 3); // key
|
assert(r->first.get() == 3); // key
|
||||||
assert(r->second.get() == 4); // value
|
assert(r->second.get() == 4); // value
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // _LIBCPP_HAS_NO_VARIADICS
|
|
||||||
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
// Testing to make sure that the max length values are correctly inserted
|
// Testing to make sure that the max length values are correctly inserted
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <cctype>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -35,11 +35,8 @@ int main()
|
|||||||
std::tm *tm = 0;
|
std::tm *tm = 0;
|
||||||
std::wint_t w = 0;
|
std::wint_t w = 0;
|
||||||
::FILE* fp = 0;
|
::FILE* fp = 0;
|
||||||
#ifdef __APPLE__
|
std::va_list va;
|
||||||
__darwin_va_list va;
|
|
||||||
#else
|
|
||||||
__builtin_va_list va;
|
|
||||||
#endif
|
|
||||||
char* ns = 0;
|
char* ns = 0;
|
||||||
wchar_t* ws = 0;
|
wchar_t* ws = 0;
|
||||||
static_assert((std::is_same<decltype(std::fwprintf(fp, L"")), int>::value), "");
|
static_assert((std::is_same<decltype(std::fwprintf(fp, L"")), int>::value), "");
|
||||||
|
|||||||
@@ -21,15 +21,22 @@
|
|||||||
// future<typename result_of<F(Args...)>::type>
|
// future<typename result_of<F(Args...)>::type>
|
||||||
// async(launch policy, F&& f, Args&&... args);
|
// async(launch policy, F&& f, Args&&... args);
|
||||||
|
|
||||||
|
|
||||||
#include <future>
|
#include <future>
|
||||||
|
#include <atomic>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
|
#include "test_macros.h"
|
||||||
|
|
||||||
typedef std::chrono::high_resolution_clock Clock;
|
typedef std::chrono::high_resolution_clock Clock;
|
||||||
typedef std::chrono::milliseconds ms;
|
typedef std::chrono::milliseconds ms;
|
||||||
|
|
||||||
|
std::atomic_bool invoked = ATOMIC_VAR_INIT(false);
|
||||||
|
|
||||||
int f0()
|
int f0()
|
||||||
{
|
{
|
||||||
|
invoked = true;
|
||||||
std::this_thread::sleep_for(ms(200));
|
std::this_thread::sleep_for(ms(200));
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
@@ -38,23 +45,27 @@ int i = 0;
|
|||||||
|
|
||||||
int& f1()
|
int& f1()
|
||||||
{
|
{
|
||||||
|
invoked = true;
|
||||||
std::this_thread::sleep_for(ms(200));
|
std::this_thread::sleep_for(ms(200));
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
void f2()
|
void f2()
|
||||||
{
|
{
|
||||||
|
invoked = true;
|
||||||
std::this_thread::sleep_for(ms(200));
|
std::this_thread::sleep_for(ms(200));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<int> f3(int j)
|
std::unique_ptr<int> f3(int j)
|
||||||
{
|
{
|
||||||
|
invoked = true;
|
||||||
std::this_thread::sleep_for(ms(200));
|
std::this_thread::sleep_for(ms(200));
|
||||||
return std::unique_ptr<int>(new int(j));
|
return std::unique_ptr<int>(new int(j));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<int> f4(std::unique_ptr<int>&& p)
|
std::unique_ptr<int> f4(std::unique_ptr<int>&& p)
|
||||||
{
|
{
|
||||||
|
invoked = true;
|
||||||
std::this_thread::sleep_for(ms(200));
|
std::this_thread::sleep_for(ms(200));
|
||||||
return std::move(p);
|
return std::move(p);
|
||||||
}
|
}
|
||||||
@@ -65,136 +76,78 @@ void f5(int j)
|
|||||||
throw j;
|
throw j;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class Ret, class CheckLamdba, class ...Args>
|
||||||
|
void test(CheckLamdba&& getAndCheckFn, bool IsDeferred, Args&&... args) {
|
||||||
|
// Reset global state.
|
||||||
|
invoked = false;
|
||||||
|
|
||||||
|
// Create the future and wait
|
||||||
|
std::future<Ret> f = std::async(std::forward<Args>(args)...);
|
||||||
|
std::this_thread::sleep_for(ms(300));
|
||||||
|
|
||||||
|
// Check that deferred async's have not invoked the function.
|
||||||
|
assert(invoked == !IsDeferred);
|
||||||
|
|
||||||
|
// Time the call to f.get() and check that the returned value matches
|
||||||
|
// what is expected.
|
||||||
|
Clock::time_point t0 = Clock::now();
|
||||||
|
assert(getAndCheckFn(f));
|
||||||
|
Clock::time_point t1 = Clock::now();
|
||||||
|
|
||||||
|
// If the async is deferred it should take more than 100ms, otherwise
|
||||||
|
// it should take less than 100ms.
|
||||||
|
if (IsDeferred) {
|
||||||
|
assert(t1-t0 > ms(100));
|
||||||
|
} else {
|
||||||
|
assert(t1-t0 < ms(100));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
{
|
// The default launch policy is implementation defined. libc++ defines
|
||||||
std::future<int> f = std::async(f0);
|
// it to be std::launch::async.
|
||||||
std::this_thread::sleep_for(ms(300));
|
bool DefaultPolicyIsDeferred = false;
|
||||||
Clock::time_point t0 = Clock::now();
|
bool DPID = DefaultPolicyIsDeferred;
|
||||||
assert(f.get() == 3);
|
|
||||||
Clock::time_point t1 = Clock::now();
|
std::launch AnyPolicy = std::launch::async | std::launch::deferred;
|
||||||
assert(t1-t0 < ms(100));
|
LIBCPP_ASSERT(AnyPolicy == std::launch::any);
|
||||||
}
|
|
||||||
{
|
|
||||||
std::future<int> f = std::async(std::launch::async, f0);
|
|
||||||
std::this_thread::sleep_for(ms(300));
|
|
||||||
Clock::time_point t0 = Clock::now();
|
|
||||||
assert(f.get() == 3);
|
|
||||||
Clock::time_point t1 = Clock::now();
|
|
||||||
assert(t1-t0 < ms(100));
|
|
||||||
}
|
|
||||||
{
|
|
||||||
std::future<int> f = std::async(std::launch::any, f0);
|
|
||||||
std::this_thread::sleep_for(ms(300));
|
|
||||||
Clock::time_point t0 = Clock::now();
|
|
||||||
assert(f.get() == 3);
|
|
||||||
Clock::time_point t1 = Clock::now();
|
|
||||||
assert(t1-t0 < ms(100));
|
|
||||||
}
|
|
||||||
{
|
|
||||||
std::future<int> f = std::async(std::launch::deferred, f0);
|
|
||||||
std::this_thread::sleep_for(ms(300));
|
|
||||||
Clock::time_point t0 = Clock::now();
|
|
||||||
assert(f.get() == 3);
|
|
||||||
Clock::time_point t1 = Clock::now();
|
|
||||||
assert(t1-t0 > ms(100));
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
{
|
||||||
std::future<int&> f = std::async(f1);
|
auto checkInt = [](std::future<int>& f) { return f.get() == 3; };
|
||||||
std::this_thread::sleep_for(ms(300));
|
test<int>(checkInt, DPID, f0);
|
||||||
Clock::time_point t0 = Clock::now();
|
test<int>(checkInt, false, std::launch::async, f0);
|
||||||
assert(&f.get() == &i);
|
test<int>(checkInt, true, std::launch::deferred, f0);
|
||||||
Clock::time_point t1 = Clock::now();
|
test<int>(checkInt, DPID, AnyPolicy, f0);
|
||||||
assert(t1-t0 < ms(100));
|
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
std::future<int&> f = std::async(std::launch::async, f1);
|
auto checkIntRef = [&](std::future<int&>& f) { return &f.get() == &i; };
|
||||||
std::this_thread::sleep_for(ms(300));
|
test<int&>(checkIntRef, DPID, f1);
|
||||||
Clock::time_point t0 = Clock::now();
|
test<int&>(checkIntRef, false, std::launch::async, f1);
|
||||||
assert(&f.get() == &i);
|
test<int&>(checkIntRef, true, std::launch::deferred, f1);
|
||||||
Clock::time_point t1 = Clock::now();
|
test<int&>(checkIntRef, DPID, AnyPolicy, f1);
|
||||||
assert(t1-t0 < ms(100));
|
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
std::future<int&> f = std::async(std::launch::any, f1);
|
auto checkVoid = [](std::future<void>& f) { f.get(); return true; };
|
||||||
std::this_thread::sleep_for(ms(300));
|
test<void>(checkVoid, DPID, f2);
|
||||||
Clock::time_point t0 = Clock::now();
|
test<void>(checkVoid, false, std::launch::async, f2);
|
||||||
assert(&f.get() == &i);
|
test<void>(checkVoid, true, std::launch::deferred, f2);
|
||||||
Clock::time_point t1 = Clock::now();
|
test<void>(checkVoid, DPID, std::launch::any, f2);
|
||||||
assert(t1-t0 < ms(100));
|
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
std::future<int&> f = std::async(std::launch::deferred, f1);
|
using Ret = std::unique_ptr<int>;
|
||||||
std::this_thread::sleep_for(ms(300));
|
auto checkUPtr = [](std::future<Ret>& f) { return *f.get() == 3; };
|
||||||
Clock::time_point t0 = Clock::now();
|
test<Ret>(checkUPtr, DPID, f3, 3);
|
||||||
assert(&f.get() == &i);
|
test<Ret>(checkUPtr, DPID, f4, std::unique_ptr<int>(new int(3)));
|
||||||
Clock::time_point t1 = Clock::now();
|
|
||||||
assert(t1-t0 > ms(100));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
|
||||||
std::future<void> f = std::async(f2);
|
|
||||||
std::this_thread::sleep_for(ms(300));
|
|
||||||
Clock::time_point t0 = Clock::now();
|
|
||||||
f.get();
|
|
||||||
Clock::time_point t1 = Clock::now();
|
|
||||||
assert(t1-t0 < ms(100));
|
|
||||||
}
|
|
||||||
{
|
|
||||||
std::future<void> f = std::async(std::launch::async, f2);
|
|
||||||
std::this_thread::sleep_for(ms(300));
|
|
||||||
Clock::time_point t0 = Clock::now();
|
|
||||||
f.get();
|
|
||||||
Clock::time_point t1 = Clock::now();
|
|
||||||
assert(t1-t0 < ms(100));
|
|
||||||
}
|
|
||||||
{
|
|
||||||
std::future<void> f = std::async(std::launch::any, f2);
|
|
||||||
std::this_thread::sleep_for(ms(300));
|
|
||||||
Clock::time_point t0 = Clock::now();
|
|
||||||
f.get();
|
|
||||||
Clock::time_point t1 = Clock::now();
|
|
||||||
assert(t1-t0 < ms(100));
|
|
||||||
}
|
|
||||||
{
|
|
||||||
std::future<void> f = std::async(std::launch::deferred, f2);
|
|
||||||
std::this_thread::sleep_for(ms(300));
|
|
||||||
Clock::time_point t0 = Clock::now();
|
|
||||||
f.get();
|
|
||||||
Clock::time_point t1 = Clock::now();
|
|
||||||
assert(t1-t0 > ms(100));
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
std::future<std::unique_ptr<int>> f = std::async(f3, 3);
|
|
||||||
std::this_thread::sleep_for(ms(300));
|
|
||||||
Clock::time_point t0 = Clock::now();
|
|
||||||
assert(*f.get() == 3);
|
|
||||||
Clock::time_point t1 = Clock::now();
|
|
||||||
assert(t1-t0 < ms(100));
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
std::future<std::unique_ptr<int>> f =
|
|
||||||
std::async(f4, std::unique_ptr<int>(new int(3)));
|
|
||||||
std::this_thread::sleep_for(ms(300));
|
|
||||||
Clock::time_point t0 = Clock::now();
|
|
||||||
assert(*f.get() == 3);
|
|
||||||
Clock::time_point t1 = Clock::now();
|
|
||||||
assert(t1-t0 < ms(100));
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
{
|
||||||
std::future<void> f = std::async(f5, 3);
|
std::future<void> f = std::async(f5, 3);
|
||||||
std::this_thread::sleep_for(ms(300));
|
std::this_thread::sleep_for(ms(300));
|
||||||
try { f.get(); assert (false); } catch ( int ex ) {}
|
try { f.get(); assert (false); } catch ( int ex ) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
std::future<void> f = std::async(std::launch::deferred, f5, 3);
|
std::future<void> f = std::async(std::launch::deferred, f5, 3);
|
||||||
std::this_thread::sleep_for(ms(300));
|
std::this_thread::sleep_for(ms(300));
|
||||||
try { f.get(); assert (false); } catch ( int ex ) {}
|
try { f.get(); assert (false); } catch ( int ex ) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,28 +15,30 @@
|
|||||||
// {
|
// {
|
||||||
// async = 1,
|
// async = 1,
|
||||||
// deferred = 2,
|
// deferred = 2,
|
||||||
// any = async | deferred
|
// any = async | deferred /* EXTENSION */
|
||||||
// };
|
// };
|
||||||
|
|
||||||
#include <future>
|
#include <future>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
|
#include "test_macros.h"
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
#ifdef _LIBCPP_HAS_NO_STRONG_ENUMS
|
#ifdef _LIBCPP_HAS_NO_STRONG_ENUMS
|
||||||
static_assert(static_cast<int>(std::launch::any) ==
|
LIBCPP_STATIC_ASSERT(static_cast<int>(std::launch::any) ==
|
||||||
(static_cast<int>(std::launch::async) | static_cast<int>(std::launch::deferred)), "");
|
(static_cast<int>(std::launch::async) | static_cast<int>(std::launch::deferred)), "");
|
||||||
#else
|
#else
|
||||||
static_assert(std::launch::any == (std::launch::async | std::launch::deferred), "");
|
LIBCPP_STATIC_ASSERT(std::launch::any == (std::launch::async | std::launch::deferred), "");
|
||||||
static_assert(std::launch(0) == (std::launch::async & std::launch::deferred), "");
|
static_assert(std::launch(0) == (std::launch::async & std::launch::deferred), "");
|
||||||
static_assert(std::launch::any == (std::launch::async ^ std::launch::deferred), "");
|
LIBCPP_STATIC_ASSERT(std::launch::any == (std::launch::async ^ std::launch::deferred), "");
|
||||||
static_assert(std::launch::deferred == ~std::launch::async, "");
|
static_assert(std::launch::deferred == ~std::launch::async, "");
|
||||||
std::launch x = std::launch::async;
|
std::launch x = std::launch::async;
|
||||||
x &= std::launch::deferred;
|
x &= std::launch::deferred;
|
||||||
assert(x == std::launch(0));
|
assert(x == std::launch(0));
|
||||||
x = std::launch::async;
|
x = std::launch::async;
|
||||||
x |= std::launch::deferred;
|
x |= std::launch::deferred;
|
||||||
assert(x == std::launch::any);
|
LIBCPP_ASSERT(x == std::launch::any);
|
||||||
x ^= std::launch::deferred;
|
x ^= std::launch::deferred;
|
||||||
assert(x == std::launch::async);
|
assert(x == std::launch::async);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user