diff --git a/test/context_setup.hpp b/test/context_setup.hpp new file mode 100644 index 00000000..e3427fe9 --- /dev/null +++ b/test/context_setup.hpp @@ -0,0 +1,39 @@ +#ifndef BOOST_COMPUTE_TEST_CONTEXT_SETUP_HPP +#define BOOST_COMPUTE_TEST_CONTEXT_SETUP_HPP + +#include + +struct Context { + static boost::compute::device device; + static boost::compute::context context; + static boost::compute::command_queue queue; + + Context() { + device = boost::compute::system::default_device(); + context = boost::compute::system::default_context(); + queue = boost::compute::command_queue(context, device); + + std::cout << device.name() << std::endl; + } +}; + +boost::compute::device Context::device; +boost::compute::context Context::context; +boost::compute::command_queue Context::queue; + +struct ContextRef { + boost::compute::device &device; + boost::compute::context &context; + boost::compute::command_queue &queue; + + ContextRef() : + device ( Context::device ), + context( Context::context ), + queue ( Context::queue ) + {} +}; + +BOOST_GLOBAL_FIXTURE( Context ) +BOOST_FIXTURE_TEST_SUITE(compute_test, ContextRef) + +#endif diff --git a/test/test_accumulate.cpp b/test/test_accumulate.cpp index e6912cd0..efa5af5a 100644 --- a/test/test_accumulate.cpp +++ b/test/test_accumulate.cpp @@ -17,6 +17,8 @@ #include #include +#include "context_setup.hpp" + BOOST_AUTO_TEST_CASE(sum_int) { int data[] = { 2, 4, 6, 8 }; @@ -39,10 +41,6 @@ BOOST_AUTO_TEST_CASE(sum_int) BOOST_AUTO_TEST_CASE(quotient_int) { - boost::compute::device device = boost::compute::system::default_device(); - boost::compute::context context(device); - boost::compute::command_queue queue(context, device); - int data[] = { 2, 8, 16 }; boost::compute::vector vector(data, data + 3, context); BOOST_CHECK_EQUAL( @@ -58,10 +56,6 @@ BOOST_AUTO_TEST_CASE(quotient_int) BOOST_AUTO_TEST_CASE(sum_counting_iterator) { - boost::compute::device device = boost::compute::system::default_device(); - boost::compute::context context(device); - boost::compute::command_queue queue(context, device); - // sum 0 -> 9 BOOST_CHECK_EQUAL( boost::compute::accumulate( @@ -125,10 +119,6 @@ BOOST_AUTO_TEST_CASE(sum_counting_iterator) BOOST_AUTO_TEST_CASE(sum_iota) { - boost::compute::device device = boost::compute::system::default_device(); - boost::compute::context context(device); - boost::compute::command_queue queue(context, device); - // size 0 boost::compute::vector vector(0, context); @@ -184,3 +174,5 @@ BOOST_AUTO_TEST_CASE(sum_iota) 524802 ); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_adjacent_difference.cpp b/test/test_adjacent_difference.cpp index 4a782ffa..45ca127e 100644 --- a/test/test_adjacent_difference.cpp +++ b/test/test_adjacent_difference.cpp @@ -18,13 +18,12 @@ #include #include +#include "context_setup.hpp" + namespace bc = boost::compute; BOOST_AUTO_TEST_CASE(adjacent_difference_int) { - bc::device device = bc::system::default_device(); - bc::context context(device); - bc::vector a(5, context); bc::iota(a.begin(), a.end(), 0); BOOST_CHECK_EQUAL(a[0], 0); @@ -59,3 +58,5 @@ BOOST_AUTO_TEST_CASE(adjacent_difference_int) BOOST_CHECK_EQUAL(b[3], 12); BOOST_CHECK_EQUAL(b[4], 33); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_adjacent_find.cpp b/test/test_adjacent_find.cpp index b9e6822c..027cb749 100644 --- a/test/test_adjacent_find.cpp +++ b/test/test_adjacent_find.cpp @@ -15,6 +15,8 @@ #include #include +#include "context_setup.hpp" + BOOST_AUTO_TEST_CASE(adjacent_find_int) { int data[] = { 1, 3, 5, 5, 6, 7, 7, 8 }; @@ -24,3 +26,5 @@ BOOST_AUTO_TEST_CASE(adjacent_find_int) boost::compute::adjacent_find(vector.begin(), vector.end()); BOOST_VERIFY(iter == vector.begin() + 2); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_adjacent_transform_iterator.cpp b/test/test_adjacent_transform_iterator.cpp index da14282d..99e896bf 100644 --- a/test/test_adjacent_transform_iterator.cpp +++ b/test/test_adjacent_transform_iterator.cpp @@ -17,6 +17,8 @@ #include #include +#include "context_setup.hpp" + BOOST_AUTO_TEST_CASE(copy) { int data[] = { 1, 2, 4, 7, 11, 16 }; @@ -53,3 +55,5 @@ BOOST_AUTO_TEST_CASE(find_largest_gap) ).base() - 1; BOOST_VERIFY(iter == vector.begin() + 1); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_allocator.cpp b/test/test_allocator.cpp index d37ec691..1531a5ea 100644 --- a/test/test_allocator.cpp +++ b/test/test_allocator.cpp @@ -20,11 +20,10 @@ #include #include +#include "context_setup.hpp" + BOOST_AUTO_TEST_CASE(allocate) { - boost::compute::context context = - boost::compute::system::default_context(); - boost::compute::allocator allocator(context); typedef boost::compute::allocator::pointer pointer; @@ -37,3 +36,5 @@ BOOST_AUTO_TEST_CASE(vector_with_pinned_allocator) boost::compute::vector > vector; vector.push_back(12); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_any_all_none_of.cpp b/test/test_any_all_none_of.cpp index 483f4915..60888bf1 100644 --- a/test/test_any_all_none_of.cpp +++ b/test/test_any_all_none_of.cpp @@ -17,6 +17,8 @@ #include #include +#include "context_setup.hpp" + namespace bc = boost::compute; BOOST_AUTO_TEST_CASE(any_all_none_of) @@ -35,3 +37,5 @@ BOOST_AUTO_TEST_CASE(any_all_none_of) BOOST_CHECK(bc::all_of(v.begin(), v.end(), _1 < 6) == false); BOOST_CHECK(bc::all_of(v.begin(), v.end(), _1 >= 1) == true); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_array.cpp b/test/test_array.cpp index 59ec6962..c2a4be42 100644 --- a/test/test_array.cpp +++ b/test/test_array.cpp @@ -16,6 +16,8 @@ #include #include +#include "context_setup.hpp" + BOOST_AUTO_TEST_CASE(concept_check) { BOOST_CONCEPT_ASSERT((boost::Container >)); @@ -47,8 +49,6 @@ BOOST_AUTO_TEST_CASE(at) BOOST_AUTO_TEST_CASE(copy_from_vector) { - boost::compute::context context = boost::compute::system::default_context(); - int data[] = { 3, 6, 9, 12 }; boost::compute::vector vector(data, data + 4, context); @@ -62,10 +62,6 @@ BOOST_AUTO_TEST_CASE(copy_from_vector) BOOST_AUTO_TEST_CASE(fill) { - boost::compute::device device = boost::compute::system::default_device(); - boost::compute::context context(device); - boost::compute::command_queue queue(context, device); - boost::compute::array array(context); array.fill(0); BOOST_CHECK_EQUAL(array[0], 0); @@ -82,10 +78,6 @@ BOOST_AUTO_TEST_CASE(fill) BOOST_AUTO_TEST_CASE(swap) { - boost::compute::device device = boost::compute::system::default_device(); - boost::compute::context context(device); - boost::compute::command_queue queue(context, device); - int data[] = { 1, 2, 6, 9 }; boost::compute::array a(context); boost::compute::copy(data, data + 4, a.begin()); @@ -111,3 +103,5 @@ BOOST_AUTO_TEST_CASE(swap) BOOST_CHECK_EQUAL(b[2], 6); BOOST_CHECK_EQUAL(b[3], 9); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_binary_search.cpp b/test/test_binary_search.cpp index 681f8bfd..91aff4a6 100644 --- a/test/test_binary_search.cpp +++ b/test/test_binary_search.cpp @@ -19,6 +19,8 @@ #include #include +#include "context_setup.hpp" + BOOST_AUTO_TEST_CASE(binary_search_int) { int data[] = { 1, 2, 2, 2, 4, 4, 5, 7 }; @@ -61,3 +63,5 @@ BOOST_AUTO_TEST_CASE(range_bounds_int) BOOST_CHECK(boost::compute::lower_bound(vector.begin(), vector.end(), int(6)) == vector.end()); BOOST_CHECK(boost::compute::upper_bound(vector.begin(), vector.end(), int(6)) == vector.end()); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_blas_gemm.cpp b/test/test_blas_gemm.cpp index 1098ee92..680d2fdc 100644 --- a/test/test_blas_gemm.cpp +++ b/test/test_blas_gemm.cpp @@ -16,12 +16,10 @@ #include #include +#include "context_setup.hpp" + BOOST_AUTO_TEST_CASE(gemm_float3x3) { - boost::compute::device device = boost::compute::system::default_device(); - boost::compute::context context(device); - boost::compute::command_queue queue(context, device); - float a[9] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f }; @@ -96,10 +94,6 @@ BOOST_AUTO_TEST_CASE(gemm_float3x3) BOOST_AUTO_TEST_CASE(gemm_float2x3) { - boost::compute::device device = boost::compute::system::default_device(); - boost::compute::context context(device); - boost::compute::command_queue queue(context, device); - float a[6] = { 2.0f, 1.0f, 4.0f, 3.0f, 6.0f, 5.0f }; @@ -231,3 +225,5 @@ BOOST_AUTO_TEST_CASE(gemm_float2x3) BOOST_CHECK_CLOSE(c[2], 198.0f, 1e-4); BOOST_CHECK_CLOSE(c[3], 153.0f, 1e-4); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_blas_gemv.cpp b/test/test_blas_gemv.cpp index ee0158ab..7a73ae96 100644 --- a/test/test_blas_gemv.cpp +++ b/test/test_blas_gemv.cpp @@ -15,12 +15,10 @@ #include #include +#include "context_setup.hpp" + BOOST_AUTO_TEST_CASE(gemv_float) { - boost::compute::device device = boost::compute::system::default_device(); - boost::compute::context context(device); - boost::compute::command_queue queue(context, device); - float matrix[9] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f }; @@ -54,3 +52,5 @@ BOOST_AUTO_TEST_CASE(gemv_float) BOOST_CHECK_CLOSE(output_vector[1], 32.0f, 1e-3); BOOST_CHECK_CLOSE(output_vector[2], 50.0f, 1e-3); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_blas_iamax.cpp b/test/test_blas_iamax.cpp index 519a2cc6..9bf7ee72 100644 --- a/test/test_blas_iamax.cpp +++ b/test/test_blas_iamax.cpp @@ -15,15 +15,15 @@ #include #include +#include "context_setup.hpp" + BOOST_AUTO_TEST_CASE(iamax_float) { - boost::compute::device device = boost::compute::system::default_device(); - boost::compute::context context(device); - boost::compute::command_queue queue(context, device); - float data[] = { 1.0f, 3.0f, 2.0f, 4.0f, 2.0f }; boost::compute::device_ptr X = boost::compute::malloc(5, context); boost::compute::copy(data, data + 5, X, queue); BOOST_CHECK_EQUAL(boost::compute::blas::iamax(5, X, 1, queue), 3); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_blas_norm2.cpp b/test/test_blas_norm2.cpp index e3b646bb..73905668 100644 --- a/test/test_blas_norm2.cpp +++ b/test/test_blas_norm2.cpp @@ -15,12 +15,10 @@ #include #include +#include "context_setup.hpp" + BOOST_AUTO_TEST_CASE(norm2_float) { - boost::compute::device device = boost::compute::system::default_device(); - boost::compute::context context(device); - boost::compute::command_queue queue(context, device); - float data[] = { 1.0f, 2.0f, 4.0f, 8.0f, 16.0f }; boost::compute::device_ptr X = boost::compute::malloc(5, context); @@ -33,3 +31,5 @@ BOOST_AUTO_TEST_CASE(norm2_float) norm = boost::compute::blas::norm2(5, &vector[0], 1, queue); BOOST_CHECK_CLOSE(norm, 18.466185312619388f, 1e-4); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_buffer.cpp b/test/test_buffer.cpp index 6bf924c2..6092f9b4 100644 --- a/test/test_buffer.cpp +++ b/test/test_buffer.cpp @@ -14,26 +14,25 @@ #include #include +#include "context_setup.hpp" + namespace bc = boost::compute; BOOST_AUTO_TEST_CASE(size) { - bc::context context = bc::system::default_context(); bc::buffer buffer(context, 100); BOOST_CHECK_EQUAL(buffer.size(), size_t(100)); BOOST_VERIFY(buffer.max_size() > buffer.size()); } -BOOST_AUTO_TEST_CASE(context) +BOOST_AUTO_TEST_CASE(cl_context) { - bc::context context = bc::system::default_context(); bc::buffer buffer(context, 100); BOOST_VERIFY(buffer.get_context() == context); } BOOST_AUTO_TEST_CASE(equality_operator) { - bc::context context = bc::system::default_context(); bc::buffer a(context, 10); bc::buffer b(context, 10); BOOST_VERIFY(a == a); @@ -48,9 +47,6 @@ BOOST_AUTO_TEST_CASE(equality_operator) BOOST_AUTO_TEST_CASE(construct_from_cl_mem) { - boost::compute::context context = - boost::compute::system::default_context(); - // create cl_mem cl_mem mem = clCreateBuffer(context, CL_MEM_READ_WRITE, 16, 0, 0); BOOST_VERIFY(mem); @@ -71,18 +67,12 @@ BOOST_AUTO_TEST_CASE(reference_count) { using boost::compute::uint_; - boost::compute::context context = - boost::compute::system::default_context(); - boost::compute::buffer buf(context, 16); BOOST_CHECK_GE(buf.reference_count(), uint_(1)); } BOOST_AUTO_TEST_CASE(move_constructor) { - boost::compute::context context = - boost::compute::system::default_context(); - boost::compute::buffer buffer1(context, 16); BOOST_CHECK(buffer1.get() != 0); BOOST_CHECK_EQUAL(buffer1.size(), size_t(16)); @@ -92,3 +82,5 @@ BOOST_AUTO_TEST_CASE(move_constructor) BOOST_CHECK(buffer2.get() != 0); BOOST_CHECK_EQUAL(buffer2.size(), size_t(16)); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_command_queue.cpp b/test/test_command_queue.cpp index 1689f794..9ad32259 100644 --- a/test/test_command_queue.cpp +++ b/test/test_command_queue.cpp @@ -16,20 +16,17 @@ #include #include +#include "context_setup.hpp" + namespace bc = boost::compute; BOOST_AUTO_TEST_CASE(get_context) { - bc::device device = bc::system::default_device(); - bc::context context(device); - bc::command_queue queue(context, device); BOOST_VERIFY(queue.get_context() == context); } BOOST_AUTO_TEST_CASE(event_profiling) { - bc::device device = bc::system::default_device(); - bc::context context(device); bc::command_queue queue(context, device, bc::command_queue::enable_profiling); int data[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; @@ -50,9 +47,6 @@ BOOST_AUTO_TEST_CASE(event_profiling) BOOST_AUTO_TEST_CASE(kernel_profiling) { - boost::compute::device device = boost::compute::system::default_device(); - boost::compute::context context(device); - // create queue with profiling enabled boost::compute::command_queue queue( context, device, boost::compute::command_queue::enable_profiling @@ -116,9 +110,6 @@ BOOST_AUTO_TEST_CASE(kernel_profiling) BOOST_AUTO_TEST_CASE(construct_from_cl_command_queue) { - boost::compute::device device = boost::compute::system::default_device(); - boost::compute::context context(device); - // create cl_command_queue cl_command_queue cl_queue = clCreateCommandQueue(context, device.id(), 0, 0); @@ -138,10 +129,6 @@ BOOST_AUTO_TEST_CASE(construct_from_cl_command_queue) #ifdef CL_VERSION_1_1 BOOST_AUTO_TEST_CASE(write_buffer_rect) { - boost::compute::device device = boost::compute::system::default_device(); - boost::compute::context context(device); - boost::compute::command_queue queue(context, device); - int data[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; boost::compute::buffer buffer(context, 8 * sizeof(int)); @@ -171,3 +158,5 @@ BOOST_AUTO_TEST_CASE(write_buffer_rect) BOOST_CHECK_EQUAL(output[3], 7); } #endif // CL_VERSION_1_1 + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_complex.cpp b/test/test_complex.cpp index acbc7451..412b416a 100644 --- a/test/test_complex.cpp +++ b/test/test_complex.cpp @@ -18,6 +18,8 @@ #include #include +#include "context_setup.hpp" + // copies a vector of complex's on the host to the device BOOST_AUTO_TEST_CASE(copy_complex_vector) { @@ -133,10 +135,6 @@ BOOST_AUTO_TEST_CASE(complex_type_name) BOOST_AUTO_TEST_CASE(transform_multiply) { - boost::compute::device device = boost::compute::system::default_device(); - boost::compute::context context(device); - boost::compute::command_queue queue(context, device); - boost::compute::vector > x(context); x.push_back(std::complex(1.0f, 2.0f)); x.push_back(std::complex(-2.0f, 5.0f)); @@ -161,3 +159,5 @@ BOOST_AUTO_TEST_CASE(transform_multiply) BOOST_CHECK_EQUAL(std::complex(z[0]), std::complex(-5.0f, 10.0f)); BOOST_CHECK_EQUAL(std::complex(z[1]), std::complex(1.0f, 12.0f)); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_constant_iterator.cpp b/test/test_constant_iterator.cpp index 74eeaef4..e08aa5d0 100644 --- a/test/test_constant_iterator.cpp +++ b/test/test_constant_iterator.cpp @@ -20,6 +20,8 @@ #include #include +#include "context_setup.hpp" + BOOST_AUTO_TEST_CASE(value_type) { BOOST_STATIC_ASSERT(( @@ -56,10 +58,6 @@ BOOST_AUTO_TEST_CASE(distance) BOOST_AUTO_TEST_CASE(copy) { - boost::compute::device device = boost::compute::system::default_device(); - boost::compute::context context(device); - boost::compute::command_queue queue(context, device); - boost::compute::vector vector(10, context); boost::compute::copy( @@ -81,3 +79,5 @@ BOOST_AUTO_TEST_CASE(copy) BOOST_CHECK_EQUAL(int(vector[8]), 42); BOOST_CHECK_EQUAL(int(vector[9]), 42); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_copy.cpp b/test/test_copy.cpp index c6092c89..8df256d6 100644 --- a/test/test_copy.cpp +++ b/test/test_copy.cpp @@ -23,6 +23,8 @@ #include #include +#include "context_setup.hpp" + namespace bc = boost::compute; BOOST_AUTO_TEST_CASE(copy_on_device) @@ -159,11 +161,6 @@ BOOST_AUTO_TEST_CASE(copy_swizzle_iterator) BOOST_AUTO_TEST_CASE(copy_int_async) { - // setup context and queue - bc::device device = bc::system::default_device(); - bc::context context(device); - bc::command_queue queue(context, device); - // setup host data int host_data[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; typedef int* host_iterator; @@ -211,3 +208,5 @@ BOOST_AUTO_TEST_CASE(copy_int_async) BOOST_CHECK_EQUAL(host_data[7], int(8)); BOOST_VERIFY(device_to_host_future.get() == host_data + 8); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_copy_if.cpp b/test/test_copy_if.cpp index 89a103db..d3f87af9 100644 --- a/test/test_copy_if.cpp +++ b/test/test_copy_if.cpp @@ -15,6 +15,8 @@ #include #include +#include "context_setup.hpp" + namespace bc = boost::compute; BOOST_AUTO_TEST_CASE(copy_if_int) @@ -106,3 +108,5 @@ BOOST_AUTO_TEST_CASE(clip_points_below_plane) dot(_1 - plane_origin, plane_normal) > 0.0f); BOOST_CHECK(iter == output.begin() + 2); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_count.cpp b/test/test_count.cpp index 97904426..5078bc8b 100644 --- a/test/test_count.cpp +++ b/test/test_count.cpp @@ -20,6 +20,8 @@ #include #include +#include "context_setup.hpp" + namespace bc = boost::compute; BOOST_AUTO_TEST_CASE(count_int) @@ -36,10 +38,6 @@ BOOST_AUTO_TEST_CASE(count_int) BOOST_AUTO_TEST_CASE(count_constant_int_range) { - bc::device device = bc::system::default_device(); - bc::context context(device); - bc::command_queue queue(context, device); - BOOST_CHECK_EQUAL( bc::count(bc::make_constant_iterator(18, 0), bc::make_constant_iterator(18, 5), @@ -109,3 +107,5 @@ BOOST_AUTO_TEST_CASE(count_int4) size_t(0) ); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_counting_iterator.cpp b/test/test_counting_iterator.cpp index 25f13fec..25d0a169 100644 --- a/test/test_counting_iterator.cpp +++ b/test/test_counting_iterator.cpp @@ -20,6 +20,8 @@ #include #include +#include "context_setup.hpp" + BOOST_AUTO_TEST_CASE(value_type) { BOOST_STATIC_ASSERT(( @@ -63,10 +65,6 @@ BOOST_AUTO_TEST_CASE(distance) BOOST_AUTO_TEST_CASE(copy) { - boost::compute::device device = boost::compute::system::default_device(); - boost::compute::context context(device); - boost::compute::command_queue queue(context, device); - boost::compute::vector vector(10, context); boost::compute::copy( @@ -88,3 +86,5 @@ BOOST_AUTO_TEST_CASE(copy) BOOST_CHECK_EQUAL(int(vector[8]), 9); BOOST_CHECK_EQUAL(int(vector[9]), 10); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_equal.cpp b/test/test_equal.cpp index 3eefe234..e86ca9d6 100644 --- a/test/test_equal.cpp +++ b/test/test_equal.cpp @@ -15,6 +15,8 @@ #include #include +#include "context_setup.hpp" + BOOST_AUTO_TEST_CASE(equal_int) { int data1[] = { 1, 2, 3, 4, 5, 6 }; @@ -37,3 +39,5 @@ BOOST_AUTO_TEST_CASE(equal_string) BOOST_CHECK(boost::compute::equal(a.begin(), a.end(), b.begin()) == true); BOOST_CHECK(boost::compute::equal(a.begin(), a.end(), c.begin()) == false); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_equal_range.cpp b/test/test_equal_range.cpp index e8a0906e..0f36be98 100644 --- a/test/test_equal_range.cpp +++ b/test/test_equal_range.cpp @@ -18,6 +18,8 @@ #include #include +#include "context_setup.hpp" + BOOST_AUTO_TEST_CASE(equal_range_int) { int data[] = { 1, 2, 2, 2, 3, 3, 4, 5 }; @@ -67,3 +69,5 @@ BOOST_AUTO_TEST_CASE(equal_range_int) BOOST_CHECK(range6.second == vector.end()); BOOST_CHECK_EQUAL(std::distance(range6.first, range6.second), ptrdiff_t(0)); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_extrema.cpp b/test/test_extrema.cpp index 249b2bf3..71aac1ff 100644 --- a/test/test_extrema.cpp +++ b/test/test_extrema.cpp @@ -21,6 +21,8 @@ #include #include +#include "context_setup.hpp" + BOOST_AUTO_TEST_CASE(int_min_max) { int data[] = { 9, 15, 1, 4 }; @@ -167,3 +169,5 @@ BOOST_AUTO_TEST_CASE(max_bits_set) BOOST_CHECK(iter == vector.begin() + 7); BOOST_CHECK_EQUAL(uint_(*iter), uint_(7)); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_fill.cpp b/test/test_fill.cpp index e672781b..392c442d 100644 --- a/test/test_fill.cpp +++ b/test/test_fill.cpp @@ -15,6 +15,8 @@ #include #include +#include "context_setup.hpp" + namespace bc = boost::compute; BOOST_AUTO_TEST_CASE(fill_int) @@ -88,3 +90,5 @@ BOOST_AUTO_TEST_CASE(fill_n_float) BOOST_CHECK_EQUAL(vector[2], 0.0f); BOOST_CHECK_EQUAL(vector[3], 0.0f); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_find.cpp b/test/test_find.cpp index 4c28de54..64c0d81a 100644 --- a/test/test_find.cpp +++ b/test/test_find.cpp @@ -19,6 +19,8 @@ #include #include +#include "context_setup.hpp" + namespace bc = boost::compute; BOOST_AUTO_TEST_CASE(find_int) @@ -75,3 +77,5 @@ BOOST_AUTO_TEST_CASE(find_if_not_int) BOOST_CHECK(iter == vector.begin() + 1); BOOST_CHECK_EQUAL(*iter, 4); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_flat_map.cpp b/test/test_flat_map.cpp index bc9ae7be..54c57b9d 100644 --- a/test/test_flat_map.cpp +++ b/test/test_flat_map.cpp @@ -17,6 +17,8 @@ #include +#include "context_setup.hpp" + BOOST_AUTO_TEST_CASE(concept_check) { BOOST_CONCEPT_ASSERT((boost::Container >)); @@ -92,3 +94,5 @@ BOOST_AUTO_TEST_CASE(simple_histogram) BOOST_CHECK_EQUAL(int(map[8]), int(1)); BOOST_CHECK_EQUAL(int(map[9]), int(4)); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_flat_set.cpp b/test/test_flat_set.cpp index ee3daa10..e49f8bfb 100644 --- a/test/test_flat_set.cpp +++ b/test/test_flat_set.cpp @@ -19,6 +19,8 @@ #include #include +#include "context_setup.hpp" + namespace bc = boost::compute; BOOST_AUTO_TEST_CASE(concept_check) @@ -32,10 +34,6 @@ BOOST_AUTO_TEST_CASE(concept_check) BOOST_AUTO_TEST_CASE(insert) { - bc::device device = bc::system::default_device(); - bc::context context(device); - bc::command_queue queue(context, device); - bc::flat_set set(context); typedef bc::flat_set::iterator iterator; std::pair location = set.insert(12); @@ -67,10 +65,6 @@ BOOST_AUTO_TEST_CASE(insert) BOOST_AUTO_TEST_CASE(erase) { - bc::device device = bc::system::default_device(); - bc::context context(device); - bc::command_queue queue(context, device); - bc::flat_set set(context); typedef bc::flat_set::iterator iterator; set.insert(1); @@ -127,3 +121,5 @@ BOOST_AUTO_TEST_CASE(clear) BOOST_CHECK(set.empty() == true); BOOST_CHECK_EQUAL(set.size(), size_t(0)); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_for_each.cpp b/test/test_for_each.cpp index bb73385a..2ab621cb 100644 --- a/test/test_for_each.cpp +++ b/test/test_for_each.cpp @@ -16,13 +16,12 @@ #include #include +#include "context_setup.hpp" + namespace bc = boost::compute; BOOST_AUTO_TEST_CASE(for_each_nop) { - bc::context context = bc::system::default_context(); - bc::command_queue queue(context, context.get_device()); - bc::vector vector(4, context); bc::iota(vector.begin(), vector.end(), 0); @@ -30,3 +29,5 @@ BOOST_AUTO_TEST_CASE(for_each_nop) bc::make_function_from_source("nop", "void nop(int x) { }"); bc::for_each(vector.begin(), vector.end(), nop, queue); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_gather.cpp b/test/test_gather.cpp index b5c2818a..e2cd4c52 100644 --- a/test/test_gather.cpp +++ b/test/test_gather.cpp @@ -15,14 +15,12 @@ #include #include +#include "context_setup.hpp" + namespace bc = boost::compute; BOOST_AUTO_TEST_CASE(gather_int) { - bc::device device = bc::system::default_device(); - bc::context context(device); - bc::command_queue queue(context, device); - int input_data[] = { 1, 2, 3, 4, 5 }; bc::vector input(input_data, input_data + 5, context); @@ -37,3 +35,5 @@ BOOST_AUTO_TEST_CASE(gather_int) BOOST_CHECK_EQUAL(output[3], 4); BOOST_CHECK_EQUAL(output[4], 3); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_generate.cpp b/test/test_generate.cpp index fdc991cd..1920fa04 100644 --- a/test/test_generate.cpp +++ b/test/test_generate.cpp @@ -16,6 +16,8 @@ #include #include +#include "context_setup.hpp" + namespace bc = boost::compute; BOOST_AUTO_TEST_CASE(generate4) @@ -33,3 +35,5 @@ BOOST_AUTO_TEST_CASE(generate4) BOOST_CHECK_EQUAL(vector[1], 4); BOOST_CHECK_EQUAL(vector[2], 4); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_histogram.cpp b/test/test_histogram.cpp index 9c908840..f0121735 100644 --- a/test/test_histogram.cpp +++ b/test/test_histogram.cpp @@ -15,6 +15,8 @@ #include #include +#include "context_setup.hpp" + BOOST_AUTO_TEST_CASE(histogram_uchar) { using boost::compute::uchar_; @@ -47,3 +49,5 @@ BOOST_AUTO_TEST_CASE(histogram_uchar) BOOST_CHECK_EQUAL(uint_(result[8]), uint_(3)); BOOST_CHECK_EQUAL(uint_(result[9]), uint_(4)); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_image2d.cpp b/test/test_image2d.cpp index 43f10370..7dc49a9c 100644 --- a/test/test_image2d.cpp +++ b/test/test_image2d.cpp @@ -17,12 +17,12 @@ #include #include +#include "context_setup.hpp" + namespace bc = boost::compute; BOOST_AUTO_TEST_CASE(image2d_get_supported_formats) { - bc::context context = bc::system::default_context(); - std::vector formats = bc::image2d::get_supported_formats(context, bc::image2d::read_only); BOOST_CHECK(!formats.empty()); @@ -30,8 +30,6 @@ BOOST_AUTO_TEST_CASE(image2d_get_supported_formats) BOOST_AUTO_TEST_CASE(get_info) { - bc::context context = bc::system::default_context(); - bc::image2d image( context, bc::image2d::read_only, @@ -57,8 +55,6 @@ BOOST_AUTO_TEST_CASE(get_info) BOOST_AUTO_TEST_CASE(count_with_pixel_iterator) { - bc::context context = bc::system::default_context(); - unsigned int data[] = { 0x00000000, 0x000000ff, 0xff0000ff, 0xffff00ff, 0x000000ff, 0xff0000ff, 0xff0000ff, 0x00ff00ff, 0x0000ffff }; @@ -105,8 +101,6 @@ BOOST_AUTO_TEST_CASE(count_with_pixel_iterator) BOOST_AUTO_TEST_CASE(find_with_pixel_iterator) { - bc::context context = bc::system::default_context(); - unsigned int data[] = { 0x00000000, 0x000000ff, 0xff0000ff, 0xffff00ff, 0x000000ff, 0xff0000ff, 0xff0000ff, 0x00ff00ff, 0x0000ffff }; @@ -143,3 +137,5 @@ BOOST_AUTO_TEST_CASE(complex_type_name) ) == 0 ); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_image3d.cpp b/test/test_image3d.cpp index 59e2be63..0826d2d2 100644 --- a/test/test_image3d.cpp +++ b/test/test_image3d.cpp @@ -14,12 +14,12 @@ #include #include +#include "context_setup.hpp" + namespace bc = boost::compute; BOOST_AUTO_TEST_CASE(image3d_get_supported_formats) { - bc::context context = bc::system::default_context(); - std::vector formats = bc::image3d::get_supported_formats(context, bc::image3d::read_only); } @@ -34,3 +34,5 @@ BOOST_AUTO_TEST_CASE(complex_type_name) ) == 0 ); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_image_sampler.cpp b/test/test_image_sampler.cpp index 4570910c..e9ff0654 100644 --- a/test/test_image_sampler.cpp +++ b/test/test_image_sampler.cpp @@ -14,19 +14,18 @@ #include #include +#include "context_setup.hpp" + namespace bc = boost::compute; BOOST_AUTO_TEST_CASE(get_context) { - bc::context context = bc::system::default_context(); bc::image_sampler sampler(context, true, CL_ADDRESS_NONE, CL_FILTER_NEAREST); BOOST_CHECK(sampler.get_context() == context); } BOOST_AUTO_TEST_CASE(get_info) { - bc::context context = bc::system::default_context(); - bc::image_sampler sampler(context, true, CL_ADDRESS_NONE, CL_FILTER_NEAREST); BOOST_CHECK_EQUAL(sampler.get_info(CL_SAMPLER_NORMALIZED_COORDS), true); BOOST_CHECK_EQUAL(sampler.get_info(CL_SAMPLER_ADDRESSING_MODE), CL_ADDRESS_NONE); @@ -37,3 +36,5 @@ BOOST_AUTO_TEST_CASE(get_info) BOOST_CHECK_EQUAL(sampler.get_info(CL_SAMPLER_ADDRESSING_MODE), CL_ADDRESS_CLAMP); BOOST_CHECK_EQUAL(sampler.get_info(CL_SAMPLER_FILTER_MODE), CL_FILTER_LINEAR); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_inner_product.cpp b/test/test_inner_product.cpp index e3e6a2b3..d6f693b0 100644 --- a/test/test_inner_product.cpp +++ b/test/test_inner_product.cpp @@ -15,14 +15,12 @@ #include #include +#include "context_setup.hpp" + namespace bc = boost::compute; BOOST_AUTO_TEST_CASE(inner_product_int) { - bc::device device = bc::system::default_device(); - bc::context context(device); - bc::command_queue queue(context, device); - int data1[] = { 1, 2, 3, 4 }; bc::vector input1(data1, data1 + 4, context); @@ -36,3 +34,5 @@ BOOST_AUTO_TEST_CASE(inner_product_int) queue); BOOST_CHECK_EQUAL(product, 300); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_inplace_reduce.cpp b/test/test_inplace_reduce.cpp index 4f43af9a..5dfde469 100644 --- a/test/test_inplace_reduce.cpp +++ b/test/test_inplace_reduce.cpp @@ -17,12 +17,10 @@ #include #include +#include "context_setup.hpp" + BOOST_AUTO_TEST_CASE(sum_int) { - boost::compute::device device = boost::compute::system::default_device(); - boost::compute::context context(device); - boost::compute::command_queue queue(context, device); - int data[] = { 1, 5, 3, 4, 9, 3, 5, 3 }; boost::compute::vector vector(data, data + 8, context); @@ -45,10 +43,6 @@ BOOST_AUTO_TEST_CASE(sum_int) BOOST_AUTO_TEST_CASE(multiply_int) { - boost::compute::device device = boost::compute::system::default_device(); - boost::compute::context context(device); - boost::compute::command_queue queue(context, device); - int data[] = { 1, 5, 3, 4, 9, 3, 5, 3 }; boost::compute::vector vector(data, data + 8, context); @@ -71,10 +65,6 @@ BOOST_AUTO_TEST_CASE(multiply_int) BOOST_AUTO_TEST_CASE(reduce_iota) { - boost::compute::device device = boost::compute::system::default_device(); - boost::compute::context context(device); - boost::compute::command_queue queue(context, device); - // 1 value boost::compute::vector vector(1, context); boost::compute::iota(vector.begin(), vector.end(), int(0), queue); @@ -125,3 +115,5 @@ BOOST_AUTO_TEST_CASE(reduce_iota) queue.finish(); BOOST_CHECK_EQUAL(int(vector[0]), int(12497500)); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_insertion_sort.cpp b/test/test_insertion_sort.cpp index daade24a..8add3406 100644 --- a/test/test_insertion_sort.cpp +++ b/test/test_insertion_sort.cpp @@ -16,16 +16,14 @@ #include #include +#include "context_setup.hpp" + namespace bc = boost::compute; BOOST_AUTO_TEST_CASE(sort_char_vector) { using boost::compute::char_; - boost::compute::device device = boost::compute::system::default_device(); - boost::compute::context context(device); - boost::compute::command_queue queue(context, device); - char_ data[] = { 'c', 'a', '0', '7', 'B', 'F', '\0', '$' }; boost::compute::vector vector(data, data + 8, context); BOOST_CHECK_EQUAL(vector.size(), size_t(8)); @@ -49,10 +47,6 @@ BOOST_AUTO_TEST_CASE(sort_uchar_vector) { using boost::compute::uchar_; - boost::compute::device device = boost::compute::system::default_device(); - boost::compute::context context(device); - boost::compute::command_queue queue(context, device); - uchar_ data[] = { 0x12, 0x00, 0xFF, 0xB4, 0x80, 0x32, 0x64, 0xA2 }; boost::compute::vector vector(data, data + 8, context); BOOST_CHECK_EQUAL(vector.size(), size_t(8)); @@ -76,10 +70,6 @@ BOOST_AUTO_TEST_CASE(sort_short_vector) { using boost::compute::short_; - boost::compute::device device = boost::compute::system::default_device(); - boost::compute::context context(device); - boost::compute::command_queue queue(context, device); - short_ data[] = { -4, 152, -94, 963, 31002, -456, 0, -2113 }; boost::compute::vector vector(data, data + 8, context); BOOST_CHECK_EQUAL(vector.size(), size_t(8)); @@ -103,10 +93,6 @@ BOOST_AUTO_TEST_CASE(sort_ushort_vector) { using boost::compute::ushort_; - boost::compute::device device = boost::compute::system::default_device(); - boost::compute::context context(device); - boost::compute::command_queue queue(context, device); - ushort_ data[] = { 4, 152, 94, 963, 63202, 34560, 0, 2113 }; boost::compute::vector vector(data, data + 8, context); BOOST_CHECK_EQUAL(vector.size(), size_t(8)); @@ -128,10 +114,6 @@ BOOST_AUTO_TEST_CASE(sort_ushort_vector) BOOST_AUTO_TEST_CASE(sort_int_vector) { - boost::compute::device device = boost::compute::system::default_device(); - boost::compute::context context(device); - boost::compute::command_queue queue(context, device); - int data[] = { -4, 152, -5000, 963, 75321, -456, 0, 1112 }; boost::compute::vector vector(data, data + 8, context); BOOST_CHECK_EQUAL(vector.size(), size_t(8)); @@ -155,10 +137,6 @@ BOOST_AUTO_TEST_CASE(sort_uint_vector) { using boost::compute::uint_; - boost::compute::device device = boost::compute::system::default_device(); - boost::compute::context context(device); - boost::compute::command_queue queue(context, device); - uint_ data[] = { 500, 1988, 123456, 562, 0, 4000000, 9852, 102030 }; boost::compute::vector vector(data, data + 8, context); BOOST_CHECK_EQUAL(vector.size(), size_t(8)); @@ -182,10 +160,6 @@ BOOST_AUTO_TEST_CASE(sort_long_vector) { using boost::compute::long_; - boost::compute::device device = boost::compute::system::default_device(); - boost::compute::context context(device); - boost::compute::command_queue queue(context, device); - long_ data[] = { 500, 1988, 123456, 562, 0, 4000000, 9852, 102030 }; boost::compute::vector vector(data, data + 8, context); BOOST_CHECK_EQUAL(vector.size(), size_t(8)); @@ -209,10 +183,6 @@ BOOST_AUTO_TEST_CASE(sort_ulong_vector) { using boost::compute::ulong_; - boost::compute::device device = boost::compute::system::default_device(); - boost::compute::context context(device); - boost::compute::command_queue queue(context, device); - ulong_ data[] = { 500, 1988, 123456, 562, 0, 4000000, 9852, 102030 }; boost::compute::vector vector(data, data + 8, context); BOOST_CHECK_EQUAL(vector.size(), size_t(8)); @@ -234,10 +204,6 @@ BOOST_AUTO_TEST_CASE(sort_ulong_vector) BOOST_AUTO_TEST_CASE(sort_float_vector) { - boost::compute::device device = boost::compute::system::default_device(); - boost::compute::context context(device); - boost::compute::command_queue queue(context, device); - float data[] = { -6023.0f, 152.5f, -63.0f, 1234567.0f, 11.2f, -5000.1f, 0.0f, 14.0f, -8.25f, -0.0f }; boost::compute::vector vector(data, data + 10, context); @@ -262,15 +228,11 @@ BOOST_AUTO_TEST_CASE(sort_float_vector) BOOST_AUTO_TEST_CASE(sort_double_vector) { - boost::compute::device device = boost::compute::system::default_device(); if(!device.supports_extension("cl_khr_fp64")){ std::cout << "skipping test: device does not support double" << std::endl; return; } - boost::compute::context context(device); - boost::compute::command_queue queue(context, device); - double data[] = { -6023.0, 152.5, -63.0, 1234567.0, 11.2, -5000.1, 0.0, 14.0, -8.25, -0.0 }; boost::compute::vector vector(data, data + 10, context); @@ -292,3 +254,5 @@ BOOST_AUTO_TEST_CASE(sort_double_vector) BOOST_CHECK_EQUAL(data[8], 152.5); BOOST_CHECK_EQUAL(data[9], 1234567.0); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_iota.cpp b/test/test_iota.cpp index d37f15f9..c0797b1b 100644 --- a/test/test_iota.cpp +++ b/test/test_iota.cpp @@ -17,6 +17,8 @@ #include #include +#include "context_setup.hpp" + namespace bc = boost::compute; BOOST_AUTO_TEST_CASE(iota_int) @@ -64,3 +66,5 @@ BOOST_AUTO_TEST_CASE(iota_permutation_iterator) BOOST_CHECK_EQUAL(output[3], 5); BOOST_CHECK_EQUAL(output[4], 4); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_is_sorted.cpp b/test/test_is_sorted.cpp index 1969d0ca..ce36cb4d 100644 --- a/test/test_is_sorted.cpp +++ b/test/test_is_sorted.cpp @@ -16,6 +16,8 @@ #include #include +#include "context_setup.hpp" + namespace bc = boost::compute; BOOST_AUTO_TEST_CASE(is_sorted_int) @@ -45,3 +47,5 @@ BOOST_AUTO_TEST_CASE(is_sorted_ones) bc::fill(vector.begin(), vector.end(), int(1)); BOOST_VERIFY(bc::is_sorted(vector.begin(), vector.end()) == true); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_kernel.cpp b/test/test_kernel.cpp index ec64639a..ae315454 100644 --- a/test/test_kernel.cpp +++ b/test/test_kernel.cpp @@ -14,11 +14,12 @@ #include #include +#include "context_setup.hpp" + namespace bc = boost::compute; BOOST_AUTO_TEST_CASE(name) { - bc::context context = bc::system::default_context(); bc::kernel foo = bc::kernel::create_with_source("__kernel void foo(int x) { }", "foo", context); @@ -32,7 +33,6 @@ BOOST_AUTO_TEST_CASE(name) BOOST_AUTO_TEST_CASE(num_args) { - bc::context context = bc::system::default_context(); bc::kernel foo = bc::kernel::create_with_source("__kernel void foo(int x) { }", "foo", context); @@ -51,9 +51,6 @@ BOOST_AUTO_TEST_CASE(num_args) BOOST_AUTO_TEST_CASE(get_work_group_info) { - boost::compute::device device = boost::compute::system::default_device(); - boost::compute::context context(device); - const char source[] = "__kernel void sum(__global const float *input,\n" " __global float *output)\n" @@ -86,8 +83,6 @@ BOOST_AUTO_TEST_CASE(get_work_group_info) #ifndef BOOST_NO_VARIADIC_TEMPLATES BOOST_AUTO_TEST_CASE(kernel_set_args) { - bc::context context = bc::system::default_context(); - bc::kernel k = bc::kernel::create_with_source( "__kernel void test(int x, float y, char z) { }", @@ -98,3 +93,5 @@ BOOST_AUTO_TEST_CASE(kernel_set_args) k.set_args(4, 2.4f, 'a'); } #endif + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_lambda.cpp b/test/test_lambda.cpp index 4cee2a73..3d21ada5 100644 --- a/test/test_lambda.cpp +++ b/test/test_lambda.cpp @@ -15,6 +15,8 @@ #include #include +#include "context_setup.hpp" + namespace bc = boost::compute; BOOST_AUTO_TEST_CASE(squared_plus_one) @@ -152,3 +154,5 @@ BOOST_AUTO_TEST_CASE(make_function_from_lamdba) BOOST_CHECK_EQUAL(int(vector[3]), int(19)); BOOST_CHECK_EQUAL(int(vector[4]), int(23)); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_malloc.cpp b/test/test_malloc.cpp index 0e3e3825..5e06a657 100644 --- a/test/test_malloc.cpp +++ b/test/test_malloc.cpp @@ -14,6 +14,8 @@ #include #include +#include "context_setup.hpp" + namespace bc = boost::compute; BOOST_AUTO_TEST_CASE(malloc_int) @@ -34,3 +36,5 @@ BOOST_AUTO_TEST_CASE(malloc_int) bc::free(ptr); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_merge.cpp b/test/test_merge.cpp index b81d27f7..812e8a2e 100644 --- a/test/test_merge.cpp +++ b/test/test_merge.cpp @@ -15,12 +15,10 @@ #include #include +#include "context_setup.hpp" + BOOST_AUTO_TEST_CASE(simple_merge_int) { - boost::compute::device device = boost::compute::system::default_device(); - boost::compute::context context(device); - boost::compute::command_queue queue(context, device); - int data1[] = { 1, 3, 5, 7 }; int data2[] = { 2, 4, 6, 8 }; @@ -128,3 +126,5 @@ BOOST_AUTO_TEST_CASE(simple_merge_int) BOOST_CHECK_EQUAL(int(v3[2]), 6); BOOST_CHECK_EQUAL(int(v3[3]), 8); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_mersenne_twister.cpp b/test/test_mersenne_twister.cpp index dc70f7e1..e89a4399 100644 --- a/test/test_mersenne_twister.cpp +++ b/test/test_mersenne_twister.cpp @@ -14,12 +14,10 @@ #include #include +#include "context_setup.hpp" + BOOST_AUTO_TEST_CASE(fill_uint) { - boost::compute::device gpu = boost::compute::system::default_device(); - boost::compute::context context(gpu); - boost::compute::command_queue queue(context, gpu); - using boost::compute::uint_; boost::compute::mt19937 rng(context); @@ -40,3 +38,5 @@ BOOST_AUTO_TEST_CASE(fill_uint) BOOST_CHECK_EQUAL(uint_(vector[8]), uint_(2715962298)); BOOST_CHECK_EQUAL(uint_(vector[9]), uint_(1323567403)); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_mismatch.cpp b/test/test_mismatch.cpp index f778b84d..338afc87 100644 --- a/test/test_mismatch.cpp +++ b/test/test_mismatch.cpp @@ -14,6 +14,8 @@ #include #include +#include "context_setup.hpp" + BOOST_AUTO_TEST_CASE(mismatch_int) { int data1[] = { 1, 2, 3, 4, 5, 6 }; @@ -31,3 +33,5 @@ BOOST_AUTO_TEST_CASE(mismatch_int) BOOST_CHECK(location.second == vector2.begin() + 3); BOOST_CHECK_EQUAL(int(*location.second), int(7)); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_pair.cpp b/test/test_pair.cpp index f5510de2..64e719ff 100644 --- a/test/test_pair.cpp +++ b/test/test_pair.cpp @@ -18,6 +18,8 @@ #include #include +#include "context_setup.hpp" + BOOST_AUTO_TEST_CASE(vector_pair_int_float) { boost::compute::vector > vector; @@ -127,3 +129,5 @@ BOOST_AUTO_TEST_CASE(find_vector_pair) ).base() == vector.begin() + 2 ); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_partial_sum.cpp b/test/test_partial_sum.cpp index 11e8a9b2..d3235f47 100644 --- a/test/test_partial_sum.cpp +++ b/test/test_partial_sum.cpp @@ -20,6 +20,8 @@ #include #include +#include "context_setup.hpp" + namespace bc = boost::compute; BOOST_AUTO_TEST_CASE(partial_sum_int) @@ -42,3 +44,5 @@ BOOST_AUTO_TEST_CASE(partial_sum_int) BOOST_CHECK_EQUAL(b[6], 25); BOOST_CHECK_EQUAL(b[7], 27); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_partition.cpp b/test/test_partition.cpp index 49f9e0e2..90fc4dbf 100644 --- a/test/test_partition.cpp +++ b/test/test_partition.cpp @@ -19,14 +19,12 @@ #include #include +#include "context_setup.hpp" + namespace bc = boost::compute; BOOST_AUTO_TEST_CASE(partition_float_vector) { - bc::device device = bc::system::default_device(); - bc::context context(device); - bc::command_queue queue(context, device); - bc::vector vector(context); vector.push_back(1.0f); vector.push_back(2.0f); @@ -68,10 +66,6 @@ BOOST_AUTO_TEST_CASE(partition_float_vector) BOOST_AUTO_TEST_CASE(partition_small_vector) { - bc::device device = bc::system::default_device(); - bc::context context(device); - bc::command_queue queue(context, device); - bc::vector vector(context); bc::partition(vector.begin(), vector.end(), bc::signbit_(), queue); @@ -86,3 +80,5 @@ BOOST_AUTO_TEST_CASE(partition_small_vector) BOOST_CHECK_EQUAL(vector[0], -1.0f); BOOST_CHECK_EQUAL(vector[1], 1.0f); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_permutation_iterator.cpp b/test/test_permutation_iterator.cpp index a80e6872..ba7b1531 100644 --- a/test/test_permutation_iterator.cpp +++ b/test/test_permutation_iterator.cpp @@ -22,6 +22,8 @@ #include #include +#include "context_setup.hpp" + BOOST_AUTO_TEST_CASE(value_type) { using boost::compute::float4_; @@ -48,10 +50,6 @@ BOOST_AUTO_TEST_CASE(value_type) BOOST_AUTO_TEST_CASE(copy) { - boost::compute::device device = boost::compute::system::default_device(); - boost::compute::context context(device); - boost::compute::command_queue queue(context, device); - int input_data[] = { 3, 4, 2, 1, 5 }; boost::compute::vector input(input_data, input_data + 5, context); @@ -73,3 +71,5 @@ BOOST_AUTO_TEST_CASE(copy) BOOST_CHECK_EQUAL(int(output[3]), 4); BOOST_CHECK_EQUAL(int(output[4]), 5); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_program.cpp b/test/test_program.cpp index 3f747d78..3ade6555 100644 --- a/test/test_program.cpp +++ b/test/test_program.cpp @@ -15,15 +15,14 @@ #include #include +#include "context_setup.hpp" + const char source[] = "__kernel void foo(__global float *x, const uint n) { }\n" "__kernel void bar(__global int *x, __global int *y) { }\n"; BOOST_AUTO_TEST_CASE(get_program_info) { - boost::compute::context context = - boost::compute::system::default_context(); - // create program boost::compute::program program = boost::compute::program::create_with_source(source, context); @@ -38,9 +37,6 @@ BOOST_AUTO_TEST_CASE(get_program_info) BOOST_AUTO_TEST_CASE(create_kernel) { - boost::compute::context context = - boost::compute::system::default_context(); - boost::compute::program program = boost::compute::program::create_with_source(source, context); program.build(); @@ -51,9 +47,6 @@ BOOST_AUTO_TEST_CASE(create_kernel) BOOST_AUTO_TEST_CASE(create_with_binary) { - boost::compute::context context = - boost::compute::system::default_context(); - // create program from source boost::compute::program source_program = boost::compute::program::create_with_source(source, context); @@ -83,3 +76,5 @@ BOOST_AUTO_TEST_CASE(create_with_binary) BOOST_CHECK_EQUAL(binary_foo_kernel.name(), std::string("foo")); BOOST_CHECK_EQUAL(binary_bar_kernel.name(), std::string("bar")); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_radix_sort.cpp b/test/test_radix_sort.cpp index 775c4c77..8f905e48 100644 --- a/test/test_radix_sort.cpp +++ b/test/test_radix_sort.cpp @@ -16,16 +16,14 @@ #include #include +#include "context_setup.hpp" + namespace bc = boost::compute; BOOST_AUTO_TEST_CASE(sort_char_vector) { using boost::compute::char_; - boost::compute::device device = boost::compute::system::default_device(); - boost::compute::context context(device); - boost::compute::command_queue queue(context, device); - char_ data[] = { 'c', 'a', '0', '7', 'B', 'F', '\0', '$' }; boost::compute::vector vector(data, data + 8, context); BOOST_CHECK_EQUAL(vector.size(), size_t(8)); @@ -49,10 +47,6 @@ BOOST_AUTO_TEST_CASE(sort_uchar_vector) { using boost::compute::uchar_; - boost::compute::device device = boost::compute::system::default_device(); - boost::compute::context context(device); - boost::compute::command_queue queue(context, device); - uchar_ data[] = { 0x12, 0x00, 0xFF, 0xB4, 0x80, 0x32, 0x64, 0xA2 }; boost::compute::vector vector(data, data + 8, context); BOOST_CHECK_EQUAL(vector.size(), size_t(8)); @@ -76,10 +70,6 @@ BOOST_AUTO_TEST_CASE(sort_short_vector) { using boost::compute::short_; - boost::compute::device device = boost::compute::system::default_device(); - boost::compute::context context(device); - boost::compute::command_queue queue(context, device); - short_ data[] = { -4, 152, -94, 963, 31002, -456, 0, -2113 }; boost::compute::vector vector(data, data + 8, context); BOOST_CHECK_EQUAL(vector.size(), size_t(8)); @@ -103,10 +93,6 @@ BOOST_AUTO_TEST_CASE(sort_ushort_vector) { using boost::compute::ushort_; - boost::compute::device device = boost::compute::system::default_device(); - boost::compute::context context(device); - boost::compute::command_queue queue(context, device); - ushort_ data[] = { 4, 152, 94, 963, 63202, 34560, 0, 2113 }; boost::compute::vector vector(data, data + 8, context); BOOST_CHECK_EQUAL(vector.size(), size_t(8)); @@ -128,10 +114,6 @@ BOOST_AUTO_TEST_CASE(sort_ushort_vector) BOOST_AUTO_TEST_CASE(sort_int_vector) { - boost::compute::device device = boost::compute::system::default_device(); - boost::compute::context context(device); - boost::compute::command_queue queue(context, device); - int data[] = { -4, 152, -5000, 963, 75321, -456, 0, 1112 }; boost::compute::vector vector(data, data + 8, context); BOOST_CHECK_EQUAL(vector.size(), size_t(8)); @@ -155,10 +137,6 @@ BOOST_AUTO_TEST_CASE(sort_uint_vector) { using boost::compute::uint_; - boost::compute::device device = boost::compute::system::default_device(); - boost::compute::context context(device); - boost::compute::command_queue queue(context, device); - uint_ data[] = { 500, 1988, 123456, 562, 0, 4000000, 9852, 102030 }; boost::compute::vector vector(data, data + 8, context); BOOST_CHECK_EQUAL(vector.size(), size_t(8)); @@ -182,10 +160,6 @@ BOOST_AUTO_TEST_CASE(sort_long_vector) { using boost::compute::long_; - boost::compute::device device = boost::compute::system::default_device(); - boost::compute::context context(device); - boost::compute::command_queue queue(context, device); - long_ data[] = { 500, 1988, 123456, 562, 0, 4000000, 9852, 102030 }; boost::compute::vector vector(data, data + 8, context); BOOST_CHECK_EQUAL(vector.size(), size_t(8)); @@ -209,10 +183,6 @@ BOOST_AUTO_TEST_CASE(sort_ulong_vector) { using boost::compute::ulong_; - boost::compute::device device = boost::compute::system::default_device(); - boost::compute::context context(device); - boost::compute::command_queue queue(context, device); - ulong_ data[] = { 500, 1988, 123456, 562, 0, 4000000, 9852, 102030 }; boost::compute::vector vector(data, data + 8, context); BOOST_CHECK_EQUAL(vector.size(), size_t(8)); @@ -234,10 +204,6 @@ BOOST_AUTO_TEST_CASE(sort_ulong_vector) BOOST_AUTO_TEST_CASE(sort_float_vector) { - boost::compute::device device = boost::compute::system::default_device(); - boost::compute::context context(device); - boost::compute::command_queue queue(context, device); - float data[] = { -6023.0f, 152.5f, -63.0f, 1234567.0f, 11.2f, -5000.1f, 0.0f, 14.0f, -8.25f, -0.0f }; boost::compute::vector vector(data, data + 10, context); @@ -262,15 +228,11 @@ BOOST_AUTO_TEST_CASE(sort_float_vector) BOOST_AUTO_TEST_CASE(sort_double_vector) { - boost::compute::device device = boost::compute::system::default_device(); if(!device.supports_extension("cl_khr_fp64")){ std::cout << "skipping test: device does not support double" << std::endl; return; } - boost::compute::context context(device); - boost::compute::command_queue queue(context, device); - double data[] = { -6023.0, 152.5, -63.0, 1234567.0, 11.2, -5000.1, 0.0, 14.0, -8.25, -0.0 }; boost::compute::vector vector(data, data + 10, context); @@ -292,3 +254,5 @@ BOOST_AUTO_TEST_CASE(sort_double_vector) BOOST_CHECK_EQUAL(data[8], 152.5); BOOST_CHECK_EQUAL(data[9], 1234567.0); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_random_shuffle.cpp b/test/test_random_shuffle.cpp index 8b97e05b..2a7b1894 100644 --- a/test/test_random_shuffle.cpp +++ b/test/test_random_shuffle.cpp @@ -18,14 +18,12 @@ #include #include +#include "context_setup.hpp" + namespace bc = boost::compute; BOOST_AUTO_TEST_CASE(shuffle_int_vector) { - bc::device device = bc::system::default_device(); - bc::context context(device); - bc::command_queue queue(context, device); - bc::vector vector(context); vector.push_back(1); vector.push_back(9); @@ -47,3 +45,5 @@ BOOST_AUTO_TEST_CASE(shuffle_int_vector) BOOST_CHECK_EQUAL(shuffled_values.size(), size_t(4)); BOOST_VERIFY(original_values == shuffled_values); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_reduce.cpp b/test/test_reduce.cpp index 13480923..b2bbea88 100644 --- a/test/test_reduce.cpp +++ b/test/test_reduce.cpp @@ -20,14 +20,12 @@ #include #include +#include "context_setup.hpp" + namespace bc = boost::compute; BOOST_AUTO_TEST_CASE(reduce_int) { - bc::device device = bc::system::default_device(); - bc::context context(device); - bc::command_queue queue(context, device); - int data[] = { 1, 5, 9, 13, 17 }; bc::vector vector(data, data + 5, context); int sum = bc::reduce(vector.begin(), @@ -47,10 +45,6 @@ BOOST_AUTO_TEST_CASE(reduce_int) BOOST_AUTO_TEST_CASE(reduce_int_min_max) { - bc::device device = bc::system::default_device(); - bc::context context(device); - bc::command_queue queue(context, device); - int data[] = { 11, 5, 92, 13, 42 }; bc::vector vector(data, data + 5, context); BOOST_CHECK_EQUAL( @@ -76,10 +70,6 @@ BOOST_AUTO_TEST_CASE(reduce_int_min_max) BOOST_AUTO_TEST_CASE(reduce_int2) { - bc::device device = bc::system::default_device(); - bc::context context(device); - bc::command_queue queue(context, device); - std::vector data; for(int i = 0; i < 6; i++){ bc::int2_ value; @@ -102,7 +92,7 @@ BOOST_AUTO_TEST_CASE(reduce_pinned_vector) int data[] = { 2, 5, 8, 11, 15 }; std::vector vector(data, data + 5); - bc::buffer buffer(bc::system::default_context(), + bc::buffer buffer(context, vector.size() * sizeof(int), bc::buffer::read_only | bc::buffer::use_host_ptr, &vector[0]); @@ -116,10 +106,6 @@ BOOST_AUTO_TEST_CASE(reduce_pinned_vector) BOOST_AUTO_TEST_CASE(reduce_constant_iterator) { - bc::device device = bc::system::default_device(); - bc::context context(device); - bc::command_queue queue(context, device); - BOOST_CHECK_EQUAL( bc::reduce(bc::make_constant_iterator(1, 0), bc::make_constant_iterator(1, 5), @@ -148,10 +134,6 @@ BOOST_AUTO_TEST_CASE(reduce_constant_iterator) BOOST_AUTO_TEST_CASE(reduce_counting_iterator) { - bc::device device = bc::system::default_device(); - bc::context context(device); - bc::command_queue queue(context, device); - BOOST_CHECK_EQUAL( bc::reduce(bc::make_counting_iterator(1), bc::make_counting_iterator(10), @@ -174,10 +156,6 @@ BOOST_AUTO_TEST_CASE(reduce_transform_iterator) { using ::boost::compute::_1; - bc::device device = bc::system::default_device(); - bc::context context(device); - bc::command_queue queue(context, device); - int data[] = { 1, 3, 5, 7, 9 }; bc::vector vector(data, data + 5, context); @@ -208,3 +186,5 @@ BOOST_AUTO_TEST_CASE(reduce_transform_iterator) int(165) ); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_remove.cpp b/test/test_remove.cpp index 1465f620..05def386 100644 --- a/test/test_remove.cpp +++ b/test/test_remove.cpp @@ -15,6 +15,8 @@ #include #include +#include "context_setup.hpp" + namespace bc = boost::compute; BOOST_AUTO_TEST_CASE(remove_int) @@ -61,3 +63,5 @@ BOOST_AUTO_TEST_CASE(remove_int) iter = bc::remove(vector.begin(), vector.begin() + 2, 3); BOOST_VERIFY(iter == vector.begin()); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_replace.cpp b/test/test_replace.cpp index f623659f..e8a7494b 100644 --- a/test/test_replace.cpp +++ b/test/test_replace.cpp @@ -19,6 +19,8 @@ #include #include +#include "context_setup.hpp" + namespace bc = boost::compute; BOOST_AUTO_TEST_CASE(replace_int) @@ -66,3 +68,5 @@ BOOST_AUTO_TEST_CASE(replace_copy_int) BOOST_CHECK_EQUAL(a[3], 3); BOOST_CHECK_EQUAL(a[4], 4); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_reverse.cpp b/test/test_reverse.cpp index f5962bc0..76a4ed10 100644 --- a/test/test_reverse.cpp +++ b/test/test_reverse.cpp @@ -20,6 +20,8 @@ #include #include +#include "context_setup.hpp" + namespace bc = boost::compute; BOOST_AUTO_TEST_CASE(reverse_int) @@ -130,3 +132,5 @@ BOOST_AUTO_TEST_CASE(reverse_copy_counting_iterator) BOOST_CHECK_EQUAL(vector[3], 2); BOOST_CHECK_EQUAL(vector[4], 1); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_scan.cpp b/test/test_scan.cpp index 58ed0661..cd31567a 100644 --- a/test/test_scan.cpp +++ b/test/test_scan.cpp @@ -21,13 +21,12 @@ #include #include +#include "context_setup.hpp" + namespace bc = boost::compute; BOOST_AUTO_TEST_CASE(inclusive_scan_int) { - bc::device device = bc::system::default_device(); - bc::context context(device); - int data[] = { 1, 2, 1, 2, 3 }; bc::vector vector(data, data + 5, context); BOOST_CHECK_EQUAL(vector.size(), size_t(5)); @@ -60,9 +59,6 @@ BOOST_AUTO_TEST_CASE(inclusive_scan_int) BOOST_AUTO_TEST_CASE(exclusive_scan_int) { - bc::device device = bc::system::default_device(); - bc::context context(device); - int data[] = { 1, 2, 1, 2, 3 }; bc::vector vector(data, data + 5, context); BOOST_CHECK_EQUAL(vector.size(), size_t(5)); @@ -118,9 +114,6 @@ BOOST_AUTO_TEST_CASE(inclusive_scan_int2) BOOST_AUTO_TEST_CASE(inclusive_scan_counting_iterator) { - bc::device device = bc::system::default_device(); - bc::context context(device); - bc::vector result(10, context); bc::inclusive_scan(bc::make_counting_iterator(1), bc::make_counting_iterator(11), @@ -139,9 +132,6 @@ BOOST_AUTO_TEST_CASE(inclusive_scan_counting_iterator) BOOST_AUTO_TEST_CASE(exclusive_scan_counting_iterator) { - bc::device device = bc::system::default_device(); - bc::context context(device); - bc::vector result(10, context); bc::exclusive_scan(bc::make_counting_iterator(1), bc::make_counting_iterator(11), @@ -160,9 +150,6 @@ BOOST_AUTO_TEST_CASE(exclusive_scan_counting_iterator) BOOST_AUTO_TEST_CASE(inclusive_scan_transform_iterator) { - bc::device device = bc::system::default_device(); - bc::context context(device); - float data[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f }; bc::vector input(data, data + 5, context); bc::vector output(5, context); @@ -187,3 +174,5 @@ BOOST_AUTO_TEST_CASE(inclusive_scan_transform_iterator) BOOST_CHECK_CLOSE(float(output[3]), 30.0f, 1e-4); BOOST_CHECK_CLOSE(float(output[4]), 55.0f, 1e-4); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_scatter.cpp b/test/test_scatter.cpp index 4b259333..38c3b75e 100644 --- a/test/test_scatter.cpp +++ b/test/test_scatter.cpp @@ -16,13 +16,12 @@ #include #include +#include "context_setup.hpp" + namespace bc = boost::compute; BOOST_AUTO_TEST_CASE(scatter_int) { - bc::device device = bc::system::default_device(); - bc::context context(device); - int input_data[] = { 1, 2, 3, 4, 5 }; bc::vector input(input_data, input_data + 5, context); @@ -40,9 +39,6 @@ BOOST_AUTO_TEST_CASE(scatter_int) BOOST_AUTO_TEST_CASE(scatter_constant_indices) { - bc::device device = bc::system::default_device(); - bc::context context(device); - int input_data[] = { 1, 2, 3, 4, 5 }; bc::vector input(input_data, input_data + 5, context); @@ -63,3 +59,5 @@ BOOST_AUTO_TEST_CASE(scatter_constant_indices) BOOST_CHECK_EQUAL(output[3], 4); BOOST_CHECK_EQUAL(output[4], 2); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_sort.cpp b/test/test_sort.cpp index 6fc584ad..a3e1bb7a 100644 --- a/test/test_sort.cpp +++ b/test/test_sort.cpp @@ -16,6 +16,8 @@ #include #include +#include "context_setup.hpp" + namespace bc = boost::compute; // test trivial sorting of zero and one element vectors @@ -260,7 +262,6 @@ BOOST_AUTO_TEST_CASE(sort_float_vector) BOOST_AUTO_TEST_CASE(sort_double_vector) { - boost::compute::device device = boost::compute::system::default_device(); if(!device.supports_extension("cl_khr_fp64")){ std::cout << "skipping test: device does not support double" << std::endl; return; @@ -313,10 +314,6 @@ BOOST_AUTO_TEST_CASE(sort_vectors_by_length) using boost::compute::lambda::_1; using boost::compute::lambda::_2; - boost::compute::device gpu = boost::compute::system::default_device(); - boost::compute::context context(gpu); - boost::compute::command_queue queue(context, gpu); - float data[] = { 1.0f, 0.2f, 1.3f, 1.0f, 6.7f, 0.0f, @@ -358,3 +355,5 @@ BOOST_AUTO_TEST_CASE(sort_vectors_by_length) BOOST_CHECK_EQUAL(data[8], 6.7f); BOOST_CHECK_EQUAL(data[9], 0.0f); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_stable_sort.cpp b/test/test_stable_sort.cpp index 11b9e600..add535ad 100644 --- a/test/test_stable_sort.cpp +++ b/test/test_stable_sort.cpp @@ -16,6 +16,8 @@ #include #include +#include "context_setup.hpp" + BOOST_AUTO_TEST_CASE(sort_int_vector) { int data[] = { -4, 152, -5000, 963, 75321, -456, 0, 1112 }; @@ -36,3 +38,5 @@ BOOST_AUTO_TEST_CASE(sort_int_vector) BOOST_CHECK_EQUAL(data[6], 1112); BOOST_CHECK_EQUAL(data[7], 75321); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_stack.cpp b/test/test_stack.cpp index 516a8138..4ce9caf1 100644 --- a/test/test_stack.cpp +++ b/test/test_stack.cpp @@ -13,6 +13,8 @@ #include +#include "context_setup.hpp" + namespace bc = boost::compute; BOOST_AUTO_TEST_CASE(size) @@ -44,3 +46,5 @@ BOOST_AUTO_TEST_CASE(push_and_pop) stack.pop(); BOOST_CHECK_EQUAL(stack.size(), size_t(0)); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_string.cpp b/test/test_string.cpp index 9c9ceb19..a796e691 100644 --- a/test/test_string.cpp +++ b/test/test_string.cpp @@ -14,6 +14,8 @@ #include #include +#include "context_setup.hpp" + BOOST_AUTO_TEST_CASE(empty) { boost::compute::string str; @@ -27,3 +29,5 @@ BOOST_AUTO_TEST_CASE(size) BOOST_CHECK_EQUAL(str.size(), 6); BOOST_CHECK_EQUAL(str.length(), 6); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_transform.cpp b/test/test_transform.cpp index b310bfd9..cbcfc36a 100644 --- a/test/test_transform.cpp +++ b/test/test_transform.cpp @@ -19,6 +19,8 @@ #include #include +#include "context_setup.hpp" + namespace bc = boost::compute; BOOST_AUTO_TEST_CASE(transform_int_abs) @@ -156,9 +158,6 @@ BOOST_AUTO_TEST_CASE(transform_custom_function) BOOST_AUTO_TEST_CASE(extract_vector_component) { - bc::device device = bc::system::default_device(); - bc::context context(device); - int data[] = { 1, 2, 3, 4, 5, 6, @@ -197,10 +196,6 @@ BOOST_AUTO_TEST_CASE(transform_pinned_vector) int data[] = { 2, -3, 4, -5, 6, -7 }; std::vector vector(data, data + 6); - bc::device device = bc::system::default_device(); - bc::context context(device); - bc::command_queue queue(context, device); - bc::buffer buffer(context, vector.size() * sizeof(int), bc::buffer::read_write | bc::buffer::use_host_ptr, @@ -228,10 +223,6 @@ BOOST_AUTO_TEST_CASE(transform_pinned_vector) BOOST_AUTO_TEST_CASE(transform_popcount) { - bc::device device = bc::system::default_device(); - bc::context context(device); - bc::command_queue queue(context, device); - using boost::compute::uint_; uint_ data[] = { 0, 1, 2, 3, 4, 45, 127, 5000, 789, 15963 }; @@ -265,10 +256,6 @@ BOOST_AUTO_TEST_CASE(generate_fibonacci_sequence) { using boost::compute::uint_; - boost::compute::device device = boost::compute::system::default_device(); - boost::compute::context context(device); - boost::compute::command_queue queue(context, device); - boost::compute::vector sequence(25, context); const char nth_fibonacci_source[] = @@ -299,3 +286,5 @@ BOOST_AUTO_TEST_CASE(generate_fibonacci_sequence) BOOST_CHECK_EQUAL(uint_(sequence[15]), 610); BOOST_CHECK_EQUAL(uint_(sequence[24]), 46368); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_transform_iterator.cpp b/test/test_transform_iterator.cpp index eee5518c..d2e5a4aa 100644 --- a/test/test_transform_iterator.cpp +++ b/test/test_transform_iterator.cpp @@ -23,6 +23,8 @@ #include #include +#include "context_setup.hpp" + BOOST_AUTO_TEST_CASE(value_type) { using boost::compute::float4_; @@ -49,10 +51,6 @@ BOOST_AUTO_TEST_CASE(value_type) BOOST_AUTO_TEST_CASE(copy) { - boost::compute::device device = boost::compute::system::default_device(); - boost::compute::context context(device); - boost::compute::command_queue queue(context, device); - int data[] = { 1, -2, 3, -4, 5 }; boost::compute::vector a(data, data + 5, context); @@ -77,3 +75,5 @@ BOOST_AUTO_TEST_CASE(copy) BOOST_CHECK_EQUAL(int(b[3]), 4); BOOST_CHECK_EQUAL(int(b[4]), 5); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_transform_reduce.cpp b/test/test_transform_reduce.cpp index efec99f3..d310dc3b 100644 --- a/test/test_transform_reduce.cpp +++ b/test/test_transform_reduce.cpp @@ -16,14 +16,12 @@ #include #include +#include "context_setup.hpp" + namespace bc = boost::compute; BOOST_AUTO_TEST_CASE(sum_abs_int) { - bc::device device = bc::system::default_device(); - bc::context context(device); - bc::command_queue queue(context, device); - int data[] = { 1, -2, -3, -4, 5 }; bc::vector vector(data, data + 5, context); @@ -39,10 +37,6 @@ BOOST_AUTO_TEST_CASE(sum_abs_int) BOOST_AUTO_TEST_CASE(multiply_vector_length) { - bc::device device = bc::system::default_device(); - bc::context context(device); - bc::command_queue queue(context, device); - float data[] = { 2.0f, 0.0f, 0.0f, 0.0f, 0.0f, 3.0f, 0.0f, 0.0f, 0.0f, 0.0f, 4.0f, 0.0f }; @@ -59,3 +53,5 @@ BOOST_AUTO_TEST_CASE(multiply_vector_length) queue); BOOST_CHECK_CLOSE(product, 24.0f, 1e-4); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_tuple.cpp b/test/test_tuple.cpp index de884bf1..a5bbdc08 100644 --- a/test/test_tuple.cpp +++ b/test/test_tuple.cpp @@ -22,6 +22,8 @@ #include #include +#include "context_setup.hpp" + BOOST_AUTO_TEST_CASE(vector_tuple_int_float) { boost::compute::vector > vector; @@ -33,9 +35,6 @@ BOOST_AUTO_TEST_CASE(vector_tuple_int_float) BOOST_AUTO_TEST_CASE(copy_vector_tuple) { - boost::compute::device device = boost::compute::system::default_device(); - boost::compute::context context(device); - // create vector of tuples on device boost::compute::vector > input(context); input.push_back(boost::make_tuple('a', 1, 2.3f)); @@ -65,3 +64,5 @@ BOOST_AUTO_TEST_CASE(copy_vector_tuple) BOOST_CHECK_EQUAL(host_output[1], boost::make_tuple('c', 3, 4.5f)); BOOST_CHECK_EQUAL(host_output[2], boost::make_tuple('f', 6, 7.8f)); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_valarray.cpp b/test/test_valarray.cpp index 82143040..fe3e3747 100644 --- a/test/test_valarray.cpp +++ b/test/test_valarray.cpp @@ -15,6 +15,8 @@ #include #include +#include "context_setup.hpp" + BOOST_AUTO_TEST_CASE(size) { boost::compute::valarray array; @@ -55,3 +57,5 @@ BOOST_AUTO_TEST_CASE(sum) BOOST_CHECK_EQUAL(array.sum(), int(10)); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_vector.cpp b/test/test_vector.cpp index 9f729354..0a4619ea 100644 --- a/test/test_vector.cpp +++ b/test/test_vector.cpp @@ -21,6 +21,8 @@ #include #include +#include "context_setup.hpp" + namespace bc = boost::compute; BOOST_AUTO_TEST_CASE(concept_check) @@ -248,8 +250,6 @@ BOOST_AUTO_TEST_CASE(initializer_list_ctor) BOOST_AUTO_TEST_CASE(vector_double) { - bc::device device = bc::system::default_device(); - if(!device.supports_extension("cl_khr_fp64")){ return; } @@ -322,3 +322,5 @@ BOOST_AUTO_TEST_CASE(vector_erase_remove) BOOST_CHECK_EQUAL(vector[1], 5); BOOST_CHECK_EQUAL(vector[2], 1); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/test_zip_iterator.cpp b/test/test_zip_iterator.cpp index dea27b81..f43d2f24 100644 --- a/test/test_zip_iterator.cpp +++ b/test/test_zip_iterator.cpp @@ -22,6 +22,8 @@ #include #include +#include "context_setup.hpp" + BOOST_AUTO_TEST_CASE(value_type) { BOOST_STATIC_ASSERT(( @@ -39,9 +41,6 @@ BOOST_AUTO_TEST_CASE(value_type) BOOST_AUTO_TEST_CASE(distance) { - boost::compute::device device = boost::compute::system::default_device(); - boost::compute::context context(device); - boost::compute::vector char_vector(5, context); boost::compute::vector int_vector(5, context); @@ -102,9 +101,6 @@ BOOST_AUTO_TEST_CASE(distance) BOOST_AUTO_TEST_CASE(copy) { - boost::compute::device device = boost::compute::system::default_device(); - boost::compute::context context(device); - // create three separate vectors of three different types char char_data[] = { 'x', 'y', 'z' }; boost::compute::vector char_vector(char_data, char_data + 3, context); @@ -150,3 +146,5 @@ BOOST_AUTO_TEST_CASE(copy) BOOST_CHECK_EQUAL(host_vector[1], boost::make_tuple('y', 7, 4.5f)); BOOST_CHECK_EQUAL(host_vector[2], boost::make_tuple('z', 9, 7.6f)); } + +BOOST_AUTO_TEST_SUITE_END()