Skip to content

Commit

Permalink
Add a state machine unit test under FppTest
Browse files Browse the repository at this point in the history
  • Loading branch information
watney committed May 28, 2024
1 parent 8b92b70 commit eb935e9
Show file tree
Hide file tree
Showing 24 changed files with 673 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Drv/GpioDriverPorts/GpioDriverPorts.fpp
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
)

}
2 changes: 2 additions & 0 deletions FppTest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ include("${CMAKE_CURRENT_LIST_DIR}/../cmake/FPrime-Code.cmake")
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/array/")
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/component/")
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/dp/")
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/state_machine/")
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/enum/")
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
Expand Down
21 changes: 21 additions & 0 deletions FppTest/state_machine/CMakeLists.txt
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()
63 changes: 63 additions & 0 deletions FppTest/state_machine/DeviceSm.cpp
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);
}
}
7 changes: 7 additions & 0 deletions FppTest/state_machine/DeviceSm.fppi
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@


enum DeviceSmStates {
OFF = 0
ON = 1
}

52 changes: 52 additions & 0 deletions FppTest/state_machine/DeviceSm.h
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
15 changes: 15 additions & 0 deletions FppTest/state_machine/DeviceSm.plantuml
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
2 changes: 2 additions & 0 deletions FppTest/state_machine/DeviceSm.trans
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
4 changes: 4 additions & 0 deletions FppTest/state_machine/Makefile
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
14 changes: 14 additions & 0 deletions FppTest/state_machine/SMEvents.fpp
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
}

}


1 change: 1 addition & 0 deletions FppTest/state_machine/SMEvents.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "FppTest/state_machine/SMEventsSerializableAc.hpp"
45 changes: 45 additions & 0 deletions FppTest/state_machine/SmTest.cpp
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
24 changes: 24 additions & 0 deletions FppTest/state_machine/SmTest.fpp
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"


}

}
95 changes: 95 additions & 0 deletions FppTest/state_machine/SmTest.hpp
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
Loading

0 comments on commit eb935e9

Please sign in to comment.