mirror of
https://github.com/intel/compute-runtime.git
synced 2025-09-15 13:01:45 +08:00
Move drm_memory_manager_tests.h and related fixtures to shared
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:

committed by
Compute-Runtime-Automation

parent
d2a29ce458
commit
58ebebeec6
@ -11,11 +11,11 @@
|
||||
#include "shared/source/execution_environment/execution_environment.h"
|
||||
#include "shared/source/helpers/hw_helper.h"
|
||||
#include "shared/source/memory_manager/os_agnostic_memory_manager.h"
|
||||
#include "shared/test/common/fixtures/memory_management_fixture.h"
|
||||
#include "shared/test/common/helpers/engine_descriptor_helper.h"
|
||||
#include "shared/test/common/mocks/mock_device.h"
|
||||
#include "shared/test/common/mocks/mock_memory_manager.h"
|
||||
|
||||
#include "opencl/test/unit_test/fixtures/memory_management_fixture.h"
|
||||
#include "opencl/test/unit_test/mocks/mock_platform.h"
|
||||
using namespace NEO;
|
||||
|
||||
|
@ -8,11 +8,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "shared/source/gmm_helper/gmm.h"
|
||||
#include "shared/test/common/fixtures/memory_management_fixture.h"
|
||||
#include "shared/test/common/helpers/debug_manager_state_restore.h"
|
||||
#include "shared/test/common/helpers/ult_hw_config.h"
|
||||
#include "shared/test/common/helpers/variable_backup.h"
|
||||
|
||||
#include "opencl/test/unit_test/fixtures/memory_management_fixture.h"
|
||||
#include "opencl/test/unit_test/mocks/mock_platform.h"
|
||||
|
||||
using namespace NEO;
|
||||
|
@ -1,182 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018-2021 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "opencl/test/unit_test/fixtures/memory_management_fixture.h"
|
||||
|
||||
#include "shared/test/common/helpers/memory_leak_listener.h"
|
||||
#include "shared/test/common/helpers/memory_management.h"
|
||||
|
||||
#include <cinttypes>
|
||||
#if defined(__linux__)
|
||||
#include <cstdio>
|
||||
#include <cxxabi.h>
|
||||
#include <dlfcn.h>
|
||||
#include <execinfo.h>
|
||||
#elif defined(_WIN32)
|
||||
#include <windows.h>
|
||||
#pragma warning(push) // Saves the current warning state.
|
||||
#pragma warning(disable : 4091) // Temporarily disables warning 4091.
|
||||
#include <DbgHelp.h>
|
||||
#pragma warning(pop) // Restores the warning state.
|
||||
#pragma comment(lib, "Dbghelp.lib")
|
||||
#endif
|
||||
|
||||
namespace Os {
|
||||
extern const char *frontEndDllName;
|
||||
extern const char *igcDllName;
|
||||
} // namespace Os
|
||||
|
||||
void MemoryManagementFixture::SetUp() {
|
||||
EXPECT_EQ(static_cast<size_t>(-1), MemoryManagement::failingAllocation);
|
||||
MemoryManagement::indexAllocation = 0;
|
||||
MemoryManagement::indexDeallocation = 0;
|
||||
MemoryManagement::failingAllocation = -1;
|
||||
previousAllocations = MemoryManagement::numAllocations.load();
|
||||
MemoryManagement::logTraces = MemoryManagement::captureCallStacks;
|
||||
}
|
||||
|
||||
void MemoryManagementFixture::TearDown() {
|
||||
clearFailingAllocation();
|
||||
checkForLeaks();
|
||||
MemoryManagement::logTraces = false;
|
||||
}
|
||||
|
||||
void MemoryManagementFixture::setFailingAllocation(size_t allocation) {
|
||||
MemoryManagement::indexAllocation = 0;
|
||||
MemoryManagement::failingAllocation = allocation;
|
||||
}
|
||||
|
||||
void MemoryManagementFixture::clearFailingAllocation() {
|
||||
MemoryManagement::failingAllocation = -1;
|
||||
}
|
||||
|
||||
::testing::AssertionResult MemoryManagementFixture::assertLeak(
|
||||
const char *leakExpr,
|
||||
size_t leakIndex) {
|
||||
using MemoryManagement::AllocationEvent;
|
||||
using MemoryManagement::eventsAllocated;
|
||||
|
||||
if (leakIndex == MemoryManagement::invalidLeakIndex) {
|
||||
return ::testing::AssertionSuccess();
|
||||
}
|
||||
auto &event = eventsAllocated[leakIndex];
|
||||
|
||||
switch (event.event) {
|
||||
case AllocationEvent::EVENT_DELETE:
|
||||
return ::testing::AssertionFailure() << "event[" << leakIndex
|
||||
<< "]: delete doesn't have corresponding new. allocation address="
|
||||
<< event.address
|
||||
<< ", allocation size=" << event.size << printCallStack(event);
|
||||
break;
|
||||
case AllocationEvent::EVENT_DELETE_ARRAY:
|
||||
return ::testing::AssertionFailure() << "event[" << leakIndex
|
||||
<< "]: delete[] doesn't have corresponding new[]. allocation address="
|
||||
<< event.address
|
||||
<< ", allocation size=" << event.size << printCallStack(event);
|
||||
break;
|
||||
case AllocationEvent::EVENT_NEW:
|
||||
return ::testing::AssertionFailure() << "event[" << leakIndex
|
||||
<< "]: new doesn't have corresponding delete. allocation address="
|
||||
<< event.address
|
||||
<< ", allocation size=" << event.size << printCallStack(event);
|
||||
break;
|
||||
case AllocationEvent::EVENT_NEW_NOTHROW:
|
||||
return ::testing::AssertionFailure() << "event[" << leakIndex
|
||||
<< "]: new (std::nothrow) doesn't have corresponding delete. allocation address="
|
||||
<< event.address
|
||||
<< ", allocation size=" << event.size << printCallStack(event);
|
||||
break;
|
||||
case AllocationEvent::EVENT_NEW_ARRAY:
|
||||
return ::testing::AssertionFailure() << "event[" << leakIndex
|
||||
<< "]: new [] doesn't have corresponding delete[]. allocation address="
|
||||
<< event.address
|
||||
<< ", allocation size=" << event.size << printCallStack(event);
|
||||
break;
|
||||
case AllocationEvent::EVENT_NEW_ARRAY_NOTHROW:
|
||||
return ::testing::AssertionFailure() << "event[" << leakIndex
|
||||
<< "] new (std::nothrow) [] doesn't have corresponding delete[]. allocation address="
|
||||
<< event.address
|
||||
<< ", allocation size=" << event.size << printCallStack(event);
|
||||
break;
|
||||
case AllocationEvent::EVENT_NEW_ARRAY_NOTHROW_FAIL:
|
||||
case AllocationEvent::EVENT_NEW_ARRAY_FAIL:
|
||||
case AllocationEvent::EVENT_NEW_NOTHROW_FAIL:
|
||||
case AllocationEvent::EVENT_NEW_FAIL:
|
||||
case AllocationEvent::EVENT_UNKNOWN:
|
||||
default:
|
||||
return ::testing::AssertionFailure() << "Unknown event[" << leakIndex << "] detected. allocation size=" << event.size;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void MemoryManagementFixture::checkForLeaks() {
|
||||
// We have to alias MemoryManagement::numAllocations because
|
||||
// the following EXPECT_EQ actually allocates more memory :-)
|
||||
auto currentAllocations = MemoryManagement::numAllocations.load();
|
||||
auto indexAllocationTop = MemoryManagement::indexAllocation.load();
|
||||
auto indexDellocationTop = MemoryManagement::indexDeallocation.load();
|
||||
if (previousAllocations != currentAllocations) {
|
||||
auto testInfo = ::testing::UnitTest::GetInstance()->current_test_info();
|
||||
auto testResult = testInfo->result();
|
||||
if (testResult->Passed()) {
|
||||
//EXPECT_EQ(previousAllocations, currentAllocations);
|
||||
size_t leakEventIndex;
|
||||
do {
|
||||
leakEventIndex = MemoryManagement::enumerateLeak(indexAllocationTop, indexDellocationTop, false, false);
|
||||
EXPECT_PRED_FORMAT1(assertLeak, leakEventIndex);
|
||||
auto invalidLeakIndexValues = MemoryManagement::invalidLeakIndex;
|
||||
EXPECT_EQ(leakEventIndex, invalidLeakIndexValues);
|
||||
} while (leakEventIndex != MemoryManagement::invalidLeakIndex);
|
||||
} else {
|
||||
printf("*** WARNING: Leaks found but dumping disabled during test failure ***\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MemoryManagementFixture::injectFailures(InjectedFunction &method, uint32_t maxIndex) {
|
||||
MemoryManagement::indexAllocation = 0;
|
||||
method(-1);
|
||||
auto numCurrentAllocations = MemoryManagement::indexAllocation.load();
|
||||
|
||||
for (auto i = 0u; i < numCurrentAllocations; i++) {
|
||||
// Force a failure
|
||||
MemoryManagement::indexAllocation = numCurrentAllocations;
|
||||
MemoryManagement::failingAllocation = i + numCurrentAllocations;
|
||||
if (MemoryManagement::eventsAllocated[i].event == MemoryManagement::AllocationEvent::EVENT_NEW ||
|
||||
MemoryManagement::eventsAllocated[i].event == MemoryManagement::AllocationEvent::EVENT_NEW_ARRAY) {
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (maxIndex != 0 && i > maxIndex) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Call the method under test
|
||||
method(i);
|
||||
|
||||
// Restore allocations
|
||||
MemoryManagement::failingAllocation = -1;
|
||||
}
|
||||
MemoryManagement::failingAllocation = -1;
|
||||
}
|
||||
|
||||
void MemoryManagementFixture::injectFailureOnIndex(InjectedFunction &method, uint32_t index) {
|
||||
MemoryManagement::indexAllocation = 0;
|
||||
method(-1);
|
||||
auto numCurrentAllocations = MemoryManagement::indexAllocation.load();
|
||||
|
||||
// Force a failure
|
||||
MemoryManagement::indexAllocation = numCurrentAllocations;
|
||||
MemoryManagement::failingAllocation = index + numCurrentAllocations;
|
||||
|
||||
// Call the method under test
|
||||
method(index);
|
||||
|
||||
// Restore allocations
|
||||
MemoryManagement::failingAllocation = -1;
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018-2021 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "shared/test/common/helpers/memory_management.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include <functional>
|
||||
|
||||
struct MemoryManagementFixture {
|
||||
MemoryManagementFixture() {
|
||||
MemoryManagement::detailedAllocationLoggingActive = true;
|
||||
};
|
||||
virtual ~MemoryManagementFixture() { MemoryManagement::detailedAllocationLoggingActive = false; };
|
||||
|
||||
// Typical Fixture methods
|
||||
virtual void SetUp(void);
|
||||
virtual void TearDown(void);
|
||||
|
||||
// Helper methods
|
||||
void setFailingAllocation(size_t allocation);
|
||||
void clearFailingAllocation(void);
|
||||
|
||||
::testing::AssertionResult assertLeak(
|
||||
const char *leakExpr,
|
||||
size_t leakIndex);
|
||||
|
||||
void checkForLeaks(void);
|
||||
|
||||
typedef std::function<void(size_t)> InjectedFunction;
|
||||
void injectFailures(InjectedFunction &method, uint32_t maxIndex = 0);
|
||||
void injectFailureOnIndex(InjectedFunction &method, uint32_t index);
|
||||
|
||||
// Used to keep track of # of allocations prior at SetUp time
|
||||
// Gets compared to # at TearDown time
|
||||
size_t previousAllocations;
|
||||
};
|
@ -8,10 +8,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "shared/source/command_stream/command_stream_receiver.h"
|
||||
#include "shared/test/common/fixtures/memory_management_fixture.h"
|
||||
|
||||
#include "opencl/test/unit_test/command_queue/command_queue_fixture.h"
|
||||
#include "opencl/test/unit_test/command_stream/command_stream_fixture.h"
|
||||
#include "opencl/test/unit_test/fixtures/memory_management_fixture.h"
|
||||
#include "opencl/test/unit_test/fixtures/simple_arg_kernel_fixture.h"
|
||||
|
||||
namespace NEO {
|
||||
|
Reference in New Issue
Block a user