GCC Code Coverage Report


Directory: ./
File: Os/Linux/Memory.cpp
Date: 2026-09-23 22:11:34
Exec Total Coverage
Lines: 9 14 64.3%
Functions: 1 2 50.0%
Branches: 2 4 50.0%

Line Branch Exec Source
1 // ======================================================================
2 // \title Os/Linux/Memory.cpp
3 // \brief Linux implementation for Os::Memory
4 // ======================================================================
5 #include <sys/sysinfo.h>
6 #include <Fw/Types/Assert.hpp>
7 #include <Os/Linux/Memory.hpp>
8 #include <cstdio>
9 #include <limits>
10 namespace Os {
11 namespace Linux {
12 namespace Memory {
13
14 241 MemoryInterface::Status LinuxMemory::_getUsage(Os::Memory::Usage& memory_usage) {
15 struct sysinfo info;
16 // Only error in sysinfo call is invalid address
17 241 const int sysinfoStatus = sysinfo(&info);
18 241 FW_ASSERT(sysinfoStatus == 0);
19 241 FW_ASSERT(info.mem_unit > 0);
20 241 const FwSizeType MAX_MEASURABLE_RAM_UNITS = std::numeric_limits<FwSizeType>::max() / info.mem_unit;
21
2/4
✓ Branch 0 taken 241 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 241 times.
241 if ((MAX_MEASURABLE_RAM_UNITS < info.totalram) || (MAX_MEASURABLE_RAM_UNITS < info.freeram)) {
22 ✗ memory_usage.total = 1;
23 ✗ memory_usage.used = 1;
24 ✗ return Status::ERROR;
25 }
26
27 241 memory_usage.total = info.totalram * info.mem_unit;
28 241 memory_usage.used = (info.totalram - info.freeram) * info.mem_unit;
29 241 return Status::OP_OK;
30 }
31
32 ✗ MemoryHandle* LinuxMemory::getHandle() {
33 ✗ return &this->m_handle;
34 }
35
36 } // namespace Memory
37 } // namespace Linux
38 } // namespace Os
39