test_context.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. #define BOOST_TEST_MODULE TestContext
  11. #include <boost/test/unit_test.hpp>
  12. #include <boost/compute/system.hpp>
  13. #include <boost/compute/context.hpp>
  14. #include "check_macros.hpp"
  15. #include "context_setup.hpp"
  16. namespace compute = boost::compute;
  17. BOOST_AUTO_TEST_CASE(construct_from_cl_context)
  18. {
  19. cl_device_id id = device.id();
  20. // create cl_context
  21. cl_context ctx = clCreateContext(0, 1, &id, 0, 0, 0);
  22. BOOST_VERIFY(ctx);
  23. // create boost::compute::context
  24. boost::compute::context context(ctx);
  25. // check context
  26. BOOST_CHECK(cl_context(context) == ctx);
  27. // cleanup cl_context
  28. clReleaseContext(ctx);
  29. }
  30. #ifndef BOOST_COMPUTE_NO_RVALUE_REFERENCES
  31. BOOST_AUTO_TEST_CASE(move_constructor)
  32. {
  33. boost::compute::device device = boost::compute::system::default_device();
  34. boost::compute::context context1(device);
  35. BOOST_VERIFY(cl_context(context1) != cl_context());
  36. boost::compute::context context2(std::move(context1));
  37. BOOST_VERIFY(cl_context(context2) != cl_context());
  38. BOOST_VERIFY(cl_context(context1) == cl_context());
  39. }
  40. #endif // BOOST_COMPUTE_NO_RVALUE_REFERENCES
  41. BOOST_AUTO_TEST_CASE(multiple_devices)
  42. {
  43. const std::vector<compute::platform> &platforms = compute::system::platforms();
  44. for(size_t i = 0; i < platforms.size(); i++){
  45. const compute::platform &platform = platforms[i];
  46. // create a context for containing all devices in the platform
  47. compute::context ctx(platform.devices());
  48. // check device count
  49. BOOST_CHECK_EQUAL(ctx.get_devices().size(), platform.device_count());
  50. }
  51. }
  52. BOOST_AUTO_TEST_SUITE_END()