Skip to content

Commit

Permalink
Adding FppTest for overflow: drop, assert, hook
Browse files Browse the repository at this point in the history
  • Loading branch information
LeStarch committed Aug 20, 2024
1 parent 7bb161f commit 3fb2a33
Show file tree
Hide file tree
Showing 18 changed files with 224 additions and 2 deletions.
20 changes: 20 additions & 0 deletions FppTest/component/active/ActiveTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,13 @@
return this->structReturnOut_out(portNum, s, sRef);
}

void ActiveTest ::
enumArgsHook_handler(
const NATIVE_INT_TYPE portNum,
const FormalParamEnum &en,
FormalParamEnum &enRef
) {}

// ----------------------------------------------------------------------
// Handler implementations for user-defined serial input ports
// ----------------------------------------------------------------------
Expand Down Expand Up @@ -696,3 +703,16 @@
this->structInterface.args.val = str;
}

// ----------------------------------------------------------------------
// Overflow hook implementations for user-defined async ports interfaces
// ----------------------------------------------------------------------

void ActiveTest ::
enumArgsHook_overflowHook(
const NATIVE_INT_TYPE portNum,
const FormalParamEnum &en,
FormalParamEnum &enRef
)
{
this->enumArgsHookOverflowed_out(portNum, en, enRef);
}
20 changes: 20 additions & 0 deletions FppTest/component/active/ActiveTest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,13 @@ class ActiveTest :
FormalParamStruct& sRef //!< A struct ref
);

//! Handler implementation for enumArgsOverflow
void enumArgsHook_handler(
NATIVE_INT_TYPE portNum, //!< The port number
const FormalParamEnum& en, //!< An enum
FormalParamEnum& enRef //!< An enum ref
);

PRIVATE:

// ----------------------------------------------------------------------
Expand Down Expand Up @@ -444,6 +451,19 @@ class ActiveTest :
const FormalParamStruct& str //!< A struct
);

PRIVATE:

// ----------------------------------------------------------------------
// Overflow hook implementations for user-defined async ports interfaces
// ----------------------------------------------------------------------

//! Overflow hook implementation for enumArgsOverflow
void enumArgsHook_overflowHook(
NATIVE_INT_TYPE portNum, //!< The port number
const FormalParamEnum& en, //!< An enum
FormalParamEnum& enRef //!< An enum ref
);

public:

//! Enables checking the serialization status of serial port invocations
Expand Down
1 change: 1 addition & 0 deletions FppTest/component/active/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ set(UT_SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/../tests/AsyncTesterHelpers.cpp"
"${CMAKE_CURRENT_LIST_DIR}/../tests/AsyncPortTests.cpp"
"${CMAKE_CURRENT_LIST_DIR}/../tests/AsyncCmdTests.cpp"
"${CMAKE_CURRENT_LIST_DIR}/../tests/OverflowTests.cpp"
"${CMAKE_CURRENT_LIST_DIR}/../types/FormalParamTypes.cpp"
"${CMAKE_CURRENT_LIST_DIR}/../../utils/Utils.cpp"
)
Expand Down
2 changes: 2 additions & 0 deletions FppTest/component/active/active.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ active component ActiveTest {
include "../include/special_ports.fppi"
include "../include/internal_ports.fppi"

include "../include/output_ports.fppi"

include "../include/commands.fppi"
include "../include/commands_async.fppi"
include "../include/events.fppi"
Expand Down
3 changes: 2 additions & 1 deletion FppTest/component/active/test/ut/Tester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
// \brief cpp file for ActiveTest test harness implementation class
// ======================================================================

#include "STest/Pick/Pick.hpp"
#include "Tester.hpp"
#include "STest/Pick/Pick.hpp"


// ----------------------------------------------------------------------
// Construction and destruction
Expand Down
11 changes: 11 additions & 0 deletions FppTest/component/active/test/ut/Tester.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "FppTest/component/tests/TlmTests.hpp"
#include "FppTest/component/types/FormalParamTypes.hpp"


class Tester : public ActiveTestGTestBase {
// ----------------------------------------------------------------------
// Construction and destruction
Expand Down Expand Up @@ -62,6 +63,12 @@ class Tester : public ActiveTestGTestBase {

void testTime();

void testOverflowAssert();

void testOverflowDrop();

void testOverflowHook();

PRIVATE:
// ----------------------------------------------------------------------
// Handlers for typed from ports
Expand Down Expand Up @@ -185,6 +192,10 @@ class Tester : public ActiveTestGTestBase {
*/
) final;

void from_enumArgsHookOverflowed_handler(const NATIVE_INT_TYPE portNum,
const FormalParamEnum& en,
FormalParamEnum& enRef);

PRIVATE:
// ----------------------------------------------------------------------
// Handlers for serial from ports
Expand Down
1 change: 1 addition & 0 deletions FppTest/component/include/output_ports.fppi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
output port enumArgsHookOverflowed: [2] EnumArgs
2 changes: 2 additions & 0 deletions FppTest/component/include/typed_ports_async.fppi
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ async input port enumArgsAsync: [2] EnumArgs assert
async input port arrayArgsAsync: [2] ArrayArgs priority 10 block

async input port structArgsAsync: [2] StructArgs priority 5 drop

async input port enumArgsHook: [2] EnumArgs hook
1 change: 1 addition & 0 deletions FppTest/component/queued/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ set(UT_SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/../tests/AsyncTesterHelpers.cpp"
"${CMAKE_CURRENT_LIST_DIR}/../tests/AsyncPortTests.cpp"
"${CMAKE_CURRENT_LIST_DIR}/../tests/AsyncCmdTests.cpp"
"${CMAKE_CURRENT_LIST_DIR}/../tests/OverflowTests.cpp"
"${CMAKE_CURRENT_LIST_DIR}/../types/FormalParamTypes.cpp"
"${CMAKE_CURRENT_LIST_DIR}/../../utils/Utils.cpp"
)
Expand Down
23 changes: 23 additions & 0 deletions FppTest/component/queued/QueuedTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,15 @@
return this->structReturnOut_out(portNum, s, sRef);
}


void QueuedTest ::
enumArgsHook_handler(
const NATIVE_INT_TYPE portNum,
const FormalParamEnum &en,
FormalParamEnum &enRef
)
{}

// ----------------------------------------------------------------------
// Handler implementations for user-defined serial input ports
// ----------------------------------------------------------------------
Expand Down Expand Up @@ -696,3 +705,17 @@
this->structInterface.args.val = str;
}


// ----------------------------------------------------------------------
// Overflow hook implementations for user-defined async ports interfaces
// ----------------------------------------------------------------------

void QueuedTest ::
enumArgsHook_overflowHook(
const NATIVE_INT_TYPE portNum,
const FormalParamEnum &en,
FormalParamEnum &enRef
)
{
this->enumArgsHookOverflowed_out(portNum, en, enRef);
}
21 changes: 21 additions & 0 deletions FppTest/component/queued/QueuedTest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,13 @@ class QueuedTest :
FormalParamStruct& sRef //!< A struct ref
);

//! Handler implementation for enumArgsOverflow
void enumArgsHook_handler(
NATIVE_INT_TYPE portNum, //!< The port number
const FormalParamEnum& en, //!< An enum
FormalParamEnum& enRef //!< An enum ref
);

PRIVATE:

// ----------------------------------------------------------------------
Expand Down Expand Up @@ -444,6 +451,20 @@ class QueuedTest :
const FormalParamStruct& str //!< A struct
);

PRIVATE:

// ----------------------------------------------------------------------
// Overflow hook implementations for user-defined async ports interfaces
// ----------------------------------------------------------------------

//! Overflow hook implementation for enumArgsOverflow
void enumArgsHook_overflowHook(
NATIVE_INT_TYPE portNum, //!< The port number
const FormalParamEnum& en, //!< An enum
FormalParamEnum& enRef //!< An enum ref
);


public:

//! Enables checking the serialization status of serial port invocations
Expand Down
2 changes: 2 additions & 0 deletions FppTest/component/queued/queued.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ queued component QueuedTest {
include "../include/special_ports.fppi"
include "../include/internal_ports.fppi"

include "../include/output_ports.fppi"

include "../include/commands.fppi"
include "../include/commands_async.fppi"
include "../include/events.fppi"
Expand Down
11 changes: 11 additions & 0 deletions FppTest/component/queued/test/ut/Tester.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ class Tester : public QueuedTestGTestBase {

void testTime();


void testOverflowAssert();

void testOverflowDrop();

void testOverflowHook();

PRIVATE:
// ----------------------------------------------------------------------
// Handlers for typed from ports
Expand Down Expand Up @@ -185,6 +192,10 @@ class Tester : public QueuedTestGTestBase {
*/
);

void from_enumArgsHookOverflowed_handler(const NATIVE_INT_TYPE portNum,
const FormalParamEnum& en,
FormalParamEnum& enRef);

PRIVATE:
// ----------------------------------------------------------------------
// Handlers for serial from ports
Expand Down
10 changes: 10 additions & 0 deletions FppTest/component/tests/AsyncTesterHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ void Tester ::connectAsyncPorts() {
this->connect_to_enumArgsAsync(i, this->component.get_enumArgsAsync_InputPort(i));
}

// enumArgsHook
for (NATIVE_INT_TYPE i = 0; i < 2; ++i) {
this->connect_to_enumArgsHook(i, this->component.get_enumArgsHook_InputPort(i));
}

// noArgsAsync
for (NATIVE_INT_TYPE i = 0; i < 2; ++i) {
this->connect_to_noArgsAsync(i, this->component.get_noArgsAsync_InputPort(i));
Expand Down Expand Up @@ -56,6 +61,11 @@ void Tester ::connectAsyncPorts() {

// serialAsyncDropPriority
this->connect_to_serialAsyncDropPriority(0, this->component.get_serialAsyncDropPriority_InputPort(0));

// enumArgsHookOverflowed
for (FwIndexType i = 0; i < 2; i++) {
this->component.set_enumArgsHookOverflowed_OutputPort(i, this->get_from_enumArgsHookOverflowed(i));
}
}

Fw::QueuedComponentBase::MsgDispatchStatus Tester ::doDispatch() {
Expand Down
16 changes: 16 additions & 0 deletions FppTest/component/tests/AsyncTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,19 @@ using InternalInterfaceTestImplementations = ::testing::Types<FppTest::Types::No
FppTest::Types::StructParam>;

INSTANTIATE_TYPED_TEST_SUITE_P(FppTest, ComponentInternalInterfaceTest, InternalInterfaceTestImplementations);

TEST(ComponentOverflow, OverflowHook) {
Tester tester;
tester.testOverflowHook();
}

TEST(ComponentOverflow, OverflowDrop) {
Tester tester;
tester.testOverflowDrop();
}

TEST(ComponentOverflow, OverflowAssert) {
Tester tester;
tester.testOverflowAssert();
}

75 changes: 75 additions & 0 deletions FppTest/component/tests/OverflowTests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// ======================================================================
// \title TimeTests.cpp
// \author T. Chieu
// \brief cpp file for time tests
//
// \copyright
// Copyright (C) 2009-2023 California Institute of Technology.
// ALL RIGHTS RESERVED. United States Government Sponsorship
// acknowledged.
//
// ======================================================================

#include "Fw/Time/Time.hpp"
#include "STest/Pick/Pick.hpp"
#include "Tester.hpp"

// ----------------------------------------------------------------------
// Overflow assert test
// ----------------------------------------------------------------------

void Tester ::testOverflowAssert() {
FormalParamEnum x = FormalParamEnum::T::X;
FormalParamEnum y = FormalParamEnum::T::Y;
FormalParamEnum z = FormalParamEnum::T::Z;

for (FwSizeType i = 0; i < Tester::TEST_INSTANCE_QUEUE_DEPTH; i++) {
this->invoke_to_enumArgsAsync(i % 2, x, y);
}
ASSERT_DEATH_IF_SUPPORTED(this->invoke_to_enumArgsAsync(0, y, z), "");
}

// ----------------------------------------------------------------------
// Overflow drop test
// ----------------------------------------------------------------------

void Tester ::testOverflowDrop() {
FormalParamStruct x;
FormalParamStruct y;
FormalParamStruct z;
for (FwSizeType i = 0; i < Tester::TEST_INSTANCE_QUEUE_DEPTH; i++) {
this->invoke_to_structArgsAsync(i % 2, x, y);
}
// This will overflow and should not crash
this->invoke_to_structArgsAsync(0, y, z);
}

// ----------------------------------------------------------------------
// Overflow hook test
// ----------------------------------------------------------------------

void Tester ::testOverflowHook() {
FormalParamEnum x = FormalParamEnum::T::X;
FormalParamEnum y = FormalParamEnum::T::Y;
FormalParamEnum z = FormalParamEnum::T::Z;

for (FwSizeType i = 0; i < Tester::TEST_INSTANCE_QUEUE_DEPTH; i++) {
this->invoke_to_enumArgsHook(i % 2, x, y);
}
this->invoke_to_enumArgsHook(0, y, z);
this->invoke_to_enumArgsHook(1, z, x);
ASSERT_from_enumArgsHookOverflowed_SIZE(2);
ASSERT_from_enumArgsHookOverflowed(0, y, z);
ASSERT_from_enumArgsHookOverflowed(1, z, x);

}

// ----------------------------------------------------------------------
// Handler to support overflow hook test
// ----------------------------------------------------------------------

void Tester ::from_enumArgsHookOverflowed_handler(const NATIVE_INT_TYPE portNum,
const FormalParamEnum& en,
FormalParamEnum& enRef) {
this->pushFromPortEntry_enumArgsHookOverflowed(en, enRef);
}
5 changes: 5 additions & 0 deletions FppTest/settings.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
; Ref requires no specific settings thus the [fprime] configuration block is empty
; For more information: https://nasa.github.io/fprime/UsersGuide/user/settings.html
[fprime]
framework_path: ..
default_cmake_options: FPRIME_SKIP_TOOLS_VERSION_CHECK=ON FPRIME_ENABLE_FRAMEWORK_UTS=OFF FPRIME_ENABLE_AUTOCODER_UTS=OFF
2 changes: 1 addition & 1 deletion FppTest/typed_tests/StringTest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class StringTest : public ::testing::Test {

// Truncate fwStr for comparison
char fwStrBuf2[bufferSize];
Fw::StringUtils::string_copy(fwStrBuf2, fwStr.toChar(), sizeof fwStrBuf2);
Fw::StringUtils::string_copy(fwStrBuf2, fwStr.toChar(), static_cast<FwSizeType>(sizeof fwStrBuf2));
fwSubstr = fwStrBuf2;
}

Expand Down

0 comments on commit 3fb2a33

Please sign in to comment.