Skip to content

Commit a5c556f

Browse files
Create TestEnvironment in ze_intel_gpu_core_tests
Change-Id: I85306b59e220c34ee6b43790b59f5ad96ea51eca Signed-off-by: Mateusz Hoppe <mateusz.hoppe@intel.com>
1 parent 2590a87 commit a5c556f

File tree

10 files changed

+50
-12
lines changed

10 files changed

+50
-12
lines changed

level_zero/core/source/kernel/kernel_imp.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ KernelImmutableData::KernelImmutableData(L0::Device *l0device) : device(l0device
6565

6666
KernelImmutableData::~KernelImmutableData() {
6767
if (nullptr != isaGraphicsAllocation) {
68-
this->getDevice()->getDriverHandle()->getMemoryManager()->freeGraphicsMemory(&*isaGraphicsAllocation);
68+
this->getDevice()->getNEODevice()->getMemoryManager()->freeGraphicsMemory(&*isaGraphicsAllocation);
6969
isaGraphicsAllocation.release();
7070
}
7171
crossThreadDataTemplate.reset();
7272
if (nullptr != privateMemoryGraphicsAllocation) {
73-
this->getDevice()->getDriverHandle()->getMemoryManager()->freeGraphicsMemory(&*privateMemoryGraphicsAllocation);
73+
this->getDevice()->getNEODevice()->getMemoryManager()->freeGraphicsMemory(&*privateMemoryGraphicsAllocation);
7474
privateMemoryGraphicsAllocation.release();
7575
}
7676
surfaceStateHeapTemplate.reset();
@@ -199,7 +199,7 @@ KernelImp::~KernelImp() {
199199
alignedFree(perThreadDataForWholeThreadGroup);
200200
}
201201
if (printfBuffer != nullptr) {
202-
module->getDevice()->getDriverHandle()->getMemoryManager()->freeGraphicsMemory(printfBuffer);
202+
module->getDevice()->getNEODevice()->getMemoryManager()->freeGraphicsMemory(printfBuffer);
203203
}
204204
slmArgSizes.clear();
205205
crossThreadData.reset();

level_zero/core/source/module/module_imp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ bool ModuleImp::initialize(const ze_module_desc_t *desc, NEO::Device *neoDevice)
331331
kernelImmDatas.reserve(this->translationUnit->programInfo.kernelInfos.size());
332332
for (auto &ki : this->translationUnit->programInfo.kernelInfos) {
333333
std::unique_ptr<KernelImmutableData> kernelImmData{new KernelImmutableData(this->device)};
334-
kernelImmData->initialize(ki, *(getDevice()->getDriverHandle()->getMemoryManager()),
334+
kernelImmData->initialize(ki, *(device->getNEODevice()->getMemoryManager()),
335335
device->getNEODevice(),
336336
device->getNEODevice()->getDeviceInfo().computeUnitsUsedForScratch,
337337
this->translationUnit->globalConstBuffer, this->translationUnit->globalVarBuffer);

level_zero/core/test/unit_tests/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ target_sources(${TARGET_NAME} PRIVATE
4343
target_sources(${TARGET_NAME} PRIVATE
4444
${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/libult/create_command_stream.cpp
4545
${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/libult/io_functions.cpp
46+
${NEO_SOURCE_DIR}/opencl/test/unit_test/global_environment.cpp
4647
$<TARGET_OBJECTS:${L0_MOCKABLE_LIB_NAME}>
4748
)
4849

@@ -103,6 +104,7 @@ if(UNIX)
103104
target_link_libraries(${TARGET_NAME} pthread rt)
104105
else()
105106
target_link_libraries(${TARGET_NAME} dbghelp)
107+
add_dependencies(${TARGET_NAME} mock_gdi)
106108
endif()
107109

108110
target_link_libraries(${TARGET_NAME}
@@ -114,6 +116,7 @@ target_link_libraries(${TARGET_NAME}
114116

115117
if(SKIP_NEO_UNIT_TESTS)
116118
add_subdirectory(${NEO_SOURCE_DIR}/opencl/test/unit_test/mock_gmm ${CMAKE_BINARY_DIR}/mock_gmm)
119+
add_subdirectory(${NEO_SOURCE_DIR}/opencl/test/unit_test/mock_gdi ${CMAKE_BINARY_DIR}/mock_gdi)
117120
endif()
118121

119122
target_sources(${TARGET_NAME} PRIVATE

level_zero/core/test/unit_tests/main.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "opencl/source/program/kernel_info.h"
1717
#include "opencl/source/utilities/logger.h"
1818
#include "opencl/test/unit_test/custom_event_listener.h"
19+
#include "opencl/test/unit_test/global_environment.h"
1920
#include "opencl/test/unit_test/mocks/mock_gmm_client_context.h"
2021
#include "opencl/test/unit_test/mocks/mock_sip.h"
2122

@@ -45,7 +46,7 @@ TEST(Should, pass) { EXPECT_TRUE(true); }
4546
namespace L0 {
4647

4748
namespace ult {
48-
::testing::Environment *environment = nullptr;
49+
TestEnvironment *environment = nullptr;
4950
}
5051
} // namespace L0
5152

@@ -219,10 +220,6 @@ int main(int argc, char **argv) {
219220
NEO::GmmHelper::createGmmContextWrapperFunc =
220221
NEO::GmmClientContextBase::create<NEO::MockGmmClientContext>;
221222

222-
if (environment) {
223-
::testing::AddGlobalTestEnvironment(environment);
224-
}
225-
226223
uint64_t hwInfoConfig = NEO::defaultHardwareInfoConfigTable[productFamily];
227224
NEO::setHwInfoValuesFromConfig(hwInfoConfig, hwInfoForTests);
228225

@@ -235,6 +232,13 @@ int main(int argc, char **argv) {
235232
NEO::useKernelDescriptor = true;
236233
NEO::MockSipData::mockSipKernel.reset(new NEO::MockSipKernel());
237234

235+
environment = reinterpret_cast<TestEnvironment *>(::testing::AddGlobalTestEnvironment(new TestEnvironment));
236+
237+
MockCompilerDebugVars fclDebugVars;
238+
MockCompilerDebugVars igcDebugVars;
239+
240+
environment->setDefaultDebugVars(fclDebugVars, igcDebugVars, hwInfoForTests);
241+
238242
auto retVal = RUN_ALL_TESTS();
239243

240244
return retVal;

level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_1.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ TEST(zeCommandListCreateImmediate, DISABLED_redirectsToObject) {
6262
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
6363
}
6464

65+
TEST_F(CommandListCreate, givenNonValidProductFamilyWhenCommandListIsCreatedThenNullptrIsReturned) {
66+
std::unique_ptr<L0::CommandList> commandList(CommandList::create(PRODUCT_FAMILY::IGFX_MAX_PRODUCT, device, false));
67+
EXPECT_EQ(nullptr, commandList);
68+
}
69+
6570
TEST_F(CommandListCreate, whenCommandListIsCreatedThenItIsInitialized) {
6671
std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily, device, false));
6772
ASSERT_NE(nullptr, commandList);
@@ -153,6 +158,18 @@ TEST_F(CommandListCreate, givenValidPtrThenAppendMemoryPrefetchReturnsSuccess) {
153158
ASSERT_EQ(res, ZE_RESULT_SUCCESS);
154159
}
155160

161+
TEST_F(CommandListCreate, givenNonValidProductFamilyWhenCommandListImmediateIsCreatedThenNullptrIsReturned) {
162+
const ze_command_queue_desc_t desc = {};
163+
bool internalEngine = false;
164+
165+
std::unique_ptr<L0::CommandList> commandList0(CommandList::createImmediate(PRODUCT_FAMILY::IGFX_MAX_PRODUCT,
166+
device,
167+
&desc,
168+
internalEngine,
169+
false));
170+
EXPECT_EQ(nullptr, commandList0);
171+
}
172+
156173
TEST_F(CommandListCreate, givenImmediateCommandListThenInternalEngineIsUsedIfRequested) {
157174
const ze_command_queue_desc_t desc = {};
158175
bool internalEngine = true;

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,8 @@ TEST_F(AllocHostMemoryTest,
305305
whenCallingAllocHostMemThenAllocateGraphicsMemoryWithPropertiesIsCalledTheNumberOfTimesOfRootDevices) {
306306
void *ptr = nullptr;
307307

308+
memoryManager->allocateGraphicsMemoryWithPropertiesCount = 0;
309+
308310
ze_result_t result = driverHandle->allocHostMem(0u,
309311
4096u, 0u, &ptr);
310312
EXPECT_EQ(memoryManager->allocateGraphicsMemoryWithPropertiesCount, numRootDevices);
@@ -321,6 +323,8 @@ TEST_F(AllocHostMemoryTest,
321323

322324
void *ptr = nullptr;
323325

326+
memoryManager->allocateGraphicsMemoryWithPropertiesCount = 0;
327+
324328
ze_result_t result = driverHandle->allocHostMem(0u,
325329
4096u, 0u, &ptr);
326330
EXPECT_EQ(memoryManager->allocateGraphicsMemoryWithPropertiesCount, 1u);
@@ -335,6 +339,8 @@ TEST_F(AllocHostMemoryTest,
335339

336340
void *ptr = nullptr;
337341

342+
memoryManager->allocateGraphicsMemoryWithPropertiesCount = 0;
343+
338344
ze_result_t result = driverHandle->allocHostMem(0u,
339345
4096u, 0u, &ptr);
340346
EXPECT_EQ(memoryManager->allocateGraphicsMemoryWithPropertiesCount, numRootDevices);

level_zero/experimental/test/unit_tests/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ target_sources(
4949
PRIVATE
5050
${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/libult/create_command_stream.cpp
5151
${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/libult/io_functions.cpp
52+
${NEO_SOURCE_DIR}/opencl/test/unit_test/global_environment.cpp
5253
$<TARGET_OBJECTS:${L0_MOCKABLE_LIB_NAME}>
5354
)
5455

@@ -107,6 +108,7 @@ if(UNIX)
107108
target_link_libraries(${TARGET_NAME} pthread rt)
108109
else()
109110
target_link_libraries(${TARGET_NAME} dbghelp)
111+
add_dependencies(${TARGET_NAME} mock_gdi)
110112
endif()
111113

112114
target_link_libraries(

level_zero/tools/test/unit_tests/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ target_sources(${TARGET_NAME} PRIVATE
4040
target_sources(${TARGET_NAME} PRIVATE
4141
${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/libult/create_command_stream.cpp
4242
${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/libult/io_functions.cpp
43+
${NEO_SOURCE_DIR}/opencl/test/unit_test/global_environment.cpp
4344
$<TARGET_OBJECTS:${L0_MOCKABLE_LIB_NAME}>
4445
)
4546

@@ -92,6 +93,7 @@ if(UNIX)
9293
target_link_libraries(${TARGET_NAME} pthread rt)
9394
else()
9495
target_link_libraries(${TARGET_NAME} dbghelp)
96+
add_dependencies(${TARGET_NAME} mock_gdi)
9597
endif()
9698

9799
target_link_libraries(${TARGET_NAME}
@@ -104,6 +106,8 @@ target_link_libraries(${TARGET_NAME}
104106
target_sources(${TARGET_NAME} PRIVATE
105107
$<TARGET_OBJECTS:mock_gmm>
106108
$<TARGET_OBJECTS:${TARGET_NAME_L0}_mocks>
109+
$<TARGET_OBJECTS:${BUILTINS_SPIRV_LIB_NAME}>
110+
$<TARGET_OBJECTS:${BUILTINS_BINARIES_LIB_NAME}>
107111
)
108112

109113
option(L0_ULT_VERBOSE "Use the default/verbose test output" OFF)

opencl/test/unit_test/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,11 @@ apply_macro_for_each_gen("TESTED")
502502
add_subdirectories()
503503
create_project_source_tree(igdrcl_tests)
504504

505+
if(MSVC)
506+
add_dependencies(unit_tests mock_gdi)
507+
add_dependencies(igdrcl_tests mock_gdi)
508+
endif()
509+
505510
set(UltPchHeader "${CMAKE_CURRENT_SOURCE_DIR}/igdrcl_tests_pch.h")
506511
set(UltPchSource "${CMAKE_CURRENT_SOURCE_DIR}/igdrcl_tests_pch.cpp")
507512
get_target_property(UltSources igdrcl_tests SOURCES)

opencl/test/unit_test/mock_gdi/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,4 @@ if(WIN32)
4141
set_target_properties(mock_gdi PROPERTIES FOLDER "test mocks")
4242

4343
target_compile_definitions(mock_gdi PUBLIC MOCKABLE_VIRTUAL=virtual)
44-
45-
add_dependencies(unit_tests mock_gdi)
46-
add_dependencies(igdrcl_tests mock_gdi)
4744
endif()

0 commit comments

Comments
 (0)