2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2022-05-10 01:40:30 +08:00
|
|
|
* Copyright (C) 2018-2022 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-09-18 15:11:08 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
2021-01-21 20:10:13 +08:00
|
|
|
#include "shared/test/common/helpers/memory_management.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
#include <functional>
|
|
|
|
|
|
|
|
struct MemoryManagementFixture {
|
2018-08-16 20:35:38 +08:00
|
|
|
MemoryManagementFixture() {
|
|
|
|
MemoryManagement::detailedAllocationLoggingActive = true;
|
|
|
|
};
|
|
|
|
virtual ~MemoryManagementFixture() { MemoryManagement::detailedAllocationLoggingActive = false; };
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
// Typical Fixture methods
|
2022-08-12 22:24:49 +08:00
|
|
|
void setUp();
|
|
|
|
void tearDown();
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
// Helper methods
|
|
|
|
void setFailingAllocation(size_t allocation);
|
2022-08-12 22:24:49 +08:00
|
|
|
void clearFailingAllocation();
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
::testing::AssertionResult assertLeak(
|
2020-03-12 14:54:21 +08:00
|
|
|
const char *leakExpr,
|
2017-12-21 07:45:38 +08:00
|
|
|
size_t leakIndex);
|
|
|
|
|
2022-08-12 22:24:49 +08:00
|
|
|
void checkForLeaks();
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
typedef std::function<void(size_t)> InjectedFunction;
|
|
|
|
void injectFailures(InjectedFunction &method, uint32_t maxIndex = 0);
|
2020-03-12 14:54:21 +08:00
|
|
|
void injectFailureOnIndex(InjectedFunction &method, uint32_t index);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
// Used to keep track of # of allocations prior at SetUp time
|
|
|
|
// Gets compared to # at TearDown time
|
|
|
|
size_t previousAllocations;
|
|
|
|
};
|