GCC Code Coverage Report


Directory: Svc/Ccsds/TestUtils/
File: TestUtils.cpp
Date: 2026-09-03 21:16:39
Exec Total Coverage
Lines: 0 15 0.0%
Functions: 0 1 0.0%
Branches: 0 18 0.0%

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 ApidOption getRandomApid() {
18 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 constexpr auto ccsdsBound = static_cast<SerialType>((1 << 11) - 1); // 11 bits
24 constexpr auto serialTypeBound = std::numeric_limits<SerialType>::max();
25 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 SerialType idx = 0;
29 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 for (SerialType candidateApid = 0; candidateApid < bound || candidateApid == bound; candidateApid++) {
33 if (ComCfg::Apid::isValid(candidateApid)) {
34 // Found a valid APID: store it
35 apid = candidateApid;
36 if (idx == selectedIdx) {
37 // We are at the selected index: done
38 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 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 const auto result = ComCfg::Apid::isValid(apid) ? ApidOption(static_cast<ComCfg::Apid::T>(apid)) : Fw::NONE;
50 return result;
51 }
52
53 } // namespace CcsdsTestUtils
54
55 } // namespace Svc
56