forked from nasa/fprime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a state machine unit test under FppTest
- Loading branch information
watney
committed
May 28, 2024
1 parent
8b92b70
commit eb935e9
Showing
24 changed files
with
673 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
module Drv { | ||
|
||
port GpioWrite( | ||
state: Fw.Logic | ||
$state: Fw.Logic | ||
) | ||
|
||
} | ||
|
||
module Drv { | ||
|
||
port GpioRead( | ||
ref state: Fw.Logic | ||
ref $state: Fw.Logic | ||
) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
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}/SmTestSmBase.cpp" | ||
"${CMAKE_CURRENT_LIST_DIR}/SMEvents.fpp" | ||
) | ||
|
||
register_fprime_module() | ||
|
||
set(UT_SOURCE_FILES | ||
"${CMAKE_CURRENT_LIST_DIR}/SmTest.fpp" | ||
"${CMAKE_CURRENT_LIST_DIR}/test/ut/TestMain.cpp" | ||
"${CMAKE_CURRENT_LIST_DIR}/test/ut/Tester.cpp" | ||
"${CMAKE_CURRENT_LIST_DIR}/test/ut/TesterHelpers.cpp" | ||
"${CMAKE_CURRENT_LIST_DIR}/DeviceSm.cpp" | ||
"${CMAKE_CURRENT_LIST_DIR}/SmTestSmBase.cpp" | ||
"${CMAKE_CURRENT_LIST_DIR}/SMEvents.fpp" | ||
) | ||
set(UT_MOD_DEPS STest) | ||
register_fprime_ut() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
|
||
// ====================================================================== | ||
// \title DeviceSm.cpp | ||
// \author Auto-generated | ||
// \brief cpp file for state machine DeviceSm | ||
// | ||
// ====================================================================== | ||
|
||
#include "stdio.h" | ||
#include "assert.h" | ||
#include "SMEvents.hpp" | ||
#include "DeviceSm.h" | ||
|
||
|
||
void FppTest::DeviceSm::init() | ||
{ | ||
this->state = OFF; | ||
|
||
} | ||
|
||
|
||
void FppTest::DeviceSm::update(const Svc::SMEvents *e) | ||
{ | ||
switch (this->state) { | ||
|
||
/** | ||
* state OFF | ||
*/ | ||
case OFF: | ||
|
||
switch (e->geteventSignal()) { | ||
|
||
case RTI_SIG: | ||
this->state = ON; | ||
|
||
break; | ||
|
||
default: | ||
break; | ||
} | ||
break; | ||
|
||
/** | ||
* state ON | ||
*/ | ||
case ON: | ||
|
||
switch (e->geteventSignal()) { | ||
|
||
case RTI_SIG: | ||
this->state = OFF; | ||
|
||
break; | ||
|
||
default: | ||
break; | ||
} | ||
break; | ||
|
||
default: | ||
assert(0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
|
||
enum DeviceSmStates { | ||
OFF = 0 | ||
ON = 1 | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
|
||
// ====================================================================== | ||
// \title DeviceSm.h | ||
// \author Auto-generated | ||
// \brief header file for state machine DeviceSm | ||
// | ||
// ====================================================================== | ||
|
||
#ifndef DEVICESM_H_ | ||
#define DEVICESM_H_ | ||
|
||
namespace Svc { | ||
class SMEvents; | ||
} | ||
|
||
namespace FppTest { | ||
|
||
class DeviceSmIf { | ||
public: | ||
|
||
}; | ||
|
||
class DeviceSm { | ||
|
||
private: | ||
DeviceSmIf *parent; | ||
|
||
public: | ||
|
||
DeviceSm(DeviceSmIf* parent) : parent(parent) {} | ||
|
||
enum DeviceSmStates { | ||
OFF, | ||
ON, | ||
}; | ||
|
||
enum DeviceSmEvents { | ||
RTI_SIG, | ||
}; | ||
|
||
enum DeviceSmStates state; | ||
|
||
void * extension; | ||
|
||
void init(); | ||
void update(const Svc::SMEvents *e); | ||
|
||
}; | ||
|
||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
@startuml | ||
|
||
[*] --> OFF | ||
|
||
state OFF { | ||
} | ||
|
||
state ON { | ||
|
||
} | ||
|
||
OFF --> ON : RTI | ||
ON --> OFF : RTI | ||
@enduml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
InitialState = OFF, Event = RTI, guard = None, action = None, TargetState = ON | ||
InitialState = ON, Event = RTI, guard = None, action = None, TargetState = OFF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
HOME_DIR := $(HOME) | ||
autocode: | ||
$(HOME_DIR)/STARS/autocoder/Stars.py -noImpl -backend fprime -namespace FppTest -model DeviceSm.plantuml | ||
$(HOME_DIR)/STARS/autocoder/Stars.py -smbase |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
# This is an Auto generate file from the STARS Autocoder | ||
|
||
module Svc { | ||
|
||
struct SMEvents { | ||
smId : U32 | ||
eventSignal: U32 | ||
payload: [128] U8 | ||
} | ||
|
||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "FppTest/state_machine/SMEventsSerializableAc.hpp" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// ====================================================================== | ||
// \title SmTest.cpp | ||
// \author watney | ||
// \brief hpp file for SmTest component implementation class | ||
// ====================================================================== | ||
|
||
#include <cstdio> | ||
|
||
#include "FppTest/state_machine/SmTest.hpp" | ||
#include "Fw/Types/Assert.hpp" | ||
|
||
namespace FppTest { | ||
|
||
// ---------------------------------------------------------------------- | ||
// Construction, initialization, and destruction | ||
// ---------------------------------------------------------------------- | ||
|
||
SmTest::SmTest(const char* const compName): | ||
SmTestSmBase(compName) {} | ||
|
||
void SmTest ::init(const NATIVE_INT_TYPE queueDepth, const NATIVE_INT_TYPE instance) { | ||
SmTestSmBase::init(queueDepth, instance); | ||
} | ||
|
||
SmTest ::~SmTest() {} | ||
|
||
// ---------------------------------------------------------------------- | ||
// Handler implementations for user-defined typed input ports | ||
// ---------------------------------------------------------------------- | ||
|
||
void SmTest::schedIn_handler(const NATIVE_INT_TYPE portNum, U32 context) { | ||
sendEvent(DeviceSm::RTI_SIG, StateMachine::DEVICE1); | ||
sendEvent(DeviceSm::RTI_SIG, StateMachine::DEVICE2); | ||
} | ||
|
||
// ---------------------------------------------------------------------- | ||
// Data product handler implementations | ||
// ---------------------------------------------------------------------- | ||
|
||
|
||
// ---------------------------------------------------------------------- | ||
// Private helper functions | ||
// ---------------------------------------------------------------------- | ||
|
||
} // end namespace FppTest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module FppTest { | ||
|
||
@ A component for testing data product code gen | ||
active component SmTest { | ||
|
||
|
||
# ---------------------------------------------------------------------- | ||
# Types | ||
# ---------------------------------------------------------------------- | ||
|
||
|
||
# ---------------------------------------------------------------------- | ||
# General ports | ||
# ---------------------------------------------------------------------- | ||
|
||
@ A schedIn port to run the data product generation | ||
async input port schedIn: Svc.Sched | ||
|
||
include "state-machine.fppi" | ||
|
||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// ====================================================================== | ||
// \title SmTest.hpp | ||
// \author watney | ||
// \brief hpp file for SmTest component implementation class | ||
// ====================================================================== | ||
|
||
#ifndef FppTest_SmTest_HPP | ||
#define FppTest_SmTest_HPP | ||
|
||
#include <array> | ||
|
||
#include "FppTest/state_machine/SmTestComponentAc.hpp" | ||
#include "FppTest/state_machine/SmTestSmBase.hpp" | ||
#include "Fw/Types/String.hpp" | ||
#include "FppTest/state_machine/SmTestSmBase.hpp" | ||
|
||
namespace FppTest { | ||
|
||
class SmTest : | ||
public SmTestSmBase | ||
{ | ||
|
||
// Friend class for testing | ||
friend class Tester; | ||
|
||
public: | ||
// ---------------------------------------------------------------------- | ||
// Constants | ||
// ---------------------------------------------------------------------- | ||
|
||
|
||
|
||
public: | ||
// ---------------------------------------------------------------------- | ||
// Types | ||
// ---------------------------------------------------------------------- | ||
|
||
|
||
public: | ||
// ---------------------------------------------------------------------- | ||
// Construction, initialization, and destruction | ||
// ---------------------------------------------------------------------- | ||
|
||
//! Construct object SmTest | ||
SmTest(const char* const compName); //!< The component name | ||
|
||
//! Initialize object SmTest | ||
void init(const NATIVE_INT_TYPE queueDepth, //!< The queue depth | ||
const NATIVE_INT_TYPE instance = 0 //!< The instance number | ||
); | ||
|
||
//! Destroy object SmTest | ||
~SmTest(); | ||
|
||
public: | ||
// ---------------------------------------------------------------------- | ||
// Public interface methods | ||
// ---------------------------------------------------------------------- | ||
|
||
|
||
|
||
private: | ||
// ---------------------------------------------------------------------- | ||
// Handler implementations for user-defined typed input ports | ||
// ---------------------------------------------------------------------- | ||
|
||
//! Handler implementation for schedIn | ||
void schedIn_handler(const NATIVE_INT_TYPE portNum, //!< The port number | ||
U32 context //!< The call order | ||
) final; | ||
|
||
private: | ||
// ---------------------------------------------------------------------- | ||
// Data product handler implementations | ||
// ---------------------------------------------------------------------- | ||
|
||
|
||
private: | ||
// ---------------------------------------------------------------------- | ||
// Private helper functions | ||
// ---------------------------------------------------------------------- | ||
|
||
|
||
|
||
private: | ||
// ---------------------------------------------------------------------- | ||
// Private member variables | ||
// ---------------------------------------------------------------------- | ||
|
||
|
||
}; | ||
|
||
} // end namespace FppTest | ||
|
||
#endif |
Oops, something went wrong.