|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r52694 - sandbox/task/libs/task/test
From: oliver.kowalke_at_[hidden]
Date: 2009-05-01 02:11:43
Author: olli
Date: 2009-05-01 02:11:40 EDT (Fri, 01 May 2009)
New Revision: 52694
URL: http://svn.boost.org/trac/boost/changeset/52694
Log:
* tests modified -> related to new async() functionality
Added:
sandbox/task/libs/task/test/test_bounded_pool.cpp (contents, props changed)
sandbox/task/libs/task/test/test_default_pool.cpp (contents, props changed)
sandbox/task/libs/task/test/test_new_thread.cpp (contents, props changed)
sandbox/task/libs/task/test/test_own_thread.cpp (contents, props changed)
sandbox/task/libs/task/test/test_unbounded_pool.cpp (contents, props changed)
Removed:
sandbox/task/libs/task/test/test_handle.cpp
sandbox/task/libs/task/test/test_in_bounded_pool.cpp
sandbox/task/libs/task/test/test_in_thread.cpp
sandbox/task/libs/task/test/test_in_unbounded_pool.cpp
Text files modified:
sandbox/task/libs/task/test/Jamfile.v2 | 9 +++++----
1 files changed, 5 insertions(+), 4 deletions(-)
Modified: sandbox/task/libs/task/test/Jamfile.v2
==============================================================================
--- sandbox/task/libs/task/test/Jamfile.v2 (original)
+++ sandbox/task/libs/task/test/Jamfile.v2 2009-05-01 02:11:40 EDT (Fri, 01 May 2009)
@@ -27,8 +27,9 @@
}
test-suite thread_pool :
- [ tp-test test_handle ]
- [ tp-test test_in_thread ]
- [ tp-test test_in_unbounded_pool ]
- [ tp-test test_in_bounded_pool ]
+ [ tp-test test_own_thread ]
+ [ tp-test test_new_thread ]
+ [ tp-test test_default_pool ]
+ [ tp-test test_unbounded_pool ]
+ [ tp-test test_bounded_pool ]
;
Added: sandbox/task/libs/task/test/test_bounded_pool.cpp
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/test/test_bounded_pool.cpp 2009-05-01 02:11:40 EDT (Fri, 01 May 2009)
@@ -0,0 +1,433 @@
+
+// Copyright Oliver Kowalke 2009.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include <cstdlib>
+#include <iostream>
+#include <map>
+#include <stdexcept>
+#include <vector>
+
+#include <boost/bind.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+#include <boost/function.hpp>
+#include <boost/ref.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/thread.hpp>
+#include <boost/thread/barrier.hpp>
+#include <boost/utility.hpp>
+
+#include <boost/task.hpp>
+
+#include "test_functions.hpp"
+
+namespace pt = boost::posix_time;
+namespace tsk = boost::task;
+
+class test_bounded_pool
+{
+public:
+ // check size, active, idle
+ void test_case_1()
+ {
+ tsk::pool<
+ tsk::bounded_channel< tsk::fifo >
+ > pool(
+ tsk::poolsize( 3),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ BOOST_CHECK_EQUAL( pool.size(), std::size_t( 3) );
+ BOOST_CHECK_EQUAL( pool.idle(), std::size_t( 3) );
+ BOOST_CHECK_EQUAL( pool.active(), std::size_t( 0) );
+ }
+
+ // check submit
+ void test_case_2()
+ {
+ tsk::pool<
+ tsk::bounded_channel< tsk::fifo >
+ > pool(
+ tsk::poolsize( 1),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ tsk::handle< int > h(
+ tsk::async(
+ pool,
+ tsk::make_task(
+ fibonacci_fn,
+ 10) ) );
+ BOOST_CHECK_EQUAL( h.get(), 55);
+ }
+
+ // check runs in pool
+ void test_case_3()
+ {
+ tsk::pool<
+ tsk::bounded_channel< tsk::fifo >
+ > pool(
+ tsk::poolsize( 1),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ tsk::handle< bool > h(
+ tsk::async(
+ pool,
+ tsk::make_task(
+ runs_in_pool_fn) ) );
+ BOOST_CHECK_EQUAL( h.get(), true);
+ }
+
+ // executed twice
+ void test_case_4()
+ {
+ tsk::pool<
+ tsk::bounded_channel< tsk::fifo >
+ > pool(
+ tsk::poolsize( 1),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ tsk::task< int > t(
+ tsk::make_task(
+ fibonacci_fn,
+ 10) );
+ tsk::handle< int > h1(
+ tsk::async(
+ pool,
+ t) );
+ BOOST_CHECK_EQUAL( h1.get(), 55);
+ tsk::handle< int > h2(
+ tsk::async(
+ pool,
+ t) );
+ BOOST_CHECK_EQUAL( h2.get(), 55);
+ }
+
+ // check shutdown
+ void test_case_5()
+ {
+ tsk::pool<
+ tsk::bounded_channel< tsk::fifo >
+ > pool(
+ tsk::poolsize( 1),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ tsk::handle< int > h(
+ tsk::async(
+ pool,
+ tsk::make_task(
+ fibonacci_fn,
+ 10) ) );
+ pool.shutdown();
+ BOOST_CHECK( pool.closed() );
+ BOOST_CHECK_EQUAL( h.get(), 55);
+ }
+
+ // check runtime_error throw inside task
+ void test_case_6()
+ {
+ tsk::pool<
+ tsk::bounded_channel< tsk::fifo >
+ > pool(
+ tsk::poolsize( 1),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ tsk::handle< void > h(
+ tsk::async(
+ pool,
+ tsk::make_task(
+ throwing_fn) ) );
+ pool.shutdown();
+ bool thrown( false);
+ try
+ { h.get(); }
+ catch ( std::runtime_error const&)
+ { thrown = true; }
+ BOOST_CHECK( thrown);
+ }
+
+ // check shutdown with task_rejected exception
+ void test_case_7()
+ {
+ tsk::pool<
+ tsk::bounded_channel< tsk::fifo >
+ > pool(
+ tsk::poolsize( 1),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ pool.shutdown();
+ BOOST_CHECK( pool.closed() );
+ bool thrown( false);
+ try
+ {
+ tsk::async(
+ pool,
+ tsk::make_task(
+ boost::bind(
+ fibonacci_fn,
+ 10) ) );
+ }
+ catch ( tsk::task_rejected const&)
+ { thrown = true; }
+ BOOST_CHECK( thrown);
+ }
+
+ // check shutdown_now with thread_interrupted exception
+ void test_case_8()
+ {
+ tsk::pool<
+ tsk::bounded_channel< tsk::fifo >
+ > pool(
+ tsk::poolsize( 1),
+ tsk::high_watermark( 1),
+ tsk::low_watermark( 1) );
+ tsk::handle< void > h(
+ tsk::async(
+ pool,
+ tsk::make_task(
+ delay_fn,
+ pt::millisec( 500) ) ) );
+ boost::this_thread::sleep( pt::millisec( 250) );
+ BOOST_CHECK_EQUAL( pool.size(), std::size_t( 1) );
+ pool.shutdown_now();
+ BOOST_CHECK( pool.closed() );
+ BOOST_CHECK_EQUAL( pool.size(), std::size_t( 1) );
+ BOOST_CHECK_EQUAL( pool.idle(), std::size_t( 1) );
+ BOOST_CHECK_EQUAL( pool.active(), std::size_t( 0) );
+ bool thrown( false);
+ try
+ { h.get(); }
+ catch ( tsk::task_interrupted const&)
+ { thrown = true; }
+ BOOST_CHECK( thrown);
+ }
+
+ // check pending
+ void test_case_9()
+ {
+ typedef tsk::pool<
+ tsk::bounded_channel< tsk::fifo >
+ > pool_type;
+ pool_type pool(
+ tsk::poolsize( 1),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ boost::barrier b( 2);
+ tsk::handle< void > h1(
+ tsk::async(
+ pool,
+ tsk::make_task(
+ barrier_fn,
+ boost::ref( b) ) ) );
+ boost::this_thread::sleep( pt::millisec( 250) );
+ BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 0) );
+ tsk::handle< int > h2(
+ tsk::async(
+ pool,
+ tsk::make_task(
+ fibonacci_fn,
+ 10) ) );
+ boost::this_thread::sleep( pt::millisec(250) );
+ BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 1) );
+ tsk::handle< int > h3(
+ tsk::async(
+ pool,
+ tsk::make_task(
+ fibonacci_fn,
+ 10) ) );
+ boost::this_thread::sleep( pt::millisec(250) );
+ BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 2) );
+ b.wait();
+ h1.get();
+ BOOST_CHECK_EQUAL( h2.get(), 55);
+ BOOST_CHECK_EQUAL( h3.get(), 55);
+ BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 0) );
+ }
+
+ // check interruption
+ void test_case_10()
+ {
+ typedef tsk::pool<
+ tsk::bounded_channel< tsk::fifo >
+ > pool_type;
+ pool_type pool(
+ tsk::poolsize( 1),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ boost::barrier b( 2);
+ tsk::async(
+ pool,
+ tsk::make_task(
+ barrier_fn,
+ boost::ref( b) ) );
+ std::vector< int > buffer;
+ tsk::handle< void > h(
+ tsk::async(
+ pool,
+ tsk::make_task(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 10) ) );
+ tsk::async(
+ pool,
+ tsk::make_task(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 0) );
+ h.interrupt();
+ b.wait();
+ pool.shutdown();
+ BOOST_CHECK_EQUAL( buffer[0], 0);
+ BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 1) );
+ bool thrown( false);
+ try
+ { h.get(); }
+ catch ( tsk::task_interrupted const&)
+ { thrown = true; }
+ BOOST_CHECK( thrown);
+ }
+
+ // check fifo scheduling
+ void test_case_11()
+ {
+ typedef tsk::pool<
+ tsk::bounded_channel< tsk::fifo >
+ > pool_type;
+ pool_type pool(
+ tsk::poolsize( 1),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ boost::barrier b( 2);
+ tsk::async(
+ pool,
+ tsk::make_task(
+ barrier_fn,
+ boost::ref( b) ) );
+ std::vector< int > buffer;
+ tsk::async(
+ pool,
+ tsk::make_task(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 10) );
+ tsk::async(
+ pool,
+ tsk::make_task(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 0) );
+ b.wait();
+ pool.shutdown();
+ BOOST_CHECK_EQUAL( buffer[0], 55);
+ BOOST_CHECK_EQUAL( buffer[1], 0);
+ BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 2) );
+ }
+
+ // check priority scheduling
+ void test_case_12()
+ {
+ typedef tsk::pool<
+ tsk::bounded_channel< tsk::priority< int > >
+ > pool_type;
+ pool_type pool(
+ tsk::poolsize( 1),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ boost::barrier b( 2);
+ tsk::async(
+ pool,
+ tsk::make_task(
+ barrier_fn,
+ boost::ref( b) ),
+ 0);
+ std::vector< int > buffer;
+ tsk::async(
+ pool,
+ tsk::make_task(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 10),
+ 1);
+ tsk::async(
+ pool,
+ tsk::make_task(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 0),
+ 0);
+ b.wait();
+ pool.shutdown();
+ BOOST_CHECK_EQUAL( buffer[0], 0);
+ BOOST_CHECK_EQUAL( buffer[1], 55);
+ BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 2) );
+ }
+
+ // check smart scheduling
+ void test_case_13()
+ {
+ typedef tsk::pool<
+ tsk::bounded_channel< tsk::smart< int, std::less< int >, tsk::replace_oldest, tsk::take_oldest > >
+ > pool_type;
+ pool_type pool(
+ tsk::poolsize( 1),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ boost::barrier b( 2);
+ tsk::async(
+ pool,
+ tsk::make_task(
+ barrier_fn,
+ boost::ref( b) ),
+ 0);
+ std::vector< int > buffer;
+ tsk::async(
+ pool,
+ tsk::make_task(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 10),
+ 2);
+ tsk::async(
+ pool,
+ tsk::make_task(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 0),
+ 1);
+ tsk::async(
+ pool,
+ tsk::make_task(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 1),
+ 2);
+ b.wait();
+ pool.shutdown();
+ BOOST_CHECK_EQUAL( buffer[0], 0);
+ BOOST_CHECK_EQUAL( buffer[1], 1);
+ BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 2) );
+ }
+};
+
+boost::unit_test::test_suite * init_unit_test_suite( int, char* [])
+{
+ boost::unit_test::test_suite * test( BOOST_TEST_SUITE("Boost.Task: test suite") );
+
+ boost::shared_ptr< test_bounded_pool > instance( new test_bounded_pool() );
+ test->add( BOOST_CLASS_TEST_CASE( & test_bounded_pool::test_case_1, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_bounded_pool::test_case_2, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_bounded_pool::test_case_3, instance) );
+ //test->add( BOOST_CLASS_TEST_CASE( & test_bounded_pool::test_case_4, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_bounded_pool::test_case_5, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_bounded_pool::test_case_6, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_bounded_pool::test_case_7, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_bounded_pool::test_case_8, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_bounded_pool::test_case_9, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_bounded_pool::test_case_10, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_bounded_pool::test_case_11, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_bounded_pool::test_case_12, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_bounded_pool::test_case_13, instance) );
+
+ return test;
+}
+
Added: sandbox/task/libs/task/test/test_default_pool.cpp
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/test/test_default_pool.cpp 2009-05-01 02:11:40 EDT (Fri, 01 May 2009)
@@ -0,0 +1,197 @@
+
+// Copyright Oliver Kowalke 2009.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include <cstdlib>
+#include <iostream>
+#include <map>
+#include <stdexcept>
+#include <vector>
+
+#include <boost/bind.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+#include <boost/function.hpp>
+#include <boost/ref.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/thread.hpp>
+#include <boost/thread/barrier.hpp>
+#include <boost/utility.hpp>
+
+#include <boost/task.hpp>
+
+#include "test_functions.hpp"
+
+namespace pt = boost::posix_time;
+namespace tsk = boost::task;
+
+class test_default_pool
+{
+public:
+ // check id
+ void test_case_1()
+ {
+ tsk::task< int > t(
+ tsk::make_task(
+ fibonacci_fn,
+ 10) );
+ tsk::handle< int > h(
+ tsk::async(
+ tsk::default_pool(),
+ t) );
+ BOOST_CHECK_EQUAL( h.get_id(), t.get_id() );
+ BOOST_CHECK_EQUAL( h.get(), 55);
+ }
+
+ // check runs in pool
+ void test_case_2()
+ {
+ tsk::handle< bool > h(
+ tsk::async(
+ tsk::default_pool(),
+ tsk::make_task(
+ runs_in_pool_fn) ) );
+ BOOST_CHECK_EQUAL( h.get(), true);
+ }
+
+ // executed twice
+ void test_case_3()
+ {
+ tsk::task< int > t(
+ tsk::make_task(
+ fibonacci_fn,
+ 10) );
+ tsk::handle< int > h1(
+ tsk::async(
+ tsk::default_pool(),
+ t) );
+ BOOST_CHECK_EQUAL( h1.get(), 55);
+ tsk::handle< int > h2(
+ tsk::async(
+ tsk::default_pool(),
+ t) );
+ BOOST_CHECK_EQUAL( h2.get(), 55);
+ }
+
+ // check runtime_error throw inside task
+ void test_case_4()
+ {
+ tsk::handle< void > h(
+ tsk::async(
+ tsk::default_pool(),
+ tsk::make_task(
+ throwing_fn) ) );
+ bool thrown( false);
+ try
+ { h.get(); }
+ catch ( std::runtime_error const&)
+ { thrown = true; }
+ BOOST_CHECK( thrown);
+ }
+
+ // check interrupt
+ void test_case_5()
+ {
+ tsk::handle< void > h(
+ tsk::async(
+ tsk::default_pool(),
+ tsk::make_task(
+ delay_fn,
+ pt::seconds( 3) ) ) );
+ h.interrupt();
+ BOOST_CHECK( h.interruption_requested() );
+ bool thrown( false);
+ try
+ { h.get(); }
+ catch ( tsk::task_interrupted const&)
+ { thrown = true; }
+ BOOST_CHECK( thrown);
+ }
+
+ // check interrupt_and_wait
+ void test_case_6()
+ {
+ bool finished( false);
+ tsk::handle< void > h(
+ tsk::async(
+ tsk::default_pool(),
+ tsk::make_task(
+ interrupt_fn,
+ pt::seconds( 3),
+ boost::ref( finished) ) ) );
+ h.interrupt_and_wait();
+ BOOST_CHECK( finished);
+ BOOST_CHECK( h.is_ready() );
+ BOOST_CHECK( h.interruption_requested() );
+ bool thrown( false);
+ try
+ { h.get(); }
+ catch ( tsk::task_interrupted const&)
+ { thrown = true; }
+ BOOST_CHECK( thrown);
+ }
+
+ // check waitfor_all()
+ void test_case_7()
+ {
+ std::vector< tsk::handle< int > > vec;
+ for ( int i = 0; i <= 5; ++i)
+ vec.push_back(
+ tsk::async(
+ tsk::default_pool(),
+ tsk::make_task(
+ fibonacci_fn,
+ i) ) );
+ tsk::waitfor_all( vec.begin(), vec.end() );
+ BOOST_CHECK( vec[0].is_ready() );
+ BOOST_CHECK( vec[1].is_ready() );
+ BOOST_CHECK( vec[2].is_ready() );
+ BOOST_CHECK( vec[3].is_ready() );
+ BOOST_CHECK( vec[4].is_ready() );
+ BOOST_CHECK( vec[5].is_ready() );
+ BOOST_CHECK_EQUAL( vec[0].get(), 0);
+ BOOST_CHECK_EQUAL( vec[1].get(), 1);
+ BOOST_CHECK_EQUAL( vec[2].get(), 1);
+ BOOST_CHECK_EQUAL( vec[3].get(), 2);
+ BOOST_CHECK_EQUAL( vec[4].get(), 3);
+ BOOST_CHECK_EQUAL( vec[5].get(), 5);
+ }
+
+ // check waitfor_any()
+ void test_case_8()
+ {
+ tsk::handle< void > h1(
+ tsk::async_in_pool(
+ tsk::make_task(
+ delay_fn,
+ pt::seconds( 3) ) ) );
+ tsk::handle< int > h2(
+ tsk::async(
+ tsk::default_pool(),
+ tsk::make_task(
+ fibonacci_fn,
+ 10) ) );
+ tsk::waitfor_any( h1, h2);
+ BOOST_CHECK( ! h1.is_ready() );
+ BOOST_CHECK( h2.is_ready() );
+ BOOST_CHECK_EQUAL( h2.get(), 55);
+ }
+};
+
+boost::unit_test::test_suite * init_unit_test_suite( int, char* [])
+{
+ boost::unit_test::test_suite * test( BOOST_TEST_SUITE("Boost.Task: test suite") );
+
+ boost::shared_ptr< test_default_pool > instance( new test_default_pool() );
+ test->add( BOOST_CLASS_TEST_CASE( & test_default_pool::test_case_1, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_default_pool::test_case_2, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_default_pool::test_case_3, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_default_pool::test_case_4, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_default_pool::test_case_5, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_default_pool::test_case_6, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_default_pool::test_case_7, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_default_pool::test_case_8, instance) );
+
+ return test;
+}
Deleted: sandbox/task/libs/task/test/test_handle.cpp
==============================================================================
--- sandbox/task/libs/task/test/test_handle.cpp 2009-05-01 02:11:40 EDT (Fri, 01 May 2009)
+++ (empty file)
@@ -1,143 +0,0 @@
-
-// Copyright Oliver Kowalke 2009.
-// Distributed under the Boost Software License, Version 1.0.
-// (See accompanying file LICENSE_1_0.txt or copy at
-// http://www.boost.org/LICENSE_1_0.txt)
-
-#include <cstdlib>
-#include <iostream>
-#include <map>
-#include <stdexcept>
-#include <vector>
-
-#include <boost/bind.hpp>
-#include <boost/date_time/posix_time/posix_time.hpp>
-#include <boost/function.hpp>
-#include <boost/ref.hpp>
-#include <boost/test/unit_test.hpp>
-#include <boost/thread.hpp>
-#include <boost/thread/barrier.hpp>
-#include <boost/utility.hpp>
-
-#include <boost/task.hpp>
-
-#include "test_functions.hpp"
-
-namespace pt = boost::posix_time;
-namespace tsk = boost::task;
-
-class test_handle
-{
-public:
- // check id
- void test_case_1()
- {
- tsk::task< int > t(
- tsk::make_task(
- fibonacci_fn,
- 10) );
- tsk::async_handle< int > h(
- tsk::async_in_thread(
- t) );
- BOOST_CHECK_EQUAL( h.get_id(), t.get_id() );
- BOOST_CHECK_EQUAL( h.get(), 55);
- }
-
- // check waitfor_all()
- void test_case_2()
- {
- std::vector< tsk::async_handle< int > > vec;
- for ( int i = 0; i <= 5; ++i)
- vec.push_back(
- tsk::async_in_pool(
- tsk::make_task(
- fibonacci_fn,
- i) ) );
- tsk::waitfor_all( vec.begin(), vec.end() );
- BOOST_CHECK( vec[0].is_ready() );
- BOOST_CHECK( vec[1].is_ready() );
- BOOST_CHECK( vec[2].is_ready() );
- BOOST_CHECK( vec[3].is_ready() );
- BOOST_CHECK( vec[4].is_ready() );
- BOOST_CHECK( vec[5].is_ready() );
- BOOST_CHECK_EQUAL( vec[0].get(), 0);
- BOOST_CHECK_EQUAL( vec[1].get(), 1);
- BOOST_CHECK_EQUAL( vec[2].get(), 1);
- BOOST_CHECK_EQUAL( vec[3].get(), 2);
- BOOST_CHECK_EQUAL( vec[4].get(), 3);
- BOOST_CHECK_EQUAL( vec[5].get(), 5);
- }
-
- // check waitfor_any()
- void test_case_3()
- {
- tsk::async_handle< void > h1(
- tsk::async_in_pool(
- tsk::make_task(
- delay_fn,
- pt::seconds( 3) ) ) );
- tsk::async_handle< int > h2(
- tsk::async_in_pool(
- tsk::make_task(
- fibonacci_fn,
- 10) ) );
- tsk::waitfor_any( h1, h2);
- BOOST_CHECK( ! h1.is_ready() );
- BOOST_CHECK( h2.is_ready() );
- BOOST_CHECK_EQUAL( h2.get(), 55);
- }
-
- // check interrupt
- void test_case_4()
- {
- tsk::async_handle< void > h(
- tsk::async_in_thread(
- tsk::make_task(
- delay_fn,
- pt::seconds( 3) ) ) );
- h.interrupt();
- BOOST_CHECK( h.interruption_requested() );
- bool thrown( false);
- try
- { h.get(); }
- catch ( tsk::task_interrupted const&)
- { thrown = true; }
- BOOST_CHECK( thrown);
- }
-
- // check interruption
- void test_case_5()
- {
- bool finished( false);
- tsk::async_handle< void > h(
- tsk::async_in_thread(
- tsk::make_task(
- interrupt_fn,
- pt::seconds( 3),
- boost::ref( finished) ) ) );
- h.interrupt_and_wait();
- BOOST_CHECK( finished);
- BOOST_CHECK( h.is_ready() );
- BOOST_CHECK( h.interruption_requested() );
- bool thrown( false);
- try
- { h.get(); }
- catch ( tsk::task_interrupted const&)
- { thrown = true; }
- BOOST_CHECK( thrown);
- }
-};
-
-boost::unit_test::test_suite * init_unit_test_suite( int, char* [])
-{
- boost::unit_test::test_suite * test( BOOST_TEST_SUITE("Boost.Task: test suite") );
-
- boost::shared_ptr< test_handle > instance( new test_handle() );
- test->add( BOOST_CLASS_TEST_CASE( & test_handle::test_case_1, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_handle::test_case_2, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_handle::test_case_3, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_handle::test_case_4, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_handle::test_case_5, instance) );
-
- return test;
-}
Deleted: sandbox/task/libs/task/test/test_in_bounded_pool.cpp
==============================================================================
--- sandbox/task/libs/task/test/test_in_bounded_pool.cpp 2009-05-01 02:11:40 EDT (Fri, 01 May 2009)
+++ (empty file)
@@ -1,437 +0,0 @@
-
-// Copyright Oliver Kowalke 2009.
-// Distributed under the Boost Software License, Version 1.0.
-// (See accompanying file LICENSE_1_0.txt or copy at
-// http://www.boost.org/LICENSE_1_0.txt)
-
-#include <cstdlib>
-#include <iostream>
-#include <map>
-#include <stdexcept>
-#include <vector>
-
-#include <boost/bind.hpp>
-#include <boost/date_time/posix_time/posix_time.hpp>
-#include <boost/function.hpp>
-#include <boost/ref.hpp>
-#include <boost/test/unit_test.hpp>
-#include <boost/thread.hpp>
-#include <boost/thread/barrier.hpp>
-#include <boost/utility.hpp>
-
-#include <boost/task.hpp>
-
-#include "test_functions.hpp"
-
-namespace pt = boost::posix_time;
-namespace tsk = boost::task;
-
-class test_in_bounded_pool
-{
-public:
- // check size, active, idle
- void test_case_1()
- {
- tsk::pool<
- tsk::bounded_channel< tsk::fifo >
- > pool(
- tsk::poolsize( 3),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- BOOST_CHECK_EQUAL( pool.size(), std::size_t( 3) );
- BOOST_CHECK_EQUAL( pool.idle(), std::size_t( 3) );
- BOOST_CHECK_EQUAL( pool.active(), std::size_t( 0) );
- }
-
- // check submit
- void test_case_2()
- {
- tsk::pool<
- tsk::bounded_channel< tsk::fifo >
- > pool(
- tsk::poolsize( 1),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- tsk::async_handle< int > h(
- tsk::async_in_pool(
- pool,
- tsk::make_task(
- fibonacci_fn,
- 10) ) );
- BOOST_CHECK_EQUAL( h.get(), 55);
- }
-
- // check runs in pool
- void test_case_3()
- {
- tsk::pool<
- tsk::bounded_channel< tsk::fifo >
- > pool(
- tsk::poolsize( 1),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- tsk::async_handle< bool > h(
- tsk::async_in_pool(
- pool,
- tsk::make_task(
- runs_in_pool_fn) ) );
- BOOST_CHECK_EQUAL( h.get(), true);
- }
-
- // don't execute twice
- void test_case_4()
- {
- tsk::pool<
- tsk::bounded_channel< tsk::fifo >
- > pool(
- tsk::poolsize( 1),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- tsk::task< int > t(
- tsk::make_task(
- fibonacci_fn,
- 10) );
- tsk::async_handle< int > h(
- tsk::async_in_pool(
- pool,
- t) );
- BOOST_CHECK_EQUAL( h.get(), 55);
- tsk::async_in_pool(
- pool,
- t);
- bool thrown( false);
- try
- { h.get(); }
- catch ( tsk::task_already_executed const&)
- { thrown = true; }
- BOOST_CHECK( thrown);
- }
-
- // check shutdown
- void test_case_5()
- {
- tsk::pool<
- tsk::bounded_channel< tsk::fifo >
- > pool(
- tsk::poolsize( 1),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- tsk::async_handle< int > h(
- tsk::async_in_pool(
- pool,
- tsk::make_task(
- fibonacci_fn,
- 10) ) );
- pool.shutdown();
- BOOST_CHECK( pool.closed() );
- BOOST_CHECK_EQUAL( h.get(), 55);
- }
-
- // check runtime_error throw inside task
- void test_case_6()
- {
- tsk::pool<
- tsk::bounded_channel< tsk::fifo >
- > pool(
- tsk::poolsize( 1),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- tsk::async_handle< void > h(
- tsk::async_in_pool(
- pool,
- tsk::make_task(
- throwing_fn) ) );
- pool.shutdown();
- bool thrown( false);
- try
- { h.get(); }
- catch ( std::runtime_error const&)
- { thrown = true; }
- BOOST_CHECK( thrown);
- }
-
- // check shutdown with task_rejected exception
- void test_case_7()
- {
- tsk::pool<
- tsk::bounded_channel< tsk::fifo >
- > pool(
- tsk::poolsize( 1),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- pool.shutdown();
- BOOST_CHECK( pool.closed() );
- bool thrown( false);
- try
- {
- tsk::async_in_pool(
- pool,
- tsk::make_task(
- boost::bind(
- fibonacci_fn,
- 10) ) );
- }
- catch ( tsk::task_rejected const&)
- { thrown = true; }
- BOOST_CHECK( thrown);
- }
-
- // check shutdown_now with thread_interrupted exception
- void test_case_8()
- {
- tsk::pool<
- tsk::bounded_channel< tsk::fifo >
- > pool(
- tsk::poolsize( 1),
- tsk::high_watermark( 1),
- tsk::low_watermark( 1) );
- tsk::async_handle< void > h(
- tsk::async_in_pool(
- pool,
- tsk::make_task(
- delay_fn,
- pt::millisec( 500) ) ) );
- boost::this_thread::sleep( pt::millisec( 250) );
- BOOST_CHECK_EQUAL( pool.size(), std::size_t( 1) );
- pool.shutdown_now();
- BOOST_CHECK( pool.closed() );
- BOOST_CHECK_EQUAL( pool.size(), std::size_t( 1) );
- BOOST_CHECK_EQUAL( pool.idle(), std::size_t( 1) );
- BOOST_CHECK_EQUAL( pool.active(), std::size_t( 0) );
- bool thrown( false);
- try
- { h.get(); }
- catch ( tsk::task_interrupted const&)
- { thrown = true; }
- BOOST_CHECK( thrown);
- }
-
- // check pending
- void test_case_9()
- {
- typedef tsk::pool<
- tsk::bounded_channel< tsk::fifo >
- > pool_type;
- pool_type pool(
- tsk::poolsize( 1),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- boost::barrier b( 2);
- tsk::async_handle< void > h1(
- tsk::async_in_pool(
- pool,
- tsk::make_task(
- barrier_fn,
- boost::ref( b) ) ) );
- boost::this_thread::sleep( pt::millisec( 250) );
- BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 0) );
- tsk::async_handle< int > h2(
- tsk::async_in_pool(
- pool,
- tsk::make_task(
- fibonacci_fn,
- 10) ) );
- boost::this_thread::sleep( pt::millisec(250) );
- BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 1) );
- tsk::async_handle< int > h3(
- tsk::async_in_pool(
- pool,
- tsk::make_task(
- fibonacci_fn,
- 10) ) );
- boost::this_thread::sleep( pt::millisec(250) );
- BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 2) );
- b.wait();
- h1.get();
- BOOST_CHECK_EQUAL( h2.get(), 55);
- BOOST_CHECK_EQUAL( h3.get(), 55);
- BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 0) );
- }
-
- // check interruption
- void test_case_10()
- {
- typedef tsk::pool<
- tsk::bounded_channel< tsk::fifo >
- > pool_type;
- pool_type pool(
- tsk::poolsize( 1),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- boost::barrier b( 2);
- tsk::async_in_pool(
- pool,
- tsk::make_task(
- barrier_fn,
- boost::ref( b) ) );
- std::vector< int > buffer;
- tsk::async_handle< void > h(
- tsk::async_in_pool(
- pool,
- tsk::make_task(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 10) ) );
- tsk::async_in_pool(
- pool,
- tsk::make_task(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 0) );
- h.interrupt();
- b.wait();
- pool.shutdown();
- BOOST_CHECK_EQUAL( buffer[0], 0);
- BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 1) );
- bool thrown( false);
- try
- { h.get(); }
- catch ( tsk::task_interrupted const&)
- { thrown = true; }
- BOOST_CHECK( thrown);
- }
-
- // check fifo scheduling
- void test_case_11()
- {
- typedef tsk::pool<
- tsk::bounded_channel< tsk::fifo >
- > pool_type;
- pool_type pool(
- tsk::poolsize( 1),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- boost::barrier b( 2);
- tsk::async_in_pool(
- pool,
- tsk::make_task(
- barrier_fn,
- boost::ref( b) ) );
- std::vector< int > buffer;
- tsk::async_in_pool(
- pool,
- tsk::make_task(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 10) );
- tsk::async_in_pool(
- pool,
- tsk::make_task(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 0) );
- b.wait();
- pool.shutdown();
- BOOST_CHECK_EQUAL( buffer[0], 55);
- BOOST_CHECK_EQUAL( buffer[1], 0);
- BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 2) );
- }
-
- // check priority scheduling
- void test_case_12()
- {
- typedef tsk::pool<
- tsk::bounded_channel< tsk::priority< int > >
- > pool_type;
- pool_type pool(
- tsk::poolsize( 1),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- boost::barrier b( 2);
- tsk::async_in_pool(
- pool,
- tsk::make_task(
- barrier_fn,
- boost::ref( b) ),
- 0);
- std::vector< int > buffer;
- tsk::async_in_pool(
- pool,
- tsk::make_task(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 10),
- 1);
- tsk::async_in_pool(
- pool,
- tsk::make_task(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 0),
- 0);
- b.wait();
- pool.shutdown();
- BOOST_CHECK_EQUAL( buffer[0], 0);
- BOOST_CHECK_EQUAL( buffer[1], 55);
- BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 2) );
- }
-
- // check smart scheduling
- void test_case_13()
- {
- typedef tsk::pool<
- tsk::bounded_channel< tsk::smart< int, std::less< int >, tsk::replace_oldest, tsk::take_oldest > >
- > pool_type;
- pool_type pool(
- tsk::poolsize( 1),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- boost::barrier b( 2);
- tsk::async_in_pool(
- pool,
- tsk::make_task(
- barrier_fn,
- boost::ref( b) ),
- 0);
- std::vector< int > buffer;
- tsk::async_in_pool(
- pool,
- tsk::make_task(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 10),
- 2);
- tsk::async_in_pool(
- pool,
- tsk::make_task(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 0),
- 1);
- tsk::async_in_pool(
- pool,
- tsk::make_task(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 1),
- 2);
- b.wait();
- pool.shutdown();
- BOOST_CHECK_EQUAL( buffer[0], 0);
- BOOST_CHECK_EQUAL( buffer[1], 1);
- BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 2) );
- }
-};
-
-boost::unit_test::test_suite * init_unit_test_suite( int, char* [])
-{
- boost::unit_test::test_suite * test( BOOST_TEST_SUITE("Boost.Task: test suite") );
-
- boost::shared_ptr< test_in_bounded_pool > instance( new test_in_bounded_pool() );
- test->add( BOOST_CLASS_TEST_CASE( & test_in_bounded_pool::test_case_1, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_in_bounded_pool::test_case_2, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_in_bounded_pool::test_case_3, instance) );
- //test->add( BOOST_CLASS_TEST_CASE( & test_in_bounded_pool::test_case_4, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_in_bounded_pool::test_case_5, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_in_bounded_pool::test_case_6, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_in_bounded_pool::test_case_7, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_in_bounded_pool::test_case_8, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_in_bounded_pool::test_case_9, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_in_bounded_pool::test_case_10, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_in_bounded_pool::test_case_11, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_in_bounded_pool::test_case_12, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_in_bounded_pool::test_case_13, instance) );
-
- return test;
-}
-
Deleted: sandbox/task/libs/task/test/test_in_thread.cpp
==============================================================================
--- sandbox/task/libs/task/test/test_in_thread.cpp 2009-05-01 02:11:40 EDT (Fri, 01 May 2009)
+++ (empty file)
@@ -1,118 +0,0 @@
-
-// Copyright Oliver Kowalke 2009.
-// Distributed under the Boost Software License, Version 1.0.
-// (See accompanying file LICENSE_1_0.txt or copy at
-// http://www.boost.org/LICENSE_1_0.txt)
-
-#include <cstdlib>
-#include <iostream>
-#include <map>
-#include <stdexcept>
-#include <vector>
-
-#include <boost/bind.hpp>
-#include <boost/date_time/posix_time/posix_time.hpp>
-#include <boost/function.hpp>
-#include <boost/ref.hpp>
-#include <boost/test/unit_test.hpp>
-#include <boost/thread.hpp>
-#include <boost/thread/barrier.hpp>
-#include <boost/utility.hpp>
-
-#include <boost/task.hpp>
-
-#include "test_functions.hpp"
-
-namespace pt = boost::posix_time;
-namespace tsk = boost::task;
-
-class test_in_thread
-{
-public:
- // check submit
- void test_case_1()
- {
- tsk::async_handle< int > h(
- tsk::async_in_thread(
- tsk::make_task(
- fibonacci_fn,
- 10) ) );
- BOOST_CHECK_EQUAL( h.get(), 55);
- }
-
- // check runs not in pool
- void test_case_2()
- {
- tsk::async_handle< bool > h(
- tsk::async_in_thread(
- tsk::make_task(
- runs_in_pool_fn) ) );
- BOOST_CHECK_EQUAL( h.get(), false);
- }
-
- // don't execute twice
- void test_case_3()
- {
- tsk::task< int > t(
- tsk::make_task(
- fibonacci_fn,
- 10) );
- tsk::async_in_thread( t);
- tsk::async_handle< int > h( tsk::async_in_thread( t) );
- BOOST_CHECK_EQUAL( h.get(), 55);
- bool thrown( false);
- try
- { h.get(); }
- catch ( tsk::task_already_executed const&)
- { thrown = true; }
- BOOST_CHECK( thrown);
- }
-
- // check runtime_error thrown inside the task
- void test_case_4()
- {
- tsk::async_handle< void > h(
- tsk::async_in_thread(
- tsk::make_task(
- throwing_fn) ) );
- bool thrown( false);
- try
- { h.get(); }
- catch ( std::runtime_error const&)
- { thrown = true; }
- BOOST_CHECK( thrown);
- }
-
- // check interruptation
- void test_case_5()
- {
- boost::barrier b( 2);
- tsk::async_handle< void > h(
- tsk::async_in_thread(
- tsk::make_task(
- barrier_fn,
- boost::ref( b) ) ) );
- h.interrupt();
- b.wait();
- bool thrown( false);
- try
- { h.get(); }
- catch ( tsk::task_interrupted const&)
- { thrown = true; }
- BOOST_CHECK( thrown);
- }
-};
-
-boost::unit_test::test_suite * init_unit_test_suite( int, char* [])
-{
- boost::unit_test::test_suite * test( BOOST_TEST_SUITE("Boost.Task: test suite") );
-
- boost::shared_ptr< test_in_thread > instance( new test_in_thread() );
- test->add( BOOST_CLASS_TEST_CASE( & test_in_thread::test_case_1, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_in_thread::test_case_2, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_in_thread::test_case_3, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_in_thread::test_case_4, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_in_thread::test_case_5, instance) );
-
- return test;
-}
Deleted: sandbox/task/libs/task/test/test_in_unbounded_pool.cpp
==============================================================================
--- sandbox/task/libs/task/test/test_in_unbounded_pool.cpp 2009-05-01 02:11:40 EDT (Fri, 01 May 2009)
+++ (empty file)
@@ -1,395 +0,0 @@
-
-// Copyright Oliver Kowalke 2009.
-// Distributed under the Boost Software License, Version 1.0.
-// (See accompanying file LICENSE_1_0.txt or copy at
-// http://www.boost.org/LICENSE_1_0.txt)
-
-#include <cstdlib>
-#include <iostream>
-#include <map>
-#include <stdexcept>
-#include <vector>
-
-#include <boost/bind.hpp>
-#include <boost/date_time/posix_time/posix_time.hpp>
-#include <boost/function.hpp>
-#include <boost/ref.hpp>
-#include <boost/test/unit_test.hpp>
-#include <boost/thread.hpp>
-#include <boost/thread/barrier.hpp>
-#include <boost/utility.hpp>
-
-#include <boost/task.hpp>
-
-#include "test_functions.hpp"
-
-namespace pt = boost::posix_time;
-namespace tsk = boost::task;
-
-class test_in_unbounded_pool
-{
-public:
- // check size, active, idle
- void test_case_1()
- {
- tsk::pool<
- tsk::unbounded_channel< tsk::fifo >
- > pool( tsk::poolsize( 3) );
- BOOST_CHECK_EQUAL( pool.size(), std::size_t( 3) );
- BOOST_CHECK_EQUAL( pool.idle(), std::size_t( 3) );
- BOOST_CHECK_EQUAL( pool.active(), std::size_t( 0) );
- }
-
- // check submit
- void test_case_2()
- {
- tsk::pool<
- tsk::unbounded_channel< tsk::fifo >
- > pool( tsk::poolsize( 1) );
- tsk::async_handle< int > h(
- tsk::async_in_pool(
- pool,
- tsk::make_task(
- fibonacci_fn,
- 10) ) );
- BOOST_CHECK_EQUAL( h.get(), 55);
- }
-
- // check runs in pool
- void test_case_3()
- {
- tsk::pool<
- tsk::unbounded_channel< tsk::fifo >
- > pool( tsk::poolsize( 1) );
- tsk::async_handle< bool > h(
- tsk::async_in_pool(
- pool,
- tsk::make_task(
- runs_in_pool_fn) ) );
- BOOST_CHECK_EQUAL( h.get(), true);
- }
-
- // don't execute twice
- void test_case_4()
- {
- tsk::pool<
- tsk::unbounded_channel< tsk::fifo >
- > pool( tsk::poolsize( 1) );
- tsk::task< int > t(
- tsk::make_task(
- fibonacci_fn,
- 10) );
- tsk::async_handle< int > h(
- tsk::async_in_pool(
- pool,
- t) );
- BOOST_CHECK_EQUAL( h.get(), 55);
- tsk::async_in_pool(
- pool,
- t);
- bool thrown( false);
- try
- { h.get(); }
- catch ( tsk::task_already_executed const&)
- { thrown = true; }
- BOOST_CHECK( thrown);
- }
-
- // check shutdown
- void test_case_5()
- {
- tsk::pool<
- tsk::unbounded_channel< tsk::fifo >
- > pool( tsk::poolsize( 1) );
- tsk::async_handle< int > h(
- tsk::async_in_pool(
- pool,
- tsk::make_task(
- fibonacci_fn,
- 10) ) );
- pool.shutdown();
- BOOST_CHECK( pool.closed() );
- BOOST_CHECK_EQUAL( h.get(), 55);
- }
-
- // check runtime_error throw inside task
- void test_case_6()
- {
- tsk::pool<
- tsk::unbounded_channel< tsk::fifo >
- > pool( tsk::poolsize( 1) );
- tsk::async_handle< void > h(
- tsk::async_in_pool(
- pool,
- tsk::make_task(
- throwing_fn) ) );
- pool.shutdown();
- bool thrown( false);
- try
- { h.get(); }
- catch ( std::runtime_error const&)
- { thrown = true; }
- BOOST_CHECK( thrown);
- }
-
- // check shutdown with task_rejected exception
- void test_case_7()
- {
- tsk::pool<
- tsk::unbounded_channel< tsk::fifo >
- > pool( tsk::poolsize( 1) );
- pool.shutdown();
- BOOST_CHECK( pool.closed() );
- bool thrown( false);
- try
- {
- tsk::async_in_pool(
- pool,
- tsk::make_task(
- boost::bind(
- fibonacci_fn,
- 10) ) );
- }
- catch ( tsk::task_rejected const&)
- { thrown = true; }
- BOOST_CHECK( thrown);
- }
-
- // check shutdown_now with thread_interrupted exception
- void test_case_8()
- {
- tsk::pool<
- tsk::unbounded_channel< tsk::fifo >
- > pool( tsk::poolsize( 1) );
- tsk::async_handle< void > h(
- tsk::async_in_pool(
- pool,
- tsk::make_task(
- delay_fn,
- pt::millisec( 500) ) ) );
- boost::this_thread::sleep( pt::millisec( 250) );
- BOOST_CHECK_EQUAL( pool.size(), std::size_t( 1) );
- pool.shutdown_now();
- BOOST_CHECK( pool.closed() );
- BOOST_CHECK_EQUAL( pool.size(), std::size_t( 1) );
- BOOST_CHECK_EQUAL( pool.idle(), std::size_t( 1) );
- BOOST_CHECK_EQUAL( pool.active(), std::size_t( 0) );
- bool thrown( false);
- try
- { h.get(); }
- catch ( tsk::task_interrupted const&)
- { thrown = true; }
- BOOST_CHECK( thrown);
- }
-
- // check pending
- void test_case_9()
- {
- typedef tsk::pool<
- tsk::unbounded_channel< tsk::fifo >
- > pool_type;
- pool_type pool( tsk::poolsize( 1) );
- boost::barrier b( 2);
- tsk::async_handle< void > h1(
- tsk::async_in_pool(
- pool,
- tsk::make_task(
- barrier_fn,
- boost::ref( b) ) ) );
- boost::this_thread::sleep( pt::millisec( 250) );
- BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 0) );
- tsk::async_handle< int > h2(
- tsk::async_in_pool(
- pool,
- tsk::make_task(
- fibonacci_fn,
- 10) ) );
- boost::this_thread::sleep( pt::millisec(250) );
- BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 1) );
- tsk::async_handle< int > h3(
- tsk::async_in_pool(
- pool,
- tsk::make_task(
- fibonacci_fn,
- 10) ) );
- boost::this_thread::sleep( pt::millisec(250) );
- BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 2) );
- b.wait();
- h1.get();
- BOOST_CHECK_EQUAL( h2.get(), 55);
- BOOST_CHECK_EQUAL( h3.get(), 55);
- BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 0) );
- }
-
- // check interruptation
- void test_case_10()
- {
- typedef tsk::pool<
- tsk::unbounded_channel< tsk::fifo >
- > pool_type;
- pool_type pool( tsk::poolsize( 1) );
- boost::barrier b( 2);
- pool.submit(
- tsk::make_task(
- barrier_fn,
- boost::ref( b) ) );
- std::vector< int > buffer;
- tsk::async_handle< void > h(
- tsk::async_in_pool(
- pool,
- tsk::make_task(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 10) ) );
- tsk::async_in_pool(
- pool,
- tsk::make_task(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 0) );
- h.interrupt();
- b.wait();
- pool.shutdown();
- BOOST_CHECK_EQUAL( buffer[0], 0);
- BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 1) );
- bool thrown( false);
- try
- { h.get(); }
- catch ( tsk::task_interrupted const&)
- { thrown = true; }
- BOOST_CHECK( thrown);
- }
-
- // check fifo scheduling
- void test_case_11()
- {
- typedef tsk::pool<
- tsk::unbounded_channel< tsk::fifo >
- > pool_type;
- pool_type pool( tsk::poolsize( 1) );
- boost::barrier b( 2);
- tsk::async_in_pool(
- pool,
- tsk::make_task(
- barrier_fn,
- boost::ref( b) ) );
- std::vector< int > buffer;
- tsk::async_in_pool(
- pool,
- tsk::make_task(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 10) );
- tsk::async_in_pool(
- pool,
- tsk::make_task(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 0) );
- b.wait();
- pool.shutdown();
- BOOST_CHECK_EQUAL( buffer[0], 55);
- BOOST_CHECK_EQUAL( buffer[1], 0);
- BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 2) );
- }
-
- // check priority scheduling
- void test_case_12()
- {
- typedef tsk::pool<
- tsk::unbounded_channel< tsk::priority< int > >
- > pool_type;
- pool_type pool( tsk::poolsize( 1) );
- boost::barrier b( 2);
- tsk::async_in_pool(
- pool,
- tsk::make_task(
- barrier_fn,
- boost::ref( b) ),
- 0);
- std::vector< int > buffer;
- tsk::async_in_pool(
- pool,
- tsk::make_task(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 10),
- 1);
- tsk::async_in_pool(
- pool,
- tsk::make_task(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 0),
- 0);
- b.wait();
- pool.shutdown();
- BOOST_CHECK_EQUAL( buffer[0], 0);
- BOOST_CHECK_EQUAL( buffer[1], 55);
- BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 2) );
- }
-
- // check smart scheduling
- void test_case_13()
- {
- typedef tsk::pool<
- tsk::unbounded_channel< tsk::smart< int, std::less< int >, tsk::replace_oldest, tsk::take_oldest > >
- > pool_type;
- pool_type pool( tsk::poolsize( 1) );
- boost::barrier b( 2);
- pool.submit(
- tsk::make_task(
- barrier_fn,
- boost::ref( b) ),
- 0);
- std::vector< int > buffer;
- tsk::async_in_pool(
- pool,
- tsk::make_task(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 10),
- 2);
- tsk::async_in_pool(
- pool,
- tsk::make_task(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 0),
- 1);
- tsk::async_in_pool(
- pool,
- tsk::make_task(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 1),
- 2);
- b.wait();
- pool.shutdown();
- BOOST_CHECK_EQUAL( buffer[0], 0);
- BOOST_CHECK_EQUAL( buffer[1], 1);
- BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 2) );
- }
-};
-
-boost::unit_test::test_suite * init_unit_test_suite( int, char* [])
-{
- boost::unit_test::test_suite * test( BOOST_TEST_SUITE("Boost.Task: test suite") );
-
- boost::shared_ptr< test_in_unbounded_pool > instance( new test_in_unbounded_pool() );
- test->add( BOOST_CLASS_TEST_CASE( & test_in_unbounded_pool::test_case_1, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_in_unbounded_pool::test_case_2, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_in_unbounded_pool::test_case_3, instance) );
-// test->add( BOOST_CLASS_TEST_CASE( & test_in_unbounded_pool::test_case_4, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_in_unbounded_pool::test_case_5, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_in_unbounded_pool::test_case_6, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_in_unbounded_pool::test_case_7, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_in_unbounded_pool::test_case_8, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_in_unbounded_pool::test_case_9, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_in_unbounded_pool::test_case_10, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_in_unbounded_pool::test_case_11, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_in_unbounded_pool::test_case_12, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_in_unbounded_pool::test_case_13, instance) );
-
- return test;
-}
Added: sandbox/task/libs/task/test/test_new_thread.cpp
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/test/test_new_thread.cpp 2009-05-01 02:11:40 EDT (Fri, 01 May 2009)
@@ -0,0 +1,197 @@
+
+// Copyright Oliver Kowalke 2009.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include <cstdlib>
+#include <iostream>
+#include <map>
+#include <stdexcept>
+#include <vector>
+
+#include <boost/bind.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+#include <boost/function.hpp>
+#include <boost/ref.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/thread.hpp>
+#include <boost/thread/barrier.hpp>
+#include <boost/utility.hpp>
+
+#include <boost/task.hpp>
+
+#include "test_functions.hpp"
+
+namespace pt = boost::posix_time;
+namespace tsk = boost::task;
+
+class test_new_thread
+{
+public:
+ // check id
+ void test_case_1()
+ {
+ tsk::task< int > t(
+ tsk::make_task(
+ fibonacci_fn,
+ 10) );
+ tsk::handle< int > h(
+ tsk::async(
+ tsk::new_thread(),
+ t) );
+ BOOST_CHECK_EQUAL( h.get_id(), t.get_id() );
+ BOOST_CHECK_EQUAL( h.get(), 55);
+ }
+
+ // check runs not in pool
+ void test_case_2()
+ {
+ tsk::handle< bool > h(
+ tsk::async(
+ tsk::new_thread(),
+ tsk::make_task(
+ runs_in_pool_fn) ) );
+ BOOST_CHECK_EQUAL( h.get(), false);
+ }
+
+ // executed twice
+ void test_case_3()
+ {
+ tsk::task< int > t(
+ tsk::make_task(
+ fibonacci_fn,
+ 10) );
+ tsk::handle< int > h1(
+ tsk::async(
+ tsk::new_thread(),
+ t) );
+ BOOST_CHECK_EQUAL( h1.get(), 55);
+ tsk::handle< int > h2(
+ tsk::async(
+ tsk::new_thread(),
+ t) );
+ BOOST_CHECK_EQUAL( h2.get(), 55);
+ }
+
+ // check runtime_error throw inside task
+ void test_case_4()
+ {
+ tsk::handle< void > h(
+ tsk::async(
+ tsk::new_thread(),
+ tsk::make_task(
+ throwing_fn) ) );
+ bool thrown( false);
+ try
+ { h.get(); }
+ catch ( std::runtime_error const&)
+ { thrown = true; }
+ BOOST_CHECK( thrown);
+ }
+
+ // check interrupt
+ void test_case_5()
+ {
+ tsk::handle< void > h(
+ tsk::async(
+ tsk::new_thread(),
+ tsk::make_task(
+ delay_fn,
+ pt::seconds( 3) ) ) );
+ h.interrupt();
+ BOOST_CHECK( h.interruption_requested() );
+ bool thrown( false);
+ try
+ { h.get(); }
+ catch ( tsk::task_interrupted const&)
+ { thrown = true; }
+ BOOST_CHECK( thrown);
+ }
+
+ // check interrupt_and_wait
+ void test_case_6()
+ {
+ bool finished( false);
+ tsk::handle< void > h(
+ tsk::async(
+ tsk::new_thread(),
+ tsk::make_task(
+ interrupt_fn,
+ pt::seconds( 3),
+ boost::ref( finished) ) ) );
+ h.interrupt_and_wait();
+ BOOST_CHECK( finished);
+ BOOST_CHECK( h.is_ready() );
+ BOOST_CHECK( h.interruption_requested() );
+ bool thrown( false);
+ try
+ { h.get(); }
+ catch ( tsk::task_interrupted const&)
+ { thrown = true; }
+ BOOST_CHECK( thrown);
+ }
+
+ // check waitfor_all()
+ void test_case_7()
+ {
+ std::vector< tsk::handle< int > > vec;
+ for ( int i = 0; i <= 5; ++i)
+ vec.push_back(
+ tsk::async(
+ tsk::new_thread(),
+ tsk::make_task(
+ fibonacci_fn,
+ i) ) );
+ tsk::waitfor_all( vec.begin(), vec.end() );
+ BOOST_CHECK( vec[0].is_ready() );
+ BOOST_CHECK( vec[1].is_ready() );
+ BOOST_CHECK( vec[2].is_ready() );
+ BOOST_CHECK( vec[3].is_ready() );
+ BOOST_CHECK( vec[4].is_ready() );
+ BOOST_CHECK( vec[5].is_ready() );
+ BOOST_CHECK_EQUAL( vec[0].get(), 0);
+ BOOST_CHECK_EQUAL( vec[1].get(), 1);
+ BOOST_CHECK_EQUAL( vec[2].get(), 1);
+ BOOST_CHECK_EQUAL( vec[3].get(), 2);
+ BOOST_CHECK_EQUAL( vec[4].get(), 3);
+ BOOST_CHECK_EQUAL( vec[5].get(), 5);
+ }
+
+ // check waitfor_any()
+ void test_case_8()
+ {
+ tsk::handle< void > h1(
+ tsk::async_in_pool(
+ tsk::make_task(
+ delay_fn,
+ pt::seconds( 3) ) ) );
+ tsk::handle< int > h2(
+ tsk::async(
+ tsk::new_thread(),
+ tsk::make_task(
+ fibonacci_fn,
+ 10) ) );
+ tsk::waitfor_any( h1, h2);
+ BOOST_CHECK( ! h1.is_ready() );
+ BOOST_CHECK( h2.is_ready() );
+ BOOST_CHECK_EQUAL( h2.get(), 55);
+ }
+};
+
+boost::unit_test::test_suite * init_unit_test_suite( int, char* [])
+{
+ boost::unit_test::test_suite * test( BOOST_TEST_SUITE("Boost.Task: test suite") );
+
+ boost::shared_ptr< test_new_thread > instance( new test_new_thread() );
+ test->add( BOOST_CLASS_TEST_CASE( & test_new_thread::test_case_1, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_new_thread::test_case_2, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_new_thread::test_case_3, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_new_thread::test_case_4, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_new_thread::test_case_5, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_new_thread::test_case_6, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_new_thread::test_case_7, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_new_thread::test_case_8, instance) );
+
+ return test;
+}
Added: sandbox/task/libs/task/test/test_own_thread.cpp
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/test/test_own_thread.cpp 2009-05-01 02:11:40 EDT (Fri, 01 May 2009)
@@ -0,0 +1,197 @@
+
+// Copyright Oliver Kowalke 2009.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include <cstdlib>
+#include <iostream>
+#include <map>
+#include <stdexcept>
+#include <vector>
+
+#include <boost/bind.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+#include <boost/function.hpp>
+#include <boost/ref.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/thread.hpp>
+#include <boost/thread/barrier.hpp>
+#include <boost/utility.hpp>
+
+#include <boost/task.hpp>
+
+#include "test_functions.hpp"
+
+namespace pt = boost::posix_time;
+namespace tsk = boost::task;
+
+class test_own_thread
+{
+public:
+ // check id
+ void test_case_1()
+ {
+ tsk::task< int > t(
+ tsk::make_task(
+ fibonacci_fn,
+ 10) );
+ tsk::handle< int > h(
+ tsk::async(
+ tsk::own_thread(),
+ t) );
+ BOOST_CHECK_EQUAL( h.get_id(), t.get_id() );
+ BOOST_CHECK_EQUAL( h.get(), 55);
+ }
+
+ // check runs not in pool
+ void test_case_2()
+ {
+ tsk::handle< bool > h(
+ tsk::async(
+ tsk::own_thread(),
+ tsk::make_task(
+ runs_in_pool_fn) ) );
+ BOOST_CHECK_EQUAL( h.get(), false);
+ }
+
+ // executed twice
+ void test_case_3()
+ {
+ tsk::task< int > t(
+ tsk::make_task(
+ fibonacci_fn,
+ 10) );
+ tsk::handle< int > h1(
+ tsk::async(
+ tsk::own_thread(),
+ t) );
+ BOOST_CHECK_EQUAL( h1.get(), 55);
+ tsk::handle< int > h2(
+ tsk::async(
+ tsk::own_thread(),
+ t) );
+ BOOST_CHECK_EQUAL( h2.get(), 55);
+ }
+
+ // check runtime_error throw inside task
+ void test_case_4()
+ {
+ tsk::handle< void > h(
+ tsk::async(
+ tsk::own_thread(),
+ tsk::make_task(
+ throwing_fn) ) );
+ bool thrown( false);
+ try
+ { h.get(); }
+ catch ( std::runtime_error const&)
+ { thrown = true; }
+ BOOST_CHECK( thrown);
+ }
+
+ // check interrupt
+ void test_case_5()
+ {
+ tsk::handle< void > h(
+ tsk::async(
+ tsk::own_thread(),
+ tsk::make_task(
+ delay_fn,
+ pt::seconds( 3) ) ) );
+ h.interrupt();
+ BOOST_CHECK( h.interruption_requested() );
+ bool thrown( false);
+ try
+ { h.get(); }
+ catch ( tsk::task_interrupted const&)
+ { thrown = true; }
+ BOOST_CHECK( ! thrown);
+ }
+
+ // check interrupt_and_wait
+ void test_case_6()
+ {
+ bool finished( false);
+ tsk::handle< void > h(
+ tsk::async(
+ tsk::own_thread(),
+ tsk::make_task(
+ interrupt_fn,
+ pt::seconds( 3),
+ boost::ref( finished) ) ) );
+ h.interrupt_and_wait();
+ BOOST_CHECK( ! finished);
+ BOOST_CHECK( h.is_ready() );
+ BOOST_CHECK( h.interruption_requested() );
+ bool thrown( false);
+ try
+ { h.get(); }
+ catch ( tsk::task_interrupted const&)
+ { thrown = true; }
+ BOOST_CHECK( ! thrown);
+ }
+
+ // check waitfor_all()
+ void test_case_7()
+ {
+ std::vector< tsk::handle< int > > vec;
+ for ( int i = 0; i <= 5; ++i)
+ vec.push_back(
+ tsk::async(
+ tsk::own_thread(),
+ tsk::make_task(
+ fibonacci_fn,
+ i) ) );
+ tsk::waitfor_all( vec.begin(), vec.end() );
+ BOOST_CHECK( vec[0].is_ready() );
+ BOOST_CHECK( vec[1].is_ready() );
+ BOOST_CHECK( vec[2].is_ready() );
+ BOOST_CHECK( vec[3].is_ready() );
+ BOOST_CHECK( vec[4].is_ready() );
+ BOOST_CHECK( vec[5].is_ready() );
+ BOOST_CHECK_EQUAL( vec[0].get(), 0);
+ BOOST_CHECK_EQUAL( vec[1].get(), 1);
+ BOOST_CHECK_EQUAL( vec[2].get(), 1);
+ BOOST_CHECK_EQUAL( vec[3].get(), 2);
+ BOOST_CHECK_EQUAL( vec[4].get(), 3);
+ BOOST_CHECK_EQUAL( vec[5].get(), 5);
+ }
+
+ // check waitfor_any()
+ void test_case_8()
+ {
+ tsk::handle< void > h1(
+ tsk::async_in_pool(
+ tsk::make_task(
+ delay_fn,
+ pt::seconds( 3) ) ) );
+ tsk::handle< int > h2(
+ tsk::async(
+ tsk::own_thread(),
+ tsk::make_task(
+ fibonacci_fn,
+ 10) ) );
+ tsk::waitfor_any( h1, h2);
+ BOOST_CHECK( ! h1.is_ready() );
+ BOOST_CHECK( h2.is_ready() );
+ BOOST_CHECK_EQUAL( h2.get(), 55);
+ }
+};
+
+boost::unit_test::test_suite * init_unit_test_suite( int, char* [])
+{
+ boost::unit_test::test_suite * test( BOOST_TEST_SUITE("Boost.Task: test suite") );
+
+ boost::shared_ptr< test_own_thread > instance( new test_own_thread() );
+ test->add( BOOST_CLASS_TEST_CASE( & test_own_thread::test_case_1, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_own_thread::test_case_2, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_own_thread::test_case_3, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_own_thread::test_case_4, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_own_thread::test_case_5, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_own_thread::test_case_6, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_own_thread::test_case_7, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_own_thread::test_case_8, instance) );
+
+ return test;
+}
Added: sandbox/task/libs/task/test/test_unbounded_pool.cpp
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/test/test_unbounded_pool.cpp 2009-05-01 02:11:40 EDT (Fri, 01 May 2009)
@@ -0,0 +1,391 @@
+
+// Copyright Oliver Kowalke 2009.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include <cstdlib>
+#include <iostream>
+#include <map>
+#include <stdexcept>
+#include <vector>
+
+#include <boost/bind.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+#include <boost/function.hpp>
+#include <boost/ref.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/thread.hpp>
+#include <boost/thread/barrier.hpp>
+#include <boost/utility.hpp>
+
+#include <boost/task.hpp>
+
+#include "test_functions.hpp"
+
+namespace pt = boost::posix_time;
+namespace tsk = boost::task;
+
+class test_unbounded_pool
+{
+public:
+ // check size, active, idle
+ void test_case_1()
+ {
+ tsk::pool<
+ tsk::unbounded_channel< tsk::fifo >
+ > pool( tsk::poolsize( 3) );
+ BOOST_CHECK_EQUAL( pool.size(), std::size_t( 3) );
+ BOOST_CHECK_EQUAL( pool.idle(), std::size_t( 3) );
+ BOOST_CHECK_EQUAL( pool.active(), std::size_t( 0) );
+ }
+
+ // check submit
+ void test_case_2()
+ {
+ tsk::pool<
+ tsk::unbounded_channel< tsk::fifo >
+ > pool( tsk::poolsize( 1) );
+ tsk::handle< int > h(
+ tsk::async(
+ pool,
+ tsk::make_task(
+ fibonacci_fn,
+ 10) ) );
+ BOOST_CHECK_EQUAL( h.get(), 55);
+ }
+
+ // check runs in pool
+ void test_case_3()
+ {
+ tsk::pool<
+ tsk::unbounded_channel< tsk::fifo >
+ > pool( tsk::poolsize( 1) );
+ tsk::handle< bool > h(
+ tsk::async(
+ pool,
+ tsk::make_task(
+ runs_in_pool_fn) ) );
+ BOOST_CHECK_EQUAL( h.get(), true);
+ }
+
+ // executed twice
+ void test_case_4()
+ {
+ tsk::pool<
+ tsk::unbounded_channel< tsk::fifo >
+ > pool( tsk::poolsize( 1) );
+ tsk::task< int > t(
+ tsk::make_task(
+ fibonacci_fn,
+ 10) );
+ tsk::handle< int > h1(
+ tsk::async(
+ pool,
+ t) );
+ BOOST_CHECK_EQUAL( h1.get(), 55);
+ tsk::handle< int > h2(
+ tsk::async(
+ pool,
+ t) );
+ BOOST_CHECK_EQUAL( h2.get(), 55);
+ }
+
+ // check shutdown
+ void test_case_5()
+ {
+ tsk::pool<
+ tsk::unbounded_channel< tsk::fifo >
+ > pool( tsk::poolsize( 1) );
+ tsk::handle< int > h(
+ tsk::async(
+ pool,
+ tsk::make_task(
+ fibonacci_fn,
+ 10) ) );
+ pool.shutdown();
+ BOOST_CHECK( pool.closed() );
+ BOOST_CHECK_EQUAL( h.get(), 55);
+ }
+
+ // check runtime_error throw inside task
+ void test_case_6()
+ {
+ tsk::pool<
+ tsk::unbounded_channel< tsk::fifo >
+ > pool( tsk::poolsize( 1) );
+ tsk::handle< void > h(
+ tsk::async(
+ pool,
+ tsk::make_task(
+ throwing_fn) ) );
+ pool.shutdown();
+ bool thrown( false);
+ try
+ { h.get(); }
+ catch ( std::runtime_error const&)
+ { thrown = true; }
+ BOOST_CHECK( thrown);
+ }
+
+ // check shutdown with task_rejected exception
+ void test_case_7()
+ {
+ tsk::pool<
+ tsk::unbounded_channel< tsk::fifo >
+ > pool( tsk::poolsize( 1) );
+ pool.shutdown();
+ BOOST_CHECK( pool.closed() );
+ bool thrown( false);
+ try
+ {
+ tsk::async(
+ pool,
+ tsk::make_task(
+ boost::bind(
+ fibonacci_fn,
+ 10) ) );
+ }
+ catch ( tsk::task_rejected const&)
+ { thrown = true; }
+ BOOST_CHECK( thrown);
+ }
+
+ // check shutdown_now with thread_interrupted exception
+ void test_case_8()
+ {
+ tsk::pool<
+ tsk::unbounded_channel< tsk::fifo >
+ > pool( tsk::poolsize( 1) );
+ tsk::handle< void > h(
+ tsk::async(
+ pool,
+ tsk::make_task(
+ delay_fn,
+ pt::millisec( 500) ) ) );
+ boost::this_thread::sleep( pt::millisec( 250) );
+ BOOST_CHECK_EQUAL( pool.size(), std::size_t( 1) );
+ pool.shutdown_now();
+ BOOST_CHECK( pool.closed() );
+ BOOST_CHECK_EQUAL( pool.size(), std::size_t( 1) );
+ BOOST_CHECK_EQUAL( pool.idle(), std::size_t( 1) );
+ BOOST_CHECK_EQUAL( pool.active(), std::size_t( 0) );
+ bool thrown( false);
+ try
+ { h.get(); }
+ catch ( tsk::task_interrupted const&)
+ { thrown = true; }
+ BOOST_CHECK( thrown);
+ }
+
+ // check pending
+ void test_case_9()
+ {
+ typedef tsk::pool<
+ tsk::unbounded_channel< tsk::fifo >
+ > pool_type;
+ pool_type pool( tsk::poolsize( 1) );
+ boost::barrier b( 2);
+ tsk::handle< void > h1(
+ tsk::async(
+ pool,
+ tsk::make_task(
+ barrier_fn,
+ boost::ref( b) ) ) );
+ boost::this_thread::sleep( pt::millisec( 250) );
+ BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 0) );
+ tsk::handle< int > h2(
+ tsk::async(
+ pool,
+ tsk::make_task(
+ fibonacci_fn,
+ 10) ) );
+ boost::this_thread::sleep( pt::millisec(250) );
+ BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 1) );
+ tsk::handle< int > h3(
+ tsk::async(
+ pool,
+ tsk::make_task(
+ fibonacci_fn,
+ 10) ) );
+ boost::this_thread::sleep( pt::millisec(250) );
+ BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 2) );
+ b.wait();
+ h1.get();
+ BOOST_CHECK_EQUAL( h2.get(), 55);
+ BOOST_CHECK_EQUAL( h3.get(), 55);
+ BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 0) );
+ }
+
+ // check interruptation
+ void test_case_10()
+ {
+ typedef tsk::pool<
+ tsk::unbounded_channel< tsk::fifo >
+ > pool_type;
+ pool_type pool( tsk::poolsize( 1) );
+ boost::barrier b( 2);
+ pool.submit(
+ tsk::make_task(
+ barrier_fn,
+ boost::ref( b) ) );
+ std::vector< int > buffer;
+ tsk::handle< void > h(
+ tsk::async(
+ pool,
+ tsk::make_task(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 10) ) );
+ tsk::async(
+ pool,
+ tsk::make_task(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 0) );
+ h.interrupt();
+ b.wait();
+ pool.shutdown();
+ BOOST_CHECK_EQUAL( buffer[0], 0);
+ BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 1) );
+ bool thrown( false);
+ try
+ { h.get(); }
+ catch ( tsk::task_interrupted const&)
+ { thrown = true; }
+ BOOST_CHECK( thrown);
+ }
+
+ // check fifo scheduling
+ void test_case_11()
+ {
+ typedef tsk::pool<
+ tsk::unbounded_channel< tsk::fifo >
+ > pool_type;
+ pool_type pool( tsk::poolsize( 1) );
+ boost::barrier b( 2);
+ tsk::async(
+ pool,
+ tsk::make_task(
+ barrier_fn,
+ boost::ref( b) ) );
+ std::vector< int > buffer;
+ tsk::async(
+ pool,
+ tsk::make_task(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 10) );
+ tsk::async(
+ pool,
+ tsk::make_task(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 0) );
+ b.wait();
+ pool.shutdown();
+ BOOST_CHECK_EQUAL( buffer[0], 55);
+ BOOST_CHECK_EQUAL( buffer[1], 0);
+ BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 2) );
+ }
+
+ // check priority scheduling
+ void test_case_12()
+ {
+ typedef tsk::pool<
+ tsk::unbounded_channel< tsk::priority< int > >
+ > pool_type;
+ pool_type pool( tsk::poolsize( 1) );
+ boost::barrier b( 2);
+ tsk::async(
+ pool,
+ tsk::make_task(
+ barrier_fn,
+ boost::ref( b) ),
+ 0);
+ std::vector< int > buffer;
+ tsk::async(
+ pool,
+ tsk::make_task(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 10),
+ 1);
+ tsk::async(
+ pool,
+ tsk::make_task(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 0),
+ 0);
+ b.wait();
+ pool.shutdown();
+ BOOST_CHECK_EQUAL( buffer[0], 0);
+ BOOST_CHECK_EQUAL( buffer[1], 55);
+ BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 2) );
+ }
+
+ // check smart scheduling
+ void test_case_13()
+ {
+ typedef tsk::pool<
+ tsk::unbounded_channel< tsk::smart< int, std::less< int >, tsk::replace_oldest, tsk::take_oldest > >
+ > pool_type;
+ pool_type pool( tsk::poolsize( 1) );
+ boost::barrier b( 2);
+ pool.submit(
+ tsk::make_task(
+ barrier_fn,
+ boost::ref( b) ),
+ 0);
+ std::vector< int > buffer;
+ tsk::async(
+ pool,
+ tsk::make_task(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 10),
+ 2);
+ tsk::async(
+ pool,
+ tsk::make_task(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 0),
+ 1);
+ tsk::async(
+ pool,
+ tsk::make_task(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 1),
+ 2);
+ b.wait();
+ pool.shutdown();
+ BOOST_CHECK_EQUAL( buffer[0], 0);
+ BOOST_CHECK_EQUAL( buffer[1], 1);
+ BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 2) );
+ }
+};
+
+boost::unit_test::test_suite * init_unit_test_suite( int, char* [])
+{
+ boost::unit_test::test_suite * test( BOOST_TEST_SUITE("Boost.Task: test suite") );
+
+ boost::shared_ptr< test_unbounded_pool > instance( new test_unbounded_pool() );
+ test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_pool::test_case_1, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_pool::test_case_2, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_pool::test_case_3, instance) );
+// test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_pool::test_case_4, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_pool::test_case_5, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_pool::test_case_6, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_pool::test_case_7, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_pool::test_case_8, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_pool::test_case_9, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_pool::test_case_10, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_pool::test_case_11, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_pool::test_case_12, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_pool::test_case_13, instance) );
+
+ return test;
+}
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk