diff options
author | Ben Cheng <bccheng@google.com> | 2014-03-25 22:37:19 -0700 |
---|---|---|
committer | Ben Cheng <bccheng@google.com> | 2014-03-25 22:37:19 -0700 |
commit | 1bc5aee63eb72b341f506ad058502cd0361f0d10 (patch) | |
tree | c607e8252f3405424ff15bc2d00aa38dadbb2518 /gcc-4.9/libstdc++-v3/testsuite/30_threads/promise | |
parent | 283a0bf58fcf333c58a2a92c3ebbc41fb9eb1fdb (diff) | |
download | toolchain_gcc-1bc5aee63eb72b341f506ad058502cd0361f0d10.tar.gz toolchain_gcc-1bc5aee63eb72b341f506ad058502cd0361f0d10.tar.bz2 toolchain_gcc-1bc5aee63eb72b341f506ad058502cd0361f0d10.zip |
Initial checkin of GCC 4.9.0 from trunk (r208799).
Change-Id: I48a3c08bb98542aa215912a75f03c0890e497dba
Diffstat (limited to 'gcc-4.9/libstdc++-v3/testsuite/30_threads/promise')
18 files changed, 1002 insertions, 0 deletions
diff --git a/gcc-4.9/libstdc++-v3/testsuite/30_threads/promise/cons/1.cc b/gcc-4.9/libstdc++-v3/testsuite/30_threads/promise/cons/1.cc new file mode 100644 index 000000000..891306016 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/30_threads/promise/cons/1.cc @@ -0,0 +1,46 @@ +// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-gnu* *-*-solaris* *-*-cygwin *-*-darwin* powerpc-ibm-aix* } } +// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-gnu* powerpc-ibm-aix* } } +// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } } +// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } +// { dg-require-atomic-builtins "" } + +// Copyright (C) 2009-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <future> +#include <testsuite_tr1.h> + +void test01() +{ + using std::promise; + using namespace __gnu_test; + + promise<int> p1; + promise<int&> p2; + promise<void> p3; + promise<ClassType> p4; + promise<AbstractClass&> p5; +} + +int main() +{ + test01(); + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/30_threads/promise/cons/alloc.cc b/gcc-4.9/libstdc++-v3/testsuite/30_threads/promise/cons/alloc.cc new file mode 100644 index 000000000..10fa8824c --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/30_threads/promise/cons/alloc.cc @@ -0,0 +1,47 @@ +// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-gnu* *-*-solaris* *-*-cygwin *-*-darwin* powerpc-ibm-aix* } } +// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-gnu* powerpc-ibm-aix* } } +// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } } +// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } +// { dg-require-atomic-builtins "" } + +// Copyright (C) 2010-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <future> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +void test01() +{ + using std::promise; + using std::allocator_arg; + using __gnu_test::uneq_allocator; + + uneq_allocator<char> alloc(99); + + promise<int> p1(allocator_arg, alloc); + p1.set_value(5); + VERIFY( p1.get_future().get() == 5 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/30_threads/promise/cons/alloc2.cc b/gcc-4.9/libstdc++-v3/testsuite/30_threads/promise/cons/alloc2.cc new file mode 100644 index 000000000..178f37c30 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/30_threads/promise/cons/alloc2.cc @@ -0,0 +1,42 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } +// { dg-require-atomic-builtins "" } + +// Copyright (C) 2011-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// Test that promise can be default-constructed or move-constructed +// in a context that does uses-allocator construction. + +#include <future> +#include <memory> +#include <tuple> + +using std::promise; +using std::allocator_arg; +using std::allocator; +using std::tuple; + +typedef promise<int> p; +typedef promise<int&> pr; +typedef promise<void> pv; +allocator<p> a; + +tuple<p, pr, pv> t1{ allocator_arg, a }; +tuple<p, pr, pv> t2{ allocator_arg, a, p{}, pr{}, pv{} }; diff --git a/gcc-4.9/libstdc++-v3/testsuite/30_threads/promise/cons/alloc_min.cc b/gcc-4.9/libstdc++-v3/testsuite/30_threads/promise/cons/alloc_min.cc new file mode 100644 index 000000000..297d5a8bd --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/30_threads/promise/cons/alloc_min.cc @@ -0,0 +1,40 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } +// { dg-require-atomic-builtins "" } + +// Copyright (C) 2011-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// Test that promise can use a minimal C++11 allocator +// and doesn't rely on C++98 allocator interface. + +#include <future> +#include <testsuite_allocator.h> + +using std::promise; +using std::allocator_arg; +using std::tuple; + +typedef promise<int> p; +typedef promise<int&> pr; +typedef promise<void> pv; +__gnu_test::SimpleAllocator<p> a; + +tuple<p, pr, pv> t1{ allocator_arg, a }; +tuple<p, pr, pv> t2{ allocator_arg, a, p{}, pr{}, pv{} }; diff --git a/gcc-4.9/libstdc++-v3/testsuite/30_threads/promise/cons/assign_neg.cc b/gcc-4.9/libstdc++-v3/testsuite/30_threads/promise/cons/assign_neg.cc new file mode 100644 index 000000000..2863856ab --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/30_threads/promise/cons/assign_neg.cc @@ -0,0 +1,35 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } +// { dg-require-atomic-builtins "" } + +// Copyright (C) 2009-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <future> + +void test01() +{ + // assign + std::promise<int> p1; + std::promise<int> p2; + p1 = p2; // { dg-error "deleted" } +} + +// { dg-prune-output "include" } diff --git a/gcc-4.9/libstdc++-v3/testsuite/30_threads/promise/cons/copy_neg.cc b/gcc-4.9/libstdc++-v3/testsuite/30_threads/promise/cons/copy_neg.cc new file mode 100644 index 000000000..4a8cce19d --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/30_threads/promise/cons/copy_neg.cc @@ -0,0 +1,34 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } +// { dg-require-atomic-builtins "" } + +// Copyright (C) 2009-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <future> + +void test01() +{ + // copy + std::promise<int> p1; + std::promise<int> p2(p1); // { dg-error "deleted" } +} + +// { dg-prune-output "include" } diff --git a/gcc-4.9/libstdc++-v3/testsuite/30_threads/promise/cons/move.cc b/gcc-4.9/libstdc++-v3/testsuite/30_threads/promise/cons/move.cc new file mode 100644 index 000000000..7196e93e0 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/30_threads/promise/cons/move.cc @@ -0,0 +1,55 @@ +// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-gnu* *-*-solaris* *-*-cygwin *-*-darwin* powerpc-ibm-aix* } } +// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-gnu* powerpc-ibm-aix* } } +// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } } +// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } +// { dg-require-atomic-builtins "" } + +// Copyright (C) 2009-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <future> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + // move assign + promise<int> p1; + p1.set_value(3); + promise<int> p2(std::move(p1)); + VERIFY( p2.get_future().get() == 3 ); + try + { + p1.get_future(); + VERIFY( false ); + } + catch (std::future_error& e) + { + VERIFY(e.code() == make_error_code(future_errc::no_state)); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/30_threads/promise/cons/move_assign.cc b/gcc-4.9/libstdc++-v3/testsuite/30_threads/promise/cons/move_assign.cc new file mode 100644 index 000000000..1bfbd3560 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/30_threads/promise/cons/move_assign.cc @@ -0,0 +1,56 @@ +// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-gnu* *-*-solaris* *-*-cygwin *-*-darwin* powerpc-ibm-aix* } } +// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-gnu* powerpc-ibm-aix* } } +// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } } +// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } +// { dg-require-atomic-builtins "" } + +// Copyright (C) 2009-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <future> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + // move assign + promise<int> p1; + p1.set_value(3); + promise<int> p2; + p2 = move(p1); + VERIFY( p2.get_future().get() == 3 ); + try + { + p1.get_future(); + VERIFY( false ); + } + catch (future_error& e) + { + VERIFY(e.code() == make_error_code(future_errc::no_state)); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/30_threads/promise/members/get_future.cc b/gcc-4.9/libstdc++-v3/testsuite/30_threads/promise/members/get_future.cc new file mode 100644 index 000000000..3f0e37a0a --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/30_threads/promise/members/get_future.cc @@ -0,0 +1,52 @@ +// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-gnu* *-*-solaris* *-*-cygwin *-*-darwin* powerpc-ibm-aix* } } +// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-gnu* powerpc-ibm-aix* } } +// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } } +// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } +// { dg-require-atomic-builtins "" } + +// Copyright (C) 2009-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <future> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::promise<int&> p1; + std::future<int&> f1 = p1.get_future(); + + VERIFY( f1.valid() ); + + int i1 = 0; + + p1.set_value(i1); + + int& i2 = f1.get(); + + VERIFY( &i1 == &i2 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/30_threads/promise/members/get_future2.cc b/gcc-4.9/libstdc++-v3/testsuite/30_threads/promise/members/get_future2.cc new file mode 100644 index 000000000..6e0814636 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/30_threads/promise/members/get_future2.cc @@ -0,0 +1,57 @@ +// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-gnu* *-*-solaris* *-*-cygwin *-*-darwin* powerpc-ibm-aix* } } +// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-gnu* powerpc-ibm-aix* } } +// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } } +// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } +// { dg-require-atomic-builtins "" } + +// Copyright (C) 2009-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <future> +#include <system_error> +#include <testsuite_hooks.h> + +void test01() +{ + bool test = false; + using namespace std; + + promise<int&> p1; + p1.get_future(); + + try + { + p1.get_future(); + VERIFY( false ); + } + catch (future_error& e) + { + VERIFY(e.code() == make_error_code(future_errc::future_already_retrieved)); + test = true; + } + + VERIFY( test ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/30_threads/promise/members/set_exception.cc b/gcc-4.9/libstdc++-v3/testsuite/30_threads/promise/members/set_exception.cc new file mode 100644 index 000000000..e07893e48 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/30_threads/promise/members/set_exception.cc @@ -0,0 +1,57 @@ +// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-gnu* *-*-solaris* *-*-cygwin *-*-darwin* powerpc-ibm-aix* } } +// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-gnu* powerpc-ibm-aix* } } +// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } } +// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } +// { dg-require-atomic-builtins "" } + +// Copyright (C) 2009-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <future> +#include <testsuite_hooks.h> + +void test01() +{ + bool test = false; + + std::promise<int> p1; + std::future<int> f1 = p1.get_future(); + + VERIFY( f1.valid() ); + + p1.set_exception(std::make_exception_ptr(0)); + + try + { + f1.get(); + } + catch (int) + { + test = true; + } + VERIFY( test ); + VERIFY( !f1.valid() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/30_threads/promise/members/set_exception2.cc b/gcc-4.9/libstdc++-v3/testsuite/30_threads/promise/members/set_exception2.cc new file mode 100644 index 000000000..949702c56 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/30_threads/promise/members/set_exception2.cc @@ -0,0 +1,93 @@ +// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-gnu* *-*-solaris* *-*-cygwin *-*-darwin* powerpc-ibm-aix* } } +// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-gnu* powerpc-ibm-aix* } } +// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } } +// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } +// { dg-require-atomic-builtins "" } + +// Copyright (C) 2009-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <future> +#include <testsuite_hooks.h> + +void test01() +{ + bool test = false; + + std::promise<int> p1; + std::future<int> f1 = p1.get_future(); + + p1.set_exception(std::make_exception_ptr(0)); + + try + { + p1.set_exception(std::make_exception_ptr(1)); + VERIFY( false ); + } + catch (std::future_error& e) + { + VERIFY(e.code() == + std::make_error_code(std::future_errc::promise_already_satisfied)); + test = true; + } + + try + { + f1.get(); + test = false; + } + catch(int i) + { + VERIFY( i == 0 ); + } + + VERIFY( test ); +} + +void test02() +{ + bool test = false; + + std::promise<int> p1; + std::future<int> f1 = p1.get_future(); + + p1.set_value(2); + + try + { + p1.set_exception(std::make_exception_ptr(0)); + VERIFY( false ); + } + catch (std::future_error& e) + { + VERIFY(e.code() == + std::make_error_code(std::future_errc::promise_already_satisfied)); + test = true; + } + + VERIFY( test ); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/30_threads/promise/members/set_value.cc b/gcc-4.9/libstdc++-v3/testsuite/30_threads/promise/members/set_value.cc new file mode 100644 index 000000000..a670ab0d8 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/30_threads/promise/members/set_value.cc @@ -0,0 +1,106 @@ +// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-gnu* *-*-solaris* *-*-cygwin *-*-darwin* powerpc-ibm-aix* } } +// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-gnu* powerpc-ibm-aix* } } +// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } } +// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } +// { dg-require-atomic-builtins "" } + +// Copyright (C) 2009-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <future> +#include <testsuite_hooks.h> +#include <testsuite_rvalref.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::promise<int> p1; + std::future<int> f1 = p1.get_future(); + + VERIFY( f1.valid() ); + + p1.set_value(0); + + int&& i1 = f1.get(); + + VERIFY( i1 == 0 ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + std::promise<rvalstruct> p1; + std::future<rvalstruct> f1 = p1.get_future(); + + VERIFY( f1.valid() ); + + p1.set_value(rvalstruct(1)); + + rvalstruct r1(f1.get()); + + VERIFY( !f1.valid() ); + VERIFY( r1.val == 1 ); +} + + +void test03() +{ + bool test __attribute__((unused)) = true; + + std::promise<int&> p1; + std::future<int&> f1 = p1.get_future(); + + VERIFY( f1.valid() ); + + int i1 = 0; + p1.set_value(i1); + int& i2 = f1.get(); + + VERIFY( !f1.valid() ); + VERIFY( &i1 == &i2 ); +} + +void test04() +{ + bool test __attribute__((unused)) = true; + + std::promise<void> p1; + std::future<void> f1 = p1.get_future(); + + VERIFY( f1.valid() ); + + p1.set_value(); + f1.get(); + + VERIFY( !f1.valid() ); +} + +int main() +{ + test01(); + test02(); + test03(); + test04(); + + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/30_threads/promise/members/set_value2.cc b/gcc-4.9/libstdc++-v3/testsuite/30_threads/promise/members/set_value2.cc new file mode 100644 index 000000000..3764d11b2 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/30_threads/promise/members/set_value2.cc @@ -0,0 +1,89 @@ +// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-gnu* *-*-solaris* *-*-cygwin *-*-darwin* powerpc-ibm-aix* } } +// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-gnu* powerpc-ibm-aix* } } +// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } } +// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } +// { dg-require-atomic-builtins "" } + +// Copyright (C) 2009-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <future> +#include <testsuite_hooks.h> + +void test01() +{ + bool test = false; + + std::promise<int> p1; + std::future<int> f1 = p1.get_future(); + + p1.set_value(1); + + try + { + p1.set_value(2); + VERIFY( false ); + } + catch (std::future_error& e) + { + VERIFY(e.code() == + std::make_error_code(std::future_errc::promise_already_satisfied)); + test = true; + } + + std::chrono::milliseconds delay(1); + VERIFY( f1.wait_for(delay) == std::future_status::ready ); + VERIFY( f1.get() == 1 ); + VERIFY( test ); +} + +void test02() +{ + bool test = false; + + std::promise<int> p1; + std::future<int> f1 = p1.get_future(); + + p1.set_value(3); + + try + { + p1.set_exception(std::make_exception_ptr(4)); + VERIFY( false ); + } + catch (std::future_error& e) + { + VERIFY(e.code() == + std::make_error_code(std::future_errc::promise_already_satisfied)); + test = true; + } + + std::chrono::milliseconds delay(1); + VERIFY( f1.wait_for(delay) == std::future_status::ready ); + VERIFY( f1.get() == 3 ); + VERIFY( test ); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/30_threads/promise/members/set_value3.cc b/gcc-4.9/libstdc++-v3/testsuite/30_threads/promise/members/set_value3.cc new file mode 100644 index 000000000..e7bd13f5f --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/30_threads/promise/members/set_value3.cc @@ -0,0 +1,80 @@ +// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-gnu* *-*-solaris* *-*-cygwin *-*-darwin* powerpc-ibm-aix* } } +// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-gnu* powerpc-ibm-aix* } } +// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } } +// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } +// { dg-require-atomic-builtins "" } + +// Copyright (C) 2009-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <future> +#include <testsuite_hooks.h> + + +// Test promise::set_value() for deadlock by checking if the state is ready +// during construction and destruction of the associated state. + +struct tester +{ + tester(int); + tester(const tester&); + tester() = delete; + tester& operator=(const tester&); +}; + +std::promise<tester> pglobal; +std::future<tester> fglobal = pglobal.get_future(); + +auto delay = std::chrono::milliseconds(1); + +tester::tester(int) +{ + bool test __attribute__((unused)) = true; + VERIFY (fglobal.wait_for(delay) == std::future_status::timeout); +} + +tester::tester(const tester&) +{ + bool test __attribute__((unused)) = true; + // if this copy happens while a mutex is locked next line could deadlock: + VERIFY (fglobal.wait_for(delay) == std::future_status::timeout); +} + +tester& tester::operator=(const tester&) +{ + bool test __attribute__((unused)) = true; + // if this copy happens while a mutex is locked next line could deadlock: + VERIFY (fglobal.wait_for(delay) == std::future_status::timeout); + return *this; +} + +void test01() +{ + bool test __attribute__((unused)) = true; + + pglobal.set_value( tester(1) ); + + VERIFY (fglobal.wait_for(delay) == std::future_status::ready); +} + +int main() +{ + test01(); + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/30_threads/promise/members/swap.cc b/gcc-4.9/libstdc++-v3/testsuite/30_threads/promise/members/swap.cc new file mode 100644 index 000000000..c003a4047 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/30_threads/promise/members/swap.cc @@ -0,0 +1,47 @@ +// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-gnu* *-*-solaris* *-*-cygwin *-*-darwin* powerpc-ibm-aix* } } +// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-gnu* powerpc-ibm-aix* } } +// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } } +// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } +// { dg-require-atomic-builtins "" } + +// Copyright (C) 2009-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <future> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::promise<int> p1; + std::promise<int> p2; + p1.set_value(1); + p1.swap(p2); + auto delay = std::chrono::milliseconds(1); + VERIFY( p1.get_future().wait_for(delay) == std::future_status::timeout ); + VERIFY( p2.get_future().wait_for(delay) == std::future_status::ready ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/30_threads/promise/requirements/explicit_instantiation.cc b/gcc-4.9/libstdc++-v3/testsuite/30_threads/promise/requirements/explicit_instantiation.cc new file mode 100644 index 000000000..033b7b836 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/30_threads/promise/requirements/explicit_instantiation.cc @@ -0,0 +1,34 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } +// { dg-require-atomic-builtins "" } + +// Copyright (C) 2009-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <future> +#include <testsuite_tr1.h> + +using namespace __gnu_test; +using std::promise; +template class promise<int>; +template class promise<int&>; +template class promise<void>; +template class promise<ClassType>; +template class promise<ClassType&>; diff --git a/gcc-4.9/libstdc++-v3/testsuite/30_threads/promise/uses_allocator.cc b/gcc-4.9/libstdc++-v3/testsuite/30_threads/promise/uses_allocator.cc new file mode 100644 index 000000000..4c9c55f0e --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/30_threads/promise/uses_allocator.cc @@ -0,0 +1,32 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } +// { dg-require-atomic-builtins "" } + +// Copyright (C) 2011-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <future> +#include <memory> + +using std::uses_allocator; +using std::allocator; +using std::promise; +static_assert( uses_allocator<promise<int>, allocator<int>>::value, + "promise supports uses-allocator construction" ); |