2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2021-05-17 02:51:16 +08:00
|
|
|
* Copyright (C) 2018-2021 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
|
|
|
|
virtual void SetUp(void);
|
|
|
|
virtual void TearDown(void);
|
|
|
|
|
|
|
|
// Helper methods
|
|
|
|
void setFailingAllocation(size_t allocation);
|
|
|
|
void clearFailingAllocation(void);
|
|
|
|
|
|
|
|
::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);
|
|
|
|
|
|
|
|
void checkForLeaks(void);
|
|
|
|
|
|
|
|
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;
|
|
|
|
};
|