2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2021-05-17 02:51:16 +08:00
|
|
|
* Copyright (C) 2018-2021 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-09-18 15:11:08 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2021-01-21 20:10:13 +08:00
|
|
|
#include "shared/test/common/mocks/mock_graphics_allocation.h"
|
2020-11-02 22:54:01 +08:00
|
|
|
|
2020-06-05 06:16:55 +08:00
|
|
|
#include "opencl/source/cl_device/cl_device.h"
|
2020-05-04 17:04:43 +08:00
|
|
|
#include "opencl/source/helpers/memory_properties_helpers.h"
|
2020-02-23 05:50:57 +08:00
|
|
|
#include "opencl/source/mem_obj/mem_obj.h"
|
|
|
|
#include "opencl/source/sharings/sharing.h"
|
2020-02-23 22:20:22 +08:00
|
|
|
#include "opencl/test/unit_test/mocks/mock_context.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-02-27 18:39:32 +08:00
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
using namespace NEO;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
TEST(sharingHandler, givenBasicSharingHandlerWhenSynchronizeObjectThenErrorIsReturned) {
|
|
|
|
struct SH : SharingHandler {
|
2018-08-14 15:48:20 +08:00
|
|
|
int synchronizeHandlerMock(UpdateData &updateData) { return synchronizeHandler(updateData); }
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
} sharingHandler;
|
|
|
|
|
2020-05-25 21:41:13 +08:00
|
|
|
const uint32_t rootDeviceIndex = 1u;
|
|
|
|
UpdateData updateData{rootDeviceIndex};
|
2018-08-14 15:48:20 +08:00
|
|
|
sharingHandler.synchronizeHandlerMock(updateData);
|
2017-12-21 07:45:38 +08:00
|
|
|
EXPECT_EQ(SynchronizeStatus::SYNCHRONIZE_ERROR, updateData.synchronizationStatus);
|
|
|
|
|
|
|
|
size_t paramSize = 0;
|
|
|
|
void *paramValue = nullptr;
|
|
|
|
// there is no default implementation. parameters should be unchanged.
|
|
|
|
sharingHandler.getMemObjectInfo(paramSize, paramValue);
|
|
|
|
EXPECT_EQ(paramSize, 0u);
|
|
|
|
EXPECT_EQ(paramValue, nullptr);
|
|
|
|
}
|
2018-03-29 00:29:55 +08:00
|
|
|
|
|
|
|
TEST(sharingHandler, givenMemObjWhenAcquireIncrementCounterThenReleaseShouldDecrementIt) {
|
|
|
|
char buffer[64];
|
|
|
|
MockContext context;
|
|
|
|
MockGraphicsAllocation *mockAllocation = new MockGraphicsAllocation(buffer, sizeof(buffer));
|
2020-06-05 06:16:55 +08:00
|
|
|
std::unique_ptr<MemObj> memObj(
|
|
|
|
new MemObj(&context, CL_MEM_OBJECT_BUFFER,
|
|
|
|
MemoryPropertiesHelper::createMemoryProperties(CL_MEM_USE_HOST_PTR, 0, 0, &context.getDevice(0)->getDevice()),
|
2020-07-21 16:21:15 +08:00
|
|
|
CL_MEM_USE_HOST_PTR, 0, sizeof(buffer), buffer, buffer, GraphicsAllocationHelper::toMultiGraphicsAllocation(mockAllocation), true, false, false));
|
2018-03-29 00:29:55 +08:00
|
|
|
|
|
|
|
struct MockSharingHandler : SharingHandler {
|
2020-05-18 20:21:14 +08:00
|
|
|
using SharingHandler::acquireCount;
|
|
|
|
|
2018-08-14 15:48:20 +08:00
|
|
|
void synchronizeObject(UpdateData &updateData) override {
|
|
|
|
updateData.synchronizationStatus = ACQUIRE_SUCCESFUL;
|
2018-03-29 00:29:55 +08:00
|
|
|
}
|
|
|
|
} sharingHandler;
|
|
|
|
|
2020-05-18 20:21:14 +08:00
|
|
|
EXPECT_EQ(0u, sharingHandler.acquireCount);
|
2020-05-25 21:41:13 +08:00
|
|
|
sharingHandler.acquire(memObj.get(), mockAllocation->getRootDeviceIndex());
|
2020-05-18 20:21:14 +08:00
|
|
|
EXPECT_EQ(1u, sharingHandler.acquireCount);
|
|
|
|
sharingHandler.release(memObj.get(), mockAllocation->getRootDeviceIndex());
|
|
|
|
EXPECT_EQ(0u, sharingHandler.acquireCount);
|
2018-03-29 00:29:55 +08:00
|
|
|
}
|
2018-04-06 01:51:28 +08:00
|
|
|
|
|
|
|
TEST(sharingHandler, givenMemObjWhenAcquireTwoTimesThenReleaseShouldBeCalledTwoTimesToReleaseObject) {
|
|
|
|
char buffer[64];
|
|
|
|
MockContext context;
|
|
|
|
MockGraphicsAllocation *mockAllocation = new MockGraphicsAllocation(buffer, sizeof(buffer));
|
2020-06-05 06:16:55 +08:00
|
|
|
std::unique_ptr<MemObj> memObj(
|
|
|
|
new MemObj(&context, CL_MEM_OBJECT_BUFFER,
|
|
|
|
MemoryPropertiesHelper::createMemoryProperties(CL_MEM_USE_HOST_PTR, 0, 0, &context.getDevice(0)->getDevice()),
|
2020-07-21 16:21:15 +08:00
|
|
|
CL_MEM_USE_HOST_PTR, 0, sizeof(buffer), buffer, buffer, GraphicsAllocationHelper::toMultiGraphicsAllocation(mockAllocation), true, false, false));
|
2018-04-06 01:51:28 +08:00
|
|
|
|
|
|
|
struct MockSharingHandler : SharingHandler {
|
2020-05-18 20:21:14 +08:00
|
|
|
using SharingHandler::acquireCount;
|
2018-08-14 15:48:20 +08:00
|
|
|
void synchronizeObject(UpdateData &updateData) override {
|
|
|
|
updateData.synchronizationStatus = ACQUIRE_SUCCESFUL;
|
2018-04-06 01:51:28 +08:00
|
|
|
}
|
2020-05-18 20:21:14 +08:00
|
|
|
void releaseResource(MemObj *memObject, uint32_t rootDeviceIndex) override {
|
2018-04-06 01:51:28 +08:00
|
|
|
releaseCount++;
|
|
|
|
};
|
2020-05-18 20:21:14 +08:00
|
|
|
int releaseCount = 0;
|
2018-04-06 01:51:28 +08:00
|
|
|
} sharingHandler;
|
|
|
|
|
2020-05-18 20:21:14 +08:00
|
|
|
EXPECT_EQ(0u, sharingHandler.acquireCount);
|
2020-05-25 21:41:13 +08:00
|
|
|
sharingHandler.acquire(memObj.get(), mockAllocation->getRootDeviceIndex());
|
2020-05-18 20:21:14 +08:00
|
|
|
EXPECT_EQ(1u, sharingHandler.acquireCount);
|
2020-05-25 21:41:13 +08:00
|
|
|
sharingHandler.acquire(memObj.get(), mockAllocation->getRootDeviceIndex());
|
2020-05-18 20:21:14 +08:00
|
|
|
EXPECT_EQ(2u, sharingHandler.acquireCount);
|
|
|
|
sharingHandler.release(memObj.get(), mockAllocation->getRootDeviceIndex());
|
|
|
|
EXPECT_EQ(1u, sharingHandler.acquireCount);
|
|
|
|
EXPECT_EQ(0, sharingHandler.releaseCount);
|
|
|
|
sharingHandler.release(memObj.get(), mockAllocation->getRootDeviceIndex());
|
|
|
|
EXPECT_EQ(0u, sharingHandler.acquireCount);
|
|
|
|
EXPECT_EQ(1, sharingHandler.releaseCount);
|
2018-04-06 01:51:28 +08:00
|
|
|
}
|
2018-04-19 20:11:45 +08:00
|
|
|
|
|
|
|
TEST(sharingHandler, givenSharingHandlerWhenValidateUpdateDataIsCalledWithNonNullInputThenAbortIsNotCalled) {
|
|
|
|
class MockSharingHandler : SharingHandler {
|
|
|
|
public:
|
|
|
|
using SharingHandler::validateUpdateData;
|
|
|
|
};
|
|
|
|
MockSharingHandler sharingHandler;
|
2020-05-25 21:41:13 +08:00
|
|
|
const uint32_t rootDeviceIndex = 1u;
|
|
|
|
UpdateData updateData{rootDeviceIndex};
|
2018-08-14 15:48:20 +08:00
|
|
|
sharingHandler.validateUpdateData(updateData);
|
2018-04-19 20:11:45 +08:00
|
|
|
}
|
2018-07-04 16:41:58 +08:00
|
|
|
|
|
|
|
TEST(sharingHandler, givenSharingHandlerWhenAcquiringThenReturnErrorCode) {
|
|
|
|
SharingHandler sharingHandler;
|
|
|
|
MockContext context;
|
|
|
|
MockGraphicsAllocation *graphicsAllocation = new MockGraphicsAllocation(nullptr, 0);
|
2020-06-05 06:16:55 +08:00
|
|
|
MemObj memObj(&context, CL_MEM_OBJECT_BUFFER,
|
|
|
|
MemoryPropertiesHelper::createMemoryProperties(CL_MEM_USE_HOST_PTR, 0, 0, &context.getDevice(0)->getDevice()),
|
2020-07-21 16:21:15 +08:00
|
|
|
CL_MEM_USE_HOST_PTR, 0, 1, nullptr, nullptr, GraphicsAllocationHelper::toMultiGraphicsAllocation(graphicsAllocation), true, false, false);
|
2018-07-04 16:41:58 +08:00
|
|
|
|
2020-05-25 21:41:13 +08:00
|
|
|
auto result = sharingHandler.acquire(&memObj, graphicsAllocation->getRootDeviceIndex());
|
2018-07-04 16:41:58 +08:00
|
|
|
EXPECT_NE(CL_SUCCESS, result);
|
|
|
|
}
|