F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
TestUtils.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title CcsdsTestUtils.cpp
3 // \author bocchino
4 // \brief Test utilities for CCSDS
5 // ======================================================================
6 
8 #include "STest/Random/Random.hpp"
9 
10 namespace Svc {
11 
12 namespace CcsdsTestUtils {
13 
16 
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  for (SerialType candidateApid = 0; candidateApid <= bound; candidateApid++) {
31  if (ComCfg::Apid::isValid(candidateApid)) {
32  // Found a valid APID: store it
33  apid = candidateApid;
34  if (idx == selectedIdx) {
35  // We are at the selected index: done
36  break;
37  }
38  // Not yet at the selected index: keep going
39  // We'll either go onto the next valid APID or use the current one
40  // if we run off the end of the 11-bit range
41  idx++;
42  }
43  }
44  // If the APID we found is not valid, then return NONE
45  // This can happen if all of the configured APIDs are out of the 11-bit range
46  // required by CCSDS
47  const auto result = ComCfg::Apid::isValid(apid) ? ApidOption(static_cast<ComCfg::Apid::T>(apid)) : Fw::NONE;
48  return result;
49 }
50 
51 } // namespace CcsdsTestUtils
52 
53 } // namespace Svc
The number of enumerated constants.
Definition: ApidEnumAc.hpp:70
Fw::Optional< ComCfg::Apid::T > ApidOption
Definition: TestUtils.cpp:15
U16 SerialType
The serial representation type.
Definition: ApidEnumAc.hpp:29
ApidOption getRandomApid()
Definition: TestUtils.cpp:17
constexpr None_t NONE
Global constant representing an absent/empty optional value.
Definition: Optional.hpp:31
static U32 min(const U32 a, const U32 b)
Definition: Checksum.cpp:16
RateGroupDivider component implementation.
bool isValid() const
Check raw enum value for validity.
Definition: ApidEnumAc.cpp:57
ComCfg::Apid::SerialType SerialType
Definition: TestUtils.cpp:14
A type-safe container for an optional value.
Definition: Optional.hpp:43