diff --git a/runtime/context/context.inl b/runtime/context/context.inl index 4b1993eb0c..d30f94c9ac 100644 --- a/runtime/context/context.inl +++ b/runtime/context/context.inl @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Intel Corporation + * Copyright (c) 2017 - 2018, Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -31,7 +31,9 @@ void Context::registerSharing(Sharing *sharing) { template Sharing *Context::getSharing() { - UNRECOVERABLE_IF(Sharing::sharingId >= sharingFunctions.size()); + if (Sharing::sharingId >= sharingFunctions.size()) { + return nullptr; + } return reinterpret_cast(sharingFunctions[Sharing::sharingId].get()); } diff --git a/runtime/os_interface/windows/d3d10_11_sharing_functions.cpp b/runtime/os_interface/windows/d3d10_11_sharing_functions.cpp index cd6308b7e5..4f80624190 100644 --- a/runtime/os_interface/windows/d3d10_11_sharing_functions.cpp +++ b/runtime/os_interface/windows/d3d10_11_sharing_functions.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Intel Corporation + * Copyright (c) 2017 - 2018, Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -20,7 +20,6 @@ * OTHER DEALINGS IN THE SOFTWARE. */ -#include "runtime/context/context.h" #include "runtime/context/context.inl" #include "runtime/os_interface/windows/d3d_sharing_functions.h" #include "runtime/sharings/sharing_factory.h" @@ -224,4 +223,4 @@ void D3DSharingFunctions::getDxgiDesc(DXGI_ADAPTER_DESC *dxgiDesc, IDXGIAda } template D3DSharingFunctions *Context::getSharing>(); -template D3DSharingFunctions *Context::getSharing>(); \ No newline at end of file +template D3DSharingFunctions *Context::getSharing>(); diff --git a/runtime/os_interface/windows/d3d9_sharing_functions.cpp b/runtime/os_interface/windows/d3d9_sharing_functions.cpp index 0fb5919a04..3d212ae4fa 100644 --- a/runtime/os_interface/windows/d3d9_sharing_functions.cpp +++ b/runtime/os_interface/windows/d3d9_sharing_functions.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Intel Corporation + * Copyright (c) 2017 - 2018, Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -20,7 +20,6 @@ * OTHER DEALINGS IN THE SOFTWARE. */ -#include "runtime/context/context.h" #include "runtime/context/context.inl" #include "runtime/os_interface/windows/d3d_sharing_functions.h" #include "runtime/sharings/sharing_factory.h" @@ -153,4 +152,4 @@ void D3DSharingFunctions::getDxgiDesc(DXGI_ADAPTER_DESC *d adapter->Release(); } -template D3DSharingFunctions *Context::getSharing>(); \ No newline at end of file +template D3DSharingFunctions *Context::getSharing>(); diff --git a/runtime/sharings/va/va_sharing.cpp b/runtime/sharings/va/va_sharing.cpp index 3cb0e8f1d3..7eccb7c117 100644 --- a/runtime/sharings/va/va_sharing.cpp +++ b/runtime/sharings/va/va_sharing.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Intel Corporation + * Copyright (c) 2017 - 2018, Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -20,7 +20,7 @@ * OTHER DEALINGS IN THE SOFTWARE. */ -#include "runtime/context/context.h" +#include "runtime/context/context.inl" #include "runtime/sharings/sharing_factory.h" #include "runtime/sharings/va/va_sharing_defines.h" #include "runtime/sharings/va/va_sharing_functions.h" @@ -28,13 +28,5 @@ namespace OCLRT { const uint32_t VASharingFunctions::sharingId = SharingType::VA_SHARING; -template <> -VASharingFunctions *Context::getSharing() { - if (VASharingFunctions::sharingId >= sharingFunctions.size()) { - DEBUG_BREAK_IF(VASharingFunctions::sharingId >= sharingFunctions.size()); - return nullptr; - } - - return reinterpret_cast(sharingFunctions[VASharingFunctions::sharingId].get()); -} +template VASharingFunctions *Context::getSharing(); } diff --git a/unit_tests/context/context_tests.cpp b/unit_tests/context/context_tests.cpp index 0b19bba58b..c443680855 100644 --- a/unit_tests/context/context_tests.cpp +++ b/unit_tests/context/context_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Intel Corporation + * Copyright (c) 2017 - 2018, Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -20,13 +20,14 @@ * OTHER DEALINGS IN THE SOFTWARE. */ -#include "runtime/context/context.h" -#include "runtime/device/device.h" -#include "runtime/helpers/options.h" -#include "runtime/command_queue/command_queue.h" -#include "runtime/device_queue/device_queue.h" -#include "unit_tests/fixtures/platform_fixture.h" #include "gtest/gtest.h" +#include "runtime/context/context.inl" +#include "runtime/command_queue/command_queue.h" +#include "runtime/device/device.h" +#include "runtime/device_queue/device_queue.h" +#include "runtime/helpers/options.h" +#include "runtime/sharings/sharing.h" +#include "unit_tests/fixtures/platform_fixture.h" #include "unit_tests/helpers/debug_manager_state_restore.h" #include "unit_tests/mocks/mock_context.h" #include "unit_tests/mocks/mock_deferred_deleter.h" @@ -262,6 +263,29 @@ TEST_F(ContextTest, GivenInteropSyncParamWhenCreateContextThenSetContextParam) { delete context; } +class MockSharingFunctions : public SharingFunctions { + public: + uint32_t getId() const override { + return sharingId; + } + static const uint32_t sharingId = 0; +}; + +TEST_F(ContextTest, givenContextWhenSharingTableEmptyThenReturnsNullptr) { + MockContext context; + context.clearSharingFunctions(); + auto *sharingF = context.getSharing(); + EXPECT_EQ(sharingF, nullptr); +} + +TEST_F(ContextTest, givenContextWhenSharingTableIsNotEmptyThenReturnsSharingFunctionPointer) { + MockContext context; + MockSharingFunctions *sharingFunctions = new MockSharingFunctions; + context.registerSharing(sharingFunctions); + auto *sharingF = context.getSharing(); + EXPECT_EQ(sharingF, sharingFunctions); +} + class ContextWithAsyncDeleterTest : public ::testing::WithParamInterface, public ::testing::Test { public: diff --git a/unit_tests/sharings/va/va_sharing_tests.cpp b/unit_tests/sharings/va/va_sharing_tests.cpp index 2a6a1e41b5..fd90f62692 100644 --- a/unit_tests/sharings/va/va_sharing_tests.cpp +++ b/unit_tests/sharings/va/va_sharing_tests.cpp @@ -397,7 +397,7 @@ TEST_F(VaSharingTests, givenVaSurfaceWhenCreateImageFromParentThenSetMediaPlaneT EXPECT_EQ(CL_SUCCESS, errCode); } -TEST_F(VaSharingTests, givenContextWhenEmptySharingTableEmptyThenReturnsNullptr) { +TEST_F(VaSharingTests, givenContextWhenSharingTableEmptyThenReturnsNullptr) { MockContext context; context.clearSharingFunctions(); VASharingFunctions *sharingF = context.getSharing();