diff options
author | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
---|---|---|
committer | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
commit | 554fd8c5195424bdbcabf5de30fdc183aba391bd (patch) | |
tree | 976dc5ab7fddf506dadce60ae936f43f58787092 /libstdc++-v3/testsuite/30_threads/promise/members | |
download | cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2 cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz |
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig;
imported gcc-4.6.4 source tree from verified upstream tarball.
downloading a git-generated archive based on the 'upstream' tag
should provide you with a source tree that is binary identical
to the one extracted from the above tarball.
if you have obtained the source via the command 'git clone',
however, do note that line-endings of files in your working
directory might differ from line-endings of the respective
files in the upstream repository.
Diffstat (limited to 'libstdc++-v3/testsuite/30_threads/promise/members')
8 files changed, 576 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/30_threads/promise/members/get_future.cc b/libstdc++-v3/testsuite/30_threads/promise/members/get_future.cc new file mode 100644 index 000000000..b09e302cc --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/promise/members/get_future.cc @@ -0,0 +1,52 @@ +// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } } +// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } } +// { 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 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/libstdc++-v3/testsuite/30_threads/promise/members/get_future2.cc b/libstdc++-v3/testsuite/30_threads/promise/members/get_future2.cc new file mode 100644 index 000000000..cc44fc479 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/promise/members/get_future2.cc @@ -0,0 +1,57 @@ +// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } } +// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } } +// { 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 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/libstdc++-v3/testsuite/30_threads/promise/members/set_exception.cc b/libstdc++-v3/testsuite/30_threads/promise/members/set_exception.cc new file mode 100644 index 000000000..4d2a1ec02 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/promise/members/set_exception.cc @@ -0,0 +1,57 @@ +// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } } +// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } } +// { 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 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::copy_exception(0)); + + try + { + f1.get(); + } + catch (int) + { + test = true; + } + VERIFY( test ); + VERIFY( !f1.valid() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/promise/members/set_exception2.cc b/libstdc++-v3/testsuite/30_threads/promise/members/set_exception2.cc new file mode 100644 index 000000000..872a4792f --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/promise/members/set_exception2.cc @@ -0,0 +1,93 @@ +// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } } +// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } } +// { 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 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::copy_exception(0)); + + try + { + p1.set_exception(std::copy_exception(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::copy_exception(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/libstdc++-v3/testsuite/30_threads/promise/members/set_value.cc b/libstdc++-v3/testsuite/30_threads/promise/members/set_value.cc new file mode 100644 index 000000000..9d3f8ead3 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/promise/members/set_value.cc @@ -0,0 +1,106 @@ +// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } } +// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } } +// { 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 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/libstdc++-v3/testsuite/30_threads/promise/members/set_value2.cc b/libstdc++-v3/testsuite/30_threads/promise/members/set_value2.cc new file mode 100644 index 000000000..09c8a52fa --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/promise/members/set_value2.cc @@ -0,0 +1,87 @@ +// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } } +// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } } +// { 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 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; + } + + VERIFY( f1.wait_for(std::chrono::milliseconds(1)) ); + 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::copy_exception(4)); + VERIFY( false ); + } + catch (std::future_error& e) + { + VERIFY(e.code() == + std::make_error_code(std::future_errc::promise_already_satisfied)); + test = true; + } + + VERIFY( f1.wait_for(std::chrono::milliseconds(1)) ); + VERIFY( f1.get() == 3 ); + VERIFY( test ); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/promise/members/set_value3.cc b/libstdc++-v3/testsuite/30_threads/promise/members/set_value3.cc new file mode 100644 index 000000000..5dabff97d --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/promise/members/set_value3.cc @@ -0,0 +1,78 @@ +// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } } +// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } } +// { 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, 2010 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(); + +tester::tester(int) +{ + bool test __attribute__((unused)) = true; + VERIFY (!fglobal.wait_for(std::chrono::milliseconds(1))); +} + +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(std::chrono::milliseconds(1))); +} + +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(std::chrono::milliseconds(1))); + return *this; +} + +void test01() +{ + bool test __attribute__((unused)) = true; + + pglobal.set_value( tester(1) ); + + VERIFY( fglobal.wait_for(std::chrono::milliseconds(1)) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/promise/members/swap.cc b/libstdc++-v3/testsuite/30_threads/promise/members/swap.cc new file mode 100644 index 000000000..b27ee2be7 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/promise/members/swap.cc @@ -0,0 +1,46 @@ +// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } } +// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } } +// { 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 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); + VERIFY( !p1.get_future().wait_for(std::chrono::milliseconds(1)) ); + VERIFY( p2.get_future().wait_for(std::chrono::milliseconds(1)) ); +} + +int main() +{ + test01(); + return 0; +} |