[PATCH] D25483: [libcxx] [test] Fix non-Standard assumptions about how many elements are allocated

llvm-svn: 285346
This commit is contained in:
Stephan T. Lavavej 2016-10-27 21:25:12 +00:00
parent c0de9c9e40
commit 50b80c36fa
12 changed files with 31 additions and 16 deletions

View File

@ -98,7 +98,7 @@ int main()
test<DefaultOnly, std::allocator<DefaultOnly> >(4096); test<DefaultOnly, std::allocator<DefaultOnly> >(4096);
test<DefaultOnly, std::allocator<DefaultOnly> >(4097); test<DefaultOnly, std::allocator<DefaultOnly> >(4097);
test1<DefaultOnly, limited_allocator<DefaultOnly, 4096> >(4095); LIBCPP_ONLY(test1<DefaultOnly, limited_allocator<DefaultOnly, 4096> >(4095));
#if TEST_STD_VER >= 11 #if TEST_STD_VER >= 11
test<DefaultOnly, min_allocator<DefaultOnly> >(4095); test<DefaultOnly, min_allocator<DefaultOnly> >(4095);

View File

@ -44,7 +44,7 @@ int main()
test<int, std::allocator<int> >(4095, 78); test<int, std::allocator<int> >(4095, 78);
test<int, std::allocator<int> >(4096, 1165); test<int, std::allocator<int> >(4096, 1165);
test<int, std::allocator<int> >(4097, 157); test<int, std::allocator<int> >(4097, 157);
test<int, limited_allocator<int, 4096> >(4095, 90); LIBCPP_ONLY(test<int, limited_allocator<int, 4096> >(4095, 90));
#if TEST_STD_VER >= 11 #if TEST_STD_VER >= 11
test<int, min_allocator<int> >(4095, 90); test<int, min_allocator<int> >(4095, 90);
#endif #endif

View File

@ -43,7 +43,8 @@ int main()
} }
{ {
int a[] = {0, 1, 2, 3}; int a[] = {0, 1, 2, 3};
std::list<int, limited_allocator<int, sizeof(a)/sizeof(a[0])> > l(input_iterator<const int*>(a), // Add 2 for implementations that dynamically allocate a sentinel node and container proxy.
std::list<int, limited_allocator<int, sizeof(a)/sizeof(a[0]) + 2> > l(input_iterator<const int*>(a),
input_iterator<const int*>(a + sizeof(a)/sizeof(a[0]))); input_iterator<const int*>(a + sizeof(a)/sizeof(a[0])));
assert(l.size() == sizeof(a)/sizeof(a[0])); assert(l.size() == sizeof(a)/sizeof(a[0]));
assert(std::distance(l.begin(), l.end()) == sizeof(a)/sizeof(a[0])); assert(std::distance(l.begin(), l.end()) == sizeof(a)/sizeof(a[0]));

View File

@ -48,7 +48,8 @@ int main()
assert(*i == 0); assert(*i == 0);
} }
{ {
std::list<int, limited_allocator<int, 3> > l(3); // Add 2 for implementations that dynamically allocate a sentinel node and container proxy.
std::list<int, limited_allocator<int, 3 + 2> > l(3);
assert(l.size() == 3); assert(l.size() == 3);
assert(std::distance(l.begin(), l.end()) == 3); assert(std::distance(l.begin(), l.end()) == 3);
std::list<int>::const_iterator i = l.begin(); std::list<int>::const_iterator i = l.begin();

View File

@ -42,7 +42,8 @@ int main()
assert(*i == 2); assert(*i == 2);
} }
{ {
std::list<int, limited_allocator<int, 3> > l(3, 2); // Add 2 for implementations that dynamically allocate a sentinel node and container proxy.
std::list<int, limited_allocator<int, 3 + 2> > l(3, 2);
assert(l.size() == 3); assert(l.size() == 3);
assert(std::distance(l.begin(), l.end()) == 3); assert(std::distance(l.begin(), l.end()) == 3);
std::list<int>::const_iterator i = l.begin(); std::list<int>::const_iterator i = l.begin();

View File

@ -37,7 +37,8 @@ int main()
assert(is_contiguous_container_asan_correct(v)); assert(is_contiguous_container_asan_correct(v));
} }
{ {
std::vector<int, limited_allocator<int, 250> > v(100); // Add 1 for implementations that dynamically allocate a container proxy.
std::vector<int, limited_allocator<int, 250 + 1> > v(100);
assert(v.capacity() == 100); assert(v.capacity() == 100);
v.reserve(50); v.reserve(50);
assert(v.size() == 100); assert(v.size() == 100);

View File

@ -33,7 +33,8 @@ int main()
assert(is_contiguous_container_asan_correct(v)); assert(is_contiguous_container_asan_correct(v));
} }
{ {
std::vector<MoveOnly, limited_allocator<MoveOnly, 300> > v(100); // Add 1 for implementations that dynamically allocate a container proxy.
std::vector<MoveOnly, limited_allocator<MoveOnly, 300 + 1> > v(100);
v.resize(50); v.resize(50);
assert(v.size() == 50); assert(v.size() == 50);
assert(v.capacity() == 100); assert(v.capacity() == 100);
@ -56,7 +57,8 @@ int main()
assert(is_contiguous_container_asan_correct(v)); assert(is_contiguous_container_asan_correct(v));
} }
{ {
std::vector<int, limited_allocator<int, 300> > v(100); // Add 1 for implementations that dynamically allocate a container proxy.
std::vector<int, limited_allocator<int, 300 + 1> > v(100);
v.resize(50); v.resize(50);
assert(v.size() == 50); assert(v.size() == 50);
assert(v.capacity() == 100); assert(v.capacity() == 100);

View File

@ -35,7 +35,8 @@ int main()
assert(v[i] == 1); assert(v[i] == 1);
} }
{ {
std::vector<int, limited_allocator<int, 300> > v(100); // Add 1 for implementations that dynamically allocate a container proxy.
std::vector<int, limited_allocator<int, 300 + 1> > v(100);
v.resize(50, 1); v.resize(50, 1);
assert(v.size() == 50); assert(v.size() == 50);
assert(v.capacity() == 100); assert(v.capacity() == 100);

View File

@ -43,10 +43,11 @@ int main()
test<std::vector<int> >(a, an); test<std::vector<int> >(a, an);
test<std::vector<int, limited_allocator<int, 63> > >(input_iterator<const int*>(a), input_iterator<const int*>(an)); test<std::vector<int, limited_allocator<int, 63> > >(input_iterator<const int*>(a), input_iterator<const int*>(an));
test<std::vector<int, limited_allocator<int, 18> > >(forward_iterator<const int*>(a), forward_iterator<const int*>(an)); // Add 1 for implementations that dynamically allocate a container proxy.
test<std::vector<int, limited_allocator<int, 18> > >(bidirectional_iterator<const int*>(a), bidirectional_iterator<const int*>(an)); test<std::vector<int, limited_allocator<int, 18 + 1> > >(forward_iterator<const int*>(a), forward_iterator<const int*>(an));
test<std::vector<int, limited_allocator<int, 18> > >(random_access_iterator<const int*>(a), random_access_iterator<const int*>(an)); test<std::vector<int, limited_allocator<int, 18 + 1> > >(bidirectional_iterator<const int*>(a), bidirectional_iterator<const int*>(an));
test<std::vector<int, limited_allocator<int, 18> > >(a, an); test<std::vector<int, limited_allocator<int, 18 + 1> > >(random_access_iterator<const int*>(a), random_access_iterator<const int*>(an));
test<std::vector<int, limited_allocator<int, 18 + 1> > >(a, an);
#if TEST_STD_VER >= 11 #if TEST_STD_VER >= 11
test<std::vector<int, min_allocator<int>> >(input_iterator<const int*>(a), input_iterator<const int*>(an)); test<std::vector<int, min_allocator<int>> >(input_iterator<const int*>(a), input_iterator<const int*>(an));
test<std::vector<int, min_allocator<int>> >(forward_iterator<const int*>(a), forward_iterator<const int*>(an)); test<std::vector<int, min_allocator<int>> >(forward_iterator<const int*>(a), forward_iterator<const int*>(an));

View File

@ -34,7 +34,8 @@ test(typename C::size_type n, const typename C::value_type& x)
int main() int main()
{ {
test<std::vector<int> >(50, 3); test<std::vector<int> >(50, 3);
test<std::vector<int, limited_allocator<int, 50> > >(50, 5); // Add 1 for implementations that dynamically allocate a container proxy.
test<std::vector<int, limited_allocator<int, 50 + 1> > >(50, 5);
#if TEST_STD_VER >= 11 #if TEST_STD_VER >= 11
test<std::vector<int, min_allocator<int>> >(50, 3); test<std::vector<int, min_allocator<int>> >(50, 3);
#endif #endif

View File

@ -48,7 +48,10 @@ int main()
assert(c[j] == j); assert(c[j] == j);
} }
{ {
std::vector<int, limited_allocator<int, 15> > c; // libc++ needs 15 because it grows by 2x (1 + 2 + 4 + 8).
// Use 17 for implementations that dynamically allocate a container proxy
// and grow by 1.5x (1 for proxy + 1 + 2 + 3 + 4 + 6).
std::vector<int, limited_allocator<int, 17> > c;
c.push_back(0); c.push_back(0);
assert(c.size() == 1); assert(c.size() == 1);
assert(is_contiguous_container_asan_correct(c)); assert(is_contiguous_container_asan_correct(c));

View File

@ -50,7 +50,10 @@ int main()
assert(c[j] == MoveOnly(j)); assert(c[j] == MoveOnly(j));
} }
{ {
std::vector<MoveOnly, limited_allocator<MoveOnly, 15> > c; // libc++ needs 15 because it grows by 2x (1 + 2 + 4 + 8).
// Use 17 for implementations that dynamically allocate a container proxy
// and grow by 1.5x (1 for proxy + 1 + 2 + 3 + 4 + 6).
std::vector<MoveOnly, limited_allocator<MoveOnly, 17> > c;
c.push_back(MoveOnly(0)); c.push_back(MoveOnly(0));
assert(c.size() == 1); assert(c.size() == 1);
assert(is_contiguous_container_asan_correct(c)); assert(is_contiguous_container_asan_correct(c));