1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
/*
* Copyright (C) 2018-2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/command_stream/preemption.h"
#include "shared/source/helpers/gfx_core_helper.h"
#include "shared/source/memory_manager/graphics_allocation.h"
#include "shared/test/common/helpers/engine_descriptor_helper.h"
#include "shared/test/common/mocks/mock_csr.h"
#include "shared/test/common/mocks/mock_device.h"
#include "shared/test/common/test_macros/hw_test.h"
#include "opencl/source/memory_manager/mem_obj_surface.h"
#include "opencl/source/platform/platform.h"
#include "opencl/test/unit_test/mocks/mock_buffer.h"
#include "opencl/test/unit_test/mocks/mock_platform.h"
#include "gtest/gtest.h"
#include <memory>
using namespace NEO;
namespace createSurface {
Surface *create(char *data, MockBuffer *buffer, GraphicsAllocation *gfxAllocation) {
return new MemObjSurface(buffer);
}
} // namespace createSurface
class SurfaceTest : public ::testing::Test {
public:
char data[10];
MockBuffer buffer;
MockGraphicsAllocation gfxAllocation{nullptr, 0};
};
HWTEST_F(SurfaceTest, GivenSurfaceWhenInterfaceIsUsedThenSurfaceBehavesCorrectly) {
int32_t execStamp;
ExecutionEnvironment *executionEnvironment = platform()->peekExecutionEnvironment();
executionEnvironment->initializeMemoryManager();
DeviceBitfield deviceBitfield(1);
auto csr = std::make_unique<MockCsr<FamilyType>>(execStamp, *executionEnvironment, 0, deviceBitfield);
auto hwInfo = *defaultHwInfo;
auto &gfxCoreHelper = executionEnvironment->rootDeviceEnvironments[0]->getHelper<GfxCoreHelper>();
auto engine = gfxCoreHelper.getGpgpuEngineInstances(*executionEnvironment->rootDeviceEnvironments[0])[0];
auto osContext = executionEnvironment->memoryManager->createAndRegisterOsContext(csr.get(), EngineDescriptorHelper::getDefaultDescriptor(engine, PreemptionHelper::getDefaultPreemptionMode(hwInfo)));
csr->setupContext(*osContext);
std::unique_ptr<Surface> surface{createSurface::create(this->data,
&this->buffer,
&this->gfxAllocation)};
ASSERT_NE(nullptr, surface);
std::unique_ptr<Surface> duplicatedSurface{surface->duplicate()};
ASSERT_NE(nullptr, duplicatedSurface);
surface->makeResident(*csr);
EXPECT_EQ(1u, csr->madeResidentGfxAllocations.size());
}
class CoherentMemObjSurface : public SurfaceTest {
public:
CoherentMemObjSurface() {
this->buffer.getGraphicsAllocation(mockRootDeviceIndex)->setCoherent(true);
}
};
TEST_F(CoherentMemObjSurface, GivenCoherentMemObjWhenCreatingSurfaceFromMemObjThenSurfaceIsCoherent) {
std::unique_ptr<Surface> surface{createSurface::create(this->data,
&this->buffer,
&this->gfxAllocation)};
EXPECT_TRUE(surface->isCoherent);
}
|