From 56fb88137345b4ef499a5467c7505dead6af14e3 Mon Sep 17 00:00:00 2001 From: Jakub Szuppe Date: Sat, 27 Aug 2016 22:45:00 +0200 Subject: [PATCH] Add new tests for distributed::vector --- test/test_distributed_vector.cpp | 92 ++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/test/test_distributed_vector.cpp b/test/test_distributed_vector.cpp index f699f5e26..6647d1eee 100644 --- a/test/test_distributed_vector.cpp +++ b/test/test_distributed_vector.cpp @@ -68,6 +68,13 @@ BOOST_AUTO_TEST_CASE(count_ctor) size_sum += distributed_vector.part_size(i); } BOOST_CHECK_EQUAL(distributed_vector.size(), size_sum); + + std::vector buffers = distributed_vector.get_buffers(); + for(size_t i = 0; i < distributed_vector.parts(); i++) + { + BOOST_CHECK(buffers[i].get() != 0); + BOOST_CHECK(buffers[i] == distributed_vector.get_buffer(i)); + } } BOOST_AUTO_TEST_CASE(command_queue_ctor) @@ -101,6 +108,32 @@ BOOST_AUTO_TEST_CASE(command_queue_ctor) BOOST_CHECK(distributed_equal(distributed_vector, value, distributed_queue)); } +BOOST_AUTO_TEST_CASE(command_queue_ctor_one_queue) +{ + // construct distributed::command_queue + // with only 1 device command queue + bc::distributed::command_queue distributed_queue = + get_distributed_queue(queue, 0); + + bc::uint_ value = 1; + bc::distributed::vector distributed_vector( + size_t(5), value, distributed_queue + ); + + BOOST_CHECK(!distributed_vector.empty()); + BOOST_CHECK(distributed_vector.size() == 5); + BOOST_CHECK(distributed_vector.parts() == 1); + BOOST_CHECK_EQUAL(distributed_vector.size(), distributed_vector.part_size(0)); + + // need to finish since back() and front() + // use different (self-made) queues + distributed_queue.finish(); + BOOST_CHECK_EQUAL(distributed_vector.back(), value); + BOOST_CHECK_EQUAL(distributed_vector.front(), value); + + BOOST_CHECK(distributed_equal(distributed_vector, value, distributed_queue)); +} + BOOST_AUTO_TEST_CASE(host_iterator_ctor) { // construct distributed::command_queue @@ -164,6 +197,15 @@ BOOST_AUTO_TEST_CASE(copy_ctor) > distributed_vector_copy3( distributed_vector, distributed_queue2 ); + bc::distributed::vector distributed_vector_copy4( + distributed_vector, distributed_queue1 + ); + bc::distributed::vector< + bc::int_, + bc::distributed::default_weight_func, bc::pinned_allocator + > distributed_vector_copy5( + distributed_vector, distributed_queue1 + ); BOOST_CHECK( distributed_equal(distributed_vector, value, distributed_queue1) @@ -177,6 +219,12 @@ BOOST_AUTO_TEST_CASE(copy_ctor) BOOST_CHECK( distributed_equal(distributed_vector_copy3, value, distributed_queue2) ); + BOOST_CHECK( + distributed_equal(distributed_vector_copy4, value, distributed_queue1) + ); + BOOST_CHECK( + distributed_equal(distributed_vector_copy5, value, distributed_queue1) + ); } BOOST_AUTO_TEST_CASE(at) @@ -247,4 +295,48 @@ BOOST_AUTO_TEST_CASE(subscript_operator) ); } +BOOST_AUTO_TEST_CASE(swap) +{ + // construct distributed::command_queue + bc::distributed::command_queue distributed_queue1 = + get_distributed_queue(queue); + // construct 2nd distributed::command_queue + bc::distributed::command_queue distributed_queue2 = + get_distributed_queue(queue, 2); + + bc::int_ value1 = -88; + bc::int_ value2 = 99; + size_t size1 = 64; + size_t size2 = 48; + + bc::distributed::vector distributed_vector1( + size1, value1, distributed_queue1 + ); + bc::distributed::vector distributed_vector2( + size2, value2, distributed_queue2 + ); + + BOOST_CHECK_EQUAL(distributed_vector1.size(), size1); + BOOST_CHECK( + distributed_equal(distributed_vector1, value1, distributed_queue1) + ); + BOOST_CHECK_EQUAL(distributed_vector2.size(), size2); + BOOST_CHECK( + distributed_equal(distributed_vector2, value2, distributed_queue2) + ); + distributed_queue1.finish(); + distributed_queue2.finish(); + + distributed_vector1.swap(distributed_vector2); + + BOOST_CHECK_EQUAL(distributed_vector1.size(), size2); + BOOST_CHECK( + distributed_equal(distributed_vector1, value2, distributed_queue2) + ); + BOOST_CHECK_EQUAL(distributed_vector2.size(), size1); + BOOST_CHECK( + distributed_equal(distributed_vector2, value1, distributed_queue1) + ); +} + BOOST_AUTO_TEST_SUITE_END()