GCC Code Coverage Report


Directory: ./
File: Os/Console.cpp
Date: 2026-09-03 21:13:48
Exec Total Coverage
Lines: 36 42 85.7%
Functions: 9 11 81.8%
Branches: 12 19 63.2%

Line Branch Exec Source
1 // ======================================================================
2 // \title Os/Console.cpp
3 // \brief common function implementation for Os::Console
4 // ======================================================================
5 #include <Fw/Types/Assert.hpp>
6 #include <Os/Console.hpp>
7
8 namespace Os {
9 16 Console::Console()
10 : ConsoleInterface(),
11 Fw::Logger(),
12
2/2
✓ Branch 3 taken 384 times.
✓ Branch 4 taken 16 times.
400 m_handle_storage(),
13
1/1
✓ Branch 17 taken 16 times.
32 m_delegate(*ConsoleInterface::getDelegate(m_handle_storage)) {}
14
15 36 Console::~Console() {
16 34 FW_ASSERT(&this->m_delegate == reinterpret_cast<ConsoleInterface*>(&this->m_handle_storage[0]));
17 34 m_delegate.~ConsoleInterface();
18 36 }
19
20 1 Console::Console(const Console& other)
21
3/3
✓ Branch 16 taken 24 times.
✓ Branch 17 taken 1 times.
✓ Branch 27 taken 1 times.
25 : m_handle_storage(), m_delegate(*Console::getDelegate(m_handle_storage, &other.m_delegate)) {
22 1 FW_ASSERT(&this->m_delegate == reinterpret_cast<Console*>(&this->m_handle_storage[0]));
23 1 }
24
25 1 Console& Console::operator=(const Console& other) {
26 1 FW_ASSERT(&this->m_delegate == reinterpret_cast<Console*>(&this->m_handle_storage[0]));
27
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (this != &other) {
28 1 this->m_delegate = *ConsoleInterface::getDelegate(m_handle_storage, &other.m_delegate);
29 }
30 1 return *this;
31 }
32
33 1 void Console::writeMessage(const CHAR* message, const FwSizeType size) {
34 1 FW_ASSERT(&this->m_delegate == reinterpret_cast<ConsoleInterface*>(&this->m_handle_storage));
35 1 FW_ASSERT(message != nullptr || size == 0);
36 1 this->m_delegate.writeMessage(message, size);
37 1 }
38
39 void Console::writeMessage(const Fw::ConstStringBase& message) {
40 this->writeMessage(message.toChar(), message.length());
41 }
42
43 2 ConsoleHandle* Console::getHandle() {
44 2 FW_ASSERT(&this->m_delegate == reinterpret_cast<ConsoleInterface*>(&this->m_handle_storage));
45 2 return this->m_delegate.getHandle();
46 }
47
48 1 void Console::write(const CHAR* message, const FwSizeType size) {
49 1 Console::getSingleton().writeMessage(message, size);
50 1 }
51
52 void Console::write(const Fw::ConstStringBase& message) {
53 Console::getSingleton().writeMessage(message.toChar(), message.length());
54 }
55
56 3 void Console::init() {
57 // Force trigger on the fly singleton setup
58 3 (void)Console::getSingleton();
59 3 }
60
61 4 Console& Console::getSingleton() {
62
3/7
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 4 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
4 static Console s_singleton;
63 // Registration happens once: re-registering on every access would silently replace a
64 // logger the project registered after the console singleton was first used
65 static bool s_registered = false;
66
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 if (not s_registered) {
67 4 s_registered = true;
68 4 Fw::Logger::registerLogger(&s_singleton);
69 }
70 4 return s_singleton;
71 }
72 } // namespace Os
73