GCC Code Coverage Report


Directory: ./
File: Svc/Ccsds/TestUtils/TestUtils.cpp
Date: 2026-09-03 21:13:48
Exec Total Coverage
Lines: 15 15 100.0%
Functions: 1 1 100.0%
Branches: 13 18 72.2%

Line Branch Exec Source
1 // ======================================================================
2 // \title CcsdsTestUtils.cpp
3 // \author bocchino
4 // \brief Test utilities for CCSDS
5 // ======================================================================
6
7 #include "Svc/Ccsds/TestUtils/TestUtils.hpp"
8 #include "STest/Random/Random.hpp"
9
10 namespace Svc {
11
12 namespace CcsdsTestUtils {
13
14 using SerialType = ComCfg::Apid::SerialType;
15 using ApidOption = Fw::Optional<ComCfg::Apid::T>;
16
17 2455 ApidOption getRandomApid() {
18
1/1
✓ Branch 1 taken 2455 times.
2455 const SerialType selectedIdx = static_cast<SerialType>(STest::Random::startLength(0, ComCfg::Apid::NUM_CONSTANTS));
19 // Choose from within the bounds provided by CCSDS and the SerialType.
20 // 1. We have to respect the CCSDS bound because we are testing CCSDS code
21 // 2. We have to respect the SerialType bound because F Prime may not be configured
22 // to use CCSDS, but we still want the test to be valid, if possible.
23 2455 constexpr auto ccsdsBound = static_cast<SerialType>((1 << 11) - 1); // 11 bits
24 2455 constexpr auto serialTypeBound = std::numeric_limits<SerialType>::max();
25 2455 constexpr auto bound = std::min(ccsdsBound, serialTypeBound);
26 // Search through the interval [0, maxApid] until we find a valid APID at the
27 // selected index, or we run out of numbers
28 2455 SerialType idx = 0;
29 2455 SerialType apid = 0;
30 // Break the loop checking into two operations so that g++ can't report a Wtype-limits warning
31 // when bound is the type max (since neither individual check is always true, but <= would be)
32
4/4
✓ Branch 0 taken 891092 times.
✓ Branch 1 taken 580 times.
✓ Branch 2 taken 380 times.
✓ Branch 3 taken 200 times.
891672 for (SerialType candidateApid = 0; candidateApid < bound || candidateApid == bound; candidateApid++) {
33
3/3
✓ Branch 1 taken 891472 times.
✓ Branch 3 taken 15568 times.
✓ Branch 4 taken 875904 times.
891472 if (ComCfg::Apid::isValid(candidateApid)) {
34 // Found a valid APID: store it
35 15568 apid = candidateApid;
36
2/2
✓ Branch 0 taken 2255 times.
✓ Branch 1 taken 13313 times.
15568 if (idx == selectedIdx) {
37 // We are at the selected index: done
38 2255 break;
39 }
40 // Not yet at the selected index: keep going
41 // We'll either go onto the next valid APID or use the current one
42 // if we run off the end of the 11-bit range
43 13313 idx++;
44 }
45 }
46 // If the APID we found is not valid, then return NONE
47 // This can happen if all of the configured APIDs are out of the 11-bit range
48 // required by CCSDS
49
3/8
✓ Branch 1 taken 2455 times.
✓ Branch 3 taken 2455 times.
✗ Branch 4 not taken.
✗ Branch 9 not taken.
✓ Branch 11 taken 2455 times.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
2455 const auto result = ComCfg::Apid::isValid(apid) ? ApidOption(static_cast<ComCfg::Apid::T>(apid)) : Fw::NONE;
50 4910 return result;
51 }
52
53 } // namespace CcsdsTestUtils
54
55 } // namespace Svc
56