GCC Code Coverage Report


Directory: ./
File: unit_tests/test-framework/unit_test_logger.cpp
Date: 2025-11-16 14:52:24
Coverage Exec Excl Total
Lines: 100.0% 22 0 22
Functions: 100.0% 4 0 4
Branches: 95.2% 20 0 21
Decisions: 83.3% 5 - 6

Line Branch Decision Exec Source
1 #include "pch.h"
2
3 #include "unit_test_logger.h"
4 #include "binary_mlg_logging.h"
5
6 FILE *mslFile = nullptr;
7
8 struct UnitTestLogBufferWriter final : public BufferedWriter<512> {
9 bool failed = false;
10
11 1685625 size_t writeInternal(const char *buffer, size_t count) override {
12 1685625 return fwrite(buffer, 1, count, mslFile);
13 }
14 };
15
16 static UnitTestLogBufferWriter unitTestLogWriter;
17
18 531078 void writeUnitTestLogLine() {
19
1/2
✓ Branch 0 taken 531078 times.
✗ Branch 1 not taken.
1/2
✓ Decision 'true' taken 531078 times.
✗ Decision 'false' not taken.
531078 if (mslFile != nullptr) {
20 531078 MLG::writeSdLogLine(unitTestLogWriter);
21 }
22 531078 }
23
24 590 void createUnitTestLog() {
25
2/2
✓ Branch 1 taken 590 times.
✓ Branch 4 taken 590 times.
590 auto testInfo = ::testing::UnitTest::GetInstance()->current_test_info();
26
1/1
✓ Branch 2 taken 590 times.
590 std::stringstream filePath;
27 filePath << TEST_RESULTS_DIR << "/unittest_" << testInfo->test_case_name()
28
6/6
✓ Branch 1 taken 590 times.
✓ Branch 4 taken 590 times.
✓ Branch 8 taken 590 times.
✓ Branch 11 taken 590 times.
✓ Branch 15 taken 590 times.
✓ Branch 18 taken 590 times.
590 << "_" << testInfo->name() << ".msl";
29 // fun fact: ASAN says not to extracjsonTracet 'fileName' into a variable, we must be doing something a bit not right?
30
2/2
✓ Branch 2 taken 590 times.
✓ Branch 6 taken 590 times.
590 mslFile = fopen(filePath.str().c_str(), "wb");
31
2/2
✓ Branch 0 taken 564 times.
✓ Branch 1 taken 26 times.
2/2
✓ Decision 'true' taken 564 times.
✓ Decision 'false' taken 26 times.
590 if (mslFile != nullptr) {
32
2/2
✓ Branch 2 taken 564 times.
✓ Branch 6 taken 564 times.
564 printf("Writing [%s]\n", filePath.str().c_str());
33
1/1
✓ Branch 1 taken 564 times.
564 MLG::resetFileLogging();
34
1/1
✓ Branch 1 taken 564 times.
564 MLG::writeSdLogLine(unitTestLogWriter);
35 }
36 1180 }
37
38 590 void closeUnitTestLog() {
39
2/2
✓ Branch 0 taken 564 times.
✓ Branch 1 taken 26 times.
2/2
✓ Decision 'true' taken 564 times.
✓ Decision 'false' taken 26 times.
590 if (mslFile != nullptr) {
40 564 unitTestLogWriter.flush();
41 564 fclose(mslFile);
42 564 mslFile = nullptr;
43 }
44 590 }
45