GCC Code Coverage Report


Directory: ./
File: Fw/Types/MemAllocator.cpp
Date: 2026-09-03 21:13:48
Exec Total Coverage
Lines: 31 32 96.9%
Functions: 11 11 100.0%
Branches: 12 18 66.7%

Line Branch Exec Source
1 /**
2 * \copyright
3 * Copyright 2009-2016, by the California Institute of Technology.
4 * ALL RIGHTS RESERVED. United States Government Sponsorship
5 * acknowledged.
6 */
7 #include <Fw/Types/Assert.hpp>
8 #include <Fw/Types/MemAllocator.hpp>
9 #include <config/MemoryAllocation.hpp>
10 #include <type_traits>
11 namespace Fw {
12
13 917 MemAllocator::MemAllocator() {}
14
15 1834 MemAllocator::~MemAllocator() {}
16
17 7630 void* MemAllocator::allocate(const FwEnumStoreType identifier, FwSizeType& size, FwSizeType alignment) {
18 7630 bool unused = false;
19
1/1
✓ Branch 6 taken 7630 times.
15260 return this->allocate(identifier, size, unused, alignment);
20 }
21
22 7702 void* MemAllocator ::checkedAllocate(const FwEnumStoreType identifier,
23 FwSizeType& size,
24 bool& recoverable,
25 FwSizeType alignment) {
26 7702 FwSizeType requestedSize = size;
27 7702 void* memory = this->allocate(identifier, size, recoverable, alignment);
28 7702 FW_ASSERT(memory != nullptr && size >= requestedSize, static_cast<FwAssertArgType>(identifier),
29 static_cast<FwAssertArgType>(requestedSize), static_cast<FwAssertArgType>(size));
30 7702 return memory;
31 }
32
33 7694 void* MemAllocator ::checkedAllocate(const FwEnumStoreType identifier, FwSizeType& size, FwSizeType alignment) {
34 7694 bool unused = false;
35
1/1
✓ Branch 4 taken 7694 times.
15388 return this->checkedAllocate(identifier, size, unused, alignment);
36 }
37
38 31 MemAllocatorRegistry::MemAllocatorRegistry() : m_defaultAllocator(MemAllocatorRegistry::getDefaultAllocator()) {
39
1/1
✓ Branch 5 taken 31 times.
31 this->registerAllocator(MemoryAllocation::MemoryAllocatorType::SYSTEM, m_defaultAllocator);
40 31 }
41
42 31 void MemAllocatorRegistry::registerAllocator(const MemoryAllocation::MemoryAllocatorType type,
43 MemAllocator& allocator) {
44 31 this->m_allocators[type] = &allocator;
45 31 }
46
47 8731 MemAllocatorRegistry& MemAllocatorRegistry::getInstance() {
48
4/7
✓ Branch 0 taken 31 times.
✓ Branch 1 taken 8700 times.
✓ Branch 3 taken 31 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 31 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
8731 static MemAllocatorRegistry registry;
49 8731 return registry;
50 }
51
52 8731 MemAllocator& MemAllocatorRegistry::getAllocator(const MemoryAllocation::MemoryAllocatorType type) {
53 8731 FW_ASSERT(this->m_allocators[type] != nullptr, static_cast<FwAssertArgType>(type));
54 8731 return *this->m_allocators[type];
55 }
56
57 8731 MemAllocator& MemAllocatorRegistry::getAnAllocator(const MemoryAllocation::MemoryAllocatorType type) {
58 // If the allocator is not registered, return the SYSTEM allocator
59
1/2
✓ Branch 6 taken 8731 times.
✗ Branch 7 not taken.
8731 if (this->m_allocators[type] == nullptr) {
60
2/2
✓ Branch 3 taken 8731 times.
✓ Branch 6 taken 8731 times.
8731 return this->getAllocator(MemoryAllocation::MemoryAllocatorType::SYSTEM);
61 }
62 return *this->m_allocators[type];
63 }
64
65 31 MemAllocator& MemAllocatorRegistry::getDefaultAllocator() {
66 static_assert(std::is_constructible<MemoryAllocation::DefaultMemoryAllocatorType>::value,
67 "DefaultMemoryAllocatorType must be constructible without arguments");
68
2/4
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 31 times.
✗ Branch 4 not taken.
31 static MemoryAllocation::DefaultMemoryAllocatorType defaultAllocator;
69 31 return defaultAllocator;
70 }
71
72 } /* namespace Fw */
73