Skip to content

Commit 9a8f2bb

Browse files
Remove mock context class definition from device fixture
Signed-off-by: Mateusz Jablonski <[email protected]>
1 parent a44ca08 commit 9a8f2bb

File tree

6 files changed

+88
-78
lines changed

6 files changed

+88
-78
lines changed

level_zero/core/test/unit_tests/fixtures/device_fixture.cpp

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,70 @@ void SingleRootMultiSubDeviceFixture::SetUp() {
154154
device = driverHandle->devices[0];
155155
neoDevice = device->getNEODevice();
156156
}
157+
void SingleRootMultiSubDeviceFixtureWithImplicitScalingImpl::SetUp() {
158+
DebugManagerStateRestore restorer;
159+
DebugManager.flags.EnableImplicitScaling.set(implicitScaling);
160+
DebugManager.flags.CreateMultipleRootDevices.set(numRootDevices);
161+
DebugManager.flags.CreateMultipleSubDevices.set(numSubDevices);
162+
163+
NEO::HardwareInfo hwInfo = *NEO::defaultHwInfo.get();
164+
hwInfo.featureTable.flags.ftrRcsNode = false;
165+
hwInfo.featureTable.flags.ftrCCSNode = true;
166+
167+
if (expectedCopyEngineCount != 0) {
168+
hwInfo.capabilityTable.blitterOperationsSupported = true;
169+
hwInfo.featureTable.ftrBcsInfo = maxNBitValue(expectedCopyEngineCount);
170+
} else {
171+
hwInfo.capabilityTable.blitterOperationsSupported = false;
172+
}
173+
174+
if (implicitScaling) {
175+
expectedComputeEngineCount = 1u;
176+
} else {
177+
expectedComputeEngineCount = hwInfo.gtSystemInfo.CCSInfo.NumberOfCCSEnabled;
178+
}
179+
180+
MockDevice *mockDevice = MockDevice::createWithNewExecutionEnvironment<MockDevice>(&hwInfo, 0);
181+
182+
NEO::DeviceVector devices;
183+
devices.push_back(std::unique_ptr<NEO::Device>(mockDevice));
184+
185+
driverHandle = std::make_unique<Mock<L0::DriverHandleImp>>();
186+
ze_result_t res = driverHandle->initialize(std::move(devices));
187+
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
188+
189+
ze_context_handle_t hContext;
190+
ze_context_desc_t desc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, nullptr, 0};
191+
res = driverHandle->createContext(&desc, 0u, nullptr, &hContext);
192+
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
193+
context = static_cast<ContextImp *>(Context::fromHandle(hContext));
194+
195+
device = driverHandle->devices[0];
196+
neoDevice = device->getNEODevice();
197+
deviceImp = static_cast<L0::DeviceImp *>(device);
198+
199+
NEO::Device *activeDevice = deviceImp->getActiveDevice();
200+
auto &engineGroups = activeDevice->getRegularEngineGroups();
201+
numEngineGroups = static_cast<uint32_t>(engineGroups.size());
202+
203+
if (activeDevice->getSubDevices().size() > 0) {
204+
NEO::Device *activeSubDevice = activeDevice->getSubDevice(0u);
205+
(void)activeSubDevice;
206+
auto &subDeviceEngineGroups = activeSubDevice->getRegularEngineGroups();
207+
(void)subDeviceEngineGroups;
208+
209+
for (uint32_t i = 0; i < subDeviceEngineGroups.size(); i++) {
210+
if (subDeviceEngineGroups[i].engineGroupType == NEO::EngineGroupType::Copy ||
211+
subDeviceEngineGroups[i].engineGroupType == NEO::EngineGroupType::LinkedCopy) {
212+
subDeviceNumEngineGroups += 1;
213+
}
214+
}
215+
}
216+
}
217+
218+
void SingleRootMultiSubDeviceFixtureWithImplicitScalingImpl::TearDown() {
219+
context->destroy();
220+
}
157221

158222
void GetMemHandlePtrTestFixture::SetUp() {
159223
NEO::MockCompilerEnableGuard mock(true);

level_zero/core/test/unit_tests/fixtures/device_fixture.h

Lines changed: 12 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,6 @@ struct ContextImp;
3030
namespace ult {
3131
class MockBuiltins;
3232

33-
struct ContextShareableMock : public L0::ContextImp {
34-
ContextShareableMock(L0::DriverHandleImp *driverHandle) : L0::ContextImp(driverHandle) {}
35-
bool isShareableMemory(const void *pNext, bool exportableMemory, NEO::Device *neoDevice) override {
36-
return true;
37-
}
38-
};
39-
4033
struct DeviceFixture {
4134
NEO::MockCompilerEnableGuard compilerMock = NEO::MockCompilerEnableGuard(true);
4235
void SetUp(); // NOLINT(readability-identifier-naming)
@@ -149,8 +142,9 @@ struct MultipleDevicesWithCustomHwInfo {
149142
const uint32_t numSubDevices = 2u;
150143
};
151144

152-
template <uint32_t copyEngineCount, uint32_t implicitScaling>
153-
struct SingleRootMultiSubDeviceFixtureWithImplicitScaling : public MultiDeviceFixture {
145+
struct SingleRootMultiSubDeviceFixtureWithImplicitScalingImpl : public MultiDeviceFixture {
146+
147+
SingleRootMultiSubDeviceFixtureWithImplicitScalingImpl(uint32_t copyEngineCount, uint32_t implicitScaling) : implicitScaling(implicitScaling), expectedCopyEngineCount(copyEngineCount){};
154148
NEO::MockCompilerEnableGuard compilerMock = NEO::MockCompilerEnableGuard(true);
155149

156150
DebugManagerStateRestore restorer;
@@ -164,77 +158,20 @@ struct SingleRootMultiSubDeviceFixtureWithImplicitScaling : public MultiDeviceFi
164158
NEO::Device *neoDevice = nullptr;
165159
L0::DeviceImp *deviceImp = nullptr;
166160

167-
NEO::HardwareInfo hwInfo;
168-
uint32_t expectedCopyEngineCount = copyEngineCount;
161+
NEO::HardwareInfo hwInfo{};
162+
const uint32_t implicitScaling;
163+
const uint32_t expectedCopyEngineCount;
169164
uint32_t expectedComputeEngineCount = 0;
170165

171166
uint32_t numEngineGroups = 0;
172167
uint32_t subDeviceNumEngineGroups = 0;
173168

174-
void SetUp() {
175-
DebugManagerStateRestore restorer;
176-
DebugManager.flags.EnableImplicitScaling.set(implicitScaling);
177-
DebugManager.flags.CreateMultipleRootDevices.set(numRootDevices);
178-
DebugManager.flags.CreateMultipleSubDevices.set(numSubDevices);
179-
180-
NEO::HardwareInfo hwInfo = *NEO::defaultHwInfo.get();
181-
hwInfo.featureTable.flags.ftrRcsNode = false;
182-
hwInfo.featureTable.flags.ftrCCSNode = true;
183-
// hwInfo.gtSystemInfo.CCSInfo.NumberOfCCSEnabled = 4;
184-
if (expectedCopyEngineCount != 0) {
185-
hwInfo.capabilityTable.blitterOperationsSupported = true;
186-
hwInfo.featureTable.ftrBcsInfo = maxNBitValue(expectedCopyEngineCount);
187-
} else {
188-
hwInfo.capabilityTable.blitterOperationsSupported = false;
189-
}
190-
191-
if (implicitScaling) {
192-
expectedComputeEngineCount = 1u;
193-
} else {
194-
expectedComputeEngineCount = hwInfo.gtSystemInfo.CCSInfo.NumberOfCCSEnabled;
195-
}
196-
197-
MockDevice *mockDevice = MockDevice::createWithNewExecutionEnvironment<MockDevice>(&hwInfo, 0);
198-
199-
NEO::DeviceVector devices;
200-
devices.push_back(std::unique_ptr<NEO::Device>(mockDevice));
201-
202-
driverHandle = std::make_unique<Mock<L0::DriverHandleImp>>();
203-
ze_result_t res = driverHandle->initialize(std::move(devices));
204-
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
205-
206-
ze_context_handle_t hContext;
207-
ze_context_desc_t desc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, nullptr, 0};
208-
res = driverHandle->createContext(&desc, 0u, nullptr, &hContext);
209-
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
210-
context = static_cast<ContextImp *>(Context::fromHandle(hContext));
211-
212-
device = driverHandle->devices[0];
213-
neoDevice = device->getNEODevice();
214-
deviceImp = static_cast<L0::DeviceImp *>(device);
215-
216-
NEO::Device *activeDevice = deviceImp->getActiveDevice();
217-
auto &engineGroups = activeDevice->getRegularEngineGroups();
218-
numEngineGroups = static_cast<uint32_t>(engineGroups.size());
219-
220-
if (activeDevice->getSubDevices().size() > 0) {
221-
NEO::Device *activeSubDevice = activeDevice->getSubDevice(0u);
222-
(void)activeSubDevice;
223-
auto &subDeviceEngineGroups = activeSubDevice->getRegularEngineGroups();
224-
(void)subDeviceEngineGroups;
225-
226-
for (uint32_t i = 0; i < subDeviceEngineGroups.size(); i++) {
227-
if (subDeviceEngineGroups[i].engineGroupType == NEO::EngineGroupType::Copy ||
228-
subDeviceEngineGroups[i].engineGroupType == NEO::EngineGroupType::LinkedCopy) {
229-
subDeviceNumEngineGroups += 1;
230-
}
231-
}
232-
}
233-
}
234-
235-
void TearDown() {
236-
context->destroy();
237-
}
169+
void SetUp();
170+
void TearDown();
171+
};
172+
template <uint32_t copyEngineCount, uint32_t implicitScalingArg>
173+
struct SingleRootMultiSubDeviceFixtureWithImplicitScaling : public SingleRootMultiSubDeviceFixtureWithImplicitScalingImpl {
174+
SingleRootMultiSubDeviceFixtureWithImplicitScaling() : SingleRootMultiSubDeviceFixtureWithImplicitScalingImpl(copyEngineCount, implicitScalingArg){};
238175
};
239176

240177
} // namespace ult

level_zero/core/test/unit_tests/mocks/mock_context.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020-2021 Intel Corporation
2+
* Copyright (C) 2020-2022 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -9,7 +9,7 @@
99

1010
#include "shared/test/common/test_macros/mock_method_macros.h"
1111

12-
#include "level_zero/core/source/context/context.h"
12+
#include "level_zero/core/source/context/context_imp.h"
1313
#include "level_zero/core/test/unit_tests/mock.h"
1414
#include "level_zero/core/test/unit_tests/white_box.h"
1515

@@ -62,5 +62,11 @@ struct Mock<Context> : public Context {
6262
ADDMETHOD_NOBASE(createImage, ze_result_t, ZE_RESULT_SUCCESS, (ze_device_handle_t hDevice, const ze_image_desc_t *desc, ze_image_handle_t *phImage));
6363
};
6464

65+
struct ContextShareableMock : public L0::ContextImp {
66+
ContextShareableMock(L0::DriverHandle *driverHandle) : L0::ContextImp(driverHandle) {}
67+
bool isShareableMemory(const void *pNext, bool exportableMemory, NEO::Device *neoDevice) override {
68+
return true;
69+
}
70+
};
6571
} // namespace ult
6672
} // namespace L0

level_zero/core/test/unit_tests/sources/device/test_device.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "level_zero/core/test/unit_tests/mocks/mock_built_ins.h"
3737
#include "level_zero/core/test/unit_tests/mocks/mock_cmdlist.h"
3838
#include "level_zero/core/test/unit_tests/mocks/mock_cmdqueue.h"
39+
#include "level_zero/core/test/unit_tests/mocks/mock_context.h"
3940
#include "level_zero/core/test/unit_tests/mocks/mock_driver_handle.h"
4041
#include "level_zero/core/test/unit_tests/mocks/mock_memory_manager.h"
4142

level_zero/core/test/unit_tests/sources/memory/test_memory.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "level_zero/core/test/unit_tests/fixtures/memory_ipc_fixture.h"
3333
#include "level_zero/core/test/unit_tests/mocks/mock_built_ins.h"
3434
#include "level_zero/core/test/unit_tests/mocks/mock_cmdlist.h"
35+
#include "level_zero/core/test/unit_tests/mocks/mock_context.h"
3536
#include "level_zero/core/test/unit_tests/mocks/mock_kernel.h"
3637

3738
namespace L0 {

level_zero/tools/test/unit_tests/sources/sysman/fabric_port/linux/mock_fabric_device.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020 Intel Corporation
2+
* Copyright (C) 2020-2022 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -8,6 +8,7 @@
88
#pragma once
99
#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h"
1010

11+
#include "gmock/gmock.h"
1112
#include "sysman/fabric_port/fabric_port.h"
1213

1314
namespace L0 {

0 commit comments

Comments
 (0)