/* * Copyright (c) Advanced Micro Devices, Inc., or its affiliates. * * SPDX-License-Identifier: MIT */ #include #include #include #include "gl_interop_common.hh" namespace { constexpr std::array kDeviceLists{ hipGLDeviceListAll, hipGLDeviceListCurrentFrame, hipGLDeviceListNextFrame}; } // anonymous namespace HIP_TEST_CASE(Unit_hipGLGetDevices_Positive_Basic) { CHECK_IMAGE_SUPPORT GLContextScopeGuard gl_context; const auto device_list = GENERATE(from_range(begin(kDeviceLists), end(kDeviceLists))); const int device_count = HipTest::getDeviceCount(); unsigned int gl_device_count = 0; std::vector gl_devices(device_count, -1); if (device_list == hipGLDeviceListNextFrame) { HIP_CHECK_ERROR(hipGLGetDevices(&gl_device_count, gl_devices.data(), device_count, device_list), hipErrorNotSupported); REQUIRE(gl_device_count == 0); REQUIRE(gl_devices.at(0) == -1); } else { HIP_CHECK(hipGLGetDevices(&gl_device_count, gl_devices.data(), device_count, device_list)); REQUIRE(gl_device_count == 1); REQUIRE(gl_devices.at(0) == 0); } } HIP_TEST_CASE(Unit_hipGLGetDevices_Positive_Parameters) { CHECK_IMAGE_SUPPORT GLContextScopeGuard gl_context; const int device_count = HipTest::getDeviceCount(); unsigned int gl_device_count = 0; std::vector gl_devices(device_count, -1); SECTION("pHipDeviceCount == nullptr") { HIP_CHECK_ERROR(hipGLGetDevices(nullptr, gl_devices.data(), device_count, hipGLDeviceListAll), hipErrorInvalidValue); REQUIRE(gl_devices.at(0) == -1); } SECTION("pHipDevices == nullptr") { HIP_CHECK_ERROR(hipGLGetDevices(&gl_device_count, nullptr, device_count, hipGLDeviceListAll), hipErrorInvalidValue); REQUIRE(gl_device_count == 0); } SECTION("hipDeviceCount == 0") { HIP_CHECK_ERROR(hipGLGetDevices(&gl_device_count, gl_devices.data(), 0, hipGLDeviceListAll), hipErrorInvalidValue); REQUIRE(gl_device_count == 0); REQUIRE(gl_devices.at(0) == -1); } } HIP_TEST_CASE(Unit_hipGLGetDevices_Negative_Parameters) { CHECK_IMAGE_SUPPORT GLContextScopeGuard gl_context; const int device_count = HipTest::getDeviceCount(); unsigned int gl_device_count = 0; std::vector gl_devices(device_count, -1); SECTION("invalid deviceList") { HIP_CHECK_ERROR(hipGLGetDevices(&gl_device_count, gl_devices.data(), device_count, static_cast(-1)), hipErrorInvalidValue); REQUIRE(gl_device_count == 0); REQUIRE(gl_devices.at(0) == -1); } }