mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-12 00:59:38 +08:00
feature: add AssertHandler
- initial implementation to support assert() on GPU Related-To: NEO-5753 Signed-off-by: Mateusz Hoppe <mateusz.hoppe@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
49b01a8ea4
commit
37dbec305d
12
shared/test/unit_test/assert_handler/CMakeLists.txt
Normal file
12
shared/test/unit_test/assert_handler/CMakeLists.txt
Normal file
@@ -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()
|
||||
@@ -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>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr));
|
||||
|
||||
MockAssertHandler assertHandler(device.get());
|
||||
|
||||
ASSERT_NE(nullptr, assertHandler.getAssertBuffer());
|
||||
EXPECT_EQ(assertHandler.assertBufferSize, assertHandler.getAssertBuffer()->getUnderlyingBufferSize());
|
||||
|
||||
EXPECT_EQ(0u, reinterpret_cast<AssertBufferHeader *>(assertHandler.getAssertBuffer()->getUnderlyingBuffer())->flags);
|
||||
EXPECT_EQ(assertHandler.assertBufferSize, reinterpret_cast<AssertBufferHeader *>(assertHandler.getAssertBuffer()->getUnderlyingBuffer())->size);
|
||||
EXPECT_EQ(sizeof(AssertBufferHeader), reinterpret_cast<AssertBufferHeader *>(assertHandler.getAssertBuffer()->getUnderlyingBuffer())->begin);
|
||||
}
|
||||
|
||||
TEST(AssertHandlerTests, GivenAssertHandlerWhenCheckingAssertThenReturnValuIsBasedOnFlags) {
|
||||
auto device = std::unique_ptr<MockDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr));
|
||||
|
||||
MockAssertHandler assertHandler(device.get());
|
||||
|
||||
ASSERT_NE(nullptr, assertHandler.getAssertBuffer());
|
||||
|
||||
EXPECT_FALSE(assertHandler.checkAssert());
|
||||
|
||||
reinterpret_cast<AssertBufferHeader *>(assertHandler.getAssertBuffer()->getUnderlyingBuffer())->flags = 1;
|
||||
EXPECT_TRUE(assertHandler.checkAssert());
|
||||
}
|
||||
|
||||
TEST(AssertHandlerTests, GivenNoFlagSetWhenPrintAssertAndAbortCalledThenAbortIsNotCalled) {
|
||||
if (sizeof(void *) == 4) {
|
||||
GTEST_SKIP();
|
||||
}
|
||||
auto device = std::unique_ptr<MockDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr));
|
||||
|
||||
MockAssertHandler assertHandler(device.get());
|
||||
ASSERT_NE(nullptr, assertHandler.getAssertBuffer());
|
||||
|
||||
reinterpret_cast<AssertBufferHeader *>(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>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr));
|
||||
|
||||
MockAssertHandler assertHandler(device.get());
|
||||
ASSERT_NE(nullptr, assertHandler.getAssertBuffer());
|
||||
|
||||
reinterpret_cast<AssertBufferHeader *>(assertHandler.getAssertBuffer()->getUnderlyingBuffer())->flags = 1;
|
||||
|
||||
char const *message = "assert!";
|
||||
auto stringAddress = ptrOffset(reinterpret_cast<uint64_t *>(assertHandler.getAssertBuffer()->getUnderlyingBuffer()), offsetof(AssertBufferHeader, begin) + sizeof(AssertBufferHeader::begin));
|
||||
auto formatStringAddress = reinterpret_cast<uint64_t>(message);
|
||||
memcpy(stringAddress, &formatStringAddress, 8);
|
||||
reinterpret_cast<AssertBufferHeader *>(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());
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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<Device>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(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<Device>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(hwInfo));
|
||||
|
||||
@@ -101,7 +101,8 @@ AllocationTypeTagTestCase allocationTypeTagValues[static_cast<int>(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<AllocationTypeTagTestCase> {};
|
||||
|
||||
TEST_P(AllocationTypeTagString, givenGraphicsAllocationTypeWhenCopyTagToStorageInfoThenCorrectTagIsReturned) {
|
||||
|
||||
@@ -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<void *>(0x1234);
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user