From 37dbec305d0db2324bfbdcd29faa57358fe456d5 Mon Sep 17 00:00:00 2001 From: Mateusz Hoppe Date: Tue, 7 Mar 2023 16:39:25 +0000 Subject: [PATCH] feature: add AssertHandler - initial implementation to support assert() on GPU Related-To: NEO-5753 Signed-off-by: Mateusz Hoppe --- shared/source/CMakeLists.txt | 3 +- shared/source/assert_handler/CMakeLists.txt | 13 +++ .../source/assert_handler/assert_handler.cpp | 56 ++++++++++++ shared/source/assert_handler/assert_handler.h | 49 +++++++++++ shared/source/aub/aub_helper.h | 1 + .../root_device_environment.cpp | 11 +++ .../root_device_environment.h | 3 + shared/source/helpers/app_resource_helper.cpp | 4 +- .../extra_allocation_data_xehp_and_later.inl | 1 + .../source/memory_manager/allocation_type.h | 3 +- .../memory_manager/graphics_allocation.h | 3 +- .../source/memory_manager/memory_manager.cpp | 1 + shared/source/os_interface/linux/print.cpp | 7 +- shared/source/os_interface/print.h | 5 +- shared/source/os_interface/windows/print.cpp | 14 ++- shared/source/program/print_formatter.h | 4 +- shared/source/utilities/logger.cpp | 4 +- .../unit_test/assert_handler/CMakeLists.txt | 12 +++ .../assert_handler/assert_handler_tests.cpp | 88 +++++++++++++++++++ .../aub_command_stream_receiver_1_tests.cpp | 3 +- .../execution_environment_tests.cpp | 11 +++ .../unit_test/helpers/app_resource_tests.cpp | 3 +- ...nager_allocate_in_preferred_pool_tests.cpp | 11 ++- .../unit_test/program/printf_helper_tests.cpp | 6 +- .../dg2/memory_manager_tests_dg2.cpp | 1 + 25 files changed, 298 insertions(+), 19 deletions(-) create mode 100644 shared/source/assert_handler/CMakeLists.txt create mode 100644 shared/source/assert_handler/assert_handler.cpp create mode 100644 shared/source/assert_handler/assert_handler.h create mode 100644 shared/test/unit_test/assert_handler/CMakeLists.txt create mode 100644 shared/test/unit_test/assert_handler/assert_handler_tests.cpp diff --git a/shared/source/CMakeLists.txt b/shared/source/CMakeLists.txt index 255d40abd3..0414688bd9 100644 --- a/shared/source/CMakeLists.txt +++ b/shared/source/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (C) 2019-2022 Intel Corporation +# Copyright (C) 2019-2023 Intel Corporation # # SPDX-License-Identifier: MIT # @@ -107,6 +107,7 @@ apply_macro_for_each_core_type("SUPPORTED") append_sources_from_properties(CORE_SOURCES NEO_CORE_AIL + NEO_CORE_ASSERT_HANDLER NEO_CORE_AUB NEO_CORE_AUB_MEM_DUMP NEO_CORE_BUILT_INS diff --git a/shared/source/assert_handler/CMakeLists.txt b/shared/source/assert_handler/CMakeLists.txt new file mode 100644 index 0000000000..f6f8c9ee21 --- /dev/null +++ b/shared/source/assert_handler/CMakeLists.txt @@ -0,0 +1,13 @@ +# +# Copyright (C) 2023 Intel Corporation +# +# SPDX-License-Identifier: MIT +# + +set(NEO_CORE_ASSERT_HANDLER + ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt + ${CMAKE_CURRENT_SOURCE_DIR}/assert_handler.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/assert_handler.h +) + +set_property(GLOBAL PROPERTY NEO_CORE_ASSERT_HANDLER ${NEO_CORE_ASSERT_HANDLER}) diff --git a/shared/source/assert_handler/assert_handler.cpp b/shared/source/assert_handler/assert_handler.cpp new file mode 100644 index 0000000000..dc5109ef3e --- /dev/null +++ b/shared/source/assert_handler/assert_handler.cpp @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2023 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/assert_handler/assert_handler.h" + +#include "shared/source/device/device.h" +#include "shared/source/helpers/abort.h" +#include "shared/source/memory_manager/allocation_properties.h" +#include "shared/source/memory_manager/memory_manager.h" +#include "shared/source/program/print_formatter.h" + +namespace NEO { +AssertHandler::AssertHandler(Device *device) : device(device) { + auto rootDeviceIndex = device->getRootDeviceIndex(); + assertBuffer = device->getMemoryManager()->allocateGraphicsMemoryWithProperties({rootDeviceIndex, assertBufferSize, AllocationType::ASSERT_BUFFER, device->getDeviceBitfield()}); + + AssertBufferHeader initialHeader = {}; + initialHeader.size = assertBufferSize; + initialHeader.flags = 0; + initialHeader.begin = sizeof(AssertBufferHeader); + *reinterpret_cast(assertBuffer->getUnderlyingBuffer()) = initialHeader; +} + +AssertHandler::~AssertHandler() { + device->getMemoryManager()->freeGraphicsMemory(assertBuffer); +} + +bool AssertHandler::checkAssert() const { + return reinterpret_cast(assertBuffer->getUnderlyingBuffer())->flags != 0; +} + +void AssertHandler::printMessage() const { + + auto messageBuffer = ptrOffset(static_cast(assertBuffer->getUnderlyingBuffer()), offsetof(AssertBufferHeader, begin)); + auto messageBufferSize = static_cast(assertBuffer->getUnderlyingBufferSize()); + + NEO::PrintFormatter printfFormatter{ + messageBuffer, + messageBufferSize, + false, + nullptr}; + printfFormatter.printKernelOutput([](char *str) { printToStderr(str); }); +} + +void AssertHandler::printAssertAndAbort() { + std::lock_guard lock(this->mtx); + if (checkAssert()) { + printMessage(); + abortExecution(); + } +} +} // namespace NEO diff --git a/shared/source/assert_handler/assert_handler.h b/shared/source/assert_handler/assert_handler.h new file mode 100644 index 0000000000..db6dfda6c2 --- /dev/null +++ b/shared/source/assert_handler/assert_handler.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2023 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#pragma once +#include "shared/source/helpers/constants.h" + +#include +#include +namespace NEO { +class Device; +class GraphicsAllocation; + +#pragma pack(1) + +struct AssertBufferHeader { + uint32_t size = 0; + uint32_t flags = 0; + uint32_t begin = 0; +}; + +static_assert(sizeof(AssertBufferHeader) == 3u * sizeof(uint32_t)); + +#pragma pack() + +class AssertHandler { + public: + AssertHandler(Device *device); + MOCKABLE_VIRTUAL ~AssertHandler(); + + GraphicsAllocation *getAssertBuffer() const { + return assertBuffer; + } + + bool checkAssert() const; + void printAssertAndAbort(); + + protected: + static constexpr size_t assertBufferSize = MemoryConstants::pageSize64k; + void printMessage() const; + + std::mutex mtx; + const Device *device = nullptr; + GraphicsAllocation *assertBuffer = nullptr; +}; +} // namespace NEO diff --git a/shared/source/aub/aub_helper.h b/shared/source/aub/aub_helper.h index 650a776707..973a78b050 100644 --- a/shared/source/aub/aub_helper.h +++ b/shared/source/aub/aub_helper.h @@ -34,6 +34,7 @@ class AubHelper : public NonCopyableOrMovableClass { case AllocationType::MAP_ALLOCATION: case AllocationType::SVM_GPU: case AllocationType::GPU_TIMESTAMP_DEVICE_BUFFER: + case AllocationType::ASSERT_BUFFER: return true; default: return false; diff --git a/shared/source/execution_environment/root_device_environment.cpp b/shared/source/execution_environment/root_device_environment.cpp index 93b7dc2093..13f1d45463 100644 --- a/shared/source/execution_environment/root_device_environment.cpp +++ b/shared/source/execution_environment/root_device_environment.cpp @@ -8,6 +8,7 @@ #include "shared/source/execution_environment/root_device_environment.h" #include "shared/source/ail/ail_configuration.h" +#include "shared/source/assert_handler/assert_handler.h" #include "shared/source/aub/aub_center.h" #include "shared/source/built_ins/built_ins.h" #include "shared/source/built_ins/sip.h" @@ -224,6 +225,16 @@ GraphicsAllocation *RootDeviceEnvironment::getDummyAllocation() const { return dummyAllocation.get(); } +AssertHandler *RootDeviceEnvironment::getAssertHandler(Device *neoDevice) { + if (this->assertHandler.get() == nullptr) { + std::lock_guard autolock(this->mtx); + if (this->assertHandler.get() == nullptr) { + this->assertHandler = std::make_unique(neoDevice); + } + } + return this->assertHandler.get(); +} + template HelperType &RootDeviceEnvironment::getHelper() const { if constexpr (std::is_same_v) { diff --git a/shared/source/execution_environment/root_device_environment.h b/shared/source/execution_environment/root_device_environment.h index 5b4422dcb7..ba0ff994ef 100644 --- a/shared/source/execution_environment/root_device_environment.h +++ b/shared/source/execution_environment/root_device_environment.h @@ -15,6 +15,7 @@ #include namespace NEO { +class AssertHandler; class AubCenter; class BindlessHeapsHelper; class BuiltIns; @@ -71,6 +72,7 @@ struct RootDeviceEnvironment { MOCKABLE_VIRTUAL CompilerInterface *getCompilerInterface(); BuiltIns *getBuiltIns(); BindlessHeapsHelper *getBindlessHeapsHelper() const; + AssertHandler *getAssertHandler(Device *neoDevice); void createBindlessHeapsHelper(MemoryManager *memoryManager, bool availableDevices, uint32_t rootDeviceIndex, DeviceBitfield deviceBitfield); void limitNumberOfCcs(uint32_t numberOfCcs); bool isNumberOfCcsLimited() const; @@ -100,6 +102,7 @@ struct RootDeviceEnvironment { std::unique_ptr gfxCoreHelper; std::unique_ptr productHelper; std::unique_ptr compilerProductHelper; + std::unique_ptr assertHandler; ExecutionEnvironment &executionEnvironment; diff --git a/shared/source/helpers/app_resource_helper.cpp b/shared/source/helpers/app_resource_helper.cpp index 80c9148c30..051bed78bf 100644 --- a/shared/source/helpers/app_resource_helper.cpp +++ b/shared/source/helpers/app_resource_helper.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021-2022 Intel Corporation + * Copyright (C) 2021-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -116,6 +116,8 @@ const char *AppResourceHelper::getResourceTagStr(AllocationType type) { return "SWTAGBF"; case AllocationType::DEFERRED_TASKS_LIST: return "TSKLIST"; + case AllocationType::ASSERT_BUFFER: + return "ASSRTBUF"; default: return "NOTFOUND"; } diff --git a/shared/source/helpers/extra_allocation_data_xehp_and_later.inl b/shared/source/helpers/extra_allocation_data_xehp_and_later.inl index 9edc919c50..7edcafa50c 100644 --- a/shared/source/helpers/extra_allocation_data_xehp_and_later.inl +++ b/shared/source/helpers/extra_allocation_data_xehp_and_later.inl @@ -24,6 +24,7 @@ void GfxCoreHelperHw::setExtraAllocationData(AllocationData &allocationD if (properties.allocationType == AllocationType::LINEAR_STREAM || properties.allocationType == AllocationType::INTERNAL_HEAP || properties.allocationType == AllocationType::PRINTF_SURFACE || + properties.allocationType == AllocationType::ASSERT_BUFFER || properties.allocationType == AllocationType::GPU_TIMESTAMP_DEVICE_BUFFER || properties.allocationType == AllocationType::RING_BUFFER || properties.allocationType == AllocationType::SEMAPHORE_BUFFER) { diff --git a/shared/source/memory_manager/allocation_type.h b/shared/source/memory_manager/allocation_type.h index 273c069d68..022e011f42 100644 --- a/shared/source/memory_manager/allocation_type.h +++ b/shared/source/memory_manager/allocation_type.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Intel Corporation + * Copyright (C) 2022-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -56,6 +56,7 @@ enum class AllocationType { GPU_TIMESTAMP_DEVICE_BUFFER, SW_TAG_BUFFER, DEFERRED_TASKS_LIST, + ASSERT_BUFFER, COUNT }; } // namespace NEO diff --git a/shared/source/memory_manager/graphics_allocation.h b/shared/source/memory_manager/graphics_allocation.h index fe7b457710..7bad839f35 100644 --- a/shared/source/memory_manager/graphics_allocation.h +++ b/shared/source/memory_manager/graphics_allocation.h @@ -196,7 +196,8 @@ class GraphicsAllocation : public IDNode { allocationType == AllocationType::DEBUG_CONTEXT_SAVE_AREA || allocationType == AllocationType::DEBUG_SBA_TRACKING_BUFFER || allocationType == AllocationType::GPU_TIMESTAMP_DEVICE_BUFFER || - allocationType == AllocationType::DEBUG_MODULE_AREA; + allocationType == AllocationType::DEBUG_MODULE_AREA || + allocationType == AllocationType::ASSERT_BUFFER; } static bool isLockable(AllocationType allocationType) { return isCpuAccessRequired(allocationType) || diff --git a/shared/source/memory_manager/memory_manager.cpp b/shared/source/memory_manager/memory_manager.cpp index a149ebdb69..8cf11a8288 100644 --- a/shared/source/memory_manager/memory_manager.cpp +++ b/shared/source/memory_manager/memory_manager.cpp @@ -372,6 +372,7 @@ bool MemoryManager::getAllocationData(AllocationData &allocationData, const Allo case AllocationType::SCRATCH_SURFACE: case AllocationType::WORK_PARTITION_SURFACE: case AllocationType::WRITE_COMBINED: + case AllocationType::ASSERT_BUFFER: allow64KbPages = true; allow32Bit = true; default: diff --git a/shared/source/os_interface/linux/print.cpp b/shared/source/os_interface/linux/print.cpp index 1cd173560b..fe28b24912 100644 --- a/shared/source/os_interface/linux/print.cpp +++ b/shared/source/os_interface/linux/print.cpp @@ -11,11 +11,16 @@ #include #include -void printToSTDOUT(const char *str) { +void printToStdout(const char *str) { fprintf(stdout, "%s", str); fflush(stdout); } +void printToStderr(const char *str) { + fprintf(stderr, "%s", str); + fflush(stderr); +} + template size_t simpleSprintf(char *output, size_t outputSize, const char *format, T value) { return snprintf(output, outputSize, format, value); diff --git a/shared/source/os_interface/print.h b/shared/source/os_interface/print.h index 7cc214e6ec..ff55bd587a 100644 --- a/shared/source/os_interface/print.h +++ b/shared/source/os_interface/print.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2022 Intel Corporation + * Copyright (C) 2019-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -9,7 +9,8 @@ #include -void printToSTDOUT(const char *str); +void printToStdout(const char *str); +void printToStderr(const char *str); template size_t simpleSprintf(char *output, size_t outputSize, const char *format, T value); diff --git a/shared/source/os_interface/windows/print.cpp b/shared/source/os_interface/windows/print.cpp index 08f166123f..92a96ee8c9 100644 --- a/shared/source/os_interface/windows/print.cpp +++ b/shared/source/os_interface/windows/print.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2022 Intel Corporation + * Copyright (C) 2018-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -15,12 +15,12 @@ #include #include -void printToSTDOUT(const char *str) { +void printToStreamHandle(const char *str, DWORD handle) { int fd = 0; HANDLE stdoutDuplicate = 0; FILE *pFile = nullptr; - if ((DuplicateHandle(GetCurrentProcess(), GetStdHandle(STD_OUTPUT_HANDLE), + if ((DuplicateHandle(GetCurrentProcess(), GetStdHandle(handle), GetCurrentProcess(), &stdoutDuplicate, 0L, TRUE, DUPLICATE_SAME_ACCESS))) { if ((fd = _open_osfhandle((DWORD_PTR)stdoutDuplicate, _O_TEXT)) && (pFile = _fdopen(fd, "w"))) { @@ -32,6 +32,14 @@ void printToSTDOUT(const char *str) { } } +void printToStdout(const char *str) { + printToStreamHandle(str, STD_OUTPUT_HANDLE); +} + +void printToStderr(const char *str) { + printToStreamHandle(str, STD_ERROR_HANDLE); +} + template size_t simpleSprintf(char *output, size_t outputSize, const char *format, T value) { #if (_MSC_VER == 1800) diff --git a/shared/source/program/print_formatter.h b/shared/source/program/print_formatter.h index b59112d3ec..9302576943 100644 --- a/shared/source/program/print_formatter.h +++ b/shared/source/program/print_formatter.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2022 Intel Corporation + * Copyright (C) 2018-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -47,7 +47,7 @@ class PrintFormatter { public: PrintFormatter(const uint8_t *printfOutputBuffer, uint32_t printfOutputBufferMaxSize, bool using32BitPointers, const StringMap *stringLiteralMap = nullptr); - void printKernelOutput(const std::function &print = [](char *str) { printToSTDOUT(str); }); + void printKernelOutput(const std::function &print = [](char *str) { printToStdout(str); }); constexpr static size_t maxSinglePrintStringLength = 16 * MemoryConstants::kiloByte; diff --git a/shared/source/utilities/logger.cpp b/shared/source/utilities/logger.cpp index 323eea6ddb..dad959124d 100644 --- a/shared/source/utilities/logger.cpp +++ b/shared/source/utilities/logger.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2022 Intel Corporation + * Copyright (C) 2019-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -243,6 +243,8 @@ const char *getAllocationTypeString(GraphicsAllocation const *graphicsAllocation return "SW_TAG_BUFFER"; case AllocationType::DEFERRED_TASKS_LIST: return "DEFERRED_TASKS_LIST"; + case AllocationType::ASSERT_BUFFER: + return "ASSERT_BUFFER"; default: return "ILLEGAL_VALUE"; } diff --git a/shared/test/unit_test/assert_handler/CMakeLists.txt b/shared/test/unit_test/assert_handler/CMakeLists.txt new file mode 100644 index 0000000000..1080b8583b --- /dev/null +++ b/shared/test/unit_test/assert_handler/CMakeLists.txt @@ -0,0 +1,12 @@ +# +# Copyright (C) 2023 Intel Corporation +# +# SPDX-License-Identifier: MIT +# + +target_sources(neo_shared_tests PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt + ${CMAKE_CURRENT_SOURCE_DIR}/assert_handler_tests.cpp +) + +add_subdirectories() diff --git a/shared/test/unit_test/assert_handler/assert_handler_tests.cpp b/shared/test/unit_test/assert_handler/assert_handler_tests.cpp new file mode 100644 index 0000000000..9f27ccadab --- /dev/null +++ b/shared/test/unit_test/assert_handler/assert_handler_tests.cpp @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2023 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/assert_handler/assert_handler.h" +#include "shared/source/memory_manager/graphics_allocation.h" +#include "shared/test/common/mocks/mock_device.h" + +#include "gtest/gtest.h" + +using namespace NEO; + +struct MockAssertHandler : AssertHandler { + + using AssertHandler::assertBufferSize; + using AssertHandler::AssertHandler; +}; + +TEST(AssertHandlerTests, WhenAssertHandlerIsCreatedThenAssertBufferIsAllocated) { + auto device = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(nullptr)); + + MockAssertHandler assertHandler(device.get()); + + ASSERT_NE(nullptr, assertHandler.getAssertBuffer()); + EXPECT_EQ(assertHandler.assertBufferSize, assertHandler.getAssertBuffer()->getUnderlyingBufferSize()); + + EXPECT_EQ(0u, reinterpret_cast(assertHandler.getAssertBuffer()->getUnderlyingBuffer())->flags); + EXPECT_EQ(assertHandler.assertBufferSize, reinterpret_cast(assertHandler.getAssertBuffer()->getUnderlyingBuffer())->size); + EXPECT_EQ(sizeof(AssertBufferHeader), reinterpret_cast(assertHandler.getAssertBuffer()->getUnderlyingBuffer())->begin); +} + +TEST(AssertHandlerTests, GivenAssertHandlerWhenCheckingAssertThenReturnValuIsBasedOnFlags) { + auto device = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(nullptr)); + + MockAssertHandler assertHandler(device.get()); + + ASSERT_NE(nullptr, assertHandler.getAssertBuffer()); + + EXPECT_FALSE(assertHandler.checkAssert()); + + reinterpret_cast(assertHandler.getAssertBuffer()->getUnderlyingBuffer())->flags = 1; + EXPECT_TRUE(assertHandler.checkAssert()); +} + +TEST(AssertHandlerTests, GivenNoFlagSetWhenPrintAssertAndAbortCalledThenAbortIsNotCalled) { + if (sizeof(void *) == 4) { + GTEST_SKIP(); + } + auto device = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(nullptr)); + + MockAssertHandler assertHandler(device.get()); + ASSERT_NE(nullptr, assertHandler.getAssertBuffer()); + + reinterpret_cast(assertHandler.getAssertBuffer()->getUnderlyingBuffer())->flags = 0; + + ::testing::internal::CaptureStderr(); + assertHandler.printAssertAndAbort(); + + std::string output = testing::internal::GetCapturedStderr(); + EXPECT_STREQ("", output.c_str()); +} + +TEST(AssertHandlerTests, GivenFlagSetWhenPrintAssertAndAbortCalledThenMessageIsPrintedAndAbortCalled) { + if (sizeof(void *) == 4) { + GTEST_SKIP(); + } + auto device = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(nullptr)); + + MockAssertHandler assertHandler(device.get()); + ASSERT_NE(nullptr, assertHandler.getAssertBuffer()); + + reinterpret_cast(assertHandler.getAssertBuffer()->getUnderlyingBuffer())->flags = 1; + + char const *message = "assert!"; + auto stringAddress = ptrOffset(reinterpret_cast(assertHandler.getAssertBuffer()->getUnderlyingBuffer()), offsetof(AssertBufferHeader, begin) + sizeof(AssertBufferHeader::begin)); + auto formatStringAddress = reinterpret_cast(message); + memcpy(stringAddress, &formatStringAddress, 8); + reinterpret_cast(assertHandler.getAssertBuffer()->getUnderlyingBuffer())->size = 2 * sizeof(uint64_t); + + ::testing::internal::CaptureStderr(); + EXPECT_THROW(assertHandler.printAssertAndAbort(), std::exception); + + std::string output = testing::internal::GetCapturedStderr(); + EXPECT_STREQ("assert!", output.c_str()); +} \ No newline at end of file diff --git a/shared/test/unit_test/command_stream/aub_command_stream_receiver_1_tests.cpp b/shared/test/unit_test/command_stream/aub_command_stream_receiver_1_tests.cpp index fbd3c47995..c0aaa4108c 100644 --- a/shared/test/unit_test/command_stream/aub_command_stream_receiver_1_tests.cpp +++ b/shared/test/unit_test/command_stream/aub_command_stream_receiver_1_tests.cpp @@ -746,7 +746,8 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenWriteMe AllocationType::TIMESTAMP_PACKET_TAG_BUFFER, AllocationType::MAP_ALLOCATION, AllocationType::SVM_GPU, - AllocationType::EXTERNAL_HOST_PTR}; + AllocationType::EXTERNAL_HOST_PTR, + AllocationType::ASSERT_BUFFER}; for (auto allocationType : onlyOneTimeAubWritableTypes) { gfxAllocation->setAubWritable(true, GraphicsAllocation::defaultBank); diff --git a/shared/test/unit_test/execution_environment/execution_environment_tests.cpp b/shared/test/unit_test/execution_environment/execution_environment_tests.cpp index b7a6ce5c6b..0a90d22eb3 100644 --- a/shared/test/unit_test/execution_environment/execution_environment_tests.cpp +++ b/shared/test/unit_test/execution_environment/execution_environment_tests.cpp @@ -132,6 +132,17 @@ TEST(RootDeviceEnvironment, givenExecutionEnvironmentWhenInitializeAubCenterIsCa EXPECT_EQ(currentAubFileStream, rootDeviceEnvironment->aubCenter->getStreamProvider()->getStream()); } +TEST(RootDeviceEnvironment, givenRootExecutionEnvironmentWhenGetAssertHandlerIsCalledThenItIsInitalizedOnce) { + const HardwareInfo *hwInfo = defaultHwInfo.get(); + auto device = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(hwInfo)); + auto executionEnvironment = device->getExecutionEnvironment(); + auto rootDeviceEnvironment = executionEnvironment->rootDeviceEnvironments[0].get(); + auto assertHandler = rootDeviceEnvironment->getAssertHandler(device.get()); + + EXPECT_NE(nullptr, assertHandler); + EXPECT_EQ(assertHandler, rootDeviceEnvironment->getAssertHandler(device.get())); +} + TEST(ExecutionEnvironment, givenExecutionEnvironmentWhenInitializeMemoryManagerIsCalledThenLocalMemorySupportedInMemoryManagerHasCorrectValue) { const HardwareInfo *hwInfo = defaultHwInfo.get(); auto device = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(hwInfo)); diff --git a/shared/test/unit_test/helpers/app_resource_tests.cpp b/shared/test/unit_test/helpers/app_resource_tests.cpp index 014f797a3f..cd54a6fc9d 100644 --- a/shared/test/unit_test/helpers/app_resource_tests.cpp +++ b/shared/test/unit_test/helpers/app_resource_tests.cpp @@ -101,7 +101,8 @@ AllocationTypeTagTestCase allocationTypeTagValues[static_cast(AllocationTyp {AllocationType::UNIFIED_SHARED_MEMORY, "USHRDMEM"}, {AllocationType::GPU_TIMESTAMP_DEVICE_BUFFER, "GPUTSDBF"}, {AllocationType::SW_TAG_BUFFER, "SWTAGBF"}, - {AllocationType::DEFERRED_TASKS_LIST, "TSKLIST"}}; + {AllocationType::DEFERRED_TASKS_LIST, "TSKLIST"}, + {AllocationType::ASSERT_BUFFER, "ASSRTBUF"}}; class AllocationTypeTagString : public ::testing::TestWithParam {}; TEST_P(AllocationTypeTagString, givenGraphicsAllocationTypeWhenCopyTagToStorageInfoThenCorrectTagIsReturned) { diff --git a/shared/test/unit_test/memory_manager/memory_manager_allocate_in_preferred_pool_tests.cpp b/shared/test/unit_test/memory_manager/memory_manager_allocate_in_preferred_pool_tests.cpp index 86a93ab7b6..d9a4cad16b 100644 --- a/shared/test/unit_test/memory_manager/memory_manager_allocate_in_preferred_pool_tests.cpp +++ b/shared/test/unit_test/memory_manager/memory_manager_allocate_in_preferred_pool_tests.cpp @@ -234,7 +234,8 @@ static const AllocationType allocationTypesWith32BitAnd64KbPagesAllowed[] = {All AllocationType::PRINTF_SURFACE, AllocationType::CONSTANT_SURFACE, AllocationType::GLOBAL_SURFACE, - AllocationType::WRITE_COMBINED}; + AllocationType::WRITE_COMBINED, + AllocationType::ASSERT_BUFFER}; INSTANTIATE_TEST_CASE_P(Allow32BitAnd64kbPagesTypes, MemoryManagerGetAlloctionData32BitAnd64kbPagesAllowedTest, @@ -726,6 +727,14 @@ HWTEST_F(GetAllocationDataTestHw, givenPrintfAllocationWhenGetAllocationDataIsCa EXPECT_TRUE(allocData.flags.requiresCpuAccess); } +HWTEST_F(GetAllocationDataTestHw, givenAssertAllocationWhenGetAllocationDataIsCalledThenDontUseSystemMemoryAndRequireCpuAccess) { + AllocationData allocData; + MockMemoryManager mockMemoryManager; + AllocationProperties properties{mockRootDeviceIndex, 1, AllocationType::ASSERT_BUFFER, mockDeviceBitfield}; + mockMemoryManager.getAllocationData(allocData, properties, nullptr, mockMemoryManager.createStorageInfoFromProperties(properties)); + EXPECT_TRUE(allocData.flags.requiresCpuAccess); +} + TEST(MemoryManagerTest, givenExternalHostMemoryWhenGetAllocationDataIsCalledThenItHasProperFieldsSet) { AllocationData allocData; auto hostPtr = reinterpret_cast(0x1234); diff --git a/shared/test/unit_test/program/printf_helper_tests.cpp b/shared/test/unit_test/program/printf_helper_tests.cpp index 97802453b1..f7057d3fa5 100644 --- a/shared/test/unit_test/program/printf_helper_tests.cpp +++ b/shared/test/unit_test/program/printf_helper_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2022 Intel Corporation + * Copyright (C) 2018-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -993,9 +993,9 @@ TEST_F(PrintFormatterTest, GivenTypeSmallerThan4BThenItIsReadAs4BValue) { EXPECT_STREQ(expectedOutput, output); } -TEST(printToSTDOUTTest, GivenStringWhenPrintingToStdoutThenOutputOccurs) { +TEST(printToStdoutTest, GivenStringWhenPrintingToStdoutThenOutputOccurs) { testing::internal::CaptureStdout(); - printToSTDOUT("test"); + printToStdout("test"); std::string output = testing::internal::GetCapturedStdout(); EXPECT_STREQ("test", output.c_str()); } diff --git a/shared/test/unit_test/xe_hpg_core/dg2/memory_manager_tests_dg2.cpp b/shared/test/unit_test/xe_hpg_core/dg2/memory_manager_tests_dg2.cpp index 34b25e8540..a64aa9a670 100644 --- a/shared/test/unit_test/xe_hpg_core/dg2/memory_manager_tests_dg2.cpp +++ b/shared/test/unit_test/xe_hpg_core/dg2/memory_manager_tests_dg2.cpp @@ -22,6 +22,7 @@ HWTEST_EXCLUDE_PRODUCT(GetAllocationDataTestHw, givenInternalHeapTypeWhenGetAllo HWTEST_EXCLUDE_PRODUCT(GetAllocationDataTestHw, givenRingBufferAllocationWhenGetAllocationDataIsCalledThenItHasProperFieldsSet, IGFX_DG2); HWTEST_EXCLUDE_PRODUCT(GetAllocationDataTestHw, givenSemaphoreBufferAllocationWhenGetAllocationDataIsCalledThenItHasProperFieldsSet, IGFX_DG2); HWTEST_EXCLUDE_PRODUCT(GetAllocationDataTestHw, givenPrintfAllocationWhenGetAllocationDataIsCalledThenDontUseSystemMemoryAndRequireCpuAccess, IGFX_DG2); +HWTEST_EXCLUDE_PRODUCT(GetAllocationDataTestHw, givenAssertAllocationWhenGetAllocationDataIsCalledThenDontUseSystemMemoryAndRequireCpuAccess, IGFX_DG2); HWTEST_EXCLUDE_PRODUCT(GetAllocationDataTestHw, givenGpuTimestampDeviceBufferTypeWhenGetAllocationDataIsCalledThenSystemMemoryIsNotRequested, IGFX_DG2); HWTEST_EXCLUDE_PRODUCT(GetAllocationDataTestHw, givenPrintfAllocationWhenGetAllocationDataIsCalledThenDontForceSystemMemoryAndRequireCpuAccess, IGFX_DG2); HWTEST_EXCLUDE_PRODUCT(GetAllocationDataTestHw, givenLinearStreamAllocationWhenGetAllocationDataIsCalledThenDontForceSystemMemoryAndRequireCpuAccess, IGFX_DG2);