1 //---------------------------------------------------------------------------// 2 // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com> 3 // 4 // Distributed under the Boost Software License, Version 1.0 5 // See accompanying file LICENSE_1_0.txt or copy at 6 // http://www.boost.org/LICENSE_1_0.txt 7 // 8 // See http://boostorg.github.com/compute for more information. 9 //---------------------------------------------------------------------------// 10 11 #define BOOST_TEST_MODULE TestContext 12 #include <boost/test/unit_test.hpp> 13 14 #include <boost/compute/system.hpp> 15 #include <boost/compute/context.hpp> 16 17 #include "check_macros.hpp" 18 #include "context_setup.hpp" 19 20 namespace compute = boost::compute; 21 BOOST_AUTO_TEST_CASE(construct_from_cl_context)22BOOST_AUTO_TEST_CASE(construct_from_cl_context) 23 { 24 cl_device_id id = device.id(); 25 26 // create cl_context 27 cl_context ctx = clCreateContext(0, 1, &id, 0, 0, 0); 28 BOOST_VERIFY(ctx); 29 30 // create boost::compute::context 31 boost::compute::context context(ctx); 32 33 // check context 34 BOOST_CHECK(cl_context(context) == ctx); 35 36 // cleanup cl_context 37 clReleaseContext(ctx); 38 } 39 40 #ifndef BOOST_COMPUTE_NO_RVALUE_REFERENCES BOOST_AUTO_TEST_CASE(move_constructor)41BOOST_AUTO_TEST_CASE(move_constructor) 42 { 43 boost::compute::device device = boost::compute::system::default_device(); 44 boost::compute::context context1(device); 45 BOOST_VERIFY(cl_context(context1) != cl_context()); 46 47 boost::compute::context context2(std::move(context1)); 48 BOOST_VERIFY(cl_context(context2) != cl_context()); 49 BOOST_VERIFY(cl_context(context1) == cl_context()); 50 } 51 #endif // BOOST_COMPUTE_NO_RVALUE_REFERENCES 52 BOOST_AUTO_TEST_CASE(multiple_devices)53BOOST_AUTO_TEST_CASE(multiple_devices) 54 { 55 const std::vector<compute::platform> &platforms = compute::system::platforms(); 56 for(size_t i = 0; i < platforms.size(); i++){ 57 const compute::platform &platform = platforms[i]; 58 59 // create a context for containing all devices in the platform 60 compute::context ctx(platform.devices()); 61 62 // check device count 63 BOOST_CHECK_EQUAL(ctx.get_devices().size(), platform.device_count()); 64 } 65 } 66 67 BOOST_AUTO_TEST_SUITE_END() 68