mirror of
https://github.com/nasa/fprime.git
synced 2025-12-10 16:29:04 -06:00
FPP v2.3.0a1 (#3066)
* Update requirements to use new fpp version * Removed unneeded files * update FppTest for new autocoder changes * Get unit tests updated and working for fpp state machines phase 1 delivery * Rename Fw/SMTest to Fw/Sm * Update STARS to use FW_ASSERT * Rename SMSignalBuffer to SmSignalBuffer * Fix spelling issues with CI * Update requirements to the FPP alpha release v2.2.0a3 * Fix requirements.txt * Fix requirements.txt * Initialize data in the constructor of SmSignalBuffer * Add constructor list to all the constructors in SmSignalBuffer * Reorganize FppTest directories Move external state machine tests to state_machine/external * Add missing file * Reorganize FppTest/state_machine external --> external_instance * Add state machine test harness * Revise SmGuard * Fix include guard * Add header file for test harness * Revise Basic state machine * Revise Basic test * Add Junction test * Add missing file * Refactor internal state machine tests * Add Nested state machine * Revise Nested test * Revise state machine tests * Fix issues in string utils * Revise FppTest Add signals to state machine tests * Refactor state machine test harness * Revise autocode for Basic test Replace with actual autocode * Update fpp version Fix F Prime to match Switch initial/basic test from checked-in to auto-generated * Revise FppTest Make state machine guards const * Update fpp version Convert initial/Junction test to autocode * Update fpp version Make initial/nested test use autocode * Start to add State/Basic test * Revise FppTest Revise namespaces in state machine tests * Revise SmState::Basic test * Update fpp version Convert SmState/Basic test to use autocoding * Update FppTest * Add SmState/BasicSelf test * Add state/BasicGuard test * Add SmState/BasicU32 test * Revise state machine tests * Refactor state machine tests * Revise FppTest * Revise comments * Refactor state machine tests * Refactor state machine tests * Refactor state machine tests * Refactor state machine tests * Revise state machine tests * Revise state machine tests * Revise state machine tests * Revise state machine tests * Revise fpp tests * Revise state machine tests * Revise state machine tests * Revise state machine tests * Revise state machine tests * Revise state machine tests * Add README files to FPP tests * Start to add StateToState test * Revise StateToState test * Revise StateToState test * Revise StateToState test * Revise StateToState test * Revise StateToState test Remove hand-generated files * Revise StateToState tests * Add BasicInternal test * Update fpp version * Revise state machine tests * Add state-to-junction test * Add Internal state machine test * Add Polymorphism test * Add StateToChild test * Revise README files * Add junction/Basic test * Revise FppTest build * Update fpp version; revise Basic test * Revise junction tests * Add BasicGuardU32 test * Add BasicGuardString test * Add BasicGuardTestAbsType test * Add BasicGuardTestArray test * Add BasicGuardTestEnum test * Add BasicGuardTestStruct test * Add junction/Sequence test * Add junction/SequenceU32 test * Add junction/InputPairU16U32 test * Add JunctionToState.fpp * Add junction/JunctionToState test * Add junction/JunctionToJunction test * Update fpp version * Update fpp version Revise test code to match * Update fpp version * Update fpp version * Fix CMakeLists * Update fpp version * Update fpp version * Refactor sm tests * Refactor sm tests * Refactor sm tests * Update fpp version * Start to add internal_instance tests * Add missing files * Revise state machine tests * Revise state machine tests * Revise sm instance initial tests * Revise sm instance init tests * Revise sm instance initial tests * Revise sm instance initial tests * Add sm instance state tests * Revise sm instance state tests * Revise sm instance state tests * Revise sm instance state tests * Revise sm instance state tests * Revise internal instance state tests * Revise sm instance state tests * Revise sm instance state tests * Revsie BasicGuardTestAbsType * Revise sm instance state tests * Revise BasicGuardTestAbsType * Add BasicGuardTestArray * Add BasicGuardTestEnum * Add BasicGuardTestStruct * Add BasicGuardU32 * Add BasicInternal * Revise BasicInternal * Add BasicSelf * Reformat code * Add BasicString test * Add BasicTestAbsType * Add BasicTestArray * Add BasicTestEnum * Add BasicTestStruct * Add BasicU32 * Remove extraneous file * Remove extraneous files * Revise sm tests * Revise state machine tests * Add Internal test * Add Polymorphism test * Add StateToChild test * Add StateToJunction test * Add StateToSelf test * Add StateToState test * Add junction/Basic * Add BasicU32 test * Add InputPairU16U32 * Add JunctionToJunction * Revise comments * Add JunctionToState * Revise JunctionToState * Revise JunctionToJunction * Add Sequence test * Add Sequence test * Revise SequenceU32 test * Revise state machine tests Add tests for queued components * Revise Basic test Add schedIn handler * Revise junction/Basic test Add schedIn handler * Revise state/Basic test Add schedIn handler * Revise initial/Basic test Add multiple instances of the same state machine * Revise state/Basic test Add multiple instances of the same state machine * Reformat code * Update fpp version * Update fpp; revise FppTest * Refactor internal/initial tests * Revise state machine tests * Revise internal/state tests * Revise state-machine/internal tests Rename junction to choice * Revise state-machine/internal tests * Reformat C++ files * Revise state-machine/internal_instance/initial tests * Revise internal_instance/state tests * Format code * Revise internal_instance/choice tests * Update fpp version * Format code * Update fpp version * Improve const correctness in Fw/Port * Update design * Revise state machines design * Revise state machine design * Revise state machine design * Revise state machine design * Revise state machine design * Revise state machines design * Revise state machines design * Revise state machines design * Revise state machines design * Revise state machines design * Revise state machines design * Revise state machines design * Revise state machines design * Revise state machines design * Revise state machines design * Revise state machines design * Revise state machines design * Revise state machines design * Revise state machines design * Revise state machines design * Revise state machines design * Revise state machines design * Revise state machines design * Revise state machines design * Revise state machines design * Revise state machines design * Revise state machines design * Revise state machines design * Revise state machines design * Revise state machines design * Revise state machines design * Revise state machines design * Revise state machines design * Revise state machine instances design * Revise state machines design * Revise state machines design * Revise state machines design * Update fpp version * Update fpp version; revise code to match * Update fpp version * Revise state machines design * Revise state machines design Add class diagram * Revise state machines design * Revise state machines design * Revise typography Close up spaces in names with embedded variables * Revise state machines design * Revise state machines design * Revise state machines design * Revise state machine unit tests * Revise state machine tests Increase code coverage * Revise state machine tests Increase code coverage * Update fpp version * Update spelling * Remove Design directory This directory no longer exists in fprime/devel * Update mkdocs --------- Co-authored-by: watney <garth.j.watney@jpl.nasa.gov> Co-authored-by: garthwatney <160269551+garthwatney@users.noreply.github.com> Co-authored-by: M Starch <LeStarch@googlemail.com>
This commit is contained in:
parent
037b199f84
commit
02a351c600
3
.github/actions/spelling/expect.txt
vendored
3
.github/actions/spelling/expect.txt
vendored
@ -42,6 +42,7 @@ argname
|
||||
argtype
|
||||
arinc
|
||||
arpa
|
||||
ASize
|
||||
ASTRING
|
||||
ATester
|
||||
ATL
|
||||
@ -103,6 +104,7 @@ carg
|
||||
caselessmatch
|
||||
CBF
|
||||
CBLOCK
|
||||
CComponent
|
||||
CCSDS
|
||||
ccsparc
|
||||
cdefs
|
||||
@ -566,6 +568,7 @@ mscfile
|
||||
mseconds
|
||||
mstarch
|
||||
mstat
|
||||
MState
|
||||
mstring
|
||||
mtype
|
||||
multiarch
|
||||
|
||||
@ -20,14 +20,20 @@ add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/struct/")
|
||||
set(SOURCE_FILES "source.cpp")
|
||||
set(MOD_DEPS
|
||||
${PROJECT_NAME}/array
|
||||
${PROJECT_NAME}/dp
|
||||
${PROJECT_NAME}/state_machine
|
||||
${PROJECT_NAME}/enum
|
||||
${PROJECT_NAME}/struct
|
||||
${PROJECT_NAME}/component/empty
|
||||
${PROJECT_NAME}/component/active
|
||||
${PROJECT_NAME}/component/queued
|
||||
${PROJECT_NAME}/component/empty
|
||||
${PROJECT_NAME}/component/passive
|
||||
${PROJECT_NAME}/component/queued
|
||||
${PROJECT_NAME}/dp
|
||||
${PROJECT_NAME}/enum
|
||||
${PROJECT_NAME}/state_machine/external_instance
|
||||
${PROJECT_NAME}/state_machine/internal/initial
|
||||
${PROJECT_NAME}/state_machine/internal/junction
|
||||
${PROJECT_NAME}/state_machine/internal/state
|
||||
${PROJECT_NAME}/state_machine/internal_instance/initial
|
||||
${PROJECT_NAME}/state_machine/internal_instance/junction
|
||||
${PROJECT_NAME}/state_machine/internal_instance/state
|
||||
${PROJECT_NAME}/struct
|
||||
)
|
||||
|
||||
register_fprime_deployment()
|
||||
|
||||
@ -1,21 +1,3 @@
|
||||
set(SOURCE_FILES
|
||||
"${CMAKE_CURRENT_LIST_DIR}/SmTest.cpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/SmTest.fpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/DeviceSm.cpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/HackSm.cpp"
|
||||
)
|
||||
set(MOD_DEPS Fw/Sm)
|
||||
|
||||
register_fprime_module()
|
||||
|
||||
set(UT_SOURCE_FILES
|
||||
"${CMAKE_CURRENT_LIST_DIR}/SmTest.fpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/test/ut/SmTestTestMain.cpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/test/ut/SmTestTester.cpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/DeviceSm.cpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/HackSm.cpp"
|
||||
)
|
||||
|
||||
set(UT_MOD_DEPS STest)
|
||||
set(UT_AUTO_HELPERS ON)
|
||||
register_fprime_ut()
|
||||
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/external_instance/")
|
||||
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/internal/")
|
||||
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/internal_instance/")
|
||||
|
||||
3
FppTest/state_machine/README.md
Normal file
3
FppTest/state_machine/README.md
Normal file
@ -0,0 +1,3 @@
|
||||
# state_machine
|
||||
|
||||
Tests for FPP state machines.
|
||||
20
FppTest/state_machine/external_instance/CMakeLists.txt
Normal file
20
FppTest/state_machine/external_instance/CMakeLists.txt
Normal file
@ -0,0 +1,20 @@
|
||||
set(SOURCE_FILES
|
||||
"${CMAKE_CURRENT_LIST_DIR}/SmTest.cpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/SmTest.fpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/DeviceSm.cpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/HackSm.cpp"
|
||||
)
|
||||
set(MOD_DEPS Fw/Sm)
|
||||
|
||||
register_fprime_module()
|
||||
|
||||
set(UT_SOURCE_FILES
|
||||
"${CMAKE_CURRENT_LIST_DIR}/SmTest.fpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/test/ut/SmTestTestMain.cpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/test/ut/SmTestTester.cpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/DeviceSm.cpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/HackSm.cpp"
|
||||
)
|
||||
set(UT_MOD_DEPS STest)
|
||||
set(UT_AUTO_HELPERS ON)
|
||||
register_fprime_ut()
|
||||
BIN
FppTest/state_machine/external_instance/DeviceSm.png
Normal file
BIN
FppTest/state_machine/external_instance/DeviceSm.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.6 KiB |
BIN
FppTest/state_machine/external_instance/HackSm.png
Normal file
BIN
FppTest/state_machine/external_instance/HackSm.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 16 KiB |
@ -6,7 +6,7 @@
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include "FppTest/state_machine/SmTest.hpp"
|
||||
#include "FppTest/state_machine/external_instance/SmTest.hpp"
|
||||
#include "Fw/Types/Assert.hpp"
|
||||
|
||||
namespace FppTest {
|
||||
@ -9,7 +9,7 @@
|
||||
|
||||
#include <array>
|
||||
|
||||
#include "FppTest/state_machine/SmTestComponentAc.hpp"
|
||||
#include "FppTest/state_machine/external_instance/SmTestComponentAc.hpp"
|
||||
#include "Fw/Types/String.hpp"
|
||||
|
||||
namespace FppTest {
|
||||
@ -2,7 +2,7 @@
|
||||
// SmTestTestMain.cpp
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
#include "FppTest/state_machine/test/ut/SmTestTester.hpp"
|
||||
#include "FppTest/state_machine/external_instance/test/ut/SmTestTester.hpp"
|
||||
#include "Fw/Test/UnitTest.hpp"
|
||||
#include "STest/Random/Random.hpp"
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include "FppTest/state_machine/test/ut/SmTestTester.hpp"
|
||||
#include "FppTest/state_machine/external_instance/test/ut/SmTestTester.hpp"
|
||||
#include "Fw/Types/ExternalString.hpp"
|
||||
#include "STest/Pick/Pick.hpp"
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
#define FppTest_SmTest_Tester_HPP
|
||||
|
||||
#include "SmTestGTestBase.hpp"
|
||||
#include "FppTest/state_machine/SmTest.hpp"
|
||||
#include "FppTest/state_machine/external_instance/SmTest.hpp"
|
||||
#include "STest/Pick/Pick.hpp"
|
||||
|
||||
namespace FppTest {
|
||||
4
FppTest/state_machine/internal/CMakeLists.txt
Normal file
4
FppTest/state_machine/internal/CMakeLists.txt
Normal file
@ -0,0 +1,4 @@
|
||||
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/choice/")
|
||||
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/harness/")
|
||||
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/initial/")
|
||||
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/state/")
|
||||
4
FppTest/state_machine/internal/README.md
Normal file
4
FppTest/state_machine/internal/README.md
Normal file
@ -0,0 +1,4 @@
|
||||
# state_machine/internal
|
||||
|
||||
Tests for internal FPP state machines, i.e., state machines whose behavior
|
||||
is expressed in FPP.
|
||||
82
FppTest/state_machine/internal/choice/Basic.cpp
Normal file
82
FppTest/state_machine/internal/choice/Basic.cpp
Normal file
@ -0,0 +1,82 @@
|
||||
// ======================================================================
|
||||
//
|
||||
// \title Basic.hpp
|
||||
// \author R. Bocchino
|
||||
// \brief Test class for basic state machine with a choice (implementation)
|
||||
//
|
||||
// \copyright
|
||||
// Copyright 2024, by the California Institute of Technology.
|
||||
// ALL RIGHTS RESERVED. United States Government Sponsorship
|
||||
// acknowledged.
|
||||
//
|
||||
// ======================================================================
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "FppTest/state_machine/internal/choice/Basic.hpp"
|
||||
#include "STest/STest/Pick/Pick.hpp"
|
||||
|
||||
namespace FppTest {
|
||||
|
||||
namespace SmChoice {
|
||||
|
||||
Basic::Basic() : BasicStateMachineBase(), m_action_a_history(), m_action_b_history(), m_guard_g() {}
|
||||
|
||||
void Basic::action_a(Signal signal) {
|
||||
this->m_action_a_history.push(signal);
|
||||
}
|
||||
|
||||
void Basic::action_b(Signal signal) {
|
||||
this->m_action_b_history.push(signal);
|
||||
}
|
||||
|
||||
bool Basic::guard_g(Signal signal) const {
|
||||
return this->m_guard_g.call(signal);
|
||||
}
|
||||
|
||||
void Basic::testTrue() {
|
||||
this->m_action_a_history.clear();
|
||||
this->m_action_b_history.clear();
|
||||
this->m_guard_g.reset();
|
||||
this->m_guard_g.setReturnValue(true);
|
||||
const FwEnumStoreType id = SmHarness::Pick::stateMachineId();
|
||||
this->initBase(id);
|
||||
ASSERT_EQ(this->m_id, id);
|
||||
ASSERT_EQ(this->getState(), State::S1);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getSize(), 0);
|
||||
ASSERT_EQ(this->m_action_a_history.getSize(), 0);
|
||||
ASSERT_EQ(this->m_action_b_history.getSize(), 0);
|
||||
this->sendSignal_s();
|
||||
this->sendSignal_s();
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getSize(), 1);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getItemAt(0), Signal::s);
|
||||
ASSERT_EQ(this->m_action_a_history.getSize(), 1);
|
||||
ASSERT_EQ(this->m_action_a_history.getItemAt(0), Signal::s);
|
||||
ASSERT_EQ(this->m_action_b_history.getSize(), 0);
|
||||
ASSERT_EQ(this->getState(), State::S2);
|
||||
}
|
||||
|
||||
void Basic::testFalse() {
|
||||
this->m_action_a_history.clear();
|
||||
this->m_action_b_history.clear();
|
||||
this->m_guard_g.reset();
|
||||
const FwEnumStoreType id = SmHarness::Pick::stateMachineId();
|
||||
this->initBase(id);
|
||||
ASSERT_EQ(this->m_id, id);
|
||||
ASSERT_EQ(this->getState(), State::S1);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getSize(), 0);
|
||||
ASSERT_EQ(this->m_action_a_history.getSize(), 0);
|
||||
ASSERT_EQ(this->m_action_b_history.getSize(), 0);
|
||||
this->sendSignal_s();
|
||||
this->sendSignal_s();
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getSize(), 1);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getItemAt(0), Signal::s);
|
||||
ASSERT_EQ(this->m_action_a_history.getSize(), 0);
|
||||
ASSERT_EQ(this->m_action_b_history.getSize(), 1);
|
||||
ASSERT_EQ(this->m_action_b_history.getItemAt(0), Signal::s);
|
||||
ASSERT_EQ(this->getState(), State::S3);
|
||||
}
|
||||
|
||||
} // namespace SmChoice
|
||||
|
||||
} // end namespace FppTest
|
||||
9
FppTest/state_machine/internal/choice/Basic.fpp
Normal file
9
FppTest/state_machine/internal/choice/Basic.fpp
Normal file
@ -0,0 +1,9 @@
|
||||
module FppTest {
|
||||
|
||||
module SmChoice {
|
||||
|
||||
include "include/Basic.fppi"
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
69
FppTest/state_machine/internal/choice/Basic.hpp
Normal file
69
FppTest/state_machine/internal/choice/Basic.hpp
Normal file
@ -0,0 +1,69 @@
|
||||
// ======================================================================
|
||||
//
|
||||
// \title Basic.hpp
|
||||
// \author R. Bocchino
|
||||
// \brief Test class for basic state machine with a choice (header)
|
||||
//
|
||||
// \copyright
|
||||
// Copyright 2024, by the California Institute of Technology.
|
||||
// ALL RIGHTS RESERVED. United States Government Sponsorship
|
||||
// acknowledged.
|
||||
//
|
||||
// ======================================================================
|
||||
|
||||
#ifndef FppTest_State_Basic_HPP
|
||||
#define FppTest_State_Basic_HPP
|
||||
|
||||
#include "FppTest/state_machine/internal/choice/BasicStateMachineAc.hpp"
|
||||
#include "FppTest/state_machine/internal/harness/Harness.hpp"
|
||||
|
||||
namespace FppTest {
|
||||
|
||||
namespace SmChoice {
|
||||
|
||||
//! A basic state machine with a choice
|
||||
class Basic final : public BasicStateMachineBase {
|
||||
public:
|
||||
//! The history size
|
||||
static constexpr FwSizeType historySize = 10;
|
||||
|
||||
public:
|
||||
//! Constructor
|
||||
Basic();
|
||||
|
||||
private:
|
||||
//! Implementation of action a
|
||||
void action_a(Signal signal //!< The signal
|
||||
) final;
|
||||
|
||||
//! Implementation of action b
|
||||
void action_b(Signal signal //!< The signal
|
||||
) final;
|
||||
|
||||
//! Implementation of guard g
|
||||
bool guard_g(Signal signal //!< The signal
|
||||
) const final;
|
||||
|
||||
public:
|
||||
//! Run the test with the true guard
|
||||
void testTrue();
|
||||
|
||||
//! Run the test with the false guard
|
||||
void testFalse();
|
||||
|
||||
private:
|
||||
//! The history associated with action a
|
||||
SmHarness::History<Signal, historySize> m_action_a_history;
|
||||
|
||||
//! The history associated with action b of Basic
|
||||
SmHarness::History<Signal, historySize> m_action_b_history;
|
||||
|
||||
//! The guard g
|
||||
SmHarness::NoArgGuard<Signal, historySize> m_guard_g;
|
||||
};
|
||||
|
||||
} // namespace SmChoice
|
||||
|
||||
} // end namespace FppTest
|
||||
|
||||
#endif
|
||||
87
FppTest/state_machine/internal/choice/BasicU32.cpp
Normal file
87
FppTest/state_machine/internal/choice/BasicU32.cpp
Normal file
@ -0,0 +1,87 @@
|
||||
// ======================================================================
|
||||
//
|
||||
// \title BasicU32.hpp
|
||||
// \author R. Bocchino
|
||||
// \brief Test class for basic state machine with a U32 choice (implementation)
|
||||
//
|
||||
// \copyright
|
||||
// Copyright 2024, by the California Institute of Technology.
|
||||
// ALL RIGHTS RESERVED. United States Government Sponsorship
|
||||
// acknowledged.
|
||||
//
|
||||
// ======================================================================
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "FppTest/state_machine/internal/choice/BasicU32.hpp"
|
||||
#include "STest/STest/Pick/Pick.hpp"
|
||||
|
||||
namespace FppTest {
|
||||
|
||||
namespace SmChoice {
|
||||
|
||||
BasicU32::BasicU32() : BasicU32StateMachineBase(), m_action_a_history(), m_action_b_history(), m_guard_g() {}
|
||||
|
||||
void BasicU32::action_a(Signal signal, U32 value) {
|
||||
this->m_action_a_history.push(signal, value);
|
||||
}
|
||||
|
||||
void BasicU32::action_b(Signal signal) {
|
||||
this->m_action_b_history.push(signal);
|
||||
}
|
||||
|
||||
bool BasicU32::guard_g(Signal signal, U32 value) const {
|
||||
return this->m_guard_g.call(signal, value);
|
||||
}
|
||||
|
||||
void BasicU32::testTrue() {
|
||||
this->m_action_a_history.clear();
|
||||
this->m_action_b_history.clear();
|
||||
this->m_guard_g.reset();
|
||||
this->m_guard_g.setReturnValue(true);
|
||||
const FwEnumStoreType id = SmHarness::Pick::stateMachineId();
|
||||
this->initBase(id);
|
||||
ASSERT_EQ(this->m_id, id);
|
||||
ASSERT_EQ(this->getState(), State::S1);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getSize(), 0);
|
||||
ASSERT_EQ(this->m_action_a_history.getSize(), 0);
|
||||
ASSERT_EQ(this->m_action_b_history.getSize(), 0);
|
||||
const U32 value = STest::Pick::any();
|
||||
this->sendSignal_s(value);
|
||||
this->sendSignal_s(value);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getSize(), 1);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getSignals().getItemAt(0), Signal::s);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getValues().getItemAt(0), value);
|
||||
ASSERT_EQ(this->m_action_a_history.getSize(), 1);
|
||||
ASSERT_EQ(this->m_action_a_history.getSignals().getItemAt(0), Signal::s);
|
||||
ASSERT_EQ(this->m_action_a_history.getValues().getItemAt(0), value);
|
||||
ASSERT_EQ(this->m_action_b_history.getSize(), 0);
|
||||
ASSERT_EQ(this->getState(), State::S2);
|
||||
}
|
||||
|
||||
void BasicU32::testFalse() {
|
||||
this->m_action_a_history.clear();
|
||||
this->m_action_b_history.clear();
|
||||
this->m_guard_g.reset();
|
||||
const FwEnumStoreType id = SmHarness::Pick::stateMachineId();
|
||||
this->initBase(id);
|
||||
ASSERT_EQ(this->m_id, id);
|
||||
ASSERT_EQ(this->getState(), State::S1);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getSize(), 0);
|
||||
ASSERT_EQ(this->m_action_a_history.getSize(), 0);
|
||||
ASSERT_EQ(this->m_action_b_history.getSize(), 0);
|
||||
const U32 value = STest::Pick::any();
|
||||
this->sendSignal_s(value);
|
||||
this->sendSignal_s(value);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getSize(), 1);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getSignals().getItemAt(0), Signal::s);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getValues().getItemAt(0), value);
|
||||
ASSERT_EQ(this->m_action_a_history.getSize(), 0);
|
||||
ASSERT_EQ(this->m_action_b_history.getSize(), 1);
|
||||
ASSERT_EQ(this->m_action_b_history.getItemAt(0), Signal::s);
|
||||
ASSERT_EQ(this->getState(), State::S3);
|
||||
}
|
||||
|
||||
} // namespace SmChoice
|
||||
|
||||
} // end namespace FppTest
|
||||
9
FppTest/state_machine/internal/choice/BasicU32.fpp
Normal file
9
FppTest/state_machine/internal/choice/BasicU32.fpp
Normal file
@ -0,0 +1,9 @@
|
||||
module FppTest {
|
||||
|
||||
module SmChoice {
|
||||
|
||||
include "include/BasicU32.fppi"
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
71
FppTest/state_machine/internal/choice/BasicU32.hpp
Normal file
71
FppTest/state_machine/internal/choice/BasicU32.hpp
Normal file
@ -0,0 +1,71 @@
|
||||
// ======================================================================
|
||||
//
|
||||
// \title BasicU32.hpp
|
||||
// \author R. Bocchino
|
||||
// \brief Test class for basic state machine with a U32 choice (header)
|
||||
//
|
||||
// \copyright
|
||||
// Copyright 2024, by the California Institute of Technology.
|
||||
// ALL RIGHTS RESERVED. United States Government Sponsorship
|
||||
// acknowledged.
|
||||
//
|
||||
// ======================================================================
|
||||
|
||||
#ifndef FppTest_State_BasicU32_HPP
|
||||
#define FppTest_State_BasicU32_HPP
|
||||
|
||||
#include "FppTest/state_machine/internal/choice/BasicU32StateMachineAc.hpp"
|
||||
#include "FppTest/state_machine/internal/harness/Harness.hpp"
|
||||
|
||||
namespace FppTest {
|
||||
|
||||
namespace SmChoice {
|
||||
|
||||
//! A basic state machine with a U32 choice
|
||||
class BasicU32 final : public BasicU32StateMachineBase {
|
||||
public:
|
||||
//! The history size
|
||||
static constexpr FwSizeType historySize = 10;
|
||||
|
||||
public:
|
||||
//! Constructor
|
||||
BasicU32();
|
||||
|
||||
private:
|
||||
//! Implementation of action a
|
||||
void action_a(Signal signal, //!< The signal
|
||||
U32 value //!< The value
|
||||
) final;
|
||||
|
||||
//! Implementation of action b
|
||||
void action_b(Signal signal //!< The signal
|
||||
) final;
|
||||
|
||||
//! Implementation of guard g
|
||||
bool guard_g(Signal signal, //!< The signal
|
||||
U32 value //!< The value
|
||||
) const final;
|
||||
|
||||
public:
|
||||
//! Run the test with the true guard
|
||||
void testTrue();
|
||||
|
||||
//! Run the test with the false guard
|
||||
void testFalse();
|
||||
|
||||
private:
|
||||
//! The history associated with action a
|
||||
SmHarness::SignalValueHistory<Signal, U32, historySize> m_action_a_history;
|
||||
|
||||
//! The history associated with action b
|
||||
SmHarness::History<Signal, historySize> m_action_b_history;
|
||||
|
||||
//! The guard g
|
||||
SmHarness::Guard<Signal, U32, historySize> m_guard_g;
|
||||
};
|
||||
|
||||
} // namespace SmChoice
|
||||
|
||||
} // end namespace FppTest
|
||||
|
||||
#endif
|
||||
24
FppTest/state_machine/internal/choice/CMakeLists.txt
Normal file
24
FppTest/state_machine/internal/choice/CMakeLists.txt
Normal file
@ -0,0 +1,24 @@
|
||||
set(SOURCE_FILES
|
||||
"${CMAKE_CURRENT_LIST_DIR}/Basic.fpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/BasicU32.fpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/ChoiceToChoice.fpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/ChoiceToState.fpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/InputPairU16U32.fpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/Sequence.fpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/SequenceU32.fpp"
|
||||
)
|
||||
set(MOD_DEPS FppTest/state_machine/internal/harness)
|
||||
register_fprime_module()
|
||||
|
||||
set(UT_SOURCE_FILES
|
||||
"${CMAKE_CURRENT_LIST_DIR}/Basic.cpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/BasicU32.cpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/ChoiceToChoice.cpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/ChoiceToState.cpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/InputPairU16U32.cpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/Sequence.cpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/SequenceU32.cpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/main.cpp"
|
||||
)
|
||||
set(UT_MOD_DEPS STest)
|
||||
register_fprime_ut()
|
||||
137
FppTest/state_machine/internal/choice/ChoiceToChoice.cpp
Normal file
137
FppTest/state_machine/internal/choice/ChoiceToChoice.cpp
Normal file
@ -0,0 +1,137 @@
|
||||
// ======================================================================
|
||||
//
|
||||
// \title ChoiceToChoice.hpp
|
||||
// \author R. Bocchino
|
||||
// \brief Test class for state machine with a choice-to-choice transition (implementation)
|
||||
//
|
||||
// \copyright
|
||||
// Copyright 2024, by the California Institute of Technology.
|
||||
// ALL RIGHTS RESERVED. United States Government Sponsorship
|
||||
// acknowledged.
|
||||
//
|
||||
// ======================================================================
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "FppTest/state_machine/internal/choice/ChoiceToChoice.hpp"
|
||||
#include "STest/STest/Pick/Pick.hpp"
|
||||
|
||||
namespace FppTest {
|
||||
|
||||
namespace SmChoice {
|
||||
|
||||
ChoiceToChoice::ChoiceToChoice() : ChoiceToChoiceStateMachineBase(), m_actionHistory(), m_guard_g1(), m_guard_g2() {}
|
||||
|
||||
void ChoiceToChoice::action_exitS1(Signal signal) {
|
||||
this->m_actionHistory.push(signal, ActionId::EXIT_S1);
|
||||
}
|
||||
|
||||
void ChoiceToChoice::action_a(Signal signal) {
|
||||
this->m_actionHistory.push(signal, ActionId::A);
|
||||
}
|
||||
|
||||
void ChoiceToChoice::action_enterS2(Signal signal) {
|
||||
this->m_actionHistory.push(signal, ActionId::ENTER_S2);
|
||||
}
|
||||
|
||||
bool ChoiceToChoice::guard_g1(Signal signal) const {
|
||||
return this->m_guard_g1.call(signal);
|
||||
}
|
||||
|
||||
bool ChoiceToChoice::guard_g2(Signal signal) const {
|
||||
return this->m_guard_g2.call(signal);
|
||||
}
|
||||
|
||||
void ChoiceToChoice::testG1True() {
|
||||
this->m_actionHistory.clear();
|
||||
this->m_guard_g1.reset();
|
||||
this->m_guard_g2.reset();
|
||||
this->m_guard_g1.setReturnValue(true);
|
||||
const FwEnumStoreType id = SmHarness::Pick::stateMachineId();
|
||||
this->initBase(id);
|
||||
ASSERT_EQ(this->m_id, id);
|
||||
ASSERT_EQ(this->getState(), State::S1);
|
||||
ASSERT_EQ(this->m_guard_g1.getCallHistory().getSize(), 0);
|
||||
ASSERT_EQ(this->m_guard_g2.getCallHistory().getSize(), 0);
|
||||
ASSERT_EQ(this->m_actionHistory.getSize(), 0);
|
||||
this->sendSignal_s();
|
||||
this->sendSignal_s();
|
||||
ASSERT_EQ(this->m_guard_g1.getCallHistory().getSize(), 1);
|
||||
ASSERT_EQ(this->m_guard_g1.getCallHistory().getItemAt(0), Signal::s);
|
||||
ASSERT_EQ(this->m_guard_g2.getCallHistory().getSize(), 0);
|
||||
const FwIndexType expectedSize = 3;
|
||||
ASSERT_EQ(this->m_actionHistory.getSize(), expectedSize);
|
||||
const auto& signals = this->m_actionHistory.getSignals();
|
||||
for (FwIndexType i = 0; i < expectedSize; i++) {
|
||||
ASSERT_EQ(signals.getItemAt(i), Signal::s);
|
||||
}
|
||||
const auto& values = this->m_actionHistory.getValues();
|
||||
ASSERT_EQ(values.getItemAt(0), ActionId::EXIT_S1);
|
||||
ASSERT_EQ(values.getItemAt(1), ActionId::A);
|
||||
ASSERT_EQ(values.getItemAt(2), ActionId::ENTER_S2);
|
||||
ASSERT_EQ(this->getState(), State::S2_S3);
|
||||
}
|
||||
|
||||
void ChoiceToChoice::testG1FalseG2True() {
|
||||
this->m_actionHistory.clear();
|
||||
this->m_guard_g1.reset();
|
||||
this->m_guard_g2.reset();
|
||||
this->m_guard_g2.setReturnValue(true);
|
||||
const FwEnumStoreType id = SmHarness::Pick::stateMachineId();
|
||||
this->initBase(id);
|
||||
ASSERT_EQ(this->m_id, id);
|
||||
ASSERT_EQ(this->getState(), State::S1);
|
||||
ASSERT_EQ(this->m_guard_g1.getCallHistory().getSize(), 0);
|
||||
ASSERT_EQ(this->m_guard_g2.getCallHistory().getSize(), 0);
|
||||
ASSERT_EQ(this->m_actionHistory.getSize(), 0);
|
||||
this->sendSignal_s();
|
||||
ASSERT_EQ(this->m_guard_g1.getCallHistory().getSize(), 1);
|
||||
ASSERT_EQ(this->m_guard_g1.getCallHistory().getItemAt(0), Signal::s);
|
||||
ASSERT_EQ(this->m_guard_g2.getCallHistory().getSize(), 1);
|
||||
ASSERT_EQ(this->m_guard_g1.getCallHistory().getItemAt(0), Signal::s);
|
||||
const FwIndexType expectedSize = 3;
|
||||
ASSERT_EQ(this->m_actionHistory.getSize(), expectedSize);
|
||||
const auto& signals = this->m_actionHistory.getSignals();
|
||||
for (FwIndexType i = 0; i < expectedSize; i++) {
|
||||
ASSERT_EQ(signals.getItemAt(i), Signal::s);
|
||||
}
|
||||
const auto& values = this->m_actionHistory.getValues();
|
||||
ASSERT_EQ(values.getItemAt(0), ActionId::EXIT_S1);
|
||||
ASSERT_EQ(values.getItemAt(1), ActionId::A);
|
||||
ASSERT_EQ(values.getItemAt(2), ActionId::ENTER_S2);
|
||||
ASSERT_EQ(this->getState(), State::S2_S3);
|
||||
}
|
||||
|
||||
void ChoiceToChoice::testG1FalseG2False() {
|
||||
this->m_actionHistory.clear();
|
||||
this->m_guard_g1.reset();
|
||||
this->m_guard_g2.reset();
|
||||
const FwEnumStoreType id = SmHarness::Pick::stateMachineId();
|
||||
this->initBase(id);
|
||||
ASSERT_EQ(this->m_id, id);
|
||||
ASSERT_EQ(this->getState(), State::S1);
|
||||
ASSERT_EQ(this->m_guard_g1.getCallHistory().getSize(), 0);
|
||||
ASSERT_EQ(this->m_guard_g2.getCallHistory().getSize(), 0);
|
||||
ASSERT_EQ(this->m_actionHistory.getSize(), 0);
|
||||
this->sendSignal_s();
|
||||
this->sendSignal_s();
|
||||
ASSERT_EQ(this->m_guard_g1.getCallHistory().getSize(), 1);
|
||||
ASSERT_EQ(this->m_guard_g1.getCallHistory().getItemAt(0), Signal::s);
|
||||
ASSERT_EQ(this->m_guard_g2.getCallHistory().getSize(), 1);
|
||||
ASSERT_EQ(this->m_guard_g1.getCallHistory().getItemAt(0), Signal::s);
|
||||
const FwIndexType expectedSize = 3;
|
||||
ASSERT_EQ(this->m_actionHistory.getSize(), expectedSize);
|
||||
const auto& signals = this->m_actionHistory.getSignals();
|
||||
for (FwIndexType i = 0; i < expectedSize; i++) {
|
||||
ASSERT_EQ(signals.getItemAt(i), Signal::s);
|
||||
}
|
||||
const auto& values = this->m_actionHistory.getValues();
|
||||
ASSERT_EQ(values.getItemAt(0), ActionId::EXIT_S1);
|
||||
ASSERT_EQ(values.getItemAt(1), ActionId::A);
|
||||
ASSERT_EQ(values.getItemAt(2), ActionId::ENTER_S2);
|
||||
ASSERT_EQ(this->getState(), State::S2_S4);
|
||||
}
|
||||
|
||||
} // namespace SmChoice
|
||||
|
||||
} // end namespace FppTest
|
||||
9
FppTest/state_machine/internal/choice/ChoiceToChoice.fpp
Normal file
9
FppTest/state_machine/internal/choice/ChoiceToChoice.fpp
Normal file
@ -0,0 +1,9 @@
|
||||
module FppTest {
|
||||
|
||||
module SmChoice {
|
||||
|
||||
include "include/ChoiceToChoice.fppi"
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
88
FppTest/state_machine/internal/choice/ChoiceToChoice.hpp
Normal file
88
FppTest/state_machine/internal/choice/ChoiceToChoice.hpp
Normal file
@ -0,0 +1,88 @@
|
||||
// ======================================================================
|
||||
//
|
||||
// \title ChoiceToChoice.hpp
|
||||
// \author R. Bocchino
|
||||
// \brief Test class for state machine with a choice-to-choice transition (header)
|
||||
//
|
||||
// \copyright
|
||||
// Copyright 2024, by the California Institute of Technology.
|
||||
// ALL RIGHTS RESERVED. United Choices Government Sponsorship
|
||||
// acknowledged.
|
||||
//
|
||||
// ======================================================================
|
||||
|
||||
#ifndef FppTest_Choice_ChoiceToChoice_HPP
|
||||
#define FppTest_Choice_ChoiceToChoice_HPP
|
||||
|
||||
#include "FppTest/state_machine/internal/choice/ChoiceToChoiceStateMachineAc.hpp"
|
||||
#include "FppTest/state_machine/internal/harness/Harness.hpp"
|
||||
|
||||
namespace FppTest {
|
||||
|
||||
namespace SmChoice {
|
||||
|
||||
//! A state machine with a choice-to-choice transition
|
||||
class ChoiceToChoice final : public ChoiceToChoiceStateMachineBase {
|
||||
public:
|
||||
//! The history size
|
||||
static constexpr FwSizeType historySize = 10;
|
||||
|
||||
public:
|
||||
//! Action IDs
|
||||
enum class ActionId {
|
||||
EXIT_S1,
|
||||
A,
|
||||
ENTER_S2,
|
||||
};
|
||||
|
||||
public:
|
||||
//! Constructor
|
||||
ChoiceToChoice();
|
||||
|
||||
private:
|
||||
//! Implementation of action exitS1
|
||||
void action_exitS1(Signal signal //!< The signal
|
||||
) final;
|
||||
|
||||
//! Implementation of action a
|
||||
void action_a(Signal signal //!< The signal
|
||||
) final;
|
||||
|
||||
//! Implementation of action enterS2
|
||||
void action_enterS2(Signal signal //!< The signal
|
||||
) final;
|
||||
|
||||
//! Implementation of guard g1
|
||||
bool guard_g1(Signal signal //!< The signal
|
||||
) const final;
|
||||
|
||||
//! Implementation of guard g2
|
||||
bool guard_g2(Signal signal //!< The signal
|
||||
) const final;
|
||||
|
||||
public:
|
||||
//! Run the test with g1 true
|
||||
void testG1True();
|
||||
|
||||
//! Run the test with g1 false and g2 true
|
||||
void testG1FalseG2True();
|
||||
|
||||
//! Run the test with g1 false and g2 false
|
||||
void testG1FalseG2False();
|
||||
|
||||
private:
|
||||
//! The action history
|
||||
SmHarness::SignalValueHistory<Signal, ActionId, historySize> m_actionHistory;
|
||||
|
||||
//! The guard g1
|
||||
SmHarness::NoArgGuard<Signal, historySize> m_guard_g1;
|
||||
|
||||
//! The guard g2
|
||||
SmHarness::NoArgGuard<Signal, historySize> m_guard_g2;
|
||||
};
|
||||
|
||||
} // namespace SmChoice
|
||||
|
||||
} // end namespace FppTest
|
||||
|
||||
#endif
|
||||
102
FppTest/state_machine/internal/choice/ChoiceToState.cpp
Normal file
102
FppTest/state_machine/internal/choice/ChoiceToState.cpp
Normal file
@ -0,0 +1,102 @@
|
||||
// ======================================================================
|
||||
//
|
||||
// \title ChoiceToState.hpp
|
||||
// \author R. Bocchino
|
||||
// \brief Test class for state machine with a choice-to-state transition (implementation)
|
||||
//
|
||||
// \copyright
|
||||
// Copyright 2024, by the California Institute of Technology.
|
||||
// ALL RIGHTS RESERVED. United States Government Sponsorship
|
||||
// acknowledged.
|
||||
//
|
||||
// ======================================================================
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "FppTest/state_machine/internal/choice/ChoiceToState.hpp"
|
||||
#include "STest/STest/Pick/Pick.hpp"
|
||||
|
||||
namespace FppTest {
|
||||
|
||||
namespace SmChoice {
|
||||
|
||||
ChoiceToState::ChoiceToState() : ChoiceToStateStateMachineBase(), m_actionHistory(), m_guard_g() {}
|
||||
|
||||
void ChoiceToState::action_exitS1(Signal signal) {
|
||||
this->m_actionHistory.push(signal, ActionId::EXIT_S1);
|
||||
}
|
||||
|
||||
void ChoiceToState::action_a(Signal signal) {
|
||||
this->m_actionHistory.push(signal, ActionId::A);
|
||||
}
|
||||
|
||||
bool ChoiceToState::guard_g(Signal signal) const {
|
||||
return this->m_guard_g.call(signal);
|
||||
}
|
||||
|
||||
void ChoiceToState::action_enterS2(Signal signal) {
|
||||
this->m_actionHistory.push(signal, ActionId::ENTER_S2);
|
||||
}
|
||||
|
||||
void ChoiceToState::action_enterS3(Signal signal) {
|
||||
this->m_actionHistory.push(signal, ActionId::ENTER_S3);
|
||||
}
|
||||
|
||||
void ChoiceToState::testTrue() {
|
||||
this->m_actionHistory.clear();
|
||||
this->m_guard_g.reset();
|
||||
this->m_guard_g.setReturnValue(true);
|
||||
const FwEnumStoreType id = SmHarness::Pick::stateMachineId();
|
||||
this->initBase(id);
|
||||
ASSERT_EQ(this->m_id, id);
|
||||
ASSERT_EQ(this->getState(), State::S1);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getSize(), 0);
|
||||
ASSERT_EQ(this->m_actionHistory.getSize(), 0);
|
||||
this->sendSignal_s();
|
||||
this->sendSignal_s();
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getSize(), 1);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getItemAt(0), Signal::s);
|
||||
const FwIndexType expectedSize = 5;
|
||||
ASSERT_EQ(this->m_actionHistory.getSize(), expectedSize);
|
||||
const auto& signals = this->m_actionHistory.getSignals();
|
||||
for (FwIndexType i = 0; i < expectedSize; i++) {
|
||||
ASSERT_EQ(signals.getItemAt(i), Signal::s);
|
||||
}
|
||||
const auto& values = this->m_actionHistory.getValues();
|
||||
ASSERT_EQ(values.getItemAt(0), ActionId::EXIT_S1);
|
||||
ASSERT_EQ(values.getItemAt(1), ActionId::A);
|
||||
ASSERT_EQ(values.getItemAt(2), ActionId::ENTER_S2);
|
||||
ASSERT_EQ(values.getItemAt(3), ActionId::A);
|
||||
ASSERT_EQ(values.getItemAt(4), ActionId::ENTER_S3);
|
||||
ASSERT_EQ(this->getState(), State::S2_S3);
|
||||
}
|
||||
|
||||
void ChoiceToState::testFalse() {
|
||||
this->m_actionHistory.clear();
|
||||
this->m_guard_g.reset();
|
||||
const FwEnumStoreType id = SmHarness::Pick::stateMachineId();
|
||||
this->initBase(id);
|
||||
ASSERT_EQ(this->m_id, id);
|
||||
ASSERT_EQ(this->getState(), State::S1);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getSize(), 0);
|
||||
ASSERT_EQ(this->m_actionHistory.getSize(), 0);
|
||||
this->sendSignal_s();
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getSize(), 1);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getItemAt(0), Signal::s);
|
||||
const FwIndexType expectedSize = 4;
|
||||
ASSERT_EQ(this->m_actionHistory.getSize(), expectedSize);
|
||||
const auto& signals = this->m_actionHistory.getSignals();
|
||||
for (FwIndexType i = 0; i < expectedSize; i++) {
|
||||
ASSERT_EQ(signals.getItemAt(i), Signal::s);
|
||||
}
|
||||
const auto& values = this->m_actionHistory.getValues();
|
||||
ASSERT_EQ(values.getItemAt(0), ActionId::EXIT_S1);
|
||||
ASSERT_EQ(values.getItemAt(1), ActionId::A);
|
||||
ASSERT_EQ(values.getItemAt(2), ActionId::ENTER_S2);
|
||||
ASSERT_EQ(values.getItemAt(3), ActionId::ENTER_S3);
|
||||
ASSERT_EQ(this->getState(), State::S2_S3);
|
||||
}
|
||||
|
||||
} // namespace SmChoice
|
||||
|
||||
} // end namespace FppTest
|
||||
9
FppTest/state_machine/internal/choice/ChoiceToState.fpp
Normal file
9
FppTest/state_machine/internal/choice/ChoiceToState.fpp
Normal file
@ -0,0 +1,9 @@
|
||||
module FppTest {
|
||||
|
||||
module SmChoice {
|
||||
|
||||
include "include/ChoiceToState.fppi"
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
83
FppTest/state_machine/internal/choice/ChoiceToState.hpp
Normal file
83
FppTest/state_machine/internal/choice/ChoiceToState.hpp
Normal file
@ -0,0 +1,83 @@
|
||||
// ======================================================================
|
||||
//
|
||||
// \title ChoiceToState.hpp
|
||||
// \author R. Bocchino
|
||||
// \brief Test class for state machine with a choice-to-state transition (header)
|
||||
//
|
||||
// \copyright
|
||||
// Copyright 2024, by the California Institute of Technology.
|
||||
// ALL RIGHTS RESERVED. United States Government Sponsorship
|
||||
// acknowledged.
|
||||
//
|
||||
// ======================================================================
|
||||
|
||||
#ifndef FppTest_State_ChoiceToState_HPP
|
||||
#define FppTest_State_ChoiceToState_HPP
|
||||
|
||||
#include "FppTest/state_machine/internal/choice/ChoiceToStateStateMachineAc.hpp"
|
||||
#include "FppTest/state_machine/internal/harness/Harness.hpp"
|
||||
|
||||
namespace FppTest {
|
||||
|
||||
namespace SmChoice {
|
||||
|
||||
//! A state machine with a choice-to-state transition
|
||||
class ChoiceToState final : public ChoiceToStateStateMachineBase {
|
||||
public:
|
||||
//! The history size
|
||||
static constexpr FwSizeType historySize = 10;
|
||||
|
||||
public:
|
||||
//! Action IDs
|
||||
enum class ActionId {
|
||||
EXIT_S1,
|
||||
A,
|
||||
ENTER_S2,
|
||||
ENTER_S3,
|
||||
};
|
||||
|
||||
public:
|
||||
//! Constructor
|
||||
ChoiceToState();
|
||||
|
||||
private:
|
||||
//! Implementation of action exitS1
|
||||
void action_exitS1(Signal signal //!< The signal
|
||||
) final;
|
||||
|
||||
//! Implementation of action a
|
||||
void action_a(Signal signal //!< The signal
|
||||
) final;
|
||||
|
||||
//! Implementation of action enterS2
|
||||
void action_enterS2(Signal signal //!< The signal
|
||||
) final;
|
||||
|
||||
//! Implementation of action enterS3
|
||||
void action_enterS3(Signal signal //!< The signal
|
||||
) final;
|
||||
|
||||
//! Implementation of guard g
|
||||
bool guard_g(Signal signal //!< The signal
|
||||
) const final;
|
||||
|
||||
public:
|
||||
//! Run the test with the true guard
|
||||
void testTrue();
|
||||
|
||||
//! Run the test with the false guard
|
||||
void testFalse();
|
||||
|
||||
private:
|
||||
//! The action history
|
||||
SmHarness::SignalValueHistory<Signal, ActionId, historySize> m_actionHistory;
|
||||
|
||||
//! The guard g
|
||||
SmHarness::NoArgGuard<Signal, historySize> m_guard_g;
|
||||
};
|
||||
|
||||
} // namespace SmChoice
|
||||
|
||||
} // end namespace FppTest
|
||||
|
||||
#endif
|
||||
121
FppTest/state_machine/internal/choice/InputPairU16U32.cpp
Normal file
121
FppTest/state_machine/internal/choice/InputPairU16U32.cpp
Normal file
@ -0,0 +1,121 @@
|
||||
// ======================================================================
|
||||
//
|
||||
// \title InputPairU16U32.hpp
|
||||
// \author R. Bocchino
|
||||
// \brief Test class for basic state machine with a U32 choice (implementation)
|
||||
//
|
||||
// \copyright
|
||||
// Copyright 2024, by the California Institute of Technology.
|
||||
// ALL RIGHTS RESERVED. United States Government Sponsorship
|
||||
// acknowledged.
|
||||
//
|
||||
// ======================================================================
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "FppTest/state_machine/internal/choice/InputPairU16U32.hpp"
|
||||
#include "STest/STest/Pick/Pick.hpp"
|
||||
|
||||
namespace FppTest {
|
||||
|
||||
namespace SmChoice {
|
||||
|
||||
InputPairU16U32::InputPairU16U32() : InputPairU16U32StateMachineBase(), m_action_a_history(), m_guard_g() {}
|
||||
|
||||
void InputPairU16U32::action_a(Signal signal, U32 value) {
|
||||
this->m_action_a_history.push(signal, value);
|
||||
}
|
||||
|
||||
bool InputPairU16U32::guard_g(Signal signal, U32 value) const {
|
||||
return this->m_guard_g.call(signal, value);
|
||||
}
|
||||
|
||||
void InputPairU16U32::testS1True() {
|
||||
this->m_action_a_history.clear();
|
||||
this->m_guard_g.reset();
|
||||
this->m_guard_g.setReturnValue(true);
|
||||
const FwEnumStoreType id = SmHarness::Pick::stateMachineId();
|
||||
this->initBase(id);
|
||||
ASSERT_EQ(this->m_id, id);
|
||||
ASSERT_EQ(this->getState(), State::S1);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getSize(), 0);
|
||||
ASSERT_EQ(this->m_action_a_history.getSize(), 0);
|
||||
const U16 value = static_cast<U16>(STest::Pick::any());
|
||||
this->sendSignal_s1(value);
|
||||
this->sendSignal_s1(value);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getSize(), 1);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getSignals().getItemAt(0), Signal::s1);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getValues().getItemAt(0), value);
|
||||
ASSERT_EQ(this->m_action_a_history.getSize(), 1);
|
||||
ASSERT_EQ(this->m_action_a_history.getSignals().getItemAt(0), Signal::s1);
|
||||
ASSERT_EQ(this->m_action_a_history.getValues().getItemAt(0), value);
|
||||
ASSERT_EQ(this->getState(), State::S2);
|
||||
}
|
||||
|
||||
void InputPairU16U32::testS1False() {
|
||||
this->m_action_a_history.clear();
|
||||
this->m_guard_g.reset();
|
||||
const FwEnumStoreType id = SmHarness::Pick::stateMachineId();
|
||||
this->initBase(id);
|
||||
ASSERT_EQ(this->m_id, id);
|
||||
ASSERT_EQ(this->getState(), State::S1);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getSize(), 0);
|
||||
ASSERT_EQ(this->m_action_a_history.getSize(), 0);
|
||||
const U16 value = static_cast<U16>(STest::Pick::any());
|
||||
this->sendSignal_s1(value);
|
||||
this->sendSignal_s1(value);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getSize(), 1);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getSignals().getItemAt(0), Signal::s1);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getValues().getItemAt(0), value);
|
||||
ASSERT_EQ(this->m_action_a_history.getSize(), 1);
|
||||
ASSERT_EQ(this->m_action_a_history.getSignals().getItemAt(0), Signal::s1);
|
||||
ASSERT_EQ(this->m_action_a_history.getValues().getItemAt(0), value);
|
||||
ASSERT_EQ(this->getState(), State::S3);
|
||||
}
|
||||
|
||||
void InputPairU16U32::testS2True() {
|
||||
this->m_action_a_history.clear();
|
||||
this->m_guard_g.reset();
|
||||
this->m_guard_g.setReturnValue(true);
|
||||
const FwEnumStoreType id = SmHarness::Pick::stateMachineId();
|
||||
this->initBase(id);
|
||||
ASSERT_EQ(this->m_id, id);
|
||||
ASSERT_EQ(this->getState(), State::S1);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getSize(), 0);
|
||||
ASSERT_EQ(this->m_action_a_history.getSize(), 0);
|
||||
const U32 value = STest::Pick::any();
|
||||
this->sendSignal_s2(value);
|
||||
this->sendSignal_s2(value);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getSize(), 1);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getSignals().getItemAt(0), Signal::s2);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getValues().getItemAt(0), value);
|
||||
ASSERT_EQ(this->m_action_a_history.getSize(), 1);
|
||||
ASSERT_EQ(this->m_action_a_history.getSignals().getItemAt(0), Signal::s2);
|
||||
ASSERT_EQ(this->m_action_a_history.getValues().getItemAt(0), value);
|
||||
ASSERT_EQ(this->getState(), State::S2);
|
||||
}
|
||||
|
||||
void InputPairU16U32::testS2False() {
|
||||
this->m_action_a_history.clear();
|
||||
this->m_guard_g.reset();
|
||||
const FwEnumStoreType id = SmHarness::Pick::stateMachineId();
|
||||
this->initBase(id);
|
||||
ASSERT_EQ(this->m_id, id);
|
||||
ASSERT_EQ(this->getState(), State::S1);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getSize(), 0);
|
||||
ASSERT_EQ(this->m_action_a_history.getSize(), 0);
|
||||
const U32 value = STest::Pick::any();
|
||||
this->sendSignal_s2(value);
|
||||
this->sendSignal_s2(value);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getSize(), 1);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getSignals().getItemAt(0), Signal::s2);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getValues().getItemAt(0), value);
|
||||
ASSERT_EQ(this->m_action_a_history.getSize(), 1);
|
||||
ASSERT_EQ(this->m_action_a_history.getSignals().getItemAt(0), Signal::s2);
|
||||
ASSERT_EQ(this->m_action_a_history.getValues().getItemAt(0), value);
|
||||
ASSERT_EQ(this->getState(), State::S3);
|
||||
}
|
||||
|
||||
} // namespace SmChoice
|
||||
|
||||
} // end namespace FppTest
|
||||
@ -0,0 +1,9 @@
|
||||
module FppTest {
|
||||
|
||||
module SmChoice {
|
||||
|
||||
include "include/InputPairU16U32.fppi"
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
70
FppTest/state_machine/internal/choice/InputPairU16U32.hpp
Normal file
70
FppTest/state_machine/internal/choice/InputPairU16U32.hpp
Normal file
@ -0,0 +1,70 @@
|
||||
// ======================================================================
|
||||
//
|
||||
// \title InputPairU16U32.hpp
|
||||
// \author R. Bocchino
|
||||
// \brief Test class for state machine with a pair of choice inputs (header)
|
||||
//
|
||||
// \copyright
|
||||
// Copyright 2024, by the California Institute of Technology.
|
||||
// ALL RIGHTS RESERVED. United States Government Sponsorship
|
||||
// acknowledged.
|
||||
//
|
||||
// ======================================================================
|
||||
|
||||
#ifndef FppTest_State_InputPairU16U32_HPP
|
||||
#define FppTest_State_InputPairU16U32_HPP
|
||||
|
||||
#include "FppTest/state_machine/internal/choice/InputPairU16U32StateMachineAc.hpp"
|
||||
#include "FppTest/state_machine/internal/harness/Harness.hpp"
|
||||
|
||||
namespace FppTest {
|
||||
|
||||
namespace SmChoice {
|
||||
|
||||
//! A basic state machine with a pair of choice inputs
|
||||
class InputPairU16U32 final : public InputPairU16U32StateMachineBase {
|
||||
public:
|
||||
//! The history size
|
||||
static constexpr FwSizeType historySize = 10;
|
||||
|
||||
public:
|
||||
//! Constructor
|
||||
InputPairU16U32();
|
||||
|
||||
private:
|
||||
//! Implementation of action a
|
||||
void action_a(Signal signal, //!< The signal
|
||||
U32 value //!< The value
|
||||
) final;
|
||||
|
||||
//! Implementation of guard g
|
||||
bool guard_g(Signal signal, //!< The signal
|
||||
U32 value //!< The value
|
||||
) const final;
|
||||
|
||||
public:
|
||||
//! Run the test with signal s1 and true guard
|
||||
void testS1True();
|
||||
|
||||
//! Run the test with signal s1 and false guard
|
||||
void testS1False();
|
||||
|
||||
//! Run the test with signal s2 and true guard
|
||||
void testS2True();
|
||||
|
||||
//! Run the test with signal s2 and false guard
|
||||
void testS2False();
|
||||
|
||||
private:
|
||||
//! The history associated with action a
|
||||
SmHarness::SignalValueHistory<Signal, U32, historySize> m_action_a_history;
|
||||
|
||||
//! The guard g
|
||||
SmHarness::Guard<Signal, U32, historySize> m_guard_g;
|
||||
};
|
||||
|
||||
} // namespace SmChoice
|
||||
|
||||
} // end namespace FppTest
|
||||
|
||||
#endif
|
||||
3
FppTest/state_machine/internal/choice/README.md
Normal file
3
FppTest/state_machine/internal/choice/README.md
Normal file
@ -0,0 +1,3 @@
|
||||
# state_machine/internal/choice
|
||||
|
||||
Tests for transitions out of choices in FPP internal state machines.
|
||||
118
FppTest/state_machine/internal/choice/Sequence.cpp
Normal file
118
FppTest/state_machine/internal/choice/Sequence.cpp
Normal file
@ -0,0 +1,118 @@
|
||||
// ======================================================================
|
||||
//
|
||||
// \title Sequence.hpp
|
||||
// \author R. Bocchino
|
||||
// \brief Test class for basic state machine with choice sequence (implementation)
|
||||
//
|
||||
// \copyright
|
||||
// Copyright 2024, by the California Institute of Technology.
|
||||
// ALL RIGHTS RESERVED. United States Government Sponsorship
|
||||
// acknowledged.
|
||||
//
|
||||
// ======================================================================
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "FppTest/state_machine/internal/choice/Sequence.hpp"
|
||||
#include "STest/STest/Pick/Pick.hpp"
|
||||
|
||||
namespace FppTest {
|
||||
|
||||
namespace SmChoice {
|
||||
|
||||
Sequence::Sequence()
|
||||
: SequenceStateMachineBase(), m_action_a_history(), m_action_b_history(), m_guard_g1(), m_guard_g2() {}
|
||||
|
||||
void Sequence::action_a(Signal signal) {
|
||||
this->m_action_a_history.push(signal);
|
||||
}
|
||||
|
||||
void Sequence::action_b(Signal signal) {
|
||||
this->m_action_b_history.push(signal);
|
||||
}
|
||||
|
||||
bool Sequence::guard_g1(Signal signal) const {
|
||||
return this->m_guard_g1.call(signal);
|
||||
}
|
||||
|
||||
bool Sequence::guard_g2(Signal signal) const {
|
||||
return this->m_guard_g2.call(signal);
|
||||
}
|
||||
|
||||
void Sequence::testG1True() {
|
||||
this->m_action_a_history.clear();
|
||||
this->m_action_b_history.clear();
|
||||
this->m_guard_g1.reset();
|
||||
this->m_guard_g1.setReturnValue(true);
|
||||
const FwEnumStoreType id = SmHarness::Pick::stateMachineId();
|
||||
this->initBase(id);
|
||||
ASSERT_EQ(this->m_id, id);
|
||||
ASSERT_EQ(this->getState(), State::S1);
|
||||
ASSERT_EQ(this->m_guard_g1.getCallHistory().getSize(), 0);
|
||||
ASSERT_EQ(this->m_guard_g2.getCallHistory().getSize(), 0);
|
||||
ASSERT_EQ(this->m_action_a_history.getSize(), 0);
|
||||
ASSERT_EQ(this->m_action_b_history.getSize(), 0);
|
||||
this->sendSignal_s();
|
||||
this->sendSignal_s();
|
||||
ASSERT_EQ(this->m_guard_g1.getCallHistory().getSize(), 1);
|
||||
ASSERT_EQ(this->m_guard_g1.getCallHistory().getItemAt(0), Signal::s);
|
||||
ASSERT_EQ(this->m_guard_g2.getCallHistory().getSize(), 0);
|
||||
ASSERT_EQ(this->m_action_a_history.getSize(), 0);
|
||||
ASSERT_EQ(this->m_action_b_history.getSize(), 0);
|
||||
ASSERT_EQ(this->getState(), State::S2);
|
||||
}
|
||||
|
||||
void Sequence::testG1FalseG2True() {
|
||||
this->m_action_a_history.clear();
|
||||
this->m_action_b_history.clear();
|
||||
this->m_guard_g1.reset();
|
||||
this->m_guard_g2.reset();
|
||||
this->m_guard_g2.setReturnValue(true);
|
||||
const FwEnumStoreType id = SmHarness::Pick::stateMachineId();
|
||||
this->initBase(id);
|
||||
ASSERT_EQ(this->m_id, id);
|
||||
ASSERT_EQ(this->getState(), State::S1);
|
||||
ASSERT_EQ(this->m_guard_g1.getCallHistory().getSize(), 0);
|
||||
ASSERT_EQ(this->m_guard_g2.getCallHistory().getSize(), 0);
|
||||
ASSERT_EQ(this->m_action_a_history.getSize(), 0);
|
||||
ASSERT_EQ(this->m_action_b_history.getSize(), 0);
|
||||
this->sendSignal_s();
|
||||
this->sendSignal_s();
|
||||
ASSERT_EQ(this->m_guard_g1.getCallHistory().getSize(), 1);
|
||||
ASSERT_EQ(this->m_guard_g1.getCallHistory().getItemAt(0), Signal::s);
|
||||
ASSERT_EQ(this->m_guard_g2.getCallHistory().getSize(), 1);
|
||||
ASSERT_EQ(this->m_guard_g2.getCallHistory().getItemAt(0), Signal::s);
|
||||
ASSERT_EQ(this->m_action_a_history.getSize(), 1);
|
||||
ASSERT_EQ(this->m_action_a_history.getItemAt(0), Signal::s);
|
||||
ASSERT_EQ(this->m_action_b_history.getSize(), 0);
|
||||
ASSERT_EQ(this->getState(), State::S3);
|
||||
}
|
||||
|
||||
void Sequence::testG1FalseG2False() {
|
||||
this->m_action_a_history.clear();
|
||||
this->m_action_b_history.clear();
|
||||
this->m_guard_g1.reset();
|
||||
this->m_guard_g2.reset();
|
||||
const FwEnumStoreType id = SmHarness::Pick::stateMachineId();
|
||||
this->initBase(id);
|
||||
ASSERT_EQ(this->m_id, id);
|
||||
ASSERT_EQ(this->getState(), State::S1);
|
||||
ASSERT_EQ(this->m_guard_g1.getCallHistory().getSize(), 0);
|
||||
ASSERT_EQ(this->m_guard_g2.getCallHistory().getSize(), 0);
|
||||
ASSERT_EQ(this->m_action_a_history.getSize(), 0);
|
||||
ASSERT_EQ(this->m_action_b_history.getSize(), 0);
|
||||
this->sendSignal_s();
|
||||
this->sendSignal_s();
|
||||
ASSERT_EQ(this->m_guard_g1.getCallHistory().getSize(), 1);
|
||||
ASSERT_EQ(this->m_guard_g1.getCallHistory().getItemAt(0), Signal::s);
|
||||
ASSERT_EQ(this->m_guard_g2.getCallHistory().getSize(), 1);
|
||||
ASSERT_EQ(this->m_guard_g2.getCallHistory().getItemAt(0), Signal::s);
|
||||
ASSERT_EQ(this->m_action_a_history.getSize(), 0);
|
||||
ASSERT_EQ(this->m_action_b_history.getSize(), 1);
|
||||
ASSERT_EQ(this->m_action_b_history.getItemAt(0), Signal::s);
|
||||
ASSERT_EQ(this->getState(), State::S4);
|
||||
}
|
||||
|
||||
} // namespace SmChoice
|
||||
|
||||
} // end namespace FppTest
|
||||
9
FppTest/state_machine/internal/choice/Sequence.fpp
Normal file
9
FppTest/state_machine/internal/choice/Sequence.fpp
Normal file
@ -0,0 +1,9 @@
|
||||
module FppTest {
|
||||
|
||||
module SmChoice {
|
||||
|
||||
include "include/Sequence.fppi"
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
79
FppTest/state_machine/internal/choice/Sequence.hpp
Normal file
79
FppTest/state_machine/internal/choice/Sequence.hpp
Normal file
@ -0,0 +1,79 @@
|
||||
// ======================================================================
|
||||
//
|
||||
// \title Sequence.hpp
|
||||
// \author R. Bocchino
|
||||
// \brief Test class for basic state machine with a choice sequence (header)
|
||||
//
|
||||
// \copyright
|
||||
// Copyright 2024, by the California Institute of Technology.
|
||||
// ALL RIGHTS RESERVED. United States Government Sponsorship
|
||||
// acknowledged.
|
||||
//
|
||||
// ======================================================================
|
||||
|
||||
#ifndef FppTest_State_Sequence_HPP
|
||||
#define FppTest_State_Sequence_HPP
|
||||
|
||||
#include "FppTest/state_machine/internal/choice/SequenceStateMachineAc.hpp"
|
||||
#include "FppTest/state_machine/internal/harness/Harness.hpp"
|
||||
|
||||
namespace FppTest {
|
||||
|
||||
namespace SmChoice {
|
||||
|
||||
//! A basic state machine with a choice sequence
|
||||
class Sequence final : public SequenceStateMachineBase {
|
||||
public:
|
||||
//! The history size
|
||||
static constexpr FwSizeType historySize = 10;
|
||||
|
||||
public:
|
||||
//! Constructor
|
||||
Sequence();
|
||||
|
||||
private:
|
||||
//! Implementation of action a
|
||||
void action_a(Signal signal //!< The signal
|
||||
) final;
|
||||
|
||||
//! Implementation of action b
|
||||
void action_b(Signal signal //!< The signal
|
||||
) final;
|
||||
|
||||
//! Implementation of guard g1
|
||||
bool guard_g1(Signal signal //!< The signal
|
||||
) const final;
|
||||
|
||||
//! Implementation of guard g2
|
||||
bool guard_g2(Signal signal //!< The signal
|
||||
) const final;
|
||||
|
||||
public:
|
||||
//! Run the test with g1 true
|
||||
void testG1True();
|
||||
|
||||
//! Run the test with g1 true and g2 true
|
||||
void testG1FalseG2True();
|
||||
|
||||
//! Run the test with g1 true and g2 false
|
||||
void testG1FalseG2False();
|
||||
|
||||
private:
|
||||
//! The history associated with action a
|
||||
SmHarness::History<Signal, historySize> m_action_a_history;
|
||||
|
||||
//! The history associated with action b
|
||||
SmHarness::History<Signal, historySize> m_action_b_history;
|
||||
|
||||
//! The guard g1
|
||||
SmHarness::NoArgGuard<Signal, historySize> m_guard_g1;
|
||||
|
||||
//! The guard g2
|
||||
SmHarness::NoArgGuard<Signal, historySize> m_guard_g2;
|
||||
};
|
||||
|
||||
} // namespace SmChoice
|
||||
|
||||
} // end namespace FppTest
|
||||
|
||||
#endif
|
||||
124
FppTest/state_machine/internal/choice/SequenceU32.cpp
Normal file
124
FppTest/state_machine/internal/choice/SequenceU32.cpp
Normal file
@ -0,0 +1,124 @@
|
||||
// ======================================================================
|
||||
//
|
||||
// \title SequenceU32.hpp
|
||||
// \author R. Bocchino
|
||||
// \brief Test class for basic state machine with a U32 choice (implementation)
|
||||
//
|
||||
// \copyright
|
||||
// Copyright 2024, by the California Institute of Technology.
|
||||
// ALL RIGHTS RESERVED. United States Government Sponsorship
|
||||
// acknowledged.
|
||||
//
|
||||
// ======================================================================
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "FppTest/state_machine/internal/choice/SequenceU32.hpp"
|
||||
#include "STest/STest/Pick/Pick.hpp"
|
||||
|
||||
namespace FppTest {
|
||||
|
||||
namespace SmChoice {
|
||||
|
||||
SequenceU32::SequenceU32()
|
||||
: SequenceU32StateMachineBase(), m_action_a_history(), m_action_b_history(), m_guard_g1(), m_guard_g2() {}
|
||||
|
||||
void SequenceU32::action_a(Signal signal, U32 value) {
|
||||
this->m_action_a_history.push(signal, value);
|
||||
}
|
||||
|
||||
void SequenceU32::action_b(Signal signal) {
|
||||
this->m_action_b_history.push(signal);
|
||||
}
|
||||
|
||||
bool SequenceU32::guard_g1(Signal signal) const {
|
||||
return this->m_guard_g1.call(signal);
|
||||
}
|
||||
|
||||
bool SequenceU32::guard_g2(Signal signal, U32 value) const {
|
||||
return this->m_guard_g2.call(signal, value);
|
||||
}
|
||||
|
||||
void SequenceU32::testG1True() {
|
||||
this->m_action_a_history.clear();
|
||||
this->m_action_b_history.clear();
|
||||
this->m_guard_g1.reset();
|
||||
this->m_guard_g1.setReturnValue(true);
|
||||
const FwEnumStoreType id = SmHarness::Pick::stateMachineId();
|
||||
this->initBase(id);
|
||||
ASSERT_EQ(this->m_id, id);
|
||||
ASSERT_EQ(this->getState(), State::S1);
|
||||
ASSERT_EQ(this->m_guard_g1.getCallHistory().getSize(), 0);
|
||||
ASSERT_EQ(this->m_guard_g2.getCallHistory().getSize(), 0);
|
||||
ASSERT_EQ(this->m_action_a_history.getSize(), 0);
|
||||
ASSERT_EQ(this->m_action_b_history.getSize(), 0);
|
||||
const U32 value = STest::Pick::any();
|
||||
this->sendSignal_s(value);
|
||||
this->sendSignal_s(value);
|
||||
ASSERT_EQ(this->m_guard_g1.getCallHistory().getSize(), 1);
|
||||
ASSERT_EQ(this->m_guard_g1.getCallHistory().getItemAt(0), Signal::s);
|
||||
ASSERT_EQ(this->m_guard_g2.getCallHistory().getSize(), 0);
|
||||
ASSERT_EQ(this->m_action_a_history.getSize(), 0);
|
||||
ASSERT_EQ(this->m_action_b_history.getSize(), 0);
|
||||
ASSERT_EQ(this->getState(), State::S2);
|
||||
}
|
||||
|
||||
void SequenceU32::testG1FalseG2True() {
|
||||
this->m_action_a_history.clear();
|
||||
this->m_action_b_history.clear();
|
||||
this->m_guard_g1.reset();
|
||||
this->m_guard_g2.reset();
|
||||
this->m_guard_g2.setReturnValue(true);
|
||||
const FwEnumStoreType id = SmHarness::Pick::stateMachineId();
|
||||
this->initBase(id);
|
||||
ASSERT_EQ(this->m_id, id);
|
||||
ASSERT_EQ(this->getState(), State::S1);
|
||||
ASSERT_EQ(this->m_guard_g1.getCallHistory().getSize(), 0);
|
||||
ASSERT_EQ(this->m_guard_g2.getCallHistory().getSize(), 0);
|
||||
ASSERT_EQ(this->m_action_a_history.getSize(), 0);
|
||||
ASSERT_EQ(this->m_action_b_history.getSize(), 0);
|
||||
const U32 value = STest::Pick::any();
|
||||
this->sendSignal_s(value);
|
||||
this->sendSignal_s(value);
|
||||
ASSERT_EQ(this->m_guard_g1.getCallHistory().getSize(), 1);
|
||||
ASSERT_EQ(this->m_guard_g1.getCallHistory().getItemAt(0), Signal::s);
|
||||
ASSERT_EQ(this->m_guard_g2.getCallHistory().getSize(), 1);
|
||||
ASSERT_EQ(this->m_guard_g2.getCallHistory().getSignals().getItemAt(0), Signal::s);
|
||||
ASSERT_EQ(this->m_guard_g2.getCallHistory().getValues().getItemAt(0), value);
|
||||
ASSERT_EQ(this->m_action_a_history.getSize(), 1);
|
||||
ASSERT_EQ(this->m_action_a_history.getSignals().getItemAt(0), Signal::s);
|
||||
ASSERT_EQ(this->m_action_a_history.getValues().getItemAt(0), value);
|
||||
ASSERT_EQ(this->m_action_b_history.getSize(), 0);
|
||||
ASSERT_EQ(this->getState(), State::S3);
|
||||
}
|
||||
|
||||
void SequenceU32::testG1FalseG2False() {
|
||||
this->m_action_a_history.clear();
|
||||
this->m_action_b_history.clear();
|
||||
this->m_guard_g1.reset();
|
||||
this->m_guard_g2.reset();
|
||||
const FwEnumStoreType id = SmHarness::Pick::stateMachineId();
|
||||
this->initBase(id);
|
||||
ASSERT_EQ(this->m_id, id);
|
||||
ASSERT_EQ(this->getState(), State::S1);
|
||||
ASSERT_EQ(this->m_guard_g1.getCallHistory().getSize(), 0);
|
||||
ASSERT_EQ(this->m_guard_g2.getCallHistory().getSize(), 0);
|
||||
ASSERT_EQ(this->m_action_a_history.getSize(), 0);
|
||||
ASSERT_EQ(this->m_action_b_history.getSize(), 0);
|
||||
const U32 value = STest::Pick::any();
|
||||
this->sendSignal_s(value);
|
||||
this->sendSignal_s(value);
|
||||
ASSERT_EQ(this->m_guard_g1.getCallHistory().getSize(), 1);
|
||||
ASSERT_EQ(this->m_guard_g1.getCallHistory().getItemAt(0), Signal::s);
|
||||
ASSERT_EQ(this->m_guard_g2.getCallHistory().getSize(), 1);
|
||||
ASSERT_EQ(this->m_guard_g2.getCallHistory().getSignals().getItemAt(0), Signal::s);
|
||||
ASSERT_EQ(this->m_guard_g2.getCallHistory().getValues().getItemAt(0), value);
|
||||
ASSERT_EQ(this->m_action_a_history.getSize(), 0);
|
||||
ASSERT_EQ(this->m_action_b_history.getSize(), 1);
|
||||
ASSERT_EQ(this->m_action_b_history.getItemAt(0), Signal::s);
|
||||
ASSERT_EQ(this->getState(), State::S4);
|
||||
}
|
||||
|
||||
} // namespace SmChoice
|
||||
|
||||
} // end namespace FppTest
|
||||
9
FppTest/state_machine/internal/choice/SequenceU32.fpp
Normal file
9
FppTest/state_machine/internal/choice/SequenceU32.fpp
Normal file
@ -0,0 +1,9 @@
|
||||
module FppTest {
|
||||
|
||||
module SmChoice {
|
||||
|
||||
include "include/SequenceU32.fppi"
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
81
FppTest/state_machine/internal/choice/SequenceU32.hpp
Normal file
81
FppTest/state_machine/internal/choice/SequenceU32.hpp
Normal file
@ -0,0 +1,81 @@
|
||||
// ======================================================================
|
||||
//
|
||||
// \title SequenceU32.hpp
|
||||
// \author R. Bocchino
|
||||
// \brief Test class for basic state machine with a U32 choice sequence (header)
|
||||
//
|
||||
// \copyright
|
||||
// Copyright 2024, by the California Institute of Technology.
|
||||
// ALL RIGHTS RESERVED. United States Government Sponsorship
|
||||
// acknowledged.
|
||||
//
|
||||
// ======================================================================
|
||||
|
||||
#ifndef FppTest_State_SequenceU32_HPP
|
||||
#define FppTest_State_SequenceU32_HPP
|
||||
|
||||
#include "FppTest/state_machine/internal/choice/SequenceU32StateMachineAc.hpp"
|
||||
#include "FppTest/state_machine/internal/harness/Harness.hpp"
|
||||
|
||||
namespace FppTest {
|
||||
|
||||
namespace SmChoice {
|
||||
|
||||
//! A basic state machine with a U32 choice sequence
|
||||
class SequenceU32 final : public SequenceU32StateMachineBase {
|
||||
public:
|
||||
//! The history size
|
||||
static constexpr FwSizeType historySize = 10;
|
||||
|
||||
public:
|
||||
//! Constructor
|
||||
SequenceU32();
|
||||
|
||||
private:
|
||||
//! Implementation of action a
|
||||
void action_a(Signal signal, //!< The signal
|
||||
U32 value //!< The value
|
||||
) final;
|
||||
|
||||
//! Implementation of action b
|
||||
void action_b(Signal signal //!< The signal
|
||||
) final;
|
||||
|
||||
//! Implementation of guard g1
|
||||
bool guard_g1(Signal signal //!< The signal
|
||||
) const final;
|
||||
|
||||
//! Implementation of guard g2
|
||||
bool guard_g2(Signal signal, //!< The signal
|
||||
U32 value //!< The value
|
||||
) const final;
|
||||
|
||||
public:
|
||||
//! Run the test with g1 true
|
||||
void testG1True();
|
||||
|
||||
//! Run the test with g1 true and g2 true
|
||||
void testG1FalseG2True();
|
||||
|
||||
//! Run the test with g1 true and g2 false
|
||||
void testG1FalseG2False();
|
||||
|
||||
private:
|
||||
//! The history associated with action a
|
||||
SmHarness::SignalValueHistory<Signal, U32, historySize> m_action_a_history;
|
||||
|
||||
//! The history associated with action b
|
||||
SmHarness::History<Signal, historySize> m_action_b_history;
|
||||
|
||||
//! The guard g1
|
||||
SmHarness::NoArgGuard<Signal, historySize> m_guard_g1;
|
||||
|
||||
//! The guard g2
|
||||
SmHarness::Guard<Signal, U32, historySize> m_guard_g2;
|
||||
};
|
||||
|
||||
} // namespace SmChoice
|
||||
|
||||
} // end namespace FppTest
|
||||
|
||||
#endif
|
||||
38
FppTest/state_machine/internal/choice/include/Basic.fppi
Normal file
38
FppTest/state_machine/internal/choice/include/Basic.fppi
Normal file
@ -0,0 +1,38 @@
|
||||
@ A basic state machine with a choice
|
||||
state machine Basic {
|
||||
|
||||
@ Action a
|
||||
action a
|
||||
|
||||
@ Action b
|
||||
action b
|
||||
|
||||
@ Signal s
|
||||
signal s
|
||||
|
||||
@ Guard g
|
||||
guard g
|
||||
|
||||
@ Initial transition
|
||||
initial enter S1
|
||||
|
||||
@ State S1
|
||||
state S1 {
|
||||
|
||||
@ State transition
|
||||
on s enter C
|
||||
|
||||
}
|
||||
|
||||
@ Choice C
|
||||
choice C {
|
||||
if g do { a } enter S2 else do { b } enter S3
|
||||
}
|
||||
|
||||
@ State S2
|
||||
state S2
|
||||
|
||||
@ State S3
|
||||
state S3
|
||||
|
||||
}
|
||||
38
FppTest/state_machine/internal/choice/include/BasicU32.fppi
Normal file
38
FppTest/state_machine/internal/choice/include/BasicU32.fppi
Normal file
@ -0,0 +1,38 @@
|
||||
@ A basic state machine with a U32 choice
|
||||
state machine BasicU32 {
|
||||
|
||||
@ Action a
|
||||
action a: U32
|
||||
|
||||
@ Action b
|
||||
action b
|
||||
|
||||
@ Signal s
|
||||
signal s: U32
|
||||
|
||||
@ Guard g
|
||||
guard g: U32
|
||||
|
||||
@ Initial transition
|
||||
initial enter S1
|
||||
|
||||
@ State S1
|
||||
state S1 {
|
||||
|
||||
@ State transition
|
||||
on s enter C
|
||||
|
||||
}
|
||||
|
||||
@ Choice C
|
||||
choice C {
|
||||
if g do { a } enter S2 else do { b } enter S3
|
||||
}
|
||||
|
||||
@ State S2
|
||||
state S2
|
||||
|
||||
@ State S3
|
||||
state S3
|
||||
|
||||
}
|
||||
@ -0,0 +1,64 @@
|
||||
@ A state machine for testing choice-to-choice transitions
|
||||
@ with hierarchy
|
||||
state machine ChoiceToChoice {
|
||||
|
||||
@ Exit S1
|
||||
action exitS1
|
||||
|
||||
@ Action a
|
||||
action a
|
||||
|
||||
@ Enter S2
|
||||
action enterS2
|
||||
|
||||
@ Signal s
|
||||
signal s
|
||||
|
||||
@ Guard g1
|
||||
guard g1
|
||||
|
||||
@ Guard g2
|
||||
guard g2
|
||||
|
||||
@ Initial transition
|
||||
initial enter S1
|
||||
|
||||
@ State S1
|
||||
state S1 {
|
||||
|
||||
@ Exit S1
|
||||
exit do { exitS1 }
|
||||
|
||||
@ Choice C1
|
||||
choice C1 {
|
||||
if g1 do { a } enter S2 else do { a } enter S2.C2
|
||||
}
|
||||
|
||||
@ State transition to C1
|
||||
on s enter C1
|
||||
|
||||
}
|
||||
|
||||
@ State S2
|
||||
state S2 {
|
||||
|
||||
@ Enter S2
|
||||
entry do { enterS2 }
|
||||
|
||||
@ Initial transition
|
||||
initial enter S3
|
||||
|
||||
@ Choice C2
|
||||
choice C2 {
|
||||
if g2 enter S3 else enter S4
|
||||
}
|
||||
|
||||
@ State S3
|
||||
state S3
|
||||
|
||||
@ State S4
|
||||
state S4
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,61 @@
|
||||
@ A state machine for testing choice-to-state transitions
|
||||
@ with hierarchy
|
||||
state machine ChoiceToState {
|
||||
|
||||
@ Exit S1
|
||||
action exitS1
|
||||
|
||||
@ Action a
|
||||
action a
|
||||
|
||||
@ Enter S2
|
||||
action enterS2
|
||||
|
||||
@ Enter S3
|
||||
action enterS3
|
||||
|
||||
@ Signal s
|
||||
signal s
|
||||
|
||||
@ Guard g
|
||||
guard g
|
||||
|
||||
@ Initial transition
|
||||
initial enter S1
|
||||
|
||||
@ State S1
|
||||
state S1 {
|
||||
|
||||
@ Exit S1
|
||||
exit do { exitS1 }
|
||||
|
||||
@ Choice C
|
||||
choice C {
|
||||
if g do { a } enter S2 else do { a } enter S2.S3
|
||||
}
|
||||
|
||||
@ State transition to C
|
||||
on s enter C
|
||||
|
||||
}
|
||||
|
||||
@ State S2
|
||||
state S2 {
|
||||
|
||||
@ Enter S2
|
||||
entry do { enterS2 }
|
||||
|
||||
@ Initial transition
|
||||
initial do { a } enter S3
|
||||
|
||||
@ State S3
|
||||
state S3 {
|
||||
|
||||
@ Enter S3
|
||||
entry do { enterS3 }
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,41 @@
|
||||
@ A state machine with two inputs to a choice
|
||||
state machine InputPairU16U32 {
|
||||
|
||||
@ Action a
|
||||
action a: U32
|
||||
|
||||
@ Signal s1
|
||||
signal s1: U16
|
||||
|
||||
@ Signal s2
|
||||
signal s2: U32
|
||||
|
||||
@ Guard g
|
||||
guard g: U32
|
||||
|
||||
@ Initial transition
|
||||
initial enter S1
|
||||
|
||||
@ State S1
|
||||
state S1 {
|
||||
|
||||
@ State transition on s1
|
||||
on s1 enter C
|
||||
|
||||
@ State transition on s2
|
||||
on s2 enter C
|
||||
|
||||
}
|
||||
|
||||
@ Choice C
|
||||
choice C {
|
||||
if g do { a } enter S2 else do { a } enter S3
|
||||
}
|
||||
|
||||
@ State S2
|
||||
state S2
|
||||
|
||||
@ State S3
|
||||
state S3
|
||||
|
||||
}
|
||||
49
FppTest/state_machine/internal/choice/include/Sequence.fppi
Normal file
49
FppTest/state_machine/internal/choice/include/Sequence.fppi
Normal file
@ -0,0 +1,49 @@
|
||||
@ A basic state machine with a choice sequence
|
||||
state machine Sequence {
|
||||
|
||||
@ Action a
|
||||
action a
|
||||
|
||||
@ Action b
|
||||
action b
|
||||
|
||||
@ Signal s
|
||||
signal s
|
||||
|
||||
@ Guard g1
|
||||
guard g1
|
||||
|
||||
@ Guard g2
|
||||
guard g2
|
||||
|
||||
@ Initial transition
|
||||
initial enter S1
|
||||
|
||||
@ State S1
|
||||
state S1 {
|
||||
|
||||
@ State transition
|
||||
on s enter C1
|
||||
|
||||
}
|
||||
|
||||
@ Choice C1
|
||||
choice C1 {
|
||||
if g1 enter S2 else enter C2
|
||||
}
|
||||
|
||||
@ Choice C2
|
||||
choice C2 {
|
||||
if g2 do { a } enter S3 else do { b } enter S4
|
||||
}
|
||||
|
||||
@ State S2
|
||||
state S2
|
||||
|
||||
@ State S3
|
||||
state S3
|
||||
|
||||
@ State S4
|
||||
state S4
|
||||
|
||||
}
|
||||
@ -0,0 +1,49 @@
|
||||
@ A basic state machine with a U32 choice sequence
|
||||
state machine SequenceU32 {
|
||||
|
||||
@ Action a
|
||||
action a: U32
|
||||
|
||||
@ Action b
|
||||
action b
|
||||
|
||||
@ Signal s
|
||||
signal s: U32
|
||||
|
||||
@ Guard g1
|
||||
guard g1
|
||||
|
||||
@ Guard g2
|
||||
guard g2: U32
|
||||
|
||||
@ Initial transition
|
||||
initial enter S1
|
||||
|
||||
@ State S1
|
||||
state S1 {
|
||||
|
||||
@ State transition
|
||||
on s enter C1
|
||||
|
||||
}
|
||||
|
||||
@ Choice C1
|
||||
choice C1 {
|
||||
if g1 enter S2 else enter C2
|
||||
}
|
||||
|
||||
@ Choice C2
|
||||
choice C2 {
|
||||
if g2 do { a } enter S3 else do { b } enter S4
|
||||
}
|
||||
|
||||
@ State S2
|
||||
state S2
|
||||
|
||||
@ State S3
|
||||
state S3
|
||||
|
||||
@ State S4
|
||||
state S4
|
||||
|
||||
}
|
||||
119
FppTest/state_machine/internal/choice/main.cpp
Normal file
119
FppTest/state_machine/internal/choice/main.cpp
Normal file
@ -0,0 +1,119 @@
|
||||
// ----------------------------------------------------------------------
|
||||
// main.cpp
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "FppTest/state_machine/internal/choice/Basic.hpp"
|
||||
#include "FppTest/state_machine/internal/choice/BasicU32.hpp"
|
||||
#include "FppTest/state_machine/internal/choice/ChoiceToChoice.hpp"
|
||||
#include "FppTest/state_machine/internal/choice/ChoiceToState.hpp"
|
||||
#include "FppTest/state_machine/internal/choice/InputPairU16U32.hpp"
|
||||
#include "FppTest/state_machine/internal/choice/Sequence.hpp"
|
||||
#include "FppTest/state_machine/internal/choice/SequenceU32.hpp"
|
||||
#include "STest/STest/Random/Random.hpp"
|
||||
|
||||
TEST(Basic, True) {
|
||||
FppTest::SmChoice::Basic basic;
|
||||
basic.testTrue();
|
||||
}
|
||||
|
||||
TEST(Basic, False) {
|
||||
FppTest::SmChoice::Basic basic;
|
||||
basic.testFalse();
|
||||
}
|
||||
|
||||
TEST(BasicU32, True) {
|
||||
FppTest::SmChoice::BasicU32 basicU32;
|
||||
basicU32.testTrue();
|
||||
}
|
||||
|
||||
TEST(BasicU32, False) {
|
||||
FppTest::SmChoice::BasicU32 basicU32;
|
||||
basicU32.testFalse();
|
||||
}
|
||||
|
||||
TEST(InputPairU16U32, S1True) {
|
||||
FppTest::SmChoice::InputPairU16U32 inputPair;
|
||||
inputPair.testS1True();
|
||||
}
|
||||
|
||||
TEST(InputPairU16U32, S1False) {
|
||||
FppTest::SmChoice::InputPairU16U32 inputPair;
|
||||
inputPair.testS1False();
|
||||
}
|
||||
|
||||
TEST(InputPairU16U32, S2True) {
|
||||
FppTest::SmChoice::InputPairU16U32 inputPair;
|
||||
inputPair.testS2True();
|
||||
}
|
||||
|
||||
TEST(InputPairU16U32, S2False) {
|
||||
FppTest::SmChoice::InputPairU16U32 inputPair;
|
||||
inputPair.testS2False();
|
||||
}
|
||||
|
||||
TEST(ChoiceToChoice, G1True) {
|
||||
FppTest::SmChoice::ChoiceToChoice choiceToChoice;
|
||||
choiceToChoice.testG1True();
|
||||
}
|
||||
|
||||
TEST(ChoiceToChoice, G1FalseG2True) {
|
||||
FppTest::SmChoice::ChoiceToChoice choiceToChoice;
|
||||
choiceToChoice.testG1FalseG2True();
|
||||
}
|
||||
|
||||
TEST(ChoiceToChoice, G1FalseG2False) {
|
||||
FppTest::SmChoice::ChoiceToChoice choiceToChoice;
|
||||
choiceToChoice.testG1FalseG2False();
|
||||
}
|
||||
|
||||
TEST(ChoiceToState, True) {
|
||||
FppTest::SmChoice::ChoiceToState choiceToState;
|
||||
choiceToState.testTrue();
|
||||
}
|
||||
|
||||
TEST(ChoiceToState, False) {
|
||||
FppTest::SmChoice::ChoiceToState choiceToState;
|
||||
choiceToState.testFalse();
|
||||
}
|
||||
|
||||
TEST(Sequence, G1True) {
|
||||
FppTest::SmChoice::Sequence sequence;
|
||||
sequence.testG1True();
|
||||
}
|
||||
|
||||
TEST(Sequence, G1FalseG2True) {
|
||||
FppTest::SmChoice::Sequence sequence;
|
||||
sequence.testG1FalseG2True();
|
||||
}
|
||||
|
||||
TEST(Sequence, G1FalseG2False) {
|
||||
FppTest::SmChoice::Sequence sequence;
|
||||
sequence.testG1FalseG2False();
|
||||
}
|
||||
|
||||
TEST(SequenceU32, G1True) {
|
||||
FppTest::SmChoice::SequenceU32 sequenceU32;
|
||||
sequenceU32.testG1True();
|
||||
}
|
||||
|
||||
TEST(SequenceU32, G1FalseG2True) {
|
||||
FppTest::SmChoice::SequenceU32 sequenceU32;
|
||||
sequenceU32.testG1FalseG2True();
|
||||
}
|
||||
|
||||
TEST(SequenceU32, G1FalseG2False) {
|
||||
FppTest::SmChoice::SequenceU32 sequenceU32;
|
||||
sequenceU32.testG1FalseG2False();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Main function
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
STest::Random::seed();
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
11
FppTest/state_machine/internal/harness/CMakeLists.txt
Normal file
11
FppTest/state_machine/internal/harness/CMakeLists.txt
Normal file
@ -0,0 +1,11 @@
|
||||
set(SOURCE_FILES
|
||||
"${CMAKE_CURRENT_LIST_DIR}/Harness.fpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/TestAbsType.cpp"
|
||||
)
|
||||
register_fprime_module()
|
||||
|
||||
set(UT_SOURCE_FILES
|
||||
"${CMAKE_CURRENT_LIST_DIR}/main.cpp"
|
||||
)
|
||||
set(UT_MOD_DEPS STest)
|
||||
register_fprime_ut()
|
||||
73
FppTest/state_machine/internal/harness/Guard.hpp
Normal file
73
FppTest/state_machine/internal/harness/Guard.hpp
Normal file
@ -0,0 +1,73 @@
|
||||
// ======================================================================
|
||||
//
|
||||
// \title Guard.hpp
|
||||
// \author R. Bocchino
|
||||
// \brief Template for test implementation of a state machine guard
|
||||
//
|
||||
// \copyright
|
||||
// Copyright 2024, by the California Institute of Technology.
|
||||
// ALL RIGHTS RESERVED. United States Government Sponsorship
|
||||
// acknowledged.
|
||||
//
|
||||
// ======================================================================
|
||||
|
||||
#ifndef FppTest_SmHarness_Guard_HPP
|
||||
#define FppTest_SmHarness_Guard_HPP
|
||||
|
||||
#include <FpConfig.hpp>
|
||||
#include "FppTest/state_machine/internal/harness/SignalValueHistory.hpp"
|
||||
|
||||
namespace FppTest {
|
||||
|
||||
namespace SmHarness {
|
||||
|
||||
//! Test implementation of a state machine guard with a value argument
|
||||
template <typename Signal, typename T, FwSizeType size>
|
||||
class Guard {
|
||||
public:
|
||||
//! The call history type
|
||||
using CallHistory = SignalValueHistory<Signal, T, size>;
|
||||
|
||||
//! Constructor
|
||||
Guard() {}
|
||||
|
||||
//! Reset the guard to the initial state
|
||||
void reset() {
|
||||
this->m_callHistory.clear();
|
||||
this->m_returnValue = false;
|
||||
}
|
||||
|
||||
//! Clear the call history but keep the return value
|
||||
void clearCallHistory() { this->m_callHistory.clear(); }
|
||||
|
||||
//! Call the guard
|
||||
bool call(Signal signal, //!< The signal
|
||||
const T& arg //!< The argument
|
||||
) const {
|
||||
// Use const cast to update the history
|
||||
const_cast<Guard<Signal, T, size>*>(this)->m_callHistory.push(signal, arg);
|
||||
return this->m_returnValue;
|
||||
}
|
||||
|
||||
//! Set the return value
|
||||
void setReturnValue(bool returnValue //!< The return value
|
||||
) {
|
||||
this->m_returnValue = returnValue;
|
||||
}
|
||||
|
||||
//! Get the call history
|
||||
const CallHistory& getCallHistory() const { return this->m_callHistory; }
|
||||
|
||||
private:
|
||||
//! The return value
|
||||
bool m_returnValue = false;
|
||||
|
||||
//! The call history
|
||||
CallHistory m_callHistory = {};
|
||||
};
|
||||
|
||||
} // namespace SmHarness
|
||||
|
||||
} // end namespace FppTest
|
||||
|
||||
#endif
|
||||
17
FppTest/state_machine/internal/harness/Harness.fpp
Normal file
17
FppTest/state_machine/internal/harness/Harness.fpp
Normal file
@ -0,0 +1,17 @@
|
||||
module FppTest {
|
||||
|
||||
module SmHarness {
|
||||
|
||||
type TestAbsType
|
||||
|
||||
enum TestEnum { A, B, C }
|
||||
|
||||
array TestArray = [3] U32
|
||||
|
||||
struct TestStruct {
|
||||
x: U32
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
24
FppTest/state_machine/internal/harness/Harness.hpp
Normal file
24
FppTest/state_machine/internal/harness/Harness.hpp
Normal file
@ -0,0 +1,24 @@
|
||||
// ======================================================================
|
||||
//
|
||||
// \title Harness.hpp
|
||||
// \author R. Bocchino
|
||||
// \brief Header file for internal state machine test harness
|
||||
//
|
||||
// \copyright
|
||||
// Copyright 2024, by the California Institute of Technology.
|
||||
// ALL RIGHTS RESERVED. United States Government Sponsorship
|
||||
// acknowledged.
|
||||
//
|
||||
// ======================================================================
|
||||
|
||||
#ifndef FppTest_SmHarness_HPP
|
||||
#define FppTest_SmHarness_HPP
|
||||
|
||||
#include "FppTest/state_machine/internal/harness/Guard.hpp"
|
||||
#include "FppTest/state_machine/internal/harness/History.hpp"
|
||||
#include "FppTest/state_machine/internal/harness/NoArgGuard.hpp"
|
||||
#include "FppTest/state_machine/internal/harness/Pick.hpp"
|
||||
#include "FppTest/state_machine/internal/harness/SignalValueHistory.hpp"
|
||||
#include "FppTest/state_machine/internal/harness/TestAbsType.hpp"
|
||||
|
||||
#endif
|
||||
81
FppTest/state_machine/internal/harness/History.hpp
Normal file
81
FppTest/state_machine/internal/harness/History.hpp
Normal file
@ -0,0 +1,81 @@
|
||||
// ======================================================================
|
||||
//
|
||||
// \title History.hpp
|
||||
// \author R. Bocchino
|
||||
// \brief Header for a history of value items
|
||||
//
|
||||
// \copyright
|
||||
// Copyright 2024, by the California Institute of Technology.
|
||||
// ALL RIGHTS RESERVED. United States Government Sponsorship
|
||||
// acknowledged.
|
||||
//
|
||||
// ======================================================================
|
||||
|
||||
#ifndef FppTest_SmHarness_History_HPP
|
||||
#define FppTest_SmHarness_History_HPP
|
||||
|
||||
#include <FpConfig.hpp>
|
||||
#include <array>
|
||||
|
||||
#include "Fw/Types/Assert.hpp"
|
||||
|
||||
namespace FppTest {
|
||||
|
||||
namespace SmHarness {
|
||||
|
||||
//! A history of value items
|
||||
template <typename T, FwSizeType size>
|
||||
class History {
|
||||
public:
|
||||
//! Constructor
|
||||
History() {}
|
||||
|
||||
//! Clear the history
|
||||
void clear() { this->m_size = 0; }
|
||||
|
||||
//! Check two histories for equality
|
||||
bool operator==(History& history //!< The other history
|
||||
) const {
|
||||
bool result = (this->m_size == history.m_size);
|
||||
if (result) {
|
||||
for (FwSizeType i = 0; i < this->m_size; i++) {
|
||||
if (this->m_items[i] != history.m_items[i]) {
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//! Push an item on the history
|
||||
void push(const T& item //!< The item
|
||||
) {
|
||||
FW_ASSERT(m_size < size);
|
||||
this->m_items[m_size] = T(item);
|
||||
this->m_size++;
|
||||
}
|
||||
|
||||
//! Get the history size
|
||||
FwSizeType getSize() const { return this->m_size; }
|
||||
|
||||
//! Get the history item at an index
|
||||
const T& getItemAt(FwIndexType index //!< The index
|
||||
) const {
|
||||
FW_ASSERT(index < this->m_size);
|
||||
return this->m_items[index];
|
||||
}
|
||||
|
||||
private:
|
||||
//! The history size
|
||||
FwSizeType m_size = 0;
|
||||
|
||||
//! The items in the history
|
||||
std::array<T, size> m_items = {};
|
||||
};
|
||||
|
||||
} // namespace SmHarness
|
||||
|
||||
} // end namespace FppTest
|
||||
|
||||
#endif
|
||||
72
FppTest/state_machine/internal/harness/NoArgGuard.hpp
Normal file
72
FppTest/state_machine/internal/harness/NoArgGuard.hpp
Normal file
@ -0,0 +1,72 @@
|
||||
// ======================================================================
|
||||
//
|
||||
// \title NoArgGuard.hpp
|
||||
// \author R. Bocchino
|
||||
// \brief Class for test implementation of a state machine guard
|
||||
// with no argument value
|
||||
//
|
||||
// \copyright
|
||||
// Copyright 2024, by the California Institute of Technology.
|
||||
// ALL RIGHTS RESERVED. United States Government Sponsorship
|
||||
// acknowledged.
|
||||
//
|
||||
// ======================================================================
|
||||
|
||||
#ifndef FppTest_SmHarness_NoArgGuard_HPP
|
||||
#define FppTest_SmHarness_NoArgGuard_HPP
|
||||
|
||||
#include "FppTest/state_machine/internal/harness/History.hpp"
|
||||
|
||||
namespace FppTest {
|
||||
|
||||
namespace SmHarness {
|
||||
|
||||
//! Test implementation of a state machine guard with no argument value
|
||||
template <typename Signal, FwSizeType size>
|
||||
class NoArgGuard {
|
||||
public:
|
||||
//! Call history type
|
||||
using CallHistory = History<Signal, size>;
|
||||
|
||||
//! Constructor
|
||||
NoArgGuard() : m_callHistory() {}
|
||||
|
||||
//! Reset the guard to the initial state
|
||||
void reset() {
|
||||
this->m_callHistory.clear();
|
||||
this->m_returnValue = false;
|
||||
}
|
||||
|
||||
//! Clear the call history but keep the return value
|
||||
void clearCallHistory() { this->m_callHistory.clear(); }
|
||||
|
||||
//! Call the guard
|
||||
bool call(Signal signal //!< The signal
|
||||
) const {
|
||||
// Use const cast to update the history
|
||||
const_cast<NoArgGuard<Signal, size>*>(this)->m_callHistory.push(signal);
|
||||
return this->m_returnValue;
|
||||
}
|
||||
|
||||
//! Set the return value
|
||||
void setReturnValue(bool returnValue //!< The return value
|
||||
) {
|
||||
this->m_returnValue = returnValue;
|
||||
}
|
||||
|
||||
//! Get the call history
|
||||
const CallHistory& getCallHistory() const { return this->m_callHistory; }
|
||||
|
||||
private:
|
||||
//! The return value
|
||||
bool m_returnValue = false;
|
||||
|
||||
//! The call history
|
||||
CallHistory m_callHistory;
|
||||
};
|
||||
|
||||
} // namespace SmHarness
|
||||
|
||||
} // end namespace FppTest
|
||||
|
||||
#endif
|
||||
88
FppTest/state_machine/internal/harness/Pick.hpp
Normal file
88
FppTest/state_machine/internal/harness/Pick.hpp
Normal file
@ -0,0 +1,88 @@
|
||||
// ======================================================================
|
||||
//
|
||||
// \title Pick.hpp
|
||||
// \author R. Bocchino
|
||||
// \brief Header file for picking state machine test values
|
||||
//
|
||||
// \copyright
|
||||
// Copyright 2024, by the California Institute of Technology.
|
||||
// ALL RIGHTS RESERVED. United States Government Sponsorship
|
||||
// acknowledged.
|
||||
//
|
||||
// ======================================================================
|
||||
|
||||
#ifndef FppTest_SmHarness_Pick_HPP
|
||||
#define FppTest_SmHarness_Pick_HPP
|
||||
|
||||
#include <FpConfig.hpp>
|
||||
#include <limits>
|
||||
|
||||
#include "FppTest/state_machine/internal/harness/TestAbsType.hpp"
|
||||
#include "FppTest/state_machine/internal/harness/TestArrayArrayAc.hpp"
|
||||
#include "FppTest/state_machine/internal/harness/TestEnumEnumAc.hpp"
|
||||
#include "FppTest/state_machine/internal/harness/TestStructSerializableAc.hpp"
|
||||
#include "Fw/Types/String.hpp"
|
||||
#include "STest/STest/Pick/Pick.hpp"
|
||||
|
||||
namespace FppTest {
|
||||
|
||||
namespace SmHarness {
|
||||
|
||||
namespace Pick {
|
||||
|
||||
//! Pick a state machine ID
|
||||
static inline FwEnumStoreType stateMachineId() {
|
||||
const U32 upper = FW_MIN(std::numeric_limits<FwEnumStoreType>::max(), std::numeric_limits<U32>::max());
|
||||
const U32 id = STest::Pick::lowerUpper(0, upper);
|
||||
return static_cast<FwEnumStoreType>(id);
|
||||
}
|
||||
|
||||
//! Pick a TestAbsType value
|
||||
static inline TestAbsType testAbsType() {
|
||||
const U32 data = STest::Pick::any();
|
||||
return TestAbsType(data);
|
||||
}
|
||||
|
||||
//! Pick a TestArray value
|
||||
static inline TestArray testArray() {
|
||||
TestArray result;
|
||||
for (FwIndexType i = 0; i < TestArray::SIZE; i++) {
|
||||
result[i] = STest::Pick::any();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//! Pick a TestEnum value
|
||||
static inline TestEnum testEnum() {
|
||||
const U32 u32Value = STest::Pick::startLength(0, TestEnum::NUM_CONSTANTS);
|
||||
const TestEnum::T enumValue = static_cast<TestEnum::T>(u32Value);
|
||||
return TestEnum(enumValue);
|
||||
}
|
||||
|
||||
//! Pick a TestStruct value
|
||||
static inline TestStruct testStruct() {
|
||||
const U32 x = STest::Pick::any();
|
||||
return TestStruct(x);
|
||||
}
|
||||
|
||||
//! Pick a string value
|
||||
static inline void string(Fw::StringBase& s, //!< The string value (output)
|
||||
FwSizeType maxLen = Fw::String::STRING_SIZE //!< The max string length
|
||||
) {
|
||||
const U32 size = STest::Pick::lowerUpper(0, maxLen);
|
||||
s = "";
|
||||
for (U32 i = 0; i < size; i++) {
|
||||
char c = static_cast<char>(STest::Pick::lowerUpper(32, 126));
|
||||
Fw::String cString;
|
||||
cString.format("%c", c);
|
||||
s += cString;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Pick
|
||||
|
||||
} // namespace SmHarness
|
||||
|
||||
} // namespace FppTest
|
||||
|
||||
#endif
|
||||
3
FppTest/state_machine/internal/harness/README.md
Normal file
3
FppTest/state_machine/internal/harness/README.md
Normal file
@ -0,0 +1,3 @@
|
||||
# state_machine/internal/harness
|
||||
|
||||
Harness code for testing FPP internal state machines.
|
||||
@ -0,0 +1,88 @@
|
||||
// ======================================================================
|
||||
//
|
||||
// \title SignalValueHistory.hpp
|
||||
// \author R. Bocchino
|
||||
// \brief Template for a history of calls with signals and values
|
||||
//
|
||||
// \copyright
|
||||
// Copyright 2024, by the California Institute of Technology.
|
||||
// ALL RIGHTS RESERVED. United States Government Sponsorship
|
||||
// acknowledged.
|
||||
//
|
||||
// ======================================================================
|
||||
|
||||
#ifndef FppTest_SmHarness_SignalValueHistory_HPP
|
||||
#define FppTest_SmHarness_SignalValueHistory_HPP
|
||||
|
||||
#include <FpConfig.hpp>
|
||||
#include <array>
|
||||
|
||||
#include "FppTest/state_machine/internal/harness/History.hpp"
|
||||
#include "Fw/Types/Assert.hpp"
|
||||
|
||||
namespace FppTest {
|
||||
|
||||
namespace SmHarness {
|
||||
|
||||
//! A history with signals and values
|
||||
template <typename Signal, typename T, FwSizeType size>
|
||||
class SignalValueHistory {
|
||||
public:
|
||||
//! The signal history type
|
||||
using SignalHistory = History<Signal, size>;
|
||||
|
||||
//! The value history type
|
||||
using ValueHistory = History<T, size>;
|
||||
|
||||
//! Constructor
|
||||
SignalValueHistory() : m_signals(), m_values() {}
|
||||
|
||||
//! Clear the history
|
||||
void clear() {
|
||||
this->m_size = 0;
|
||||
this->m_signals.clear();
|
||||
this->m_values.clear();
|
||||
}
|
||||
|
||||
//! Check two histories for equality
|
||||
bool operator==(SignalValueHistory& history //!< The other history
|
||||
) const {
|
||||
return (this->m_size == history.m_size) && (this->m_signals = history.m_signals) &&
|
||||
(this->m_values = history.m_values);
|
||||
}
|
||||
|
||||
//! Push an item on the history
|
||||
void push(Signal signal, //!< The signal
|
||||
const T& value //!< The value
|
||||
) {
|
||||
FW_ASSERT(this->m_size < size, static_cast<FwAssertArgType>(this->m_size));
|
||||
this->m_signals.push(signal);
|
||||
this->m_values.push(value);
|
||||
this->m_size++;
|
||||
}
|
||||
|
||||
//! Get the history size
|
||||
FwSizeType getSize() const { return this->m_size; }
|
||||
|
||||
//! Get the signal history
|
||||
const SignalHistory& getSignals() const { return this->m_signals; }
|
||||
|
||||
//! Get the value history
|
||||
const ValueHistory& getValues() const { return this->m_values; }
|
||||
|
||||
private:
|
||||
//! The size of the history
|
||||
FwSizeType m_size = 0;
|
||||
|
||||
//! The signal history
|
||||
SignalHistory m_signals = {};
|
||||
|
||||
//! The values in the history
|
||||
ValueHistory m_values = {};
|
||||
};
|
||||
|
||||
} // namespace SmHarness
|
||||
|
||||
} // end namespace FppTest
|
||||
|
||||
#endif
|
||||
38
FppTest/state_machine/internal/harness/TestAbsType.cpp
Normal file
38
FppTest/state_machine/internal/harness/TestAbsType.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
// ======================================================================
|
||||
//
|
||||
// \title TestAbsType.cpp
|
||||
// \author R. Bocchino
|
||||
// \brief An abstract type for testing (implementation)
|
||||
//
|
||||
// \copyright
|
||||
// Copyright 2024, by the California Institute of Technology.
|
||||
// ALL RIGHTS RESERVED. United States Government Sponsorship
|
||||
// acknowledged.
|
||||
//
|
||||
// ======================================================================
|
||||
|
||||
#include "FppTest/state_machine/internal/harness/TestAbsType.hpp"
|
||||
|
||||
namespace FppTest {
|
||||
|
||||
namespace SmHarness {
|
||||
|
||||
#ifdef BUILD_UT
|
||||
std::ostream& operator<<(std::ostream& os, const TestAbsType& obj) {
|
||||
Fw::String s;
|
||||
obj.toString(s);
|
||||
os << s;
|
||||
return os;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if FW_SERIALIZABLE_TO_STRING
|
||||
void TestAbsType::toString(Fw::StringBase& sb) const {
|
||||
static const char* formatString = "TestAbsType(%" PRIu32 ")";
|
||||
sb.format(formatString, this->m_data);
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace SmHarness
|
||||
|
||||
} // namespace FppTest
|
||||
77
FppTest/state_machine/internal/harness/TestAbsType.hpp
Normal file
77
FppTest/state_machine/internal/harness/TestAbsType.hpp
Normal file
@ -0,0 +1,77 @@
|
||||
// ======================================================================
|
||||
//
|
||||
// \title TestAbsType.hpp
|
||||
// \author R. Bocchino
|
||||
// \brief An abstract type for testing
|
||||
//
|
||||
// \copyright
|
||||
// Copyright 2024, by the California Institute of Technology.
|
||||
// ALL RIGHTS RESERVED. United States Government Sponsorship
|
||||
// acknowledged.
|
||||
//
|
||||
// ======================================================================
|
||||
|
||||
#ifndef FppTest_SmHarness_TestAbsType_HPP
|
||||
#define FppTest_SmHarness_TestAbsType_HPP
|
||||
|
||||
#include <ostream>
|
||||
|
||||
#include "Fw/Types/Serializable.hpp"
|
||||
#include "Fw/Types/String.hpp"
|
||||
|
||||
namespace FppTest {
|
||||
|
||||
namespace SmHarness {
|
||||
|
||||
//! An abstract type for testing
|
||||
struct TestAbsType final : public Fw::Serializable {
|
||||
//! The serialized size
|
||||
static constexpr FwSizeType SERIALIZED_SIZE = sizeof(U32);
|
||||
|
||||
//! Default-argument constructor
|
||||
TestAbsType() : m_data(0) {}
|
||||
|
||||
//! Supplied-argument constructor
|
||||
TestAbsType(U32 data //!< The data
|
||||
)
|
||||
: m_data(data) {}
|
||||
|
||||
//! Comparison operator
|
||||
bool operator==(const TestAbsType& obj) const { return this->m_data == obj.m_data; }
|
||||
|
||||
#ifdef BUILD_UT
|
||||
//! Ostream operator
|
||||
friend std::ostream& operator<<(std::ostream& os, //!< The ostream
|
||||
const TestAbsType& obj //!< The object
|
||||
);
|
||||
#endif
|
||||
|
||||
//! Serialize function
|
||||
//! \return Status
|
||||
Fw::SerializeStatus serialize(Fw::SerializeBufferBase& sbb //!< The serialize buffer base
|
||||
) const final {
|
||||
return sbb.serialize(this->m_data);
|
||||
}
|
||||
|
||||
//! Deserialize method
|
||||
//! \return status
|
||||
Fw::SerializeStatus deserialize(Fw::SerializeBufferBase& sbb //!< The serialize buffer base
|
||||
) final {
|
||||
return sbb.deserialize(this->m_data);
|
||||
}
|
||||
|
||||
#if FW_SERIALIZABLE_TO_STRING
|
||||
//! Convert TestAbsType to string
|
||||
void toString(Fw::StringBase& sb //!< The StringBase object to hold the result
|
||||
) const;
|
||||
#endif
|
||||
|
||||
//! The data
|
||||
U32 m_data;
|
||||
};
|
||||
|
||||
} // namespace SmHarness
|
||||
|
||||
} // namespace FppTest
|
||||
|
||||
#endif
|
||||
7
FppTest/state_machine/internal/harness/main.cpp
Normal file
7
FppTest/state_machine/internal/harness/main.cpp
Normal file
@ -0,0 +1,7 @@
|
||||
// Main function so we can do a unit test build in this directory
|
||||
|
||||
#include "Harness.hpp"
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
return 0;
|
||||
}
|
||||
44
FppTest/state_machine/internal/initial/Basic.cpp
Normal file
44
FppTest/state_machine/internal/initial/Basic.cpp
Normal file
@ -0,0 +1,44 @@
|
||||
// ======================================================================
|
||||
//
|
||||
// \title Basic.hpp
|
||||
// \author R. Bocchino
|
||||
// \brief Test class for basic state machine (implementation)
|
||||
//
|
||||
// \copyright
|
||||
// Copyright 2024, by the California Institute of Technology.
|
||||
// ALL RIGHTS RESERVED. United States Government Sponsorship
|
||||
// acknowledged.
|
||||
//
|
||||
// ======================================================================
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "FppTest/state_machine/internal/initial/Basic.hpp"
|
||||
#include "STest/STest/Pick/Pick.hpp"
|
||||
|
||||
namespace FppTest {
|
||||
|
||||
namespace SmInitial {
|
||||
|
||||
Basic::Basic() : BasicStateMachineBase(), m_action_a_history() {}
|
||||
|
||||
void Basic::action_a(Signal signal) {
|
||||
this->m_action_a_history.push(signal);
|
||||
}
|
||||
|
||||
void Basic::test() {
|
||||
this->m_action_a_history.clear();
|
||||
const FwEnumStoreType id = SmHarness::Pick::stateMachineId();
|
||||
this->initBase(id);
|
||||
ASSERT_EQ(this->m_id, id);
|
||||
ASSERT_EQ(this->getState(), State::S);
|
||||
const FwSizeType expectedSize = 3;
|
||||
ASSERT_EQ(this->m_action_a_history.getSize(), expectedSize);
|
||||
for (FwSizeType i = 0; i < expectedSize; i++) {
|
||||
ASSERT_EQ(this->m_action_a_history.getItemAt(i), Signal::__FPRIME_AC_INITIAL_TRANSITION);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace SmInitial
|
||||
|
||||
} // end namespace FppTest
|
||||
9
FppTest/state_machine/internal/initial/Basic.fpp
Normal file
9
FppTest/state_machine/internal/initial/Basic.fpp
Normal file
@ -0,0 +1,9 @@
|
||||
module FppTest {
|
||||
|
||||
module SmInitial {
|
||||
|
||||
include "include/Basic.fppi"
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
52
FppTest/state_machine/internal/initial/Basic.hpp
Normal file
52
FppTest/state_machine/internal/initial/Basic.hpp
Normal file
@ -0,0 +1,52 @@
|
||||
// ======================================================================
|
||||
//
|
||||
// \title Basic.hpp
|
||||
// \author R. Bocchino
|
||||
// \brief Test class for basic state machine (header)
|
||||
//
|
||||
// \copyright
|
||||
// Copyright 2024, by the California Institute of Technology.
|
||||
// ALL RIGHTS RESERVED. United States Government Sponsorship
|
||||
// acknowledged.
|
||||
//
|
||||
// ======================================================================
|
||||
|
||||
#ifndef FppTest_Basic_HPP
|
||||
#define FppTest_Basic_HPP
|
||||
|
||||
#include "FppTest/state_machine/internal/harness/Harness.hpp"
|
||||
#include "FppTest/state_machine/internal/initial/BasicStateMachineAc.hpp"
|
||||
|
||||
namespace FppTest {
|
||||
|
||||
namespace SmInitial {
|
||||
|
||||
//! Basic state machine
|
||||
class Basic final : public BasicStateMachineBase {
|
||||
public:
|
||||
//! The history size
|
||||
static constexpr FwSizeType historySize = 10;
|
||||
|
||||
public:
|
||||
//! Constructor
|
||||
Basic();
|
||||
|
||||
private:
|
||||
//! Implementation of action a
|
||||
void action_a(Signal signal //!< The signal
|
||||
) final;
|
||||
|
||||
public:
|
||||
//! Run the test
|
||||
void test();
|
||||
|
||||
private:
|
||||
//! The history associated with action a
|
||||
SmHarness::History<Signal, historySize> m_action_a_history;
|
||||
};
|
||||
|
||||
} // namespace SmInitial
|
||||
|
||||
} // end namespace FppTest
|
||||
|
||||
#endif
|
||||
16
FppTest/state_machine/internal/initial/CMakeLists.txt
Normal file
16
FppTest/state_machine/internal/initial/CMakeLists.txt
Normal file
@ -0,0 +1,16 @@
|
||||
set(SOURCE_FILES
|
||||
"${CMAKE_CURRENT_LIST_DIR}/Basic.fpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/Choice.fpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/Nested.fpp"
|
||||
)
|
||||
set(MOD_DEPS FppTest/state_machine/internal/harness)
|
||||
register_fprime_module()
|
||||
|
||||
set(UT_SOURCE_FILES
|
||||
"${CMAKE_CURRENT_LIST_DIR}/Basic.cpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/Choice.cpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/Nested.cpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/main.cpp"
|
||||
)
|
||||
set(UT_MOD_DEPS STest)
|
||||
register_fprime_ut()
|
||||
72
FppTest/state_machine/internal/initial/Choice.cpp
Normal file
72
FppTest/state_machine/internal/initial/Choice.cpp
Normal file
@ -0,0 +1,72 @@
|
||||
// ======================================================================
|
||||
//
|
||||
// \title Choice.hpp
|
||||
// \author R. Bocchino
|
||||
// \brief Test class for choice state machine (implementation)
|
||||
//
|
||||
// \copyright
|
||||
// Copyright 2024, by the California Institute of Technology.
|
||||
// ALL RIGHTS RESERVED. United States Government Sponsorship
|
||||
// acknowledged.
|
||||
//
|
||||
// ======================================================================
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <limits>
|
||||
|
||||
#include "FppTest/state_machine/internal/initial/Choice.hpp"
|
||||
#include "STest/STest/Pick/Pick.hpp"
|
||||
|
||||
namespace FppTest {
|
||||
|
||||
namespace SmInitial {
|
||||
|
||||
Choice::Choice() : ChoiceStateMachineBase(), m_action_a_history(), m_guard_g() {}
|
||||
|
||||
void Choice::action_a(Signal signal) {
|
||||
this->m_action_a_history.push(signal);
|
||||
}
|
||||
|
||||
bool Choice::guard_g(Signal signal) const {
|
||||
return m_guard_g.call(signal);
|
||||
}
|
||||
|
||||
void Choice::testFalse() {
|
||||
this->m_action_a_history.clear();
|
||||
this->m_guard_g.reset();
|
||||
const FwEnumStoreType id = SmHarness::Pick::stateMachineId();
|
||||
this->initBase(id);
|
||||
ASSERT_EQ(this->m_id, id);
|
||||
ASSERT_EQ(this->getState(), State::T);
|
||||
const FwSizeType expectedActionSize = 5;
|
||||
const FwSizeType expectedGuardSize = 1;
|
||||
this->checkActionsAndGuards(expectedActionSize, expectedGuardSize);
|
||||
}
|
||||
|
||||
void Choice::testTrue() {
|
||||
this->m_action_a_history.clear();
|
||||
this->m_guard_g.reset();
|
||||
this->m_guard_g.setReturnValue(true);
|
||||
const FwEnumStoreType id = SmHarness::Pick::stateMachineId();
|
||||
this->initBase(id);
|
||||
ASSERT_EQ(this->m_id, id);
|
||||
ASSERT_EQ(this->m_state, State::S);
|
||||
const FwSizeType expectedActionSize = 3;
|
||||
const FwSizeType expectedGuardSize = 1;
|
||||
this->checkActionsAndGuards(expectedActionSize, expectedGuardSize);
|
||||
}
|
||||
|
||||
void Choice::checkActionsAndGuards(FwSizeType expectedActionSize, FwSizeType expectedGuardSize) {
|
||||
ASSERT_EQ(this->m_action_a_history.getSize(), expectedActionSize);
|
||||
for (FwSizeType i = 0; i < expectedActionSize; i++) {
|
||||
ASSERT_EQ(this->m_action_a_history.getItemAt(i), Signal::__FPRIME_AC_INITIAL_TRANSITION);
|
||||
}
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getSize(), expectedGuardSize);
|
||||
for (FwSizeType i = 0; i < expectedGuardSize; i++) {
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getItemAt(i), Signal::__FPRIME_AC_INITIAL_TRANSITION);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace SmInitial
|
||||
|
||||
} // end namespace FppTest
|
||||
9
FppTest/state_machine/internal/initial/Choice.fpp
Normal file
9
FppTest/state_machine/internal/initial/Choice.fpp
Normal file
@ -0,0 +1,9 @@
|
||||
module FppTest {
|
||||
|
||||
module SmInitial {
|
||||
|
||||
include "include/Choice.fppi"
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
67
FppTest/state_machine/internal/initial/Choice.hpp
Normal file
67
FppTest/state_machine/internal/initial/Choice.hpp
Normal file
@ -0,0 +1,67 @@
|
||||
// ======================================================================
|
||||
//
|
||||
// \title Choice.hpp
|
||||
// \author R. Bocchino
|
||||
// \brief Test class for choice state machine (header)
|
||||
//
|
||||
// \copyright
|
||||
// Copyright 2024, by the California Institute of Technology.
|
||||
// ALL RIGHTS RESERVED. United States Government Sponsorship
|
||||
// acknowledged.
|
||||
//
|
||||
// ======================================================================
|
||||
|
||||
#ifndef FppTest_Choice_HPP
|
||||
#define FppTest_Choice_HPP
|
||||
|
||||
#include "FppTest/state_machine/internal/harness/Harness.hpp"
|
||||
#include "FppTest/state_machine/internal/initial/ChoiceStateMachineAc.hpp"
|
||||
|
||||
namespace FppTest {
|
||||
|
||||
namespace SmInitial {
|
||||
|
||||
//! Choice state machine
|
||||
class Choice final : public ChoiceStateMachineBase {
|
||||
public:
|
||||
static constexpr FwSizeType historySize = 10;
|
||||
|
||||
public:
|
||||
//! Constructor
|
||||
Choice();
|
||||
|
||||
private:
|
||||
//! Implementation of action a
|
||||
void action_a(Signal signal //!< The signal
|
||||
) final;
|
||||
|
||||
//! Implementation of guard g
|
||||
bool guard_g(Signal signal //!< The signal
|
||||
) const;
|
||||
|
||||
public:
|
||||
//! Test with true guard
|
||||
void testTrue();
|
||||
|
||||
//! Test with false guard
|
||||
void testFalse();
|
||||
|
||||
private:
|
||||
//! Helper function for checking actions and guards
|
||||
void checkActionsAndGuards(FwSizeType expectedActionSize, //!< The expected action size
|
||||
FwSizeType expectedGuardSize //!< The expected guard size
|
||||
);
|
||||
|
||||
private:
|
||||
//! The history associated with action a
|
||||
SmHarness::History<Signal, historySize> m_action_a_history;
|
||||
|
||||
//! The guard g
|
||||
SmHarness::NoArgGuard<Signal, historySize> m_guard_g;
|
||||
};
|
||||
|
||||
} // namespace SmInitial
|
||||
|
||||
} // end namespace FppTest
|
||||
|
||||
#endif
|
||||
45
FppTest/state_machine/internal/initial/Nested.cpp
Normal file
45
FppTest/state_machine/internal/initial/Nested.cpp
Normal file
@ -0,0 +1,45 @@
|
||||
// ======================================================================
|
||||
//
|
||||
// \title Nested.hpp
|
||||
// \author R. Bocchino
|
||||
// \brief Test class for basic state machine (implementation)
|
||||
//
|
||||
// \copyright
|
||||
// Copyright 2024, by the California Institute of Technology.
|
||||
// ALL RIGHTS RESERVED. United States Government Sponsorship
|
||||
// acknowledged.
|
||||
//
|
||||
// ======================================================================
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <limits>
|
||||
|
||||
#include "FppTest/state_machine/internal/initial/Nested.hpp"
|
||||
#include "STest/STest/Pick/Pick.hpp"
|
||||
|
||||
namespace FppTest {
|
||||
|
||||
namespace SmInitial {
|
||||
|
||||
Nested::Nested() : NestedStateMachineBase(), m_action_a_history() {}
|
||||
|
||||
void Nested::action_a(Signal signal) {
|
||||
this->m_action_a_history.push(signal);
|
||||
}
|
||||
|
||||
void Nested::test() {
|
||||
this->m_action_a_history.clear();
|
||||
const FwEnumStoreType id = SmHarness::Pick::stateMachineId();
|
||||
this->initBase(id);
|
||||
ASSERT_EQ(this->m_id, id);
|
||||
ASSERT_EQ(this->getState(), State::S_T);
|
||||
const FwSizeType expectedActionSize = 6;
|
||||
ASSERT_EQ(this->m_action_a_history.getSize(), expectedActionSize);
|
||||
for (FwSizeType i = 0; i < expectedActionSize; i++) {
|
||||
ASSERT_EQ(this->m_action_a_history.getItemAt(i), Signal::__FPRIME_AC_INITIAL_TRANSITION);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace SmInitial
|
||||
|
||||
} // end namespace FppTest
|
||||
9
FppTest/state_machine/internal/initial/Nested.fpp
Normal file
9
FppTest/state_machine/internal/initial/Nested.fpp
Normal file
@ -0,0 +1,9 @@
|
||||
module FppTest {
|
||||
|
||||
module SmInitial {
|
||||
|
||||
include "include/Nested.fppi"
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
52
FppTest/state_machine/internal/initial/Nested.hpp
Normal file
52
FppTest/state_machine/internal/initial/Nested.hpp
Normal file
@ -0,0 +1,52 @@
|
||||
// ======================================================================
|
||||
//
|
||||
// \title Nested.hpp
|
||||
// \author R. Bocchino
|
||||
// \brief Test class for basic state machine (header)
|
||||
//
|
||||
// \copyright
|
||||
// Copyright 2024, by the California Institute of Technology.
|
||||
// ALL RIGHTS RESERVED. United States Government Sponsorship
|
||||
// acknowledged.
|
||||
//
|
||||
// ======================================================================
|
||||
|
||||
#ifndef FppTest_Nested_HPP
|
||||
#define FppTest_Nested_HPP
|
||||
|
||||
#include "FppTest/state_machine/internal/harness/Harness.hpp"
|
||||
#include "FppTest/state_machine/internal/initial/NestedStateMachineAc.hpp"
|
||||
|
||||
namespace FppTest {
|
||||
|
||||
namespace SmInitial {
|
||||
|
||||
//! Nested state machine
|
||||
class Nested final : public NestedStateMachineBase {
|
||||
public:
|
||||
//! The history size
|
||||
static constexpr FwSizeType historySize = 10;
|
||||
|
||||
public:
|
||||
//! Constructor
|
||||
Nested();
|
||||
|
||||
private:
|
||||
//! Implementation of action a
|
||||
void action_a(Signal signal //!< The signal
|
||||
) final;
|
||||
|
||||
public:
|
||||
//! Run the test
|
||||
void test();
|
||||
|
||||
private:
|
||||
//! The history associated with action a
|
||||
SmHarness::History<Signal, historySize> m_action_a_history;
|
||||
};
|
||||
|
||||
} // namespace SmInitial
|
||||
|
||||
} // end namespace FppTest
|
||||
|
||||
#endif
|
||||
3
FppTest/state_machine/internal/initial/README.md
Normal file
3
FppTest/state_machine/internal/initial/README.md
Normal file
@ -0,0 +1,3 @@
|
||||
# state_machine/internal/initial
|
||||
|
||||
Tests for initial transitions in FPP internal state machines.
|
||||
14
FppTest/state_machine/internal/initial/include/Basic.fppi
Normal file
14
FppTest/state_machine/internal/initial/include/Basic.fppi
Normal file
@ -0,0 +1,14 @@
|
||||
@ A basic state machine
|
||||
state machine Basic {
|
||||
|
||||
@ Action a
|
||||
action a
|
||||
|
||||
initial do { a } enter S
|
||||
|
||||
@ State S
|
||||
state S {
|
||||
entry do { a, a }
|
||||
}
|
||||
|
||||
}
|
||||
25
FppTest/state_machine/internal/initial/include/Choice.fppi
Normal file
25
FppTest/state_machine/internal/initial/include/Choice.fppi
Normal file
@ -0,0 +1,25 @@
|
||||
@ A state machine with an initial choice
|
||||
state machine Choice {
|
||||
|
||||
@ Action a
|
||||
action a
|
||||
|
||||
@ Guard g
|
||||
guard g
|
||||
|
||||
initial do { a } enter C
|
||||
|
||||
@ Choice C
|
||||
choice C { if g do { a } enter S else do { a, a } enter T }
|
||||
|
||||
@ State S
|
||||
state S {
|
||||
entry do { a }
|
||||
}
|
||||
|
||||
@ State T
|
||||
state T {
|
||||
entry do { a, a }
|
||||
}
|
||||
|
||||
}
|
||||
23
FppTest/state_machine/internal/initial/include/Nested.fppi
Normal file
23
FppTest/state_machine/internal/initial/include/Nested.fppi
Normal file
@ -0,0 +1,23 @@
|
||||
@ A state machine with nested initial transitions
|
||||
state machine Nested {
|
||||
|
||||
@ Action a
|
||||
action a
|
||||
|
||||
initial do { a } enter S
|
||||
|
||||
@ State S
|
||||
state S {
|
||||
|
||||
entry do { a, a }
|
||||
|
||||
initial enter T
|
||||
|
||||
@ State S.T
|
||||
state T {
|
||||
entry do { a, a, a }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
40
FppTest/state_machine/internal/initial/main.cpp
Normal file
40
FppTest/state_machine/internal/initial/main.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
// ----------------------------------------------------------------------
|
||||
// main.cpp
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "FppTest/state_machine/internal/initial/Basic.hpp"
|
||||
#include "FppTest/state_machine/internal/initial/Choice.hpp"
|
||||
#include "FppTest/state_machine/internal/initial/Nested.hpp"
|
||||
#include "STest/STest/Random/Random.hpp"
|
||||
|
||||
TEST(Basic, Test) {
|
||||
FppTest::SmInitial::Basic basic;
|
||||
basic.test();
|
||||
}
|
||||
|
||||
TEST(Choice, False) {
|
||||
FppTest::SmInitial::Choice choice;
|
||||
choice.testFalse();
|
||||
}
|
||||
|
||||
TEST(Choice, True) {
|
||||
FppTest::SmInitial::Choice choice;
|
||||
choice.testTrue();
|
||||
}
|
||||
|
||||
TEST(Nested, Test) {
|
||||
FppTest::SmInitial::Nested nested;
|
||||
nested.test();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Main function
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
STest::Random::seed();
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
49
FppTest/state_machine/internal/state/Basic.cpp
Normal file
49
FppTest/state_machine/internal/state/Basic.cpp
Normal file
@ -0,0 +1,49 @@
|
||||
// ======================================================================
|
||||
//
|
||||
// \title Basic.hpp
|
||||
// \author R. Bocchino
|
||||
// \brief Test class for basic state machine (implementation)
|
||||
//
|
||||
// \copyright
|
||||
// Copyright 2024, by the California Institute of Technology.
|
||||
// ALL RIGHTS RESERVED. United States Government Sponsorship
|
||||
// acknowledged.
|
||||
//
|
||||
// ======================================================================
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "FppTest/state_machine/internal/state/Basic.hpp"
|
||||
#include "STest/STest/Pick/Pick.hpp"
|
||||
|
||||
namespace FppTest {
|
||||
|
||||
namespace SmState {
|
||||
|
||||
Basic::Basic() : BasicStateMachineBase(), m_action_a_history() {}
|
||||
|
||||
void Basic::action_a(Signal signal) {
|
||||
this->m_action_a_history.push(signal);
|
||||
}
|
||||
|
||||
void Basic::test() {
|
||||
this->m_action_a_history.clear();
|
||||
const FwEnumStoreType id = SmHarness::Pick::stateMachineId();
|
||||
this->initBase(id);
|
||||
ASSERT_EQ(this->m_id, id);
|
||||
ASSERT_EQ(this->getState(), State::S);
|
||||
ASSERT_EQ(this->m_action_a_history.getSize(), 0);
|
||||
this->sendSignal_s();
|
||||
ASSERT_EQ(this->getState(), State::T);
|
||||
this->sendSignal_s();
|
||||
ASSERT_EQ(this->getState(), State::T);
|
||||
const FwSizeType expectedSize = 6;
|
||||
ASSERT_EQ(this->m_action_a_history.getSize(), expectedSize);
|
||||
for (FwSizeType i = 0; i < expectedSize; i++) {
|
||||
ASSERT_EQ(this->m_action_a_history.getItemAt(i), Signal::s);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace SmState
|
||||
|
||||
} // end namespace FppTest
|
||||
9
FppTest/state_machine/internal/state/Basic.fpp
Normal file
9
FppTest/state_machine/internal/state/Basic.fpp
Normal file
@ -0,0 +1,9 @@
|
||||
module FppTest {
|
||||
|
||||
module SmState {
|
||||
|
||||
include "include/Basic.fppi"
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
52
FppTest/state_machine/internal/state/Basic.hpp
Normal file
52
FppTest/state_machine/internal/state/Basic.hpp
Normal file
@ -0,0 +1,52 @@
|
||||
// ======================================================================
|
||||
//
|
||||
// \title Basic.hpp
|
||||
// \author R. Bocchino
|
||||
// \brief Test class for basic state machine (header)
|
||||
//
|
||||
// \copyright
|
||||
// Copyright 2024, by the California Institute of Technology.
|
||||
// ALL RIGHTS RESERVED. United States Government Sponsorship
|
||||
// acknowledged.
|
||||
//
|
||||
// ======================================================================
|
||||
|
||||
#ifndef FppTest_State_Basic_HPP
|
||||
#define FppTest_State_Basic_HPP
|
||||
|
||||
#include "FppTest/state_machine/internal/harness/Harness.hpp"
|
||||
#include "FppTest/state_machine/internal/state/BasicStateMachineAc.hpp"
|
||||
|
||||
namespace FppTest {
|
||||
|
||||
namespace SmState {
|
||||
|
||||
//! A basic state machine
|
||||
class Basic final : public BasicStateMachineBase {
|
||||
public:
|
||||
//! The history size
|
||||
static constexpr FwSizeType historySize = 10;
|
||||
|
||||
public:
|
||||
//! Constructor
|
||||
Basic();
|
||||
|
||||
private:
|
||||
//! Implementation of action a
|
||||
void action_a(Signal signal //!< The signal
|
||||
) final;
|
||||
|
||||
public:
|
||||
//! Run the test
|
||||
void test();
|
||||
|
||||
private:
|
||||
//! The history associated with action a
|
||||
SmHarness::History<Signal, historySize> m_action_a_history;
|
||||
};
|
||||
|
||||
} // namespace SmState
|
||||
|
||||
} // end namespace FppTest
|
||||
|
||||
#endif
|
||||
75
FppTest/state_machine/internal/state/BasicGuard.cpp
Normal file
75
FppTest/state_machine/internal/state/BasicGuard.cpp
Normal file
@ -0,0 +1,75 @@
|
||||
// ======================================================================
|
||||
//
|
||||
// \title BasicGuard.hpp
|
||||
// \author R. Bocchino
|
||||
// \brief Test class for basic state machine with guard (implementation)
|
||||
//
|
||||
// \copyright
|
||||
// Copyright 2024, by the California Institute of Technology.
|
||||
// ALL RIGHTS RESERVED. United States Government Sponsorship
|
||||
// acknowledged.
|
||||
//
|
||||
// ======================================================================
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "FppTest/state_machine/internal/state/BasicGuard.hpp"
|
||||
#include "STest/STest/Pick/Pick.hpp"
|
||||
|
||||
namespace FppTest {
|
||||
|
||||
namespace SmState {
|
||||
|
||||
BasicGuard::BasicGuard() : BasicGuardStateMachineBase(), m_action_a_history(), m_guard_g() {}
|
||||
|
||||
void BasicGuard::action_a(Signal signal) {
|
||||
this->m_action_a_history.push(signal);
|
||||
}
|
||||
|
||||
bool BasicGuard::guard_g(Signal signal) const {
|
||||
return this->m_guard_g.call(signal);
|
||||
}
|
||||
|
||||
void BasicGuard::testFalse() {
|
||||
this->m_action_a_history.clear();
|
||||
this->m_guard_g.reset();
|
||||
const FwEnumStoreType id = SmHarness::Pick::stateMachineId();
|
||||
this->initBase(id);
|
||||
ASSERT_EQ(this->m_id, id);
|
||||
ASSERT_EQ(this->getState(), State::S);
|
||||
ASSERT_EQ(this->m_action_a_history.getSize(), 0);
|
||||
this->sendSignal_s();
|
||||
ASSERT_EQ(this->getState(), State::S);
|
||||
this->checkActionsAndGuards(0, 1);
|
||||
}
|
||||
|
||||
void BasicGuard::testTrue() {
|
||||
this->m_action_a_history.clear();
|
||||
this->m_guard_g.reset();
|
||||
this->m_guard_g.setReturnValue(true);
|
||||
const FwEnumStoreType id = SmHarness::Pick::stateMachineId();
|
||||
this->initBase(id);
|
||||
ASSERT_EQ(this->m_id, id);
|
||||
ASSERT_EQ(this->getState(), State::S);
|
||||
ASSERT_EQ(this->m_action_a_history.getSize(), 0);
|
||||
this->sendSignal_s();
|
||||
ASSERT_EQ(this->getState(), State::T);
|
||||
this->sendSignal_s();
|
||||
ASSERT_EQ(this->getState(), State::T);
|
||||
this->checkActionsAndGuards(6, 1);
|
||||
}
|
||||
|
||||
void BasicGuard::checkActionsAndGuards(FwSizeType expectedActionSize, FwSizeType expectedGuardSize) {
|
||||
ASSERT_EQ(this->m_action_a_history.getSize(), expectedActionSize);
|
||||
for (FwSizeType i = 0; i < expectedActionSize; i++) {
|
||||
ASSERT_EQ(this->m_action_a_history.getItemAt(i), Signal::s);
|
||||
}
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getSize(), expectedGuardSize);
|
||||
for (FwSizeType i = 0; i < expectedGuardSize; i++) {
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getItemAt(i), Signal::s);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace SmState
|
||||
|
||||
} // end namespace FppTest
|
||||
9
FppTest/state_machine/internal/state/BasicGuard.fpp
Normal file
9
FppTest/state_machine/internal/state/BasicGuard.fpp
Normal file
@ -0,0 +1,9 @@
|
||||
module FppTest {
|
||||
|
||||
module SmState {
|
||||
|
||||
include "include/BasicGuard.fppi"
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
68
FppTest/state_machine/internal/state/BasicGuard.hpp
Normal file
68
FppTest/state_machine/internal/state/BasicGuard.hpp
Normal file
@ -0,0 +1,68 @@
|
||||
// ======================================================================
|
||||
//
|
||||
// \title BasicGuard.hpp
|
||||
// \author R. Bocchino
|
||||
// \brief Test class for basic state machine with guard (header)
|
||||
//
|
||||
// \copyright
|
||||
// Copyright 2024, by the California Institute of Technology.
|
||||
// ALL RIGHTS RESERVED. United States Government Sponsorship
|
||||
// acknowledged.
|
||||
//
|
||||
// ======================================================================
|
||||
|
||||
#ifndef FppTest_State_BasicGuard_HPP
|
||||
#define FppTest_State_BasicGuard_HPP
|
||||
|
||||
#include "FppTest/state_machine/internal/harness/Harness.hpp"
|
||||
#include "FppTest/state_machine/internal/state/BasicGuardStateMachineAc.hpp"
|
||||
|
||||
namespace FppTest {
|
||||
|
||||
namespace SmState {
|
||||
|
||||
//! A basic state machine with a guard
|
||||
class BasicGuard final : public BasicGuardStateMachineBase {
|
||||
public:
|
||||
//! The history size
|
||||
static constexpr FwSizeType historySize = 10;
|
||||
|
||||
public:
|
||||
//! Constructor
|
||||
BasicGuard();
|
||||
|
||||
private:
|
||||
//! Implementation of action a
|
||||
void action_a(Signal signal //!< The signal
|
||||
) final;
|
||||
|
||||
//! Implementation of guard g
|
||||
bool guard_g(Signal signal //!< The signal
|
||||
) const;
|
||||
|
||||
public:
|
||||
//! Test with true guard
|
||||
void testTrue();
|
||||
|
||||
//! Test with false guard
|
||||
void testFalse();
|
||||
|
||||
private:
|
||||
//! Helper function for checking actions and guards
|
||||
void checkActionsAndGuards(FwSizeType expectedActionSize, //!< The expected action size
|
||||
FwSizeType expectedGuardSize //!< The expected guard size
|
||||
);
|
||||
|
||||
private:
|
||||
//! The history associated with action a
|
||||
SmHarness::History<Signal, historySize> m_action_a_history;
|
||||
|
||||
//! The guard g
|
||||
SmHarness::NoArgGuard<Signal, historySize> m_guard_g;
|
||||
};
|
||||
|
||||
} // namespace SmState
|
||||
|
||||
} // end namespace FppTest
|
||||
|
||||
#endif
|
||||
77
FppTest/state_machine/internal/state/BasicGuardString.cpp
Normal file
77
FppTest/state_machine/internal/state/BasicGuardString.cpp
Normal file
@ -0,0 +1,77 @@
|
||||
// ======================================================================
|
||||
//
|
||||
// \title BasicGuardString.hpp
|
||||
// \author R. Bocchino
|
||||
// \brief Test class for basic state machine with string guard (implementation)
|
||||
//
|
||||
// \copyright
|
||||
// Copyright 2024, by the California Institute of Technology.
|
||||
// ALL RIGHTS RESERVED. United States Government Sponsorship
|
||||
// acknowledged.
|
||||
//
|
||||
// ======================================================================
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "FppTest/state_machine/internal/state/BasicGuardString.hpp"
|
||||
#include "STest/STest/Pick/Pick.hpp"
|
||||
|
||||
namespace FppTest {
|
||||
|
||||
namespace SmState {
|
||||
|
||||
BasicGuardString::BasicGuardString() : BasicGuardStringStateMachineBase(), m_action_a_history(), m_guard_g() {}
|
||||
|
||||
void BasicGuardString::action_a(Signal signal, const Fw::StringBase& value) {
|
||||
this->m_action_a_history.push(signal, Fw::String(value));
|
||||
}
|
||||
|
||||
bool BasicGuardString::guard_g(Signal signal, const Fw::StringBase& value) const {
|
||||
return this->m_guard_g.call(signal, Fw::String(value));
|
||||
}
|
||||
|
||||
void BasicGuardString::testFalse() {
|
||||
this->m_action_a_history.clear();
|
||||
this->m_guard_g.reset();
|
||||
const FwEnumStoreType id = SmHarness::Pick::stateMachineId();
|
||||
this->initBase(id);
|
||||
ASSERT_EQ(this->m_id, id);
|
||||
ASSERT_EQ(this->getState(), State::S);
|
||||
ASSERT_EQ(this->m_action_a_history.getSize(), 0);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getSize(), 0);
|
||||
Fw::String value;
|
||||
SmHarness::Pick::string(value);
|
||||
this->sendSignal_s(value);
|
||||
ASSERT_EQ(this->getState(), State::S);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getSize(), 1);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getSignals().getItemAt(0), Signal::s);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getValues().getItemAt(0), value);
|
||||
ASSERT_EQ(this->m_action_a_history.getSize(), 0);
|
||||
}
|
||||
|
||||
void BasicGuardString::testTrue() {
|
||||
this->m_action_a_history.clear();
|
||||
this->m_guard_g.reset();
|
||||
this->m_guard_g.setReturnValue(true);
|
||||
const FwEnumStoreType id = SmHarness::Pick::stateMachineId();
|
||||
this->initBase(id);
|
||||
ASSERT_EQ(this->m_id, id);
|
||||
ASSERT_EQ(this->getState(), State::S);
|
||||
ASSERT_EQ(this->m_action_a_history.getSize(), 0);
|
||||
Fw::String value;
|
||||
SmHarness::Pick::string(value);
|
||||
this->sendSignal_s(value);
|
||||
ASSERT_EQ(this->getState(), State::T);
|
||||
this->sendSignal_s(value);
|
||||
ASSERT_EQ(this->getState(), State::T);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getSize(), 1);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getSignals().getItemAt(0), Signal::s);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getValues().getItemAt(0), value);
|
||||
ASSERT_EQ(this->m_action_a_history.getSize(), 1);
|
||||
ASSERT_EQ(this->m_action_a_history.getSignals().getItemAt(0), Signal::s);
|
||||
ASSERT_EQ(this->m_action_a_history.getValues().getItemAt(0), value);
|
||||
}
|
||||
|
||||
} // namespace SmState
|
||||
|
||||
} // end namespace FppTest
|
||||
@ -0,0 +1,9 @@
|
||||
module FppTest {
|
||||
|
||||
module SmState {
|
||||
|
||||
include "include/BasicGuardString.fppi"
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
64
FppTest/state_machine/internal/state/BasicGuardString.hpp
Normal file
64
FppTest/state_machine/internal/state/BasicGuardString.hpp
Normal file
@ -0,0 +1,64 @@
|
||||
// ======================================================================
|
||||
//
|
||||
// \title BasicGuardString.hpp
|
||||
// \author R. Bocchino
|
||||
// \brief Test class for basic state machine with string guard (header)
|
||||
//
|
||||
// \copyright
|
||||
// Copyright 2024, by the California Institute of Technology.
|
||||
// ALL RIGHTS RESERVED. United States Government Sponsorship
|
||||
// acknowledged.
|
||||
//
|
||||
// ======================================================================
|
||||
|
||||
#ifndef FppTest_State_BasicGuardString_HPP
|
||||
#define FppTest_State_BasicGuardString_HPP
|
||||
|
||||
#include "FppTest/state_machine/internal/harness/Harness.hpp"
|
||||
#include "FppTest/state_machine/internal/state/BasicGuardStringStateMachineAc.hpp"
|
||||
|
||||
namespace FppTest {
|
||||
|
||||
namespace SmState {
|
||||
|
||||
//! A basic state machine with a String guard
|
||||
class BasicGuardString final : public BasicGuardStringStateMachineBase {
|
||||
public:
|
||||
//! The history size
|
||||
static constexpr FwSizeType historySize = 10;
|
||||
|
||||
public:
|
||||
//! Constructor
|
||||
BasicGuardString();
|
||||
|
||||
private:
|
||||
//! Implementation of action a
|
||||
void action_a(Signal signal, //!< The signal
|
||||
const Fw::StringBase& value //!< The value
|
||||
) final;
|
||||
|
||||
//! Implementation of guard g
|
||||
bool guard_g(Signal signal, //!< The signal
|
||||
const Fw::StringBase& value //!< The value
|
||||
) const;
|
||||
|
||||
public:
|
||||
//! Test with true guard
|
||||
void testTrue();
|
||||
|
||||
//! Test with false guard
|
||||
void testFalse();
|
||||
|
||||
private:
|
||||
//! The history associated with action a
|
||||
SmHarness::SignalValueHistory<Signal, Fw::String, historySize> m_action_a_history;
|
||||
|
||||
//! The guard g
|
||||
SmHarness::Guard<Signal, Fw::String, historySize> m_guard_g;
|
||||
};
|
||||
|
||||
} // namespace SmState
|
||||
|
||||
} // end namespace FppTest
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,76 @@
|
||||
// ======================================================================
|
||||
//
|
||||
// \title BasicGuardTestAbsType.hpp
|
||||
// \author R. Bocchino
|
||||
// \brief Test class for basic state machine with TestAbsType guard (implementation)
|
||||
//
|
||||
// \copyright
|
||||
// Copyright 2024, by the California Institute of Technology.
|
||||
// ALL RIGHTS RESERVED. United States Government Sponsorship
|
||||
// acknowledged.
|
||||
//
|
||||
// ======================================================================
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "FppTest/state_machine/internal/state/BasicGuardTestAbsType.hpp"
|
||||
#include "STest/STest/Pick/Pick.hpp"
|
||||
|
||||
namespace FppTest {
|
||||
|
||||
namespace SmState {
|
||||
|
||||
BasicGuardTestAbsType::BasicGuardTestAbsType()
|
||||
: BasicGuardTestAbsTypeStateMachineBase(), m_action_a_history(), m_guard_g() {}
|
||||
|
||||
void BasicGuardTestAbsType::action_a(Signal signal, const SmHarness::TestAbsType& value) {
|
||||
this->m_action_a_history.push(signal, value);
|
||||
}
|
||||
|
||||
bool BasicGuardTestAbsType::guard_g(Signal signal, const SmHarness::TestAbsType& value) const {
|
||||
return this->m_guard_g.call(signal, value);
|
||||
}
|
||||
|
||||
void BasicGuardTestAbsType::testFalse() {
|
||||
this->m_action_a_history.clear();
|
||||
this->m_guard_g.reset();
|
||||
const FwEnumStoreType id = SmHarness::Pick::stateMachineId();
|
||||
this->initBase(id);
|
||||
ASSERT_EQ(this->m_id, id);
|
||||
ASSERT_EQ(this->getState(), State::S);
|
||||
ASSERT_EQ(this->m_action_a_history.getSize(), 0);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getSize(), 0);
|
||||
const SmHarness::TestAbsType value = SmHarness::Pick::testAbsType();
|
||||
this->sendSignal_s(value);
|
||||
ASSERT_EQ(this->getState(), State::S);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getSize(), 1);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getSignals().getItemAt(0), Signal::s);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getValues().getItemAt(0), value);
|
||||
ASSERT_EQ(this->m_action_a_history.getSize(), 0);
|
||||
}
|
||||
|
||||
void BasicGuardTestAbsType::testTrue() {
|
||||
this->m_action_a_history.clear();
|
||||
this->m_guard_g.reset();
|
||||
this->m_guard_g.setReturnValue(true);
|
||||
const FwEnumStoreType id = SmHarness::Pick::stateMachineId();
|
||||
this->initBase(id);
|
||||
ASSERT_EQ(this->m_id, id);
|
||||
ASSERT_EQ(this->getState(), State::S);
|
||||
ASSERT_EQ(this->m_action_a_history.getSize(), 0);
|
||||
const SmHarness::TestAbsType value = SmHarness::Pick::testAbsType();
|
||||
this->sendSignal_s(value);
|
||||
ASSERT_EQ(this->getState(), State::T);
|
||||
this->sendSignal_s(value);
|
||||
ASSERT_EQ(this->getState(), State::T);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getSize(), 1);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getSignals().getItemAt(0), Signal::s);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getValues().getItemAt(0), value);
|
||||
ASSERT_EQ(this->m_action_a_history.getSize(), 1);
|
||||
ASSERT_EQ(this->m_action_a_history.getSignals().getItemAt(0), Signal::s);
|
||||
ASSERT_EQ(this->m_action_a_history.getValues().getItemAt(0), value);
|
||||
}
|
||||
|
||||
} // namespace SmState
|
||||
|
||||
} // end namespace FppTest
|
||||
@ -0,0 +1,9 @@
|
||||
module FppTest {
|
||||
|
||||
module SmState {
|
||||
|
||||
include "include/BasicGuardTestAbsType.fppi"
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,64 @@
|
||||
// ======================================================================
|
||||
//
|
||||
// \title BasicGuardTestAbsType.hpp
|
||||
// \author R. Bocchino
|
||||
// \brief Test class for basic state machine with TestAbsType guard (header)
|
||||
//
|
||||
// \copyright
|
||||
// Copyright 2024, by the California Institute of Technology.
|
||||
// ALL RIGHTS RESERVED. United States Government Sponsorship
|
||||
// acknowledged.
|
||||
//
|
||||
// ======================================================================
|
||||
|
||||
#ifndef FppTest_State_BasicGuardTestAbsType_HPP
|
||||
#define FppTest_State_BasicGuardTestAbsType_HPP
|
||||
|
||||
#include "FppTest/state_machine/internal/harness/Harness.hpp"
|
||||
#include "FppTest/state_machine/internal/state/BasicGuardTestAbsTypeStateMachineAc.hpp"
|
||||
|
||||
namespace FppTest {
|
||||
|
||||
namespace SmState {
|
||||
|
||||
//! A basic state machine with a TestAbsType guard
|
||||
class BasicGuardTestAbsType final : public BasicGuardTestAbsTypeStateMachineBase {
|
||||
public:
|
||||
//! The history size
|
||||
static constexpr FwSizeType historySize = 10;
|
||||
|
||||
public:
|
||||
//! Constructor
|
||||
BasicGuardTestAbsType();
|
||||
|
||||
private:
|
||||
//! Implementation of action a
|
||||
void action_a(Signal signal, //!< The signal
|
||||
const SmHarness::TestAbsType& value //!< The value
|
||||
) final;
|
||||
|
||||
//! Implementation of guard g
|
||||
bool guard_g(Signal signal, //!< The signal
|
||||
const SmHarness::TestAbsType& value //!< The value
|
||||
) const;
|
||||
|
||||
public:
|
||||
//! Test with true guard
|
||||
void testTrue();
|
||||
|
||||
//! Test with false guard
|
||||
void testFalse();
|
||||
|
||||
private:
|
||||
//! The history associated with action a
|
||||
SmHarness::SignalValueHistory<Signal, SmHarness::TestAbsType, historySize> m_action_a_history;
|
||||
|
||||
//! The guard g
|
||||
SmHarness::Guard<Signal, SmHarness::TestAbsType, historySize> m_guard_g;
|
||||
};
|
||||
|
||||
} // namespace SmState
|
||||
|
||||
} // end namespace FppTest
|
||||
|
||||
#endif
|
||||
75
FppTest/state_machine/internal/state/BasicGuardTestArray.cpp
Normal file
75
FppTest/state_machine/internal/state/BasicGuardTestArray.cpp
Normal file
@ -0,0 +1,75 @@
|
||||
// ======================================================================
|
||||
//
|
||||
// \title BasicGuardTestArray.hpp
|
||||
// \author R. Bocchino
|
||||
// \brief Test class for basic state machine with TestArray guard (implementation)
|
||||
//
|
||||
// \copyright
|
||||
// Copyright 2024, by the California Institute of Technology.
|
||||
// ALL RIGHTS RESERVED. United States Government Sponsorship
|
||||
// acknowledged.
|
||||
//
|
||||
// ======================================================================
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "FppTest/state_machine/internal/state/BasicGuardTestArray.hpp"
|
||||
#include "STest/STest/Pick/Pick.hpp"
|
||||
|
||||
namespace FppTest {
|
||||
|
||||
namespace SmState {
|
||||
|
||||
BasicGuardTestArray::BasicGuardTestArray() : BasicGuardTestArrayStateMachineBase(), m_action_a_history(), m_guard_g() {}
|
||||
|
||||
void BasicGuardTestArray::action_a(Signal signal, const SmHarness::TestArray& value) {
|
||||
this->m_action_a_history.push(signal, value);
|
||||
}
|
||||
|
||||
bool BasicGuardTestArray::guard_g(Signal signal, const SmHarness::TestArray& value) const {
|
||||
return this->m_guard_g.call(signal, value);
|
||||
}
|
||||
|
||||
void BasicGuardTestArray::testFalse() {
|
||||
this->m_action_a_history.clear();
|
||||
this->m_guard_g.reset();
|
||||
const FwEnumStoreType id = SmHarness::Pick::stateMachineId();
|
||||
this->initBase(id);
|
||||
ASSERT_EQ(this->m_id, id);
|
||||
ASSERT_EQ(this->getState(), State::S);
|
||||
ASSERT_EQ(this->m_action_a_history.getSize(), 0);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getSize(), 0);
|
||||
const SmHarness::TestArray value = SmHarness::Pick::testArray();
|
||||
this->sendSignal_s(value);
|
||||
ASSERT_EQ(this->getState(), State::S);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getSize(), 1);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getSignals().getItemAt(0), Signal::s);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getValues().getItemAt(0), value);
|
||||
ASSERT_EQ(this->m_action_a_history.getSize(), 0);
|
||||
}
|
||||
|
||||
void BasicGuardTestArray::testTrue() {
|
||||
this->m_action_a_history.clear();
|
||||
this->m_guard_g.reset();
|
||||
this->m_guard_g.setReturnValue(true);
|
||||
const FwEnumStoreType id = SmHarness::Pick::stateMachineId();
|
||||
this->initBase(id);
|
||||
ASSERT_EQ(this->m_id, id);
|
||||
ASSERT_EQ(this->getState(), State::S);
|
||||
ASSERT_EQ(this->m_action_a_history.getSize(), 0);
|
||||
const SmHarness::TestArray value = SmHarness::Pick::testArray();
|
||||
this->sendSignal_s(value);
|
||||
ASSERT_EQ(this->getState(), State::T);
|
||||
this->sendSignal_s(value);
|
||||
ASSERT_EQ(this->getState(), State::T);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getSize(), 1);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getSignals().getItemAt(0), Signal::s);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getValues().getItemAt(0), value);
|
||||
ASSERT_EQ(this->m_action_a_history.getSize(), 1);
|
||||
ASSERT_EQ(this->m_action_a_history.getSignals().getItemAt(0), Signal::s);
|
||||
ASSERT_EQ(this->m_action_a_history.getValues().getItemAt(0), value);
|
||||
}
|
||||
|
||||
} // namespace SmState
|
||||
|
||||
} // end namespace FppTest
|
||||
@ -0,0 +1,9 @@
|
||||
module FppTest {
|
||||
|
||||
module SmState {
|
||||
|
||||
include "include/BasicGuardTestArray.fppi"
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
64
FppTest/state_machine/internal/state/BasicGuardTestArray.hpp
Normal file
64
FppTest/state_machine/internal/state/BasicGuardTestArray.hpp
Normal file
@ -0,0 +1,64 @@
|
||||
// ======================================================================
|
||||
//
|
||||
// \title BasicGuardTestArray.hpp
|
||||
// \author R. Bocchino
|
||||
// \brief Test class for basic state machine with TestArray guard (header)
|
||||
//
|
||||
// \copyright
|
||||
// Copyright 2024, by the California Institute of Technology.
|
||||
// ALL RIGHTS RESERVED. United States Government Sponsorship
|
||||
// acknowledged.
|
||||
//
|
||||
// ======================================================================
|
||||
|
||||
#ifndef FppTest_State_BasicGuardTestArray_HPP
|
||||
#define FppTest_State_BasicGuardTestArray_HPP
|
||||
|
||||
#include "FppTest/state_machine/internal/harness/Harness.hpp"
|
||||
#include "FppTest/state_machine/internal/state/BasicGuardTestArrayStateMachineAc.hpp"
|
||||
|
||||
namespace FppTest {
|
||||
|
||||
namespace SmState {
|
||||
|
||||
//! A basic state machine with a TestArray guard
|
||||
class BasicGuardTestArray final : public BasicGuardTestArrayStateMachineBase {
|
||||
public:
|
||||
//! The history size
|
||||
static constexpr FwSizeType historySize = 10;
|
||||
|
||||
public:
|
||||
//! Constructor
|
||||
BasicGuardTestArray();
|
||||
|
||||
private:
|
||||
//! Implementation of action a
|
||||
void action_a(Signal signal, //!< The signal
|
||||
const SmHarness::TestArray& value //!< The value
|
||||
) final;
|
||||
|
||||
//! Implementation of guard g
|
||||
bool guard_g(Signal signal, //!< The signal
|
||||
const SmHarness::TestArray& value //!< The value
|
||||
) const;
|
||||
|
||||
public:
|
||||
//! Test with true guard
|
||||
void testTrue();
|
||||
|
||||
//! Test with false guard
|
||||
void testFalse();
|
||||
|
||||
private:
|
||||
//! The history associated with action a
|
||||
SmHarness::SignalValueHistory<Signal, SmHarness::TestArray, historySize> m_action_a_history;
|
||||
|
||||
//! The guard g
|
||||
SmHarness::Guard<Signal, SmHarness::TestArray, historySize> m_guard_g;
|
||||
};
|
||||
|
||||
} // namespace SmState
|
||||
|
||||
} // end namespace FppTest
|
||||
|
||||
#endif
|
||||
75
FppTest/state_machine/internal/state/BasicGuardTestEnum.cpp
Normal file
75
FppTest/state_machine/internal/state/BasicGuardTestEnum.cpp
Normal file
@ -0,0 +1,75 @@
|
||||
// ======================================================================
|
||||
//
|
||||
// \title BasicGuardTestEnum.hpp
|
||||
// \author R. Bocchino
|
||||
// \brief Test class for basic state machine with TestEnum guard (implementation)
|
||||
//
|
||||
// \copyright
|
||||
// Copyright 2024, by the California Institute of Technology.
|
||||
// ALL RIGHTS RESERVED. United States Government Sponsorship
|
||||
// acknowledged.
|
||||
//
|
||||
// ======================================================================
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "FppTest/state_machine/internal/state/BasicGuardTestEnum.hpp"
|
||||
#include "STest/STest/Pick/Pick.hpp"
|
||||
|
||||
namespace FppTest {
|
||||
|
||||
namespace SmState {
|
||||
|
||||
BasicGuardTestEnum::BasicGuardTestEnum() : BasicGuardTestEnumStateMachineBase(), m_action_a_history(), m_guard_g() {}
|
||||
|
||||
void BasicGuardTestEnum::action_a(Signal signal, const SmHarness::TestEnum& value) {
|
||||
this->m_action_a_history.push(signal, value);
|
||||
}
|
||||
|
||||
bool BasicGuardTestEnum::guard_g(Signal signal, const SmHarness::TestEnum& value) const {
|
||||
return this->m_guard_g.call(signal, value);
|
||||
}
|
||||
|
||||
void BasicGuardTestEnum::testFalse() {
|
||||
this->m_action_a_history.clear();
|
||||
this->m_guard_g.reset();
|
||||
const FwEnumStoreType id = SmHarness::Pick::stateMachineId();
|
||||
this->initBase(id);
|
||||
ASSERT_EQ(this->m_id, id);
|
||||
ASSERT_EQ(this->getState(), State::S);
|
||||
ASSERT_EQ(this->m_action_a_history.getSize(), 0);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getSize(), 0);
|
||||
const SmHarness::TestEnum value = SmHarness::Pick::testEnum();
|
||||
this->sendSignal_s(value);
|
||||
ASSERT_EQ(this->getState(), State::S);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getSize(), 1);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getSignals().getItemAt(0), Signal::s);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getValues().getItemAt(0), value);
|
||||
ASSERT_EQ(this->m_action_a_history.getSize(), 0);
|
||||
}
|
||||
|
||||
void BasicGuardTestEnum::testTrue() {
|
||||
this->m_action_a_history.clear();
|
||||
this->m_guard_g.reset();
|
||||
this->m_guard_g.setReturnValue(true);
|
||||
const FwEnumStoreType id = SmHarness::Pick::stateMachineId();
|
||||
this->initBase(id);
|
||||
ASSERT_EQ(this->m_id, id);
|
||||
ASSERT_EQ(this->getState(), State::S);
|
||||
ASSERT_EQ(this->m_action_a_history.getSize(), 0);
|
||||
const SmHarness::TestEnum value = SmHarness::Pick::testEnum();
|
||||
this->sendSignal_s(value);
|
||||
ASSERT_EQ(this->getState(), State::T);
|
||||
this->sendSignal_s(value);
|
||||
ASSERT_EQ(this->getState(), State::T);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getSize(), 1);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getSignals().getItemAt(0), Signal::s);
|
||||
ASSERT_EQ(this->m_guard_g.getCallHistory().getValues().getItemAt(0), value);
|
||||
ASSERT_EQ(this->m_action_a_history.getSize(), 1);
|
||||
ASSERT_EQ(this->m_action_a_history.getSignals().getItemAt(0), Signal::s);
|
||||
ASSERT_EQ(this->m_action_a_history.getValues().getItemAt(0), value);
|
||||
}
|
||||
|
||||
} // namespace SmState
|
||||
|
||||
} // end namespace FppTest
|
||||
@ -0,0 +1,9 @@
|
||||
module FppTest {
|
||||
|
||||
module SmState {
|
||||
|
||||
include "include/BasicGuardTestEnum.fppi"
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
64
FppTest/state_machine/internal/state/BasicGuardTestEnum.hpp
Normal file
64
FppTest/state_machine/internal/state/BasicGuardTestEnum.hpp
Normal file
@ -0,0 +1,64 @@
|
||||
// ======================================================================
|
||||
//
|
||||
// \title BasicGuardTestEnum.hpp
|
||||
// \author R. Bocchino
|
||||
// \brief Test class for basic state machine with TestEnum guard (header)
|
||||
//
|
||||
// \copyright
|
||||
// Copyright 2024, by the California Institute of Technology.
|
||||
// ALL RIGHTS RESERVED. United States Government Sponsorship
|
||||
// acknowledged.
|
||||
//
|
||||
// ======================================================================
|
||||
|
||||
#ifndef FppTest_State_BasicGuardTestEnum_HPP
|
||||
#define FppTest_State_BasicGuardTestEnum_HPP
|
||||
|
||||
#include "FppTest/state_machine/internal/harness/Harness.hpp"
|
||||
#include "FppTest/state_machine/internal/state/BasicGuardTestEnumStateMachineAc.hpp"
|
||||
|
||||
namespace FppTest {
|
||||
|
||||
namespace SmState {
|
||||
|
||||
//! A basic state machine with a TestEnum guard
|
||||
class BasicGuardTestEnum final : public BasicGuardTestEnumStateMachineBase {
|
||||
public:
|
||||
//! The history size
|
||||
static constexpr FwSizeType historySize = 10;
|
||||
|
||||
public:
|
||||
//! Constructor
|
||||
BasicGuardTestEnum();
|
||||
|
||||
private:
|
||||
//! Implementation of action a
|
||||
void action_a(Signal signal, //!< The signal
|
||||
const SmHarness::TestEnum& value //!< The value
|
||||
) final;
|
||||
|
||||
//! Implementation of guard g
|
||||
bool guard_g(Signal signal, //!< The signal
|
||||
const SmHarness::TestEnum& value //!< The value
|
||||
) const;
|
||||
|
||||
public:
|
||||
//! Test with true guard
|
||||
void testTrue();
|
||||
|
||||
//! Test with false guard
|
||||
void testFalse();
|
||||
|
||||
private:
|
||||
//! The history associated with action a
|
||||
SmHarness::SignalValueHistory<Signal, SmHarness::TestEnum, historySize> m_action_a_history;
|
||||
|
||||
//! The guard g
|
||||
SmHarness::Guard<Signal, SmHarness::TestEnum, historySize> m_guard_g;
|
||||
};
|
||||
|
||||
} // namespace SmState
|
||||
|
||||
} // end namespace FppTest
|
||||
|
||||
#endif
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user