GCC Code Coverage Report


Directory: ./
File: Os/Linux/Memory.cpp
Date: 2026-09-03 21:13:48
Exec Total Coverage
Lines: 10 15 66.7%
Functions: 1 2 50.0%
Branches: 3 6 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 5 MemoryInterface::Status LinuxMemory::_getUsage(Os::Memory::Usage& memory_usage) {
15 5 struct sysinfo info;
16 // Only error in sysinfo call is invalid address
17 5 const int sysinfoStatus = sysinfo(&info);
18 5 FW_ASSERT(sysinfoStatus == 0);
19 5 FW_ASSERT(info.mem_unit > 0);
20
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 const FwSizeType MAX_MEASURABLE_RAM_UNITS = std::numeric_limits<FwSizeType>::max() / info.mem_unit;
21
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
5 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 5 memory_usage.total = info.totalram * info.mem_unit;
28 5 memory_usage.used = (info.totalram - info.freeram) * info.mem_unit;
29 5 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