Skip to content

Commit e43c345

Browse files
sharing: add context tests
Change-Id: I1dc504f6931ab0ae5645e9460ae0c0284704404c
1 parent 6b648bc commit e43c345

File tree

6 files changed

+41
-25
lines changed

6 files changed

+41
-25
lines changed

runtime/context/context.inl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, Intel Corporation
2+
* Copyright (c) 2017 - 2018, Intel Corporation
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a
55
* copy of this software and associated documentation files (the "Software"),
@@ -31,7 +31,9 @@ void Context::registerSharing(Sharing *sharing) {
3131

3232
template <typename Sharing>
3333
Sharing *Context::getSharing() {
34-
UNRECOVERABLE_IF(Sharing::sharingId >= sharingFunctions.size());
34+
if (Sharing::sharingId >= sharingFunctions.size()) {
35+
return nullptr;
36+
}
3537

3638
return reinterpret_cast<Sharing *>(sharingFunctions[Sharing::sharingId].get());
3739
}

runtime/os_interface/windows/d3d10_11_sharing_functions.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, Intel Corporation
2+
* Copyright (c) 2017 - 2018, Intel Corporation
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a
55
* copy of this software and associated documentation files (the "Software"),
@@ -20,7 +20,6 @@
2020
* OTHER DEALINGS IN THE SOFTWARE.
2121
*/
2222

23-
#include "runtime/context/context.h"
2423
#include "runtime/context/context.inl"
2524
#include "runtime/os_interface/windows/d3d_sharing_functions.h"
2625
#include "runtime/sharings/sharing_factory.h"
@@ -224,4 +223,4 @@ void D3DSharingFunctions<D3D>::getDxgiDesc(DXGI_ADAPTER_DESC *dxgiDesc, IDXGIAda
224223
}
225224

226225
template D3DSharingFunctions<D3DTypesHelper::D3D10> *Context::getSharing<D3DSharingFunctions<D3DTypesHelper::D3D10>>();
227-
template D3DSharingFunctions<D3DTypesHelper::D3D11> *Context::getSharing<D3DSharingFunctions<D3DTypesHelper::D3D11>>();
226+
template D3DSharingFunctions<D3DTypesHelper::D3D11> *Context::getSharing<D3DSharingFunctions<D3DTypesHelper::D3D11>>();

runtime/os_interface/windows/d3d9_sharing_functions.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, Intel Corporation
2+
* Copyright (c) 2017 - 2018, Intel Corporation
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a
55
* copy of this software and associated documentation files (the "Software"),
@@ -20,7 +20,6 @@
2020
* OTHER DEALINGS IN THE SOFTWARE.
2121
*/
2222

23-
#include "runtime/context/context.h"
2423
#include "runtime/context/context.inl"
2524
#include "runtime/os_interface/windows/d3d_sharing_functions.h"
2625
#include "runtime/sharings/sharing_factory.h"
@@ -153,4 +152,4 @@ void D3DSharingFunctions<D3DTypesHelper::D3D9>::getDxgiDesc(DXGI_ADAPTER_DESC *d
153152
adapter->Release();
154153
}
155154

156-
template D3DSharingFunctions<D3DTypesHelper::D3D9> *Context::getSharing<D3DSharingFunctions<D3DTypesHelper::D3D9>>();
155+
template D3DSharingFunctions<D3DTypesHelper::D3D9> *Context::getSharing<D3DSharingFunctions<D3DTypesHelper::D3D9>>();

runtime/sharings/va/va_sharing.cpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, Intel Corporation
2+
* Copyright (c) 2017 - 2018, Intel Corporation
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a
55
* copy of this software and associated documentation files (the "Software"),
@@ -20,21 +20,13 @@
2020
* OTHER DEALINGS IN THE SOFTWARE.
2121
*/
2222

23-
#include "runtime/context/context.h"
23+
#include "runtime/context/context.inl"
2424
#include "runtime/sharings/sharing_factory.h"
2525
#include "runtime/sharings/va/va_sharing_defines.h"
2626
#include "runtime/sharings/va/va_sharing_functions.h"
2727

2828
namespace OCLRT {
2929
const uint32_t VASharingFunctions::sharingId = SharingType::VA_SHARING;
3030

31-
template <>
32-
VASharingFunctions *Context::getSharing() {
33-
if (VASharingFunctions::sharingId >= sharingFunctions.size()) {
34-
DEBUG_BREAK_IF(VASharingFunctions::sharingId >= sharingFunctions.size());
35-
return nullptr;
36-
}
37-
38-
return reinterpret_cast<VASharingFunctions *>(sharingFunctions[VASharingFunctions::sharingId].get());
39-
}
31+
template VASharingFunctions *Context::getSharing<VASharingFunctions>();
4032
}

unit_tests/context/context_tests.cpp

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, Intel Corporation
2+
* Copyright (c) 2017 - 2018, Intel Corporation
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a
55
* copy of this software and associated documentation files (the "Software"),
@@ -20,13 +20,14 @@
2020
* OTHER DEALINGS IN THE SOFTWARE.
2121
*/
2222

23-
#include "runtime/context/context.h"
24-
#include "runtime/device/device.h"
25-
#include "runtime/helpers/options.h"
23+
#include "gtest/gtest.h"
24+
#include "runtime/context/context.inl"
2625
#include "runtime/command_queue/command_queue.h"
26+
#include "runtime/device/device.h"
2727
#include "runtime/device_queue/device_queue.h"
28+
#include "runtime/helpers/options.h"
29+
#include "runtime/sharings/sharing.h"
2830
#include "unit_tests/fixtures/platform_fixture.h"
29-
#include "gtest/gtest.h"
3031
#include "unit_tests/helpers/debug_manager_state_restore.h"
3132
#include "unit_tests/mocks/mock_context.h"
3233
#include "unit_tests/mocks/mock_deferred_deleter.h"
@@ -262,6 +263,29 @@ TEST_F(ContextTest, GivenInteropSyncParamWhenCreateContextThenSetContextParam) {
262263
delete context;
263264
}
264265

266+
class MockSharingFunctions : public SharingFunctions {
267+
public:
268+
uint32_t getId() const override {
269+
return sharingId;
270+
}
271+
static const uint32_t sharingId = 0;
272+
};
273+
274+
TEST_F(ContextTest, givenContextWhenSharingTableEmptyThenReturnsNullptr) {
275+
MockContext context;
276+
context.clearSharingFunctions();
277+
auto *sharingF = context.getSharing<MockSharingFunctions>();
278+
EXPECT_EQ(sharingF, nullptr);
279+
}
280+
281+
TEST_F(ContextTest, givenContextWhenSharingTableIsNotEmptyThenReturnsSharingFunctionPointer) {
282+
MockContext context;
283+
MockSharingFunctions *sharingFunctions = new MockSharingFunctions;
284+
context.registerSharing<MockSharingFunctions>(sharingFunctions);
285+
auto *sharingF = context.getSharing<MockSharingFunctions>();
286+
EXPECT_EQ(sharingF, sharingFunctions);
287+
}
288+
265289
class ContextWithAsyncDeleterTest : public ::testing::WithParamInterface<bool>,
266290
public ::testing::Test {
267291
public:

unit_tests/sharings/va/va_sharing_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ TEST_F(VaSharingTests, givenVaSurfaceWhenCreateImageFromParentThenSetMediaPlaneT
397397
EXPECT_EQ(CL_SUCCESS, errCode);
398398
}
399399

400-
TEST_F(VaSharingTests, givenContextWhenEmptySharingTableEmptyThenReturnsNullptr) {
400+
TEST_F(VaSharingTests, givenContextWhenSharingTableEmptyThenReturnsNullptr) {
401401
MockContext context;
402402
context.clearSharingFunctions();
403403
VASharingFunctions *sharingF = context.getSharing<VASharingFunctions>();

0 commit comments

Comments
 (0)