repo_name
stringclasses 10
values | file_path
stringlengths 29
222
| content
stringlengths 24
926k
| extention
stringclasses 5
values |
---|---|---|---|
fprime | data/projects/fprime/FppTest/enum/EnumToStringTest.cpp | // ======================================================================
// \title EnumToStringTest.cpp
// \author T. Chieu
// \brief cpp file for EnumToStringTest class
//
// \copyright
// Copyright (C) 2009-2022 California Institute of Technology.
// ALL RIGHTS RESERVED. United States Government Sponsorship
// acknowledged.
//
// ======================================================================
#include "FppTest/enum/ImplicitEnumAc.hpp"
#include "FppTest/enum/ExplicitEnumAc.hpp"
#include "FppTest/enum/DefaultEnumAc.hpp"
#include "FppTest/enum/IntervalEnumAc.hpp"
#include "FppTest/enum/SerializeTypeU8EnumAc.hpp"
#include "FppTest/enum/SerializeTypeU64EnumAc.hpp"
#include "gtest/gtest.h"
#include <cstring>
#include <sstream>
namespace FppTest {
// Populate an array with enum values
template <typename EnumType>
void setEnumValArray(typename EnumType::T (&a)[EnumType::NUM_CONSTANTS+1]) {
for (U32 i = 0; i < EnumType::NUM_CONSTANTS + 1; i++) {
a[i] = static_cast<typename EnumType::T>(i);
}
}
template<>
void setEnumValArray<Explicit>(Explicit::T (&a)[Explicit::NUM_CONSTANTS+1]) {
a[0] = Explicit::A;
a[1] = Explicit::B;
a[2] = Explicit::C;
a[3] = static_cast<Explicit::T>(11);
}
template<>
void setEnumValArray<Interval>(Interval::T (&a)[Interval::NUM_CONSTANTS+1]) {
a[0] = Interval::A;
a[1] = Interval::B;
a[2] = Interval::C;
a[3] = Interval::D;
a[4] = Interval::E;
a[5] = Interval::F;
a[6] = Interval::G;
a[7] = static_cast<Interval::T>(11);
}
// Populate an array with strings representing enum values
template <typename EnumType>
void setEnumStrArray(std::string (&a)[EnumType::NUM_CONSTANTS+1]) {
a[0] = "A (0)";
a[1] = "B (1)";
a[2] = "C (2)";
a[3] = "D (3)";
a[4] = "E (4)";
a[5] = "[invalid] (5)";
}
template<>
void setEnumStrArray<Explicit>(std::string (&a)[Explicit::NUM_CONSTANTS+1]) {
a[0] = "A (-1952875139)";
a[1] = "B (2)";
a[2] = "C (2000999333)";
a[3] = "[invalid] (11)";
}
template <>
void setEnumStrArray<Interval>(std::string (&a)[Interval::NUM_CONSTANTS+1]) {
a[0] = "A (0)";
a[1] = "B (3)";
a[2] = "C (4)";
a[3] = "D (5)";
a[4] = "E (10)";
a[5] = "F (100)";
a[6] = "G (101)";
a[7] = "[invalid] (11)";
}
} // namespace FppTest
// Test enum string functions
template <typename EnumType>
class EnumToStringTest : public ::testing::Test {
protected:
void SetUp() override {
FppTest::setEnumValArray<EnumType>(vals);
FppTest::setEnumStrArray<EnumType>(strs);
};
EnumType e;
std::stringstream buf;
typename EnumType::T vals[EnumType::NUM_CONSTANTS+1];
std::string strs[EnumType::NUM_CONSTANTS+1];
};
// Specify type parameters for this test suite
using EnumTypes = ::testing::Types<
Implicit,
Explicit,
Default,
Interval,
SerializeTypeU8,
SerializeTypeU64
>;
TYPED_TEST_SUITE(EnumToStringTest, EnumTypes);
// Test enum toString() and ostream operator functions
TYPED_TEST(EnumToStringTest, ToString) {
for (U32 i = 0; i < TypeParam::NUM_CONSTANTS + 1; i++) {
this->e = this->vals[i];
this->buf << this->e;
ASSERT_STREQ(this->buf.str().c_str(), this->strs[i].c_str());
this->buf.str("");
}
}
| cpp |
fprime | data/projects/fprime/FppTest/enum/IsValidTest.cpp | // ======================================================================
// \title IsValidTest.cpp
// \author T. Chieu
// \brief cpp file for IsValidTest class
//
// \copyright
// Copyright (C) 2009-2022 California Institute of Technology.
// ALL RIGHTS RESERVED. United States Government Sponsorship
// acknowledged.
//
// ======================================================================
#include "FppTest/enum/IntervalEnumAc.hpp"
#include "gtest/gtest.h"
// Test boundary values for enum isValid() function
TEST(IsValidTest, IntervalEnum) {
Interval e = static_cast<Interval::T>(-1);
ASSERT_FALSE(e.isValid());
e = static_cast<Interval::T>(0);
ASSERT_TRUE(e.isValid());
e = static_cast<Interval::T>(1);
ASSERT_FALSE(e.isValid());
e = static_cast<Interval::T>(2);
ASSERT_FALSE(e.isValid());
e = static_cast<Interval::T>(3);
ASSERT_TRUE(e.isValid());
e = static_cast<Interval::T>(5);
ASSERT_TRUE(e.isValid());
e = static_cast<Interval::T>(6);
ASSERT_FALSE(e.isValid());
e = static_cast<Interval::T>(10);
ASSERT_TRUE(e.isValid());
e = static_cast<Interval::T>(99);
ASSERT_FALSE(e.isValid());
e = static_cast<Interval::T>(100);
ASSERT_TRUE(e.isValid());
e = static_cast<Interval::T>(101);
ASSERT_TRUE(e.isValid());
e = static_cast<Interval::T>(102);
ASSERT_FALSE(e.isValid());
}
| cpp |
fprime | data/projects/fprime/FppTest/typed_tests/ArrayTest.hpp | // ======================================================================
// \title ArrayTest.hpp
// \author T. Chieu
// \brief hpp file for ArrayTest class
//
// \copyright
// Copyright (C) 2009-2022 California Institute of Technology.
// ALL RIGHTS RESERVED. United States Government Sponsorship
// acknowledged.
//
// ======================================================================
#ifndef FPP_TEST_ARRAY_TEST_HPP
#define FPP_TEST_ARRAY_TEST_HPP
#include "Fw/Types/SerialBuffer.hpp"
#include "STest/Pick/Pick.hpp"
#include "gtest/gtest.h"
#include <sstream>
namespace FppTest {
namespace Array {
// Set default values for an array type
template <typename ArrayType>
void setDefaultVals
(typename ArrayType::ElementType (&a)[ArrayType::SIZE]) {}
// Set test values for an array type
template <typename ArrayType>
void setTestVals
(typename ArrayType::ElementType (&a)[ArrayType::SIZE]);
template <typename ArrayType>
ArrayType getMultiElementConstructedArray
(typename ArrayType::ElementType (&a)[ArrayType::SIZE]);
// Get the serialized size of an array
template <typename ArrayType>
U32 getSerializedSize
(typename ArrayType::ElementType (&a)[ArrayType::SIZE]) {
return ArrayType::SERIALIZED_SIZE;
}
} // namespace Array
} // namespace FppTest
// Test an array class
template <typename ArrayType>
class ArrayTest : public ::testing::Test {
protected:
void SetUp() override {
FppTest::Array::setDefaultVals<ArrayType>(defaultVals);
FppTest::Array::setTestVals<ArrayType>(testVals);
ASSERT_FALSE(valsAreEqual());
};
bool valsAreEqual() {
for (U32 i = 0; i < ArrayType::SIZE; i++) {
if (defaultVals[i] != testVals[i]) {
return false;
}
}
return true;
}
typename ArrayType::ElementType defaultVals[ArrayType::SIZE];
typename ArrayType::ElementType testVals[ArrayType::SIZE];
};
TYPED_TEST_SUITE_P(ArrayTest);
// Test array constants and default constructor
TYPED_TEST_P(ArrayTest, Default) {
TypeParam a;
// Constants
ASSERT_EQ(TypeParam::SIZE, 3);
ASSERT_EQ(
TypeParam::SERIALIZED_SIZE,
TypeParam::SIZE * TypeParam::ElementType::SERIALIZED_SIZE
);
// Default constructor
for (U32 i = 0; i < TypeParam::SIZE; i++) {
ASSERT_EQ(a[i], this->defaultVals[i]);
}
}
// Test array constructors
TYPED_TEST_P(ArrayTest, Constructors) {
// Array constructor
TypeParam a1(this->testVals);
for (U32 i = 0; i < TypeParam::SIZE; i++) {
ASSERT_EQ(a1[i], this->testVals[i]);
}
// Single element constructor
TypeParam a2(this->testVals[0]);
for (U32 i = 0; i < TypeParam::SIZE; i++) {
ASSERT_EQ(a2[i], this->testVals[0]);
}
// Multiple element constructor
TypeParam a3 = FppTest::Array::getMultiElementConstructedArray<TypeParam>
(this->testVals);
for (U32 i = 0; i < TypeParam::SIZE; i++) {
ASSERT_EQ(a3[i], this->testVals[i]);
}
// Copy constructor
TypeParam a4(a1);
for (U32 i = 0; i < TypeParam::SIZE; i++) {
ASSERT_EQ(a4[i], a1[i]);
}
}
// Test array subscript operator
TYPED_TEST_P(ArrayTest, SubscriptOp) {
TypeParam a;
for (U32 i = 0; i < TypeParam::SIZE; i++) {
a[i] = this->testVals[0];
ASSERT_EQ(a[i], this->testVals[0]);
}
}
// Test array assignment operator
TYPED_TEST_P(ArrayTest, AssignmentOp) {
TypeParam a1, a2;
// Array assignment
a1 = this->testVals;
for (U32 i = 0; i < TypeParam::SIZE; i++) {
ASSERT_EQ(a1[i], this->testVals[i]);
}
// Copy assignment
TypeParam& a1Ref = a1;
a1 = a1Ref;
ASSERT_EQ(&a1, &a1Ref);
a1 = a2;
for (U32 i = 0; i < TypeParam::SIZE; i++) {
ASSERT_EQ(a2[i], a1[i]);
}
// Single element assignment
a1 = this->testVals[0];
for (U32 i = 0; i < TypeParam::SIZE; i++) {
ASSERT_EQ(a1[i], this->testVals[0]);
}
}
// Test array equality and inequality operators
TYPED_TEST_P(ArrayTest, EqualityOp) {
TypeParam a1, a2;
ASSERT_TRUE(a1 == a2);
ASSERT_FALSE(a1 != a2);
a2 = this->testVals;
ASSERT_FALSE(a1 == a2);
ASSERT_TRUE(a1 != a2);
a1 = a2;
ASSERT_TRUE(a1 == a2);
ASSERT_FALSE(a1 != a2);
}
// Test array serialization and deserialization
TYPED_TEST_P(ArrayTest, Serialization) {
TypeParam a(this->testVals);
U32 serializedSize =
FppTest::Array::getSerializedSize<TypeParam>(this->testVals);
Fw::SerializeStatus status;
// Test successful serialization
TypeParam aCopy;
U8 data[TypeParam::SERIALIZED_SIZE];
Fw::SerialBuffer buf(data, sizeof(data));
// Serialize
status = buf.serialize(a);
ASSERT_EQ(status, Fw::FW_SERIALIZE_OK);
ASSERT_EQ(
buf.getBuffLength(),
serializedSize
);
// Deserialize
status = buf.deserialize(aCopy);
ASSERT_EQ(status, Fw::FW_SERIALIZE_OK);
ASSERT_EQ(a, aCopy);
// Test unsuccessful serialization
TypeParam aCopy2;
U8 data2[serializedSize-1];
Fw::SerialBuffer buf2(data2, sizeof(data2));
// Serialize
status = buf2.serialize(a);
ASSERT_NE(status, Fw::FW_SERIALIZE_OK);
ASSERT_NE(
buf2.getBuffLength(),
serializedSize
);
// Deserialize
status = buf2.deserialize(aCopy2);
ASSERT_NE(status, Fw::FW_SERIALIZE_OK);
}
// Register all test patterns
REGISTER_TYPED_TEST_SUITE_P(ArrayTest,
Default,
Constructors,
SubscriptOp,
AssignmentOp,
EqualityOp,
Serialization
);
#endif
| hpp |
fprime | data/projects/fprime/FppTest/typed_tests/PortTest.hpp | // ======================================================================
// \title PortTest.hpp
// \author T. Chieu
// \brief hpp file for PortTest class
//
// \copyright
// Copyright (C) 2009-2023 California Institute of Technology.
// ALL RIGHTS RESERVED. United States Government Sponsorship
// acknowledged.
//
// ======================================================================
#ifndef FPP_TEST_PORT_TEST_HPP
#define FPP_TEST_PORT_TEST_HPP
#include "Tester.hpp"
#include "FppTest/component/active/TypedPortIndexEnumAc.hpp"
#include "gtest/gtest.h"
// Typed port tests (sync and guarded)
template <typename PortType>
class TypedPortTest : public ::testing::Test {
protected:
Tester tester;
PortType port;
};
TYPED_TEST_SUITE_P(TypedPortTest);
TYPED_TEST_P(TypedPortTest, SyncPort) {
this->tester.testSyncPortInvoke(TypedPortIndex::TYPED, this->port);
this->tester.testSyncPortCheck(this->port);
}
TYPED_TEST_P(TypedPortTest, GuardedPort) {
this->tester.testGuardedPortInvoke(TypedPortIndex::TYPED, this->port);
this->tester.testGuardedPortCheck(this->port);
}
REGISTER_TYPED_TEST_SUITE_P(TypedPortTest,
SyncPort,
GuardedPort
);
// Typed async port tests
template <typename PortType>
class TypedAsyncPortTest : public ::testing::Test {
protected:
Tester tester;
PortType port;
};
TYPED_TEST_SUITE_P(TypedAsyncPortTest);
TYPED_TEST_P(TypedAsyncPortTest, AsyncPort) {
this->tester.testAsyncPortInvoke(TypedPortIndex::TYPED, this->port);
this->tester.doDispatch();
this->tester.testAsyncPortCheck(this->port);
}
REGISTER_TYPED_TEST_SUITE_P(TypedAsyncPortTest,
AsyncPort
);
// Serial port tests (sync and guarded)
template <typename PortType>
class SerialPortTest : public ::testing::Test {
protected:
Tester tester;
PortType port;
};
TYPED_TEST_SUITE_P(SerialPortTest);
TYPED_TEST_P(SerialPortTest, ToSerialSync) {
this->tester.testSyncPortInvoke(TypedPortIndex::SERIAL, this->port);
this->tester.testSyncPortCheckSerial(this->port);
}
TYPED_TEST_P(SerialPortTest, FromSerialSync) {
this->tester.testSyncPortInvokeSerial(TypedPortIndex::SERIAL, this->port);
this->tester.testSyncPortCheck(this->port);
}
TYPED_TEST_P(SerialPortTest, ToSerialGuarded) {
this->tester.testGuardedPortInvoke(TypedPortIndex::SERIAL, this->port);
this->tester.testGuardedPortCheckSerial(this->port);
}
TYPED_TEST_P(SerialPortTest, FromSerialGuarded) {
this->tester.testGuardedPortInvokeSerial(TypedPortIndex::SERIAL, this->port);
this->tester.testGuardedPortCheck(this->port);
}
REGISTER_TYPED_TEST_SUITE_P(SerialPortTest,
ToSerialSync,
FromSerialSync,
ToSerialGuarded,
FromSerialGuarded
);
// Serial async port tests
template <typename PortType>
class SerialAsyncPortTest : public ::testing::Test {
protected:
Tester tester;
PortType port;
};
TYPED_TEST_SUITE_P(SerialAsyncPortTest);
TYPED_TEST_P(SerialAsyncPortTest, ToSerialAsync) {
this->tester.testAsyncPortInvoke(TypedPortIndex::SERIAL, this->port);
this->tester.doDispatch();
this->tester.testAsyncPortCheckSerial(this->port);
}
TYPED_TEST_P(SerialAsyncPortTest, FromSerialAsync) {
this->tester.testAsyncPortInvokeSerial(TypedPortIndex::SERIAL, this->port);
this->tester.testAsyncPortCheck(this->port);
}
REGISTER_TYPED_TEST_SUITE_P(SerialAsyncPortTest,
ToSerialAsync,
FromSerialAsync
);
#endif
| hpp |
fprime | data/projects/fprime/FppTest/typed_tests/EnumTest.hpp | // ======================================================================
// \title EnumTest.hpp
// \author T. Chieu
// \brief hpp file for EnumTest class
//
// \copyright
// Copyright (C) 2009-2022 California Institute of Technology.
// ALL RIGHTS RESERVED. United States Government Sponsorship
// acknowledged.
//
// ======================================================================
#ifndef FPP_TEST_ENUM_TEST_HPP
#define FPP_TEST_ENUM_TEST_HPP
#include "Fw/Types/SerialBuffer.hpp"
#include "STest/Pick/Pick.hpp"
#include "gtest/gtest.h"
#include <limits>
namespace FppTest {
namespace Enum {
// Get the default value of an enum
template <typename EnumType>
typename EnumType::T getDefaultValue() {
return static_cast<typename EnumType::T>(0);
}
// Get a valid value of an enum
template <typename EnumType>
typename EnumType::T getValidValue() {
U32 val = STest::Pick::startLength(
0,
EnumType::NUM_CONSTANTS
);
return static_cast<typename EnumType::T>(val);
}
// Get an invalid value of an enum
template <typename EnumType>
typename EnumType::T getInvalidValue() {
U8 sign = 0;
if (std::numeric_limits<typename EnumType::SerialType>::min() < 0) {
sign = STest::Pick::lowerUpper(0, 1);
}
switch (sign) {
case 0:
return static_cast<typename EnumType::T>(STest::Pick::lowerUpper(
EnumType::NUM_CONSTANTS,
static_cast<U32>(
std::numeric_limits<typename EnumType::SerialType>::max()
)
));
default:
return static_cast<typename EnumType::T>(STest::Pick::lowerUpper(
1,
static_cast<U32>((-1) *
(std::numeric_limits<typename EnumType::SerialType>::min() + 1)
)
) * (-1));
}
}
} // namespace Enum
} // namespace FppTest
// Test core enum interface
template <typename EnumType>
class EnumTest : public ::testing::Test {};
TYPED_TEST_SUITE_P(EnumTest);
// Test enum constants and default construction
TYPED_TEST_P(EnumTest, Default) {
TypeParam e;
// Constants
ASSERT_EQ(
TypeParam::SERIALIZED_SIZE,
sizeof(typename TypeParam::SerialType)
);
// Default constructor
ASSERT_EQ(e.e, FppTest::Enum::getDefaultValue<TypeParam>());
}
// Test enum constructors
TYPED_TEST_P(EnumTest, Constructors) {
typename TypeParam::T validVal = FppTest::Enum::getValidValue<TypeParam>();
// Raw enum value constructor
TypeParam e1(validVal);
ASSERT_EQ(e1.e, validVal);
// Copy constructor
TypeParam e2(e1);
ASSERT_EQ(e2.e, validVal);
}
// Test enum assignment operator
TYPED_TEST_P(EnumTest, AssignmentOp) {
TypeParam e1;
TypeParam e2;
typename TypeParam::T validVal = FppTest::Enum::getValidValue<TypeParam>();
// Raw enum value assignment
e1 = validVal;
ASSERT_EQ(e1.e, validVal);
// Object assignment
e2 = e1;
ASSERT_EQ(e2.e, validVal);
}
// Test enum equality and inequality operator
TYPED_TEST_P(EnumTest, EqualityOp) {
// Initialize two distinct valid values
typename TypeParam::T validVal1 = FppTest::Enum::getValidValue<TypeParam>();
typename TypeParam::T validVal2 = FppTest::Enum::getValidValue<TypeParam>();
while (validVal1 == validVal2) {
validVal2 = FppTest::Enum::getValidValue<TypeParam>();
}
TypeParam e1;
TypeParam e2;
TypeParam e3(validVal1);
TypeParam e4(validVal2);
// operator==
ASSERT_TRUE(e3 == validVal1);
ASSERT_TRUE(e4 == validVal2);
ASSERT_FALSE(e3 == validVal2);
ASSERT_FALSE(e4 == validVal1);
ASSERT_TRUE(e1 == e2);
ASSERT_FALSE(e3 == e4);
// operator!=
ASSERT_TRUE(e3 != validVal2);
ASSERT_TRUE(e4 != validVal1);
ASSERT_FALSE(e3 != validVal1);
ASSERT_FALSE(e4 != validVal2);
ASSERT_TRUE(e3 != e4);
ASSERT_FALSE(e1 != e2);
}
// Test enum isValid() function
TYPED_TEST_P(EnumTest, IsValidFunction) {
TypeParam validEnum = FppTest::Enum::getValidValue<TypeParam>();
TypeParam invalidEnum = FppTest::Enum::getInvalidValue<TypeParam>();
ASSERT_TRUE(validEnum.isValid());
ASSERT_FALSE(invalidEnum.isValid());
}
// Test enum serialization and deserialization
TYPED_TEST_P(EnumTest, Serialization) {
TypeParam validEnum = FppTest::Enum::getValidValue<TypeParam>();
TypeParam invalidEnum = FppTest::Enum::getInvalidValue<TypeParam>();
// Copy of enums to test after serialization
TypeParam validEnumCopy;
TypeParam invalidEnumCopy;
Fw::SerializeStatus status;
U8 data[TypeParam::SERIALIZED_SIZE * 2];
Fw::SerialBuffer buf(data, sizeof(data));
// Serialize the enums
status = buf.serialize(validEnum);
ASSERT_EQ(status, Fw::FW_SERIALIZE_OK);
ASSERT_EQ(buf.getBuffLength(), sizeof(typename TypeParam::SerialType));
status = buf.serialize(invalidEnum);
ASSERT_EQ(status, Fw::FW_SERIALIZE_OK);
ASSERT_EQ(buf.getBuffLength(), sizeof(typename TypeParam::SerialType) * 2);
// Deserialize the enums
status = buf.deserialize(validEnumCopy);
ASSERT_EQ(status, Fw::FW_SERIALIZE_OK);
ASSERT_EQ(validEnumCopy, validEnum);
status = buf.deserialize(invalidEnumCopy);
ASSERT_EQ(status, Fw::FW_DESERIALIZE_FORMAT_ERROR);
}
// Register all test patterns
REGISTER_TYPED_TEST_SUITE_P(EnumTest,
Default,
Constructors,
AssignmentOp,
EqualityOp,
IsValidFunction,
Serialization
);
#endif
| hpp |
fprime | data/projects/fprime/FppTest/typed_tests/ComponentTest.hpp | // ======================================================================
// \title ComponentTest.hpp
// \author T. Chieu
// \brief hpp file for component test classes
//
// \copyright
// Copyright (C) 2009-2023 California Institute of Technology.
// ALL RIGHTS RESERVED. United States Government Sponsorship
// acknowledged.
//
// ======================================================================
#ifndef FPP_TEST_COMPONENT_TEST_HPP
#define FPP_TEST_COMPONENT_TEST_HPP
#include "Tester.hpp"
#include "gtest/gtest.h"
template <typename FormalParamType>
class ComponentCommandTest : public ::testing::Test {
protected:
Tester tester;
FormalParamType data;
};
TYPED_TEST_SUITE_P(ComponentCommandTest);
TYPED_TEST_P(ComponentCommandTest, CommandTest) {
this->tester.testCommand(0, this->data);
}
REGISTER_TYPED_TEST_SUITE_P(ComponentCommandTest,
CommandTest
);
template <typename FormalParamType>
class ComponentAsyncCommandTest : public ::testing::Test {
protected:
Tester tester;
FormalParamType data;
};
TYPED_TEST_SUITE_P(ComponentAsyncCommandTest);
TYPED_TEST_P(ComponentAsyncCommandTest, AsyncCommandTest) {
this->tester.testAsyncCommand(0, this->data);
}
REGISTER_TYPED_TEST_SUITE_P(ComponentAsyncCommandTest,
AsyncCommandTest
);
template <typename FormalParamType>
class ComponentEventTest : public ::testing::Test {
protected:
Tester tester;
FormalParamType data;
};
TYPED_TEST_SUITE_P(ComponentEventTest);
TYPED_TEST_P(ComponentEventTest, EventTest) {
this->tester.connectTimeGetOut();
this->tester.testEvent(0, this->data);
}
REGISTER_TYPED_TEST_SUITE_P(ComponentEventTest,
EventTest
);
template <typename FormalParamType>
class ComponentTelemetryTest : public ::testing::Test {
protected:
Tester tester;
FormalParamType data;
};
TYPED_TEST_SUITE_P(ComponentTelemetryTest);
TYPED_TEST_P(ComponentTelemetryTest, TelemetryTest) {
this->tester.connectTimeGetOut();
this->tester.testTelemetry(0, this->data);
}
REGISTER_TYPED_TEST_SUITE_P(ComponentTelemetryTest,
TelemetryTest
);
template <typename FormalParamType>
class ComponentParamCommandTest : public ::testing::Test {
protected:
Tester tester;
FormalParamType data;
};
TYPED_TEST_SUITE_P(ComponentParamCommandTest);
TYPED_TEST_P(ComponentParamCommandTest, ParamTest) {
this->tester.testParamCommand(0, this->data);
}
REGISTER_TYPED_TEST_SUITE_P(ComponentParamCommandTest,
ParamTest
);
template <typename FormalParamType>
class ComponentInternalInterfaceTest : public ::testing::Test {
protected:
Tester tester;
FormalParamType data;
};
TYPED_TEST_SUITE_P(ComponentInternalInterfaceTest);
TYPED_TEST_P(ComponentInternalInterfaceTest, InternalInterfaceTest) {
this->tester.testInternalInterface(this->data);
}
REGISTER_TYPED_TEST_SUITE_P(ComponentInternalInterfaceTest,
InternalInterfaceTest);
#endif
| hpp |
fprime | data/projects/fprime/FppTest/typed_tests/StringTest.hpp | // ======================================================================
// \title StringTest.hpp
// \author T. Chieu
// \brief hpp file for StringTest class
//
// \copyright
// Copyright (C) 2009-2022 California Institute of Technology.
// ALL RIGHTS RESERVED. United States Government Sponsorship
// acknowledged.
//
// ======================================================================
#ifndef FPP_TEST_STRING_TEST_HPP
#define FPP_TEST_STRING_TEST_HPP
#include "FppTest/utils/Utils.hpp"
#include "Fw/Types/String.hpp"
#include "Fw/Types/StringUtils.hpp"
#include "gtest/gtest.h"
namespace FppTest {
namespace String {
// Get the size of a string type
template <typename StringType>
U32 getSize() {
return 80;
}
} // namespace String
} // namespace FppTest
// Test a nested string class
template <class StringType>
class StringTest : public ::testing::Test {
protected:
void SetUp() override {
size = FppTest::String::getSize<StringType>();
FppTest::Utils::setString(src, size);
char fwStrBuf1[Fw::String::STRING_SIZE];
FppTest::Utils::setString(fwStrBuf1, sizeof(fwStrBuf1));
fwStr = fwStrBuf1;
// Truncate fwStr for comparison
char fwStrBuf2[size];
Fw::StringUtils::string_copy(fwStrBuf2, fwStr.toChar(), size);
fwSubstr = fwStrBuf2;
}
U32 size;
char src[StringType::SERIALIZED_SIZE];
Fw::String fwStr;
Fw::String fwSubstr;
};
TYPED_TEST_SUITE_P(StringTest);
// Test string capacity and default constructor
TYPED_TEST_P(StringTest, Default) {
TypeParam str;
// Capacity
ASSERT_EQ(str.getCapacity(), this->size);
// Serialized size
ASSERT_EQ(
TypeParam::SERIALIZED_SIZE,
this->size + sizeof(FwBuffSizeType)
);
// Default constructors
ASSERT_STREQ(str.toChar(), "");
}
// Test string constructors
TYPED_TEST_P(StringTest, Constructors) {
// Char array constructor
TypeParam str1(this->src);
ASSERT_STREQ(str1.toChar(), this->src);
// Copy constructor
TypeParam str2(str1);
ASSERT_STREQ(str2.toChar(), str1.toChar());
// Fw::StringBase constructor
TypeParam str3(this->fwStr);
ASSERT_STREQ(str3.toChar(), this->fwSubstr.toChar());
}
// Test string assignment operator
TYPED_TEST_P(StringTest, AssignmentOp) {
TypeParam str1;
TypeParam str2;
TypeParam str3;
// Char array assignment
str1 = this->src;
ASSERT_STREQ(str1.toChar(), this->src);
// Copy assignment
TypeParam& strRef = str1;
str1 = strRef;
ASSERT_EQ(&str1, &strRef);
str2 = str1;
ASSERT_STREQ(str1.toChar(), str1.toChar());
// Fw::StringBase assignment
Fw::StringBase& sbRef = str1;
str1 = sbRef;
ASSERT_EQ(&str1, &sbRef);
str3 = this->fwStr;
ASSERT_STREQ(str3.toChar(), this->fwSubstr.toChar());
}
// Register all test patterns
REGISTER_TYPED_TEST_SUITE_P(StringTest,
Default,
Constructors,
AssignmentOp
);
#endif
| hpp |
fprime | data/projects/fprime/FppTest/utils/Utils.hpp | // ======================================================================
// \title Utils.hpp
// \author T. Chieu
// \brief hpp file for Utils class
//
// \copyright
// Copyright (C) 2009-2022 California Institute of Technology.
// ALL RIGHTS RESERVED. United States Government Sponsorship
// acknowledged.
//
// ======================================================================
#ifndef FPP_TEST_UTILS_HPP
#define FPP_TEST_UTILS_HPP
namespace FppTest {
namespace Utils {
// Returns a random nonzero U8
U8 getNonzeroU8();
// Returns a random nonzero U32
U32 getNonzeroU32();
// Returns a random non-null char
char getChar();
// Populates buf with a random string of random length that fits
// within capacity, including the null terminator (i.e., length + 1 <= capacity)
void setString(
char *buf, //!< The buffer pointer
FwSizeType capacity, //!< The buffer capacity
FwSizeType minLength = 0 //!< The minimum string length, not including the null terminator
//!< minLength + 1 must be <= capacity
);
} // namespace Utils
} // namespace FppTest
#endif
| hpp |
fprime | data/projects/fprime/FppTest/utils/Utils.cpp | // ======================================================================
// \title Utils.cpp
// \author T. Chieu
// \brief cpp file for Utils class
//
// \copyright
// Copyright (C) 2009-2022 California Institute of Technology.
// ALL RIGHTS RESERVED. United States Government Sponsorship
// acknowledged.
//
// ======================================================================
#include <string>
#include <limits>
#include <iostream>
#include "Fw/Types/Assert.hpp"
#include "STest/Pick/Pick.hpp"
namespace FppTest {
namespace Utils {
U8 getNonzeroU8() {
return static_cast<U8>(STest::Pick::lowerUpper(
1,
std::numeric_limits<U8>::max()
));
}
U32 getNonzeroU32() {
return STest::Pick::lowerUpper(
1,
std::numeric_limits<U32>::max()
);
}
char getChar() {
return static_cast<char>(STest::Pick::lowerUpper(32, 127));
}
void setString(char* buf, FwSizeType capacity, FwSizeType minLength) {
FW_ASSERT(buf != nullptr);
// capacity must be able to hold a null-terminated string
FW_ASSERT(capacity > 0);
// min length must fit within capacity
FW_ASSERT(minLength < capacity);
U32 length = STest::Pick::lowerUpper(minLength, capacity - 1);
for (U32 i = 0; i < length; i++) {
FW_ASSERT(i < capacity);
buf[i] = getChar();
}
FW_ASSERT(length < capacity);
buf[length] = 0;
}
} // namespace Utils
} // namespace FppTest
| cpp |
fprime | data/projects/fprime/cmake/empty.cpp | static_assert(false, "empty.cpp should never be compiled");
| cpp |
fprime | data/projects/fprime/cmake/test/data/test-fprime-library/TestLibrary/TestComponent/TestComponent.cpp | #include <TestLibrary/TestComponent/TestComponent.hpp>
namespace TestLibrary {
TestComponent ::TestComponent(const char* name) :
TestComponentComponentBase(name)
{}
void TestComponent ::init(const NATIVE_INT_TYPE instance) {
TestComponentComponentBase::init(instance);
}
TestComponent ::~TestComponent() {}
void TestComponent ::schedIn_handler(NATIVE_INT_TYPE portNum, U32 context) {}
};
| cpp |
fprime | data/projects/fprime/cmake/test/data/test-fprime-library/TestLibrary/TestComponent/TestComponent.hpp | #ifndef TestLibrary_TestComponent_HPP
#define TestLibrary_TestComponent_HPP
#include <TestLibrary/TestComponent/TestComponentComponentAc.hpp>
namespace TestLibrary {
class TestComponent : public TestComponentComponentBase
{
public:
TestComponent(const char* name);
void init(const NATIVE_INT_TYPE instance);
~TestComponent();
private:
void schedIn_handler(NATIVE_INT_TYPE portNum, U32 context);
};
};
#endif
| hpp |
fprime | data/projects/fprime/cmake/test/data/test-fprime-library2/TestLibrary2/TestComponent/TestComponent.cpp | #include <TestLibrary2/TestComponent/TestComponent.hpp>
namespace TestLibrary2 {
TestComponent ::TestComponent(const char* name) :
TestComponentComponentBase(name)
{}
void TestComponent ::init(const NATIVE_INT_TYPE instance) {
TestComponentComponentBase::init(instance);
}
TestComponent ::~TestComponent() {}
void TestComponent ::schedIn_handler(NATIVE_INT_TYPE portNum, U32 context) {}
};
| cpp |
fprime | data/projects/fprime/cmake/test/data/test-fprime-library2/TestLibrary2/TestComponent/TestComponent.hpp | #ifndef TestLibrary_TestComponent_HPP
#define TestLibrary_TestComponent_HPP
#include <TestLibrary2/TestComponent/TestComponentComponentAc.hpp>
namespace TestLibrary2 {
class TestComponent : public TestComponentComponentBase
{
public:
TestComponent(const char* name);
void init(const NATIVE_INT_TYPE instance);
~TestComponent();
private:
void schedIn_handler(NATIVE_INT_TYPE portNum, U32 context);
};
};
#endif
| hpp |
fprime | data/projects/fprime/cmake/test/data/test-implementations/Deployment/Main.cpp | // No operation executable
int main(int argc, char** argv) {
return 0;
} | cpp |
fprime | data/projects/fprime/cmake/test/data/TestDeployment/Main.cpp | // No operation executable
int main(int argc, char** argv) {
return 0;
} | cpp |
fprime | data/projects/fprime/cmake/profile/profile.c | #include <sys/time.h>
#include <stdio.h>
int main(int argc, char** argv) {
struct timeval val;
gettimeofday(&val, 0);
FILE* pointer = stdout;
if (argc > 1)
{
pointer = fopen(argv[1], "a");
}
fprintf(pointer, "%ld.%06d", val.tv_sec, val.tv_usec);
for (int i = 2; i < argc; i++)
{
fprintf(pointer, " %s", argv[i]);
}
fprintf(pointer, "\n");
}
| c |
fprime | data/projects/fprime/cmake/platform/types/PlatformTypes.h | /**
* \brief PlatformTypes.h C-compatible type definitions for Linux/Darwin
*
* PlatformTypes.h is typically published by platform developers to define
* the standard available arithmetic types for use in fprime. This standard
* types header is designed to support standard Linux/Darwin distributions
* running on x86, x86_64 machines and using the standard gcc/clang compilers
* shipped with the operating system.
*
* In C++ code, users may use std::numeric_limits<PlatformIntType>::min()
* to reference the min/max limits of a type.
*/
#ifndef PLATFORM_TYPES_H_
#define PLATFORM_TYPES_H_
// Section 0: C Standard Types
// fprime depends on the existence of intN_t and uintN_t C standard ints and
// the mix/max values for those types. Platform developers must either:
// 1. define these types and definitions
// 2. include headers that define these types
//
// In addition, support for various type widths can be turned on/off with the
// switches in this section to control which of the C standard types are
// available in the system. fprime consumes this information and produces the
// UN, IN, and FN types we see in fprime code.
#include <inttypes.h>
#include <stdint.h>
// Define what types and checks are supported by this platform
#define FW_HAS_64_BIT 1 //!< Architecture supports 64 bit integers
#define FW_HAS_32_BIT 1 //!< Architecture supports 32 bit integers
#define FW_HAS_16_BIT 1 //!< Architecture supports 16 bit integers
#define FW_HAS_F64 1 //!< Architecture supports 64 bit floating point numbers
#define SKIP_FLOAT_IEEE_754_COMPLIANCE 0 //!< Check IEEE 754 compliance of floating point arithmetic
// Section 1: Logical Types
// fprime requires platform implementors to define logical types for their
// system. The list of logical types can be found in the document:
// docs/Design/numerical-types.md with the names of the form "Platform*"
typedef int PlatformIntType;
#define PRI_PlatformIntType "d"
typedef unsigned int PlatformUIntType;
#define PRI_PlatformUIntType "u"
typedef PlatformIntType PlatformIndexType;
#define PRI_PlatformIndexType PRI_PlatformIntType
typedef int64_t PlatformSignedSizeType;
#define PRI_PlatformSignedSizeType PRId64
typedef uint64_t PlatformSizeType;
#define PRI_PlatformSizeType PRIu64
typedef PlatformIntType PlatformAssertArgType;
#define PRI_PlatformAssertArgType PRI_PlatformIntType
// Linux/Darwin definitions for pointer have various sizes across platforms
// and since these definitions need to be consistent we must ask the size.
#ifndef PLATFORM_POINTER_CAST_TYPE_DEFINED
// Check for __SIZEOF_POINTER__ or cause error
#ifndef __SIZEOF_POINTER__
#error "Compiler does not support __SIZEOF_POINTER__, cannot use Linux/Darwin types"
#endif
// Pointer sizes are determined by compiler
#if __SIZEOF_POINTER__ == 8
typedef uint64_t PlatformPointerCastType;
#define PRI_PlatformPointerCastType PRIx64
#elif __SIZEOF_POINTER__ == 4
typedef uint32_t PlatformPointerCastType;
#define PRI_PlatformPointerCastType PRIx32
#elif __SIZEOF_POINTER__ == 2
typedef uint16_t PlatformPointerCastType;
#define PRI_PlatformPointerCastType PRIx16
#elif __SIZEOF_POINTER__ == 1
typedef uint8_t PlatformPointerCastType;
#define PRI_PlatformPointerCastType PRIx8
#else
#error "Expected __SIZEOF_POINTER__ to be one of 8, 4, 2, or 1"
#endif
#endif
#endif // PLATFORM_TYPES_H_
| h |
fprime | data/projects/fprime/CFDP/Checksum/Checksum.cpp | // ======================================================================
// \title CFDP/Checksum/Checksum.cpp
// \author bocchino
// \brief cpp file for CFDP checksum class
//
// \copyright
// Copyright 2009-2016, by the California Institute of Technology.
// ALL RIGHTS RESERVED. United States Government Sponsorship
// acknowledged.
//
// ======================================================================
#include "CFDP/Checksum/Checksum.hpp"
#include "Fw/Types/Assert.hpp"
static U32 min(const U32 a, const U32 b) {
return (a < b) ? a : b;
}
namespace CFDP {
Checksum ::
Checksum() : m_value(0)
{
}
Checksum ::
Checksum(const U32 value) : m_value(value)
{
}
Checksum ::
Checksum(const Checksum &original)
{
this->m_value = original.getValue();
}
Checksum ::
~Checksum()
{
}
Checksum& Checksum ::
operator=(const Checksum& checksum)
{
this->m_value = checksum.m_value;
return *this;
}
bool Checksum ::
operator==(const Checksum& checksum) const
{
return this->m_value == checksum.m_value;
}
bool Checksum ::
operator!=(const Checksum& checksum) const
{
return not (*this == checksum);
}
U32 Checksum ::
getValue() const
{
return this->m_value;
}
void Checksum ::
update(
const U8 *const data,
const U32 offset,
const U32 length
)
{
U32 index = 0;
// Add the first word unaligned if necessary
const U32 offsetMod4 = offset % 4;
if (offsetMod4 != 0) {
const U8 wordLength = static_cast<U8>(min(length, 4 - offsetMod4));
this->addWordUnaligned(
&data[index],
static_cast<U8>(offset + index),
wordLength
);
index += wordLength;
}
// Add the middle words aligned
for ( ; index + 4 <= length; index += 4)
addWordAligned(&data[index]);
// Add the last word unaligned if necessary
if (index < length) {
const U8 wordLength = static_cast<U8>(length - index);
this->addWordUnaligned(
&data[index],
static_cast<U8>(offset + index),
wordLength
);
}
}
void Checksum ::
addWordAligned(const U8 *const word)
{
for (U8 i = 0; i < 4; ++i)
addByteAtOffset(word[i], i);
}
void Checksum ::
addWordUnaligned(
const U8 *word,
const U8 position,
const U8 length
)
{
FW_ASSERT(length < 4);
U8 offset = position % 4;
for (U8 i = 0; i < length; ++i) {
addByteAtOffset(word[i], offset);
++offset;
if (offset == 4)
offset = 0;
}
}
void Checksum ::
addByteAtOffset(
const U8 byte,
const U8 offset
)
{
FW_ASSERT(offset < 4);
const U32 addend = byte << (8*(3-offset));
this->m_value += addend;
}
}
| cpp |
fprime | data/projects/fprime/CFDP/Checksum/Checksum.hpp | // ======================================================================
// \title CFDP/Checksum/Checksum.hpp
// \author bocchino
// \brief hpp file for CFDP checksum class
//
// \copyright
// Copyright 2009-2016, by the California Institute of Technology.
// ALL RIGHTS RESERVED. United States Government Sponsorship
// acknowledged.
//
// ======================================================================
#ifndef CFDP_Checksum_HPP
#define CFDP_Checksum_HPP
#include <FpConfig.hpp>
namespace CFDP {
//! \class Checksum
//! \brief Class representing a CFDP checksum
//!
class Checksum {
public:
// ----------------------------------------------------------------------
// Types
// ----------------------------------------------------------------------
public:
// ----------------------------------------------------------------------
// Construction and destruction
// ----------------------------------------------------------------------
//! Construct a fresh Checksum object
Checksum();
//! Construct a Checksum object and initialize it with a value
Checksum(const U32 value);
//! Copy a Checksum object
Checksum(const Checksum &original);
//! Destroy a Checksum object
~Checksum();
public:
// ----------------------------------------------------------------------
// Public instance methods
// ----------------------------------------------------------------------
//! Assign checksum to this
Checksum& operator=(const Checksum& checksum);
//! Compare checksum and this for equality
bool operator==(const Checksum& checksum) const;
//! Compare checksum and this for inequality
bool operator!=(const Checksum& checksum) const;
//! Update the checksum value by accumulating the words in the data
void update(
const U8 *const data, //!< The data
const U32 offset, //!< The offset of the start of the data, relative to the start of the file
const U32 length //!< The length of the data in bytes
);
//! Get the checksum value
U32 getValue() const;
PRIVATE:
// ----------------------------------------------------------------------
// Private instance methods
// ----------------------------------------------------------------------
//! Add a four-byte aligned word to the checksum value
void addWordAligned(
const U8 *const word //! The word
);
//! Add a four-byte unaligned word to the checksum value
void addWordUnaligned(
const U8 *const word, //! The word
const U8 position, //! The position of the word relative to the start of the file
const U8 length //! The number of valid bytes in the word
);
//! Add byte to value at offset in word
void addByteAtOffset(
const U8 byte, //! The byte
const U8 offset //! The offset
);
PRIVATE:
// ----------------------------------------------------------------------
// Private member variables
// ----------------------------------------------------------------------
//! The accumulated checksum value
U32 m_value;
};
}
#endif
| hpp |
fprime | data/projects/fprime/CFDP/Checksum/GTest/Checksums.hpp | // ======================================================================
// \title CFDP/Checksum/GTest/Checksums.hpp
// \author bocchino
// \brief hpp file for CFDP Checksum gtest utilities
//
// \copyright
// Copyright (C) 2016 California Institute of Technology.
// ALL RIGHTS RESERVED. United States Government Sponsorship
// acknowledged.
//
// ======================================================================
#ifndef GTest_CFDP_Checksums_HPP
#define GTest_CFDP_Checksums_HPP
#include "gtest/gtest.h"
#include "CFDP/Checksum/Checksum.hpp"
namespace CFDP {
namespace GTest {
//! Utilities for testing Checksum operations
//!
namespace Checksums {
void compare(
const CFDP::Checksum& expected, //!< Expected value
const CFDP::Checksum& actual //!< Actual value
);
}
}
}
#endif
| hpp |
fprime | data/projects/fprime/CFDP/Checksum/GTest/Checksums.cpp | // ======================================================================
// \title CFDP/Checksum/GTest/Checksums.cpp
// \author bocchino
// \brief cpp file for CFDP Checksum gtest utilities
//
// \copyright
// Copyright (C) 2016, California Institute of Technology.
// ALL RIGHTS RESERVED. United States Government Sponsorship
// acknowledged.
//
// ======================================================================
#include "CFDP/Checksum/GTest/Checksums.hpp"
namespace CFDP {
namespace GTest {
void Checksums ::
compare(
const CFDP::Checksum& expected,
const CFDP::Checksum& actual
)
{
const U32 expectedValue = expected.getValue();
const U32 actualValue = actual.getValue();
ASSERT_EQ(expectedValue, actualValue);
}
}
}
| cpp |
fprime | data/projects/fprime/CFDP/Checksum/test/ut/ChecksumMain.cpp | // ----------------------------------------------------------------------
// Main.cpp
// ----------------------------------------------------------------------
#include "gtest/gtest.h"
#include "CFDP/Checksum/Checksum.hpp"
using namespace CFDP;
const U8 data[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
const U32 expectedValue =
(data[0] << 3*8) + (data[1] << 2*8) + (data[2] << 1*8) + data[3] +
(data[4] << 3*8) + (data[5] << 2*8) + (data[6] << 1*8) + data[7];
TEST(Checksum, OnePacket) {
Checksum checksum;
checksum.update(data, 0, 8);
ASSERT_EQ(expectedValue, checksum.getValue());
}
TEST(Checksum, TwoPacketsAligned) {
Checksum checksum;
checksum.update(&data[0], 0, 4);
checksum.update(&data[4], 4, 4);
ASSERT_EQ(expectedValue, checksum.getValue());
}
TEST(Checksum, TwoPacketsUnaligned1) {
Checksum checksum;
checksum.update(&data[0], 0, 3);
checksum.update(&data[3], 3, 5);
ASSERT_EQ(expectedValue, checksum.getValue());
}
TEST(Checksum, TwoPacketsUnaligned2) {
Checksum checksum;
checksum.update(&data[0], 0, 5);
checksum.update(&data[5], 5, 3);
ASSERT_EQ(expectedValue, checksum.getValue());
}
TEST(Checksum, ThreePackets) {
Checksum checksum;
checksum.update(&data[0], 0, 2);
checksum.update(&data[2], 2, 3);
checksum.update(&data[5], 5, 3);
ASSERT_EQ(expectedValue, checksum.getValue());
}
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
| cpp |
fprime | data/projects/fprime/Autocoders/Python/templates/ExampleComponentImpl.hpp | /*
* ExampleComponentImpl.hpp
*
* Created on: Nov 3, 2014
* Author: tcanham
*/
#ifndef EXAMPLECOMPONENTIMPL_HPP_
#define EXAMPLECOMPONENTIMPL_HPP_
#include <Autocoders/Python/templates/ExampleComponentAc.hpp>
namespace ExampleComponents {
class ExampleComponentImpl: public ExampleComponentBase {
public:
ExampleComponentImpl(const char* name);
void init(NATIVE_INT_TYPE queueDepth, NATIVE_INT_TYPE instance = 0);
virtual ~ExampleComponentImpl();
protected:
private:
void exampleInput_handler(NATIVE_INT_TYPE portNum, I32 arg1, const ANameSpace::mytype& arg2, U8 arg3, const Example3::ExampleSerializable& arg4, AnotherExample::SomeEnum arg5);
SomeOtherNamespace::AnotherEnum anotherInput_handler(NATIVE_INT_TYPE portNum, I32 arg1, F64 arg2, SomeOtherNamespace::SomeEnum arg3);
void TEST_CMD_1_cmdHandler(FwOpcodeType opCode, U32 cmdSeq, I32 arg1, ExampleComponentBase::CmdEnum arg2, const Fw::CmdStringArg& arg3);
void TEST_CMD_2_cmdHandler(FwOpcodeType opCode, U32 cmdSeq, I32 arg1, F32 arg2);
// interfaces
void test_internalInterfaceHandler(I32 arg1, F32 arg2, U8 arg3);
void test2_internalInterfaceHandler(I32 arg1, SomeEnum arg2, const Fw::InternalInterfaceString& arg3, const Example4::Example2& arg4);
void parameterUpdated(FwPrmIdType id);
};
} /* namespace ExampleComponents */
#endif /* EXAMPLECOMPONENTIMPL_HPP_ */
| hpp |
fprime | data/projects/fprime/Autocoders/Python/templates/ExampleType.hpp | #ifndef EXAMPLE_TYPE_HPP
#define EXAMPLE_TYPE_HPP
// A hand-coded serializable
#include <FpConfig.hpp>
#include <Fw/Types/Serializable.hpp>
#if FW_SERIALIZABLE_TO_STRING
#include <Fw/Types/StringType.hpp>
#include <cstdio> // snprintf
#endif
namespace ANameSpace {
class mytype : public Fw::Serializable {
public:
enum {
SERIALIZED_SIZE = sizeof(U32),
TYPE_ID = 2000
};
mytype(); // Default constructor
mytype(const mytype* src); // copy constructor
mytype(const mytype& src); // copy constructor
mytype(U32 arg); // constructor with arguments
mytype& operator=(const mytype& src); // Equal operator
bool operator==(const mytype& src) const;
void setVal(U32 arg); // set values
U32 getVal();
Fw::SerializeStatus serialize(Fw::SerializeBufferBase& buffer) const;
Fw::SerializeStatus deserialize(Fw::SerializeBufferBase& buffer);
#if FW_SERIALIZABLE_TO_STRING
void toString(Fw::StringBase& text) const; //!< generate text from serializable
#endif
protected:
private:
U32 m_val; // stored value
};
}
#endif
| hpp |
fprime | data/projects/fprime/Autocoders/Python/templates/ExampleComponentImpl.cpp | /*
* ExampleComponentImpl.cpp
*
* Created on: Nov 3, 2014
* Author: tcanham
*/
#include <Autocoders/Python/templates/ExampleComponentImpl.hpp>
#include <cstdio>
namespace ExampleComponents {
ExampleComponentImpl::ExampleComponentImpl(const char* name) : ExampleComponentBase(name) {
}
ExampleComponentImpl::~ExampleComponentImpl() {
}
void ExampleComponentImpl::init(NATIVE_INT_TYPE queueDepth, NATIVE_INT_TYPE instance) {
ExampleComponentBase::init(queueDepth,instance);
}
void ExampleComponentImpl::exampleInput_handler(NATIVE_INT_TYPE portNum, I32 arg1, const ANameSpace::mytype& arg2, U8 arg3, const Example3::ExampleSerializable& arg4, AnotherExample::SomeEnum arg5) {
Fw::TlmString arg = "A string arg";
// write some telemetry
this->tlmWrite_stringchan(arg);
// call the output port
if (this->isConnected_exampleOutput_OutputPort(0)) {
this->exampleOutput_out(0,arg1,arg2,arg3,arg4,arg5);
} else {
printf("Output port not connected.\n");
}
}
SomeOtherNamespace::AnotherEnum ExampleComponentImpl::anotherInput_handler(NATIVE_INT_TYPE portNum, I32 arg1, F64 arg2, SomeOtherNamespace::SomeEnum arg3) {
return SomeOtherNamespace::MEMB1;
}
void ExampleComponentImpl::TEST_CMD_1_cmdHandler(FwOpcodeType opCode, U32 cmdSeq, I32 arg1, ExampleComponentBase::CmdEnum arg2, const Fw::CmdStringArg& arg3) {
// issue the test event with the opcode
Fw::LogStringArg str = "TEST_CMD_1";
this->log_ACTIVITY_HI_SomeEvent(opCode, static_cast<F32>(arg1), Example4::Example2(2.0,3.0,4,5), str,ExampleComponentBase::EVENT_MEMB2);
// write a value to a telemetry channel
U32 chan = 12;
this->tlmWrite_somechan(chan);
this->cmdResponse_out(opCode,cmdSeq, Fw::CmdResponse::OK);
}
void ExampleComponentImpl::TEST_CMD_2_cmdHandler(FwOpcodeType opCode, U32 cmdSeq, I32 arg1, F32 arg2) {
Fw::LogStringArg str = "TEST_CMD_2";
this->log_ACTIVITY_HI_SomeEvent(opCode,arg2, Example4::Example2(6.0,7.0,8,9), str,ExampleComponentBase::EVENT_MEMB3);
Example4::Example2 ex(10.0,11.0,12,13);
this->tlmWrite_anotherchan(ex); // <! Example output port
this->cmdResponse_out(opCode,cmdSeq, Fw::CmdResponse::EXECUTION_ERROR);
}
void ExampleComponentImpl::parameterUpdated(FwPrmIdType id) {
printf("Parameter ID %d was updated!\n",id);
}
void ExampleComponentImpl::test_internalInterfaceHandler(I32 arg1, F32 arg2, U8 arg3) {
}
void ExampleComponentImpl::test2_internalInterfaceHandler(I32 arg1, SomeEnum arg2, const Fw::InternalInterfaceString& arg3, const Example4::Example2& arg4) {
}
} /* namespace ExampleComponents */
| cpp |
fprime | data/projects/fprime/Autocoders/Python/templates/ExampleType.cpp | #include <Autocoders/Python/templates/ExampleType.hpp>
#include <Fw/Types/Assert.hpp>
namespace ANameSpace {
mytype::mytype(): Serializable() {
}
mytype::mytype(const mytype& src) : Serializable() {
this->setVal(src.m_val);
}
mytype::mytype(const mytype* src) : Serializable() {
FW_ASSERT(src);
this->setVal(src->m_val);
}
mytype::mytype(U32 val) : Serializable() {
this->setVal(val);
}
mytype& mytype::operator=(const mytype& src) {
this->setVal(src.m_val);
return *this;
}
bool mytype::operator==(const mytype& src) const {
return (this->m_val == src.m_val);
}
U32 mytype::getVal() {
return this->m_val;
}
void mytype::setVal(U32 val) {
this->m_val = val;
}
Fw::SerializeStatus mytype::serialize(Fw::SerializeBufferBase& buffer) const {
Fw::SerializeStatus stat = buffer.serialize(this->m_val);
if (Fw::FW_SERIALIZE_OK != stat) {
return stat;
}
return buffer.serialize(static_cast<NATIVE_INT_TYPE>(mytype::TYPE_ID));
}
Fw::SerializeStatus mytype::deserialize(Fw::SerializeBufferBase& buffer) {
NATIVE_INT_TYPE id;
Fw::SerializeStatus stat = buffer.deserialize(id);
if (Fw::FW_SERIALIZE_OK != stat) {
return stat;
}
if (id != static_cast<NATIVE_INT_TYPE>(mytype::TYPE_ID)) {
return Fw::FW_DESERIALIZE_TYPE_MISMATCH;
}
return buffer.deserialize(this->m_val);
}
#if FW_SERIALIZABLE_TO_STRING
void mytype::toString(Fw::StringBase& text) const {
static const char * formatString = "(val = %u)";
// declare strings to hold any serializable toString() arguments
char outputString[FW_SERIALIZABLE_TO_STRING_BUFFER_SIZE];
snprintf(outputString,FW_SERIALIZABLE_TO_STRING_BUFFER_SIZE,formatString,this->m_val);
outputString[FW_SERIALIZABLE_TO_STRING_BUFFER_SIZE-1] = 0; // NULL terminate
text = outputString;
}
#endif
}
| cpp |
fprime | data/projects/fprime/Autocoders/Python/templates/test/ut/main.cpp | #ifdef FPRIME_CMAKE
#include "Autocoder/GTestBase.hpp"
#else
#include <templatesGTestBase.hpp>
#endif
// Very minimal to test autocoder. Some day they'll be actual unit test code
class ATester : public ExampleComponents::ExampleGTestBase {
public:
ATester() : ExampleComponents::ExampleGTestBase("comp",10) {}
void from_exampleOutput_handler(
const NATIVE_INT_TYPE portNum, //!< The port number
I32 arg1, //!< A built-in type argument
const ANameSpace::mytype &arg2, //!< A user-defined type argument
U8 arg3, //!< The third argument
const Example3::ExampleSerializable &arg4, //!< The third argument
AnotherExample::SomeEnum arg5 //!< The ENUM argument
) {
}
};
int main(int argc, char* argv[]) {
ATester testBase;
}
| cpp |
fprime | data/projects/fprime/Autocoders/Python/test/serial_passive/main.cpp | #include <FpConfig.hpp>
#include <Fw/Obj/SimpleObjRegistry.hpp>
int main(int argc, char* argv[]) {
}
| cpp |
fprime | data/projects/fprime/Autocoders/Python/test/serial_passive/TestSerialImpl.hpp | // ======================================================================
// \title TestSerialImpl.hpp
// \author tim
// \brief hpp file for TestSerial component implementation class
//
// \copyright
// Copyright 2009-2015, by the California Institute of Technology.
// ALL RIGHTS RESERVED. United States Government Sponsorship
// acknowledged.
//
// ======================================================================
#ifndef TestSerial_HPP
#define TestSerial_HPP
#include "Autocoders/Python/test/serial_passive/TestComponentAc.hpp"
namespace TestComponents {
class TestSerialImpl :
public TestSerialComponentBase
{
public:
// ----------------------------------------------------------------------
// Construction, initialization, and destruction
// ----------------------------------------------------------------------
//! Construct object TestSerial
//!
TestSerialImpl(
const char *const compName //!< The component name
);
//! Initialize object TestSerial
//!
void init(
const NATIVE_INT_TYPE queueDepth, //!< The queue depth
const NATIVE_INT_TYPE msgSize, //!< The message size
const NATIVE_INT_TYPE instance = 0 //!< The instance number
);
//! Destroy object TestSerial
//!
~TestSerialImpl();
PRIVATE:
// ----------------------------------------------------------------------
// Handler implementations for user-defined serial input ports
// ----------------------------------------------------------------------
//! Handler implementation for SerialInSync
//!
void SerialInSync_handler(
NATIVE_INT_TYPE portNum, //!< The port number
Fw::SerializeBufferBase &Buffer //!< The serialization buffer
);
//! Handler implementation for SerialInGuarded
//!
void SerialInGuarded_handler(
NATIVE_INT_TYPE portNum, //!< The port number
Fw::SerializeBufferBase &Buffer //!< The serialization buffer
);
//! Handler implementation for SerialInAsync
//!
void SerialInAsync_handler(
NATIVE_INT_TYPE portNum, //!< The port number
Fw::SerializeBufferBase &Buffer //!< The serialization buffer
);
};
} // end namespace TestComponents
#endif
| hpp |
fprime | data/projects/fprime/Autocoders/Python/test/serial_passive/TestSerialImpl.cpp | // ======================================================================
// \title TestSerialImpl.cpp
// \author tim
// \brief cpp file for TestSerial component implementation class
//
// \copyright
// Copyright 2009-2015, by the California Institute of Technology.
// ALL RIGHTS RESERVED. United States Government Sponsorship
// acknowledged.
//
// ======================================================================
#include <Autocoders/Python/test/serial_passive/TestSerialImpl.hpp>
#include <FpConfig.hpp>
namespace TestComponents {
// ----------------------------------------------------------------------
// Construction, initialization, and destruction
// ----------------------------------------------------------------------
TestSerialImpl ::
TestSerialImpl(
const char *const compName
) :
TestSerialComponentBase(compName)
{
}
void TestSerialImpl ::
init(
const NATIVE_INT_TYPE queueDepth,
const NATIVE_INT_TYPE msgSize,
const NATIVE_INT_TYPE instance
)
{
TestSerialComponentBase::init(queueDepth, msgSize, instance);
}
TestSerialImpl ::
~TestSerialImpl()
{
}
// ----------------------------------------------------------------------
// Handler implementations for user-defined serial input ports
// ----------------------------------------------------------------------
void TestSerialImpl ::
SerialInSync_handler(
NATIVE_INT_TYPE portNum, //!< The port number
Fw::SerializeBufferBase &Buffer //!< The serialization buffer
)
{
this->SerialOut_out(0,Buffer);
}
void TestSerialImpl ::
SerialInGuarded_handler(
NATIVE_INT_TYPE portNum, //!< The port number
Fw::SerializeBufferBase &Buffer //!< The serialization buffer
)
{
this->SerialOut_out(0,Buffer);
}
void TestSerialImpl ::
SerialInAsync_handler(
NATIVE_INT_TYPE portNum, //!< The port number
Fw::SerializeBufferBase &Buffer //!< The serialization buffer
)
{
this->SerialOut_out(0,Buffer);
}
} // end namespace TestComponents
| cpp |
fprime | data/projects/fprime/Autocoders/Python/test/serial_passive/test/ut/serial_passiveTester.cpp | // ======================================================================
// \title TestSerial.hpp
// \author tim
// \brief cpp file for TestSerial test harness implementation class
//
// \copyright
// Copyright 2009-2015, by the California Institute of Technology.
// ALL RIGHTS RESERVED. United States Government Sponsorship
// acknowledged.
//
// ======================================================================
#include "serial_passiveTester.hpp"
#define INSTANCE 0
#define MAX_HISTORY_SIZE 10
#define QUEUE_DEPTH 10
namespace TestComponents {
// ----------------------------------------------------------------------
// Construction and destruction
// ----------------------------------------------------------------------
serial_passiveTester ::
serial_passiveTester() :
TestSerialGTestBase("Tester", MAX_HISTORY_SIZE),
component("TestSerial")
{
this->initComponents();
this->connectPorts();
}
serial_passiveTester ::
~serial_passiveTester()
{
}
// ----------------------------------------------------------------------
// Tests
// ----------------------------------------------------------------------
void serial_passiveTester ::
toDo()
{
// TODO
}
// ----------------------------------------------------------------------
// Handlers for serial from ports
// ----------------------------------------------------------------------
void serial_passiveTester ::
from_SerialOut_handler(
NATIVE_INT_TYPE portNum, //!< The port number
Fw::SerializeBufferBase &Buffer //!< The serialization buffer
)
{
// TODO
}
// ----------------------------------------------------------------------
// Helper methods
// ----------------------------------------------------------------------
void serial_passiveTester ::
connectPorts()
{
}
void serial_passiveTester ::
initComponents()
{
this->init();
this->component.init(
QUEUE_DEPTH, INSTANCE
);
}
} // end namespace TestComponents
| cpp |
fprime | data/projects/fprime/Autocoders/Python/test/serial_passive/test/ut/main.cpp | #include <Autocoders/Python/test/serial_passive/TestSerialImpl.hpp>
#include <Autocoders/Python/test/port_loopback/ExampleComponentImpl.hpp>
int main(int argc, char* argv[]) {
TestComponents::TestSerialImpl serImpl("SerImpl");
serImpl.init(10,100);
ExampleComponents::ExampleComponentImpl exImpl("ExImpl");
exImpl.init();
serImpl.start();
// connect ports
exImpl.set_exampleOutput_OutputPort(0,serImpl.get_SerialInSync_InputPort(0));
exImpl.set_exampleOutput_OutputPort(1,serImpl.get_SerialInGuarded_InputPort(0));
exImpl.set_exampleOutput_OutputPort(2,serImpl.get_SerialInAsync_InputPort(0));
serImpl.set_SerialOut_OutputPort(0,exImpl.get_exampleInput_InputPort(0));
exImpl.makePortCall(0);
exImpl.makePortCall(1);
exImpl.makePortCall(2);
Os::Task::delay(500);
serImpl.exit();
serImpl.ActiveComponentBase::join(nullptr);
return 0;
}
| cpp |
fprime | data/projects/fprime/Autocoders/Python/test/serial_passive/test/ut/serial_passiveTester.hpp | // ======================================================================
// \title TestSerial/test/ut/Tester.hpp
// \author tim
// \brief hpp file for TestSerial test harness implementation class
//
// \copyright
// Copyright 2009-2015, by the California Institute of Technology.
// ALL RIGHTS RESERVED. United States Government Sponsorship
// acknowledged.
//
// ======================================================================
#ifndef TESTER_HPP
#define TESTER_HPP
#include "serial_passiveGTestBase.hpp"
#include "Autocoders/Python/test/serial_passive/TestSerialImpl.hpp"
namespace TestComponents {
class serial_passiveTester :
public TestSerialGTestBase
{
// ----------------------------------------------------------------------
// Construction and destruction
// ----------------------------------------------------------------------
public:
//! Construct object serial_passiveTester
//!
serial_passiveTester();
//! Destroy object serial_passiveTester
//!
~serial_passiveTester();
public:
// ----------------------------------------------------------------------
// Tests
// ----------------------------------------------------------------------
//! To do
//!
void toDo();
private:
// ----------------------------------------------------------------------
// Handlers for serial from ports
// ----------------------------------------------------------------------
//! Handler for from_SerialOut
//!
void from_SerialOut_handler(
NATIVE_INT_TYPE portNum, //!< The port number
Fw::SerializeBufferBase &Buffer //!< The serialization buffer
);
private:
// ----------------------------------------------------------------------
// Helper methods
// ----------------------------------------------------------------------
//! Connect ports
//!
void connectPorts();
//! Initialize components
//!
void initComponents();
private:
// ----------------------------------------------------------------------
// Variables
// ----------------------------------------------------------------------
//! The component under test
//!
TestSerialImpl component;
};
} // end namespace TestComponents
#endif
| hpp |
fprime | data/projects/fprime/Autocoders/Python/test/time_get/TestTimeGetImpl.hpp | /*
* TestTelemRecvImpl.hpp
*
* Created on: Mar 28, 2014
* Author: tcanham
*/
#ifndef TESTTEXTLOGIMPL_HPP_
#define TESTTEXTLOGIMPL_HPP_
#include <Autocoders/Python/test/time_get/TimeGetComponentAc.hpp>
class TimeGetTesterImpl: public TimeGet::TimeGetTesterComponentBase {
public:
TimeGetTesterImpl(const char* compName);
virtual ~TimeGetTesterImpl();
void init();
protected:
void test_time_get_handler();
};
#endif /* TESTTIMEIMPL_HPP_ */
| hpp |
fprime | data/projects/fprime/Autocoders/Python/test/time_get/TestTimeGetImpl.cpp | /*
* TestCommand1Impl.cpp
*
* Created on: Mar 28, 2014
* Author: tcanham
*/
#include <cstdio>
#include "TestTimeGetImpl.hpp"
TimeGetTesterImpl::TimeGetTesterImpl(const char* name) : TimeGet::TimeGetTesterComponentBase(name)
{
}
TimeGetTesterImpl::~TimeGetTesterImpl() {
}
void TimeGetTesterImpl::init() {
TimeGet::TimeGetTesterComponentBase::init();
}
void TimeGetTesterImpl::test_time_get_handler() {
this->getTime(); // Tests independent getTime() function
}
| cpp |
fprime | data/projects/fprime/Autocoders/Python/test/time_get/test/ut/main.cpp | #include "time_getGTestBase.hpp"
#include <FpConfig.hpp>
#include <Autocoders/Python/test/time_get/TestTimeGetImpl.hpp>
// Very minimal to test autocoder. Some day they'll be actual unit test code
// Here we test to ensure test harness generates correctly
class ATester : public TimeGet::TimeGetTesterGTestBase {
public:
ATester() : TimeGet::TimeGetTesterGTestBase("comp",10) {}
};
int main(int argc, char* argv[]) {
ATester testBase;
TimeGetTesterImpl component("name");
component.getTime();
}
| cpp |
fprime | data/projects/fprime/Autocoders/Python/test/enum_xml/main.cpp | #include <Autocoders/Python/test/enum_xml/Component1ComponentAc.hpp>
#include <Autocoders/Python/test/enum_xml/Component1Impl.hpp>
#include <Autocoders/Python/test/enum_xml/Enum1EnumAc.hpp>
#include <Autocoders/Python/test/enum_xml/Port1PortAc.hpp>
#include <Autocoders/Python/test/enum_xml/Serial1SerializableAc.hpp>
#include <Fw/Types/SerialBuffer.hpp>
#include <Fw/Types/Assert.hpp>
#include "Fw/Test/UnitTestAssert.hpp"
#include "STest/Pick/Pick.hpp"
#include "STest/Random/Random.hpp"
#include "gtest/gtest.h"
#include <iostream>
#include <cstring>
using namespace std;
// Instantiate the inst1 and inst2 components
Example::ExampleEnumImpl inst1("inst1");
Example::ExampleEnumImpl inst2("inst2");
void constructArchitecture() {
// Connect inst1 to inst2
inst1.set_EnumOut_OutputPort(0, inst2.get_EnumIn_InputPort(0));
// Connect inst2 to inst1
inst2.set_EnumOut_OutputPort(0, inst1.get_EnumIn_InputPort(0));
// Instantiate components
inst1.init(100);
inst2.init(100);
}
Example::SubNamespace::Enum1::t getEnumConstant() {
Example::SubNamespace::Enum1::t c = Example::SubNamespace::Enum1::Item1;
const U32 i = STest::Pick::lowerUpper(0, 4);
switch(i) {
case 0:
c = Example::SubNamespace::Enum1::Item1;
break;
case 1:
c = Example::SubNamespace::Enum1::Item2;
break;
case 2:
c = Example::SubNamespace::Enum1::Item3;
break;
case 3:
c = Example::SubNamespace::Enum1::Item4;
break;
case 4:
c = Example::SubNamespace::Enum1::Item5;
break;
default:
FW_ASSERT(0, i);
break;
}
return c;
}
Example::SubNamespace::Enum1::t getNonnegativeConstant() {
Example::SubNamespace::Enum1::t c = Example::SubNamespace::Enum1::Item1;
const U32 i = STest::Pick::lowerUpper(0, 2);
switch(i) {
case 0:
c = Example::SubNamespace::Enum1::Item2;
break;
case 1:
c = Example::SubNamespace::Enum1::Item3;
break;
case 2:
c = Example::SubNamespace::Enum1::Item4;
break;
default:
FW_ASSERT(0, i);
break;
}
return c;
}
Example::SubNamespace::Enum1::t getNegativeConstant() {
Example::SubNamespace::Enum1::t c = Example::SubNamespace::Enum1::Item1;
const U32 i = STest::Pick::lowerUpper(0, 1);
switch(i) {
case 0:
c = Example::SubNamespace::Enum1::Item1;
break;
case 1:
c = Example::SubNamespace::Enum1::Item5;
break;
default:
FW_ASSERT(0, i);
break;
}
return c;
}
Example::SubNamespace::Enum1 getEnum() {
const Example::SubNamespace::Enum1 e = getEnumConstant();
return e;
}
Example::SubNamespace::Enum1 getEnumFromI32() {
Example::SubNamespace::Enum1 e = getEnumConstant();
e = static_cast<I32>(getEnumConstant());
return e;
}
Example::SubNamespace::Enum1 getEnumFromU32() {
Example::SubNamespace::Enum1 e = getNonnegativeConstant();
e = static_cast<U32>(getNonnegativeConstant());
return e;
}
void checkAssertionFailure(
const ::Test::UnitTestAssert& uta,
const U32 expectedLineNumber,
const U32 expectedArg1
) {
ASSERT_TRUE(uta.assertFailed());
Test::UnitTestAssert::File file = Test::UnitTestAssert::fileInit;
NATIVE_UINT_TYPE lineNo = 0;
NATIVE_UINT_TYPE numArgs = 0;
FwAssertArgType arg1 = 0;
FwAssertArgType arg2 = 0;
FwAssertArgType arg3 = 0;
FwAssertArgType arg4 = 0;
FwAssertArgType arg5 = 0;
FwAssertArgType arg6 = 0;
uta.retrieveAssert(file, lineNo, numArgs, arg1, arg2, arg3, arg4, arg5, arg6);
ASSERT_EQ(expectedLineNumber, lineNo);
ASSERT_EQ(1U, numArgs);
ASSERT_EQ(expectedArg1, arg1);
}
TEST(EnumXML, InvalidNegativeConstant) {
::Test::UnitTestAssert uta;
Example::SubNamespace::Enum1 enum1 = getEnum();
// Get a valid negative constant
const I32 negativeConstant = getNegativeConstant();
const U32 expectedLineNumber = 62;
// Turn it into a U32
const U32 expectedArg1 = negativeConstant;
// As a U32, the constant is not valid
// This should cause an assertion failure
enum1 = expectedArg1;
checkAssertionFailure(uta, expectedLineNumber, expectedArg1);
}
TEST(EnumXML, InvalidConstant) {
::Test::UnitTestAssert uta;
Example::SubNamespace::Enum1 enum1 = getEnum();
// Get an invalid constant
const I32 invalidConstant = 42;
// This should cause an assertion failure
enum1 = invalidConstant;
const U32 expectedLineNumber = 55;
const U32 expectedArg1 = invalidConstant;
checkAssertionFailure(uta, expectedLineNumber, expectedArg1);
}
TEST(EnumXML, OK) {
// Explicitly set enum1 to the default value
Example::SubNamespace::Enum1 enum1(Example::SubNamespace::Enum1::Item4);
Example::SubNamespace::Enum1 enum2;
Example::SubNamespace::Enum1 enum3;
Example::Enum2 enum4;
Example::Enum3 enum5;
Example::Serial1 serial1;
// Check that other enums are set to default value
ASSERT_EQ(enum1, enum2);
ASSERT_EQ(enum1, enum3);
// Check that enum are set to uninitialized value
ASSERT_EQ(enum4.e, 0);
// Check that the enum serializable types are set correctly
ASSERT_EQ(Example::SubNamespace::Enum1::SERIALIZED_SIZE, sizeof(FwEnumStoreType));
ASSERT_EQ(Example::Enum2::SERIALIZED_SIZE, sizeof(U64));
ASSERT_EQ(Example::Enum3::SERIALIZED_SIZE, sizeof(U8));
enum1 = getEnumFromI32();
cout << "Created first enum: " << enum1 << endl;
enum2 = getEnum();
cout << "Created second enum: " << enum2 << endl;
enum3 = getEnumFromU32();
cout << "Created third enum: " << enum3 << endl;
// Save copy of enums to test against post-serialization
Example::SubNamespace::Enum1 enum1Save = enum1;
Example::SubNamespace::Enum1 enum2Save = enum2;
int serial_arg1 = 0;
int serial_arg2 = 0;
// Serialize enums
U8 buffer1[1024];
U8 buffer2[1024];
U8 buffer3[1024];
U8 buffer4[1024];
U8 buffer5[1024];
Fw::SerialBuffer enumSerial1 = Fw::SerialBuffer(buffer1, sizeof(buffer1));
Fw::SerialBuffer enumSerial2 = Fw::SerialBuffer(buffer2, sizeof(buffer2));
Fw::SerialBuffer enumSerial3 = Fw::SerialBuffer(buffer3, sizeof(buffer3));
Fw::SerialBuffer enumSerial4 = Fw::SerialBuffer(buffer4, sizeof(buffer4));
Fw::SerialBuffer enumSerial5 = Fw::SerialBuffer(buffer5, sizeof(buffer5));
ASSERT_EQ(enumSerial1.serialize(enum1), Fw::FW_SERIALIZE_OK);
cout << "Serialized enum1" << endl;
ASSERT_EQ(enumSerial2.serialize(enum2), Fw::FW_SERIALIZE_OK);
cout << "Serialized enum2" << endl;
ASSERT_EQ(enumSerial3.serialize(enum3), Fw::FW_SERIALIZE_OK);
cout << "Serialized enum3" << endl;
ASSERT_EQ(enumSerial4.serialize(enum4), Fw::FW_SERIALIZE_OK);
cout << "Serialized enum4" << endl;
ASSERT_EQ(enumSerial5.serialize(enum5), Fw::FW_SERIALIZE_OK);
cout << "Serialized enum5" << endl;
cout << "Serialized enums" << endl;
// Check that the serialized types are correctly set
ASSERT_EQ(enumSerial1.getBuffLength(), sizeof(FwEnumStoreType));
ASSERT_EQ(enumSerial2.getBuffLength(), sizeof(FwEnumStoreType));
ASSERT_EQ(enumSerial3.getBuffLength(), sizeof(FwEnumStoreType));
ASSERT_EQ(enumSerial4.getBuffLength(), sizeof(U64));
ASSERT_EQ(enumSerial5.getBuffLength(), sizeof(U8));
// Deserialize enums
ASSERT_EQ(enumSerial1.deserialize(enum1Save), Fw::FW_SERIALIZE_OK);
cout << "Deserialized enum1" << endl;
ASSERT_EQ(enumSerial2.deserialize(enum2Save), Fw::FW_SERIALIZE_OK);
cout << "Deserialized enum2" << endl;
ASSERT_EQ(enum1, enum1Save);
ASSERT_FALSE(enum1 != enum1Save);
cout << "Successful enum1 check" << endl;
ASSERT_EQ(enum2, enum2Save);
ASSERT_FALSE(enum2 != enum2Save);
cout << "Successful enum2 check" << endl;
cout << "Deserialized enums" << endl;
// Create serializable and test that enum is saved
serial1 = Example::Serial1(serial_arg1, serial_arg2, enum2);
ASSERT_EQ(serial1.getMember3(), enum2);
cout << "Created serializable with enum arg" << endl;
cout << "Created serializable" << endl;
// Invoke ports to test enum usage
cout << "Invoking inst1..." << endl;
inst1.get_ExEnumIn_InputPort(0)->invoke(enum1, serial1);
inst1.doDispatch();
inst1.get_ExEnumIn_InputPort(0)->invoke(enum2, serial1);
inst1.doDispatch();
cout << "Invoking inst2..." << endl;
inst2.get_ExEnumIn_InputPort(0)->invoke(enum1, serial1);
inst2.doDispatch();
inst2.get_ExEnumIn_InputPort(0)->invoke(enum2, serial1);
inst2.doDispatch();
cout << "Invoked ports" << endl;
}
int main(int argc, char* argv[]) {
::testing::InitGoogleTest(&argc, argv);
STest::Random::seed();
constructArchitecture();
int status = RUN_ALL_TESTS();
return status;
}
| cpp |
fprime | data/projects/fprime/Autocoders/Python/test/enum_xml/Component1Impl.cpp | #include <Autocoders/Python/test/enum_xml/Component1Impl.hpp>
#include <FpConfig.hpp>
#include <iostream>
#include <cstdio>
using namespace std;
namespace Example {
ExampleEnumImpl::ExampleEnumImpl(const char* compName) : Component1ComponentBase(compName) {
}
ExampleEnumImpl::~ExampleEnumImpl() {
}
void ExampleEnumImpl::init(NATIVE_INT_TYPE queueDepth) {
Component1ComponentBase::init(queueDepth);
}
void ExampleEnumImpl::ExEnumIn_handler(NATIVE_INT_TYPE portNum, const Example::SubNamespace::Enum1& enum1, const Example::Serial1& serial1) {
printf("%s Invoked ExEnumIn_handler(%d, %d, %d, %d, %d);\n", FW_OPTIONAL_NAME(this->getObjName()), portNum, static_cast<FwEnumStoreType>(enum1.e), serial1.getMember1(), serial1.getMember2(), static_cast<FwEnumStoreType>(serial1.getMember3().e));
this->EnumOut_out(0, enum1, serial1);
}
void ExampleEnumImpl::EnumIn_handler(NATIVE_INT_TYPE portNum, const Example::SubNamespace::Enum1& enum1, const Example::Serial1& serial1) {
printf("%s Invoked EnumIn_handler(%d, %d, %d, %d, %d);\n", FW_OPTIONAL_NAME(this->getObjName()), portNum, static_cast<FwEnumStoreType>(enum1.e), serial1.getMember1(), serial1.getMember2(), static_cast<FwEnumStoreType>(serial1.getMember3().e));
}
};
| cpp |
fprime | data/projects/fprime/Autocoders/Python/test/enum_xml/Component1Impl.hpp | #ifndef EXAMPLE_ENUM_IMPL_HPP
#define EXAMPLE_ENUM_IMPL_HPP
#include <Autocoders/Python/test/enum_xml/Component1ComponentAc.hpp>
namespace Example {
class ExampleEnumImpl : public Component1ComponentBase {
public:
// Only called by derived class
ExampleEnumImpl(const char* compName);
~ExampleEnumImpl();
void init(NATIVE_INT_TYPE queueDepth);
private:
void ExEnumIn_handler(NATIVE_INT_TYPE portNum, const Example::SubNamespace::Enum1& enum1, const Example::Serial1& serial1);
void EnumIn_handler(NATIVE_INT_TYPE portNum, const Example::SubNamespace::Enum1& enum1, const Example::Serial1& serial1);
};
};
#endif
| hpp |
fprime | data/projects/fprime/Autocoders/Python/test/port_loopback/ExampleComponentImpl.hpp | // ======================================================================
// \title ExampleImpl.hpp
// \author tim
// \brief hpp file for Example component implementation class
//
// \copyright
// Copyright 2009-2015, by the California Institute of Technology.
// ALL RIGHTS RESERVED. United States Government Sponsorship
// acknowledged.
//
// ======================================================================
#ifndef Example_HPP
#define Example_HPP
#include "Autocoders/Python/test/port_loopback/ExampleComponentAc.hpp"
namespace ExampleComponents {
class ExampleComponentImpl :
public ExampleComponentBase
{
public:
// ----------------------------------------------------------------------
// Construction, initialization, and destruction
// ----------------------------------------------------------------------
//! Construct object Example
//!
ExampleComponentImpl(
const char *const compName //!< The component name
);
//! Initialize object Example
//!
void init(
const NATIVE_INT_TYPE instance = 0 //!< The instance number
);
//! Destroy object Example
//!
~ExampleComponentImpl();
void makePortCall(NATIVE_INT_TYPE port);
PRIVATE:
// ----------------------------------------------------------------------
// Handler implementations for user-defined typed input ports
// ----------------------------------------------------------------------
//! Handler implementation for exampleInput
//!
void exampleInput_handler(
const NATIVE_INT_TYPE portNum, //!< The port number
I32 arg1, //!< A built-in type argument
AnotherExample::SomeEnum arg2, //!< The ENUM argument
const AnotherExample::arg6String& arg6
);
};
} // end namespace ExampleComponents
#endif
| hpp |
fprime | data/projects/fprime/Autocoders/Python/test/port_loopback/ExampleType.hpp | #ifndef EXAMPLE_TYPE_HPP
#define EXAMPLE_TYPE_HPP
// A hand-coded serializable
#include <FpConfig.hpp>
#include <Fw/Types/Serializable.hpp>
#if FW_SERIALIZABLE_TO_STRING
#include <Fw/Types/StringType.hpp>
#include <cstdio> // snprintf
#endif
namespace ANameSpace {
class mytype : public Fw::Serializable {
public:
enum {
SERIALIZED_SIZE = sizeof(U32),
TYPE_ID = 2000
};
mytype(); // Default constructor
mytype(const mytype* src); // copy constructor
mytype(const mytype& src); // copy constructor
mytype(U32 arg); // constructor with arguments
mytype& operator=(const mytype& src); // Equal operator
bool operator==(const mytype& src) const;
void setVal(U32 arg); // set values
U32 getVal();
Fw::SerializeStatus serialize(Fw::SerializeBufferBase& buffer) const;
Fw::SerializeStatus deserialize(Fw::SerializeBufferBase& buffer);
#if FW_SERIALIZABLE_TO_STRING
void toString(Fw::StringBase& text) const; //!< generate text from serializable
#endif
protected:
private:
U32 m_val; // stored value
};
}
#endif
| hpp |
fprime | data/projects/fprime/Autocoders/Python/test/port_loopback/ExampleComponentImpl.cpp | // ======================================================================
// \title ExampleImpl.cpp
// \author tim
// \brief cpp file for Example component implementation class
//
// \copyright
// Copyright 2009-2015, by the California Institute of Technology.
// ALL RIGHTS RESERVED. United States Government Sponsorship
// acknowledged.
//
// ======================================================================
#include <Autocoders/Python/test/port_loopback/ExampleComponentImpl.hpp>
#include <FpConfig.hpp>
#include <cstdio>
namespace ExampleComponents {
// ----------------------------------------------------------------------
// Construction, initialization, and destruction
// ----------------------------------------------------------------------
ExampleComponentImpl ::
ExampleComponentImpl(
const char *const compName
) :
ExampleComponentBase(compName)
{
}
void ExampleComponentImpl ::
init(
const NATIVE_INT_TYPE instance
)
{
ExampleComponentBase::init(instance);
}
ExampleComponentImpl ::
~ExampleComponentImpl()
{
}
// ----------------------------------------------------------------------
// Handler implementations for user-defined typed input ports
// ----------------------------------------------------------------------
void ExampleComponentImpl ::
exampleInput_handler(
const NATIVE_INT_TYPE portNum,
I32 arg1,
AnotherExample::SomeEnum arg2,
const AnotherExample::arg6String& arg6
)
{
printf("%d %d %s\n",arg1,arg2,arg6.toChar());
}
void ExampleComponentImpl::makePortCall(NATIVE_INT_TYPE port) {
AnotherExample::arg6String arg6 = "foo";
this->exampleOutput_out(port,10,AnotherExample::MEMBER2,arg6);
}
} // end namespace ExampleComponents
| cpp |
fprime | data/projects/fprime/Autocoders/Python/test/port_loopback/ExampleType.cpp | #include <Autocoders/Python/templates/ExampleType.hpp>
#include <Fw/Types/Assert.hpp>
namespace ANameSpace {
mytype::mytype(): Serializable() {
}
mytype::mytype(const mytype& src) : Serializable() {
this->setVal(src.m_val);
}
mytype::mytype(const mytype* src) : Serializable() {
FW_ASSERT(src);
this->setVal(src->m_val);
}
mytype::mytype(U32 val) : Serializable() {
this->setVal(val);
}
mytype& mytype::operator=(const mytype& src) {
this->setVal(src.m_val);
return *this;
}
bool mytype::operator==(const mytype& src) const {
return (this->m_val == src.m_val);
}
U32 mytype::getVal() {
return this->m_val;
}
void mytype::setVal(U32 val) {
this->m_val = val;
}
Fw::SerializeStatus mytype::serialize(Fw::SerializeBufferBase& buffer) const {
Fw::SerializeStatus stat = buffer.serialize(this->m_val);
if (Fw::FW_SERIALIZE_OK != stat) {
return stat;
}
return buffer.serialize(static_cast<NATIVE_INT_TYPE>(mytype::TYPE_ID));
}
Fw::SerializeStatus mytype::deserialize(Fw::SerializeBufferBase& buffer) {
NATIVE_INT_TYPE id;
Fw::SerializeStatus stat = buffer.deserialize(id);
if (Fw::FW_SERIALIZE_OK != stat) {
return stat;
}
if (id != static_cast<NATIVE_INT_TYPE>(mytype::TYPE_ID)) {
return Fw::FW_DESERIALIZE_TYPE_MISMATCH;
}
return buffer.deserialize(this->m_val);
}
#if FW_SERIALIZABLE_TO_STRING
void mytype::toString(Fw::StringBase& text) const {
static const char * formatString = "(val = %u)";
// declare strings to hold any serializable toString() arguments
char outputString[FW_SERIALIZABLE_TO_STRING_BUFFER_SIZE];
snprintf(outputString,FW_SERIALIZABLE_TO_STRING_BUFFER_SIZE,formatString,this->m_val);
outputString[FW_SERIALIZABLE_TO_STRING_BUFFER_SIZE-1] = 0; // NULL terminate
text = outputString;
}
#endif
}
| cpp |
fprime | data/projects/fprime/Autocoders/Python/test/port_loopback/test/ut/main.cpp | #ifdef FPRIME_CMAKE
#include "Autocoder/GTestBase.hpp"
#else
#include <port_loopbackGTestBase.hpp>
#endif
// Very minimal to test autocoder. Some day they'll be actual unit test code
class ATester : public ExampleComponents::ExampleGTestBase {
public:
ATester() : ExampleComponents::ExampleGTestBase("comp",10) {
}
void from_exampleOutput_handler(
const NATIVE_INT_TYPE portNum, //!< The port number
I32 arg1, //!< A built-in type argument
AnotherExample::SomeEnum arg2, //!< The ENUM argument
const AnotherExample::arg6String& arg6
);
};
void ATester::from_exampleOutput_handler(
const NATIVE_INT_TYPE portNum, //!< The port number
I32 arg1, //!< A built-in type argument
AnotherExample::SomeEnum arg2, //!< The ENUM argument
const AnotherExample::arg6String& arg6
) {
}
int main(int argc, char* argv[]) {
ATester testBase;
}
| cpp |
fprime | data/projects/fprime/Autocoders/Python/test/stress/TestCommandImpl.hpp | /*
* TestCommand1Impl.hpp
*
* Created on: Mar 28, 2014
* Author: tcanham
*/
#ifndef TESTCOMMAND2IMPL_HPP_
#define TESTCOMMAND2IMPL_HPP_
#include <Autocoders/Python/test/stress/TestComponentAc.hpp>
class TestCommand1Impl: public StressTest::TestCommandComponentBase {
public:
TestCommand1Impl(const char* compName);
void init(NATIVE_INT_TYPE queueDepth);
virtual ~TestCommand1Impl();
void printParam();
void genTlm(Ref::Gnc::Quaternion val);
void sendEvent(I32 arg1, F32 arg2, U8 arg3);
private:
void aport_handler(NATIVE_INT_TYPE portNum, I32 arg4, F32 arg5, U8 arg6);
void aport2_handler(NATIVE_INT_TYPE portNum, I32 arg4, F32 arg5, const Ref::Gnc::Quaternion& arg6);
void TEST_CMD_1_cmdHandler(FwOpcodeType opCode, U32 cmdSeq, I32 arg1, StressTest::TestCommandComponentBase::SomeEnum arg2);
void TEST_CMD_2_cmdHandler(FwOpcodeType opCode, U32 cmdSeq, I32 arg1, F32 arg2);
};
#endif /* TESTCOMMAND1IMPL_HPP_ */
| hpp |
fprime | data/projects/fprime/Autocoders/Python/test/stress/main.cpp | #include <FpConfig.hpp>
#include <Autocoders/Python/test/stress/TestCommandImpl.hpp>
#include <Autocoders/Python/test/stress/TestCommandSourceImpl.hpp>
#include <Autocoders/Python/test/stress/TestPrmSourceImpl.hpp>
#include <Autocoders/Python/test/stress/TestTelemRecvImpl.hpp>
#include <Autocoders/Python/test/stress/TestLogRecvImpl.hpp>
#include <Autocoders/Python/test/time_tester/TestTimeImpl.hpp>
#include <Autocoders/Python/test/stress/TestPtSourceImpl.hpp>
#include <Fw/Obj/SimpleObjRegistry.hpp>
int main(int argc, char* argv[]) {
#if FW_PORT_TRACING
Fw::PortBase::setTrace(true);
#endif
#if FW_OBJECT_REGISTRATION
Fw::SimpleObjRegistry objReg;
#endif
TestCommand1Impl testImpl ("TestCmdImpl");
testImpl.init(10);
testImpl.start();
TestCommandSourceImpl cmdSrc ("TestCmdSource");
cmdSrc.init();
TestParamSourceImpl prmSrc ("TestPrmSrc");
prmSrc.init();
TestTelemRecvImpl tlmRecv ("TestTlmRecv");
tlmRecv.init();
TestTimeImpl timeSource ("TimeComp");
timeSource.init();
TestLogRecvImpl logRecv ("TestLogRecv");
logRecv.init();
TestPtSourceImpl portTest ("PortTest");
portTest.init();
testImpl.set_CmdStatus_OutputPort(0,
cmdSrc.get_cmdStatusPort_InputPort(0));
testImpl.set_CmdReg_OutputPort(0,cmdSrc.get_cmdRegPort_InputPort(0));
cmdSrc.set_cmdSendPort_OutputPort(0, testImpl.get_CmdDisp_InputPort(0));
testImpl.regCommands();
testImpl.set_ParamGet_OutputPort(0,prmSrc.get_paramGetPort_InputPort(0));
testImpl.set_ParamSet_OutputPort(0,prmSrc.get_paramSetPort_InputPort(0));
testImpl.set_Tlm_OutputPort(0,tlmRecv.get_tlmRecvPort_InputPort(0));
testImpl.set_Time_OutputPort(0,timeSource.get_timeGetPort_InputPort(0));
testImpl.set_Log_OutputPort(0,logRecv.get_logRecvPort_InputPort(0));
portTest.set_aport_OutputPort(0,testImpl.get_aport_InputPort(0));
portTest.set_aport2_OutputPort(0,testImpl.get_aport2_InputPort(0));
#if FW_ENABLE_TEXT_LOGGING
testImpl.set_LogText_OutputPort(0,
logRecv.get_textLogRecvPort_InputPort(0));
#endif
#if FW_OBJECT_REGISTRATION == 1
objReg.dump();
#endif
cmdSrc.test_TEST_CMD_1(10, 7);
Os::Task::delay(1000);
prmSrc.setPrm(15);
testImpl.loadParameters();
testImpl.printParam();
testImpl.genTlm(Ref::Gnc::Quaternion(0.1, 0.2, 0.3, 0.4));
portTest.aport_Test(29,56.5,240);
portTest.aport2_Test2(30,57.5,Ref::Gnc::Quaternion(0.3,0.4,0.5,0.6));
testImpl.sendEvent(2,3.0,4);
testImpl.exit();
Os::Task::delay(1000);
}
| cpp |
fprime | data/projects/fprime/Autocoders/Python/test/stress/TestTelemRecvImpl.cpp | /*
* TestCommand1Impl.cpp
*
* Created on: Mar 28, 2014
* Author: tcanham
*/
#include <Autocoders/Python/test/stress/TestTelemRecvImpl.hpp>
#include <Fw/Types/String.hpp>
#include <Autocoders/Python/test/stress/QuaternionSerializableAc.hpp>
#include <cstdio>
TestTelemRecvImpl::TestTelemRecvImpl(const char* name) : Tlm::TelemTesterComponentBase(name)
{
}
TestTelemRecvImpl::~TestTelemRecvImpl() {
}
void TestTelemRecvImpl::tlmRecvPort_handler(NATIVE_INT_TYPE portNum, FwChanIdType id, Fw::Time &timeTag, Fw::TlmBuffer &val) {
Ref::Gnc::Quaternion tlmVal;
val.deserialize(tlmVal);
Fw::String str;
#if FW_SERIALIZABLE_TO_STRING
tlmVal.toString(str);
#endif
printf("ID: %d TLM value is %s. Time is %d:%d base: %d\n",id,str.toChar(),timeTag.getSeconds(),timeTag.getUSeconds(),timeTag.getTimeBase());
}
void TestTelemRecvImpl::init() {
Tlm::TelemTesterComponentBase::init();
}
| cpp |
fprime | data/projects/fprime/Autocoders/Python/test/stress/TestPrmSourceImpl.hpp | /*
* TestTelemRecvImpl.hpp
*
* Created on: Mar 28, 2014
* Author: tcanham
*/
#ifndef TESTPARAMRECVIMPL_HPP_
#define TESTPARAMRECVIMPL_HPP_
#include <Autocoders/Python/test/param_tester/ParamTestComponentAc.hpp>
class TestParamSourceImpl: public Prm::ParamTesterComponentBase {
public:
TestParamSourceImpl(const char* compName);
virtual ~TestParamSourceImpl();
void init();
void setPrm(U32 val);
protected:
private:
Fw::ParamValid paramGetPort_handler(NATIVE_INT_TYPE portNum, FwPrmIdType id, Fw::ParamBuffer &val);
void paramSetPort_handler(NATIVE_INT_TYPE portNum, FwPrmIdType id, Fw::ParamBuffer &val);
Fw::ParamBuffer m_prm;
};
#endif /* TESTCOMMANDSOURCEIMPL_HPP_ */
| hpp |
fprime | data/projects/fprime/Autocoders/Python/test/stress/TestLogRecvImpl.cpp | /*
* TestCommand1Impl.cpp
*
* Created on: Mar 28, 2014
* Author: tcanham
*/
#include <Autocoders/Python/test/stress/TestLogRecvImpl.hpp>
#include <cstdio>
TestLogRecvImpl::TestLogRecvImpl(const char* name) : LogTextImpl(name)
{
}
TestLogRecvImpl::~TestLogRecvImpl() {
}
void TestLogRecvImpl::logRecvPort_handler(NATIVE_INT_TYPE portNum, FwEventIdType id, Fw::Time &timeTag, const Fw::LogSeverity& severity, Fw::LogBuffer &args) {
printf("Received log %d, Time (%d,%d:%d) severity %d\n",id,timeTag.getTimeBase(),timeTag.getSeconds(),timeTag.getUSeconds(),severity.e);
I32 arg1;
F32 arg2;
U8 arg3;
// deserialize them in reverse order
args.deserialize(arg3);
args.deserialize(arg2);
args.deserialize(arg1);
printf("Args: %d %f %c\n",arg1,arg2,arg3);
}
void TestLogRecvImpl::init() {
LogTextImpl::init();
}
| cpp |
fprime | data/projects/fprime/Autocoders/Python/test/stress/TestLogRecvImpl.hpp | /*
* TestTelemRecvImpl.hpp
*
* Created on: Mar 28, 2014
* Author: tcanham
*/
#ifndef TESTLOGRECVIMPL_HPP_
#define TESTLOGRECVIMPL_HPP_
#include <Autocoders/Python/test/log_tester/TestTextLogImpl.hpp>
class TestLogRecvImpl: public LogTextImpl {
public:
TestLogRecvImpl(const char* compName);
virtual ~TestLogRecvImpl();
void init();
protected:
void logRecvPort_handler(NATIVE_INT_TYPE portNum, FwEventIdType id, Fw::Time &timeTag, const Fw::LogSeverity& severity, Fw::LogBuffer &args);
private:
};
#endif /* TESTLOGRECVIMPL_HPP_ */
| hpp |
fprime | data/projects/fprime/Autocoders/Python/test/stress/TestPrmSourceImpl.cpp | /*
* TestCommand1Impl.cpp
*
* Created on: Mar 28, 2014
* Author: tcanham
*/
#include <Autocoders/Python/test/stress/TestPrmSourceImpl.hpp>
#include <cstdio>
TestParamSourceImpl::TestParamSourceImpl(const char* name) : Prm::ParamTesterComponentBase(name)
{
}
TestParamSourceImpl::~TestParamSourceImpl() {
}
void TestParamSourceImpl::init() {
Prm::ParamTesterComponentBase::init();
}
void TestParamSourceImpl::setPrm(U32 val) {
printf("Setting parameter to %d\n",val);
this->m_prm.resetSer();
this->m_prm.serialize(val);
}
Fw::ParamValid TestParamSourceImpl::paramGetPort_handler(NATIVE_INT_TYPE portNum, FwPrmIdType id, Fw::ParamBuffer &val) {
val = this->m_prm;
return Fw::ParamValid::VALID;
}
void TestParamSourceImpl::paramSetPort_handler(NATIVE_INT_TYPE portNum, FwPrmIdType id, Fw::ParamBuffer &val) {
}
| cpp |
fprime | data/projects/fprime/Autocoders/Python/test/stress/TestTelemRecvImpl.hpp | /*
* TestTelemRecvImpl.hpp
*
* Created on: Mar 28, 2014
* Author: tcanham
*/
#ifndef TESTTELEMRECVIMPL_HPP_
#define TESTTELEMRECVIMPL_HPP_
#include <Autocoders/Python/test/telem_tester/TelemTestComponentAc.hpp>
class TestTelemRecvImpl: public Tlm::TelemTesterComponentBase {
public:
TestTelemRecvImpl(const char* compName);
virtual ~TestTelemRecvImpl();
void init();
protected:
void tlmRecvPort_handler(NATIVE_INT_TYPE portNum, FwChanIdType id, Fw::Time &timeTag, Fw::TlmBuffer &val);
private:
};
#endif /* TESTCOMMANDSOURCEIMPL_HPP_ */
| hpp |
fprime | data/projects/fprime/Autocoders/Python/test/stress/TestPtSourceImpl.hpp | /*
* TestCommand1Impl.hpp
*
* Created on: Mar 28, 2014
* Author: tcanham
*/
#ifndef TESTPTSOURCEIMPL_HPP_
#define TESTPTSOURCEIMPL_HPP_
#include <Autocoders/Python/test/stress/TestPtComponentAc.hpp>
class TestPtSourceImpl: public StressTest::TestPortComponentBase {
public:
TestPtSourceImpl(const char* compName);
virtual ~TestPtSourceImpl();
void init();
void aport_Test(I32 arg4, F32 arg5, U8 arg6);
void aport2_Test2(I32 arg4, F32 arg5, const Ref::Gnc::Quaternion& arg6);
protected:
private:
};
#endif /* TESTCOMMANDSOURCEIMPL_HPP_ */
| hpp |
fprime | data/projects/fprime/Autocoders/Python/test/stress/TestCommandSourceImpl.cpp | /*
* TestCommand1Impl.cpp
*
* Created on: Mar 28, 2014
* Author: tcanham
*/
#include <Autocoders/Python/test/stress/TestCommandSourceImpl.hpp>
#include <cstdio>
TestCommandSourceImpl::TestCommandSourceImpl(const char* name) : Cmd::CommandTesterComponentBase(name)
{
}
TestCommandSourceImpl::~TestCommandSourceImpl() {
}
void TestCommandSourceImpl::cmdStatusPort_handler(
NATIVE_INT_TYPE portNum, FwOpcodeType opCode, U32 cmdSeq,
const Fw::CmdResponse& response) {
this->printStatus(response);
}
void TestCommandSourceImpl::cmdRegPort_handler(NATIVE_INT_TYPE portNum, FwOpcodeType opCode) {
printf("Received registration for opcode %d\n",opCode);
}
void TestCommandSourceImpl::init() {
Cmd::CommandTesterComponentBase::init();
}
void TestCommandSourceImpl::printStatus(const Fw::CmdResponse& response) {
switch (response.e) {
case Fw::CmdResponse::OK:
printf("COMMAND OK\n");
break;
case Fw::CmdResponse::INVALID_OPCODE:
printf("INVALID OPCODE\n");
break;
case Fw::CmdResponse::VALIDATION_ERROR:
printf("VALIDATION ERROR\n");
break;
case Fw::CmdResponse::FORMAT_ERROR:
printf("FORMAT ERROR\n");
break;
case Fw::CmdResponse::EXECUTION_ERROR:
printf("EXECUTION ERROR\n");
break;
default:
printf("Unknown status %d\n", response.e);
break;
}
}
void TestCommandSourceImpl::test_TEST_CMD_1(I32 arg1, I32 arg2) {
// serialize parameters
if (!this->isConnected_cmdSendPort_OutputPort(0)) {
printf("Test command port not connected.");
return;
}
Fw::CmdArgBuffer argBuff;
// do nominal case
argBuff.serialize(arg1);
argBuff.serialize(arg2);
this->cmdSendPort_out(0, 0x100, 1, argBuff);
// wrong value
argBuff.resetSer();
argBuff.serialize(arg1);
argBuff.serialize(arg2+1);
this->cmdSendPort_out(0, 0x100, 1, argBuff);
// too many arguments
argBuff.resetSer();
argBuff.serialize(arg1);
argBuff.serialize(arg2);
argBuff.serialize(arg2);
this->cmdSendPort_out(0, 0x100, 1, argBuff);
// too few arguments
argBuff.resetSer();
argBuff.serialize(arg1);
this->cmdSendPort_out(0, 0x100, 1, argBuff);
}
| cpp |
fprime | data/projects/fprime/Autocoders/Python/test/stress/TestCommandSourceImpl.hpp | /*
* TestCommand1Impl.hpp
*
* Created on: Mar 28, 2014
* Author: tcanham
*/
#ifndef TESTCOMMANDSOURCEIMPL_HPP_
#define TESTCOMMANDSOURCEIMPL_HPP_
#include <Autocoders/Python/test/command_tester/CommandTestComponentAc.hpp>
#include <Autocoders/Python/test/stress/TestComponentAc.hpp>
class TestCommandSourceImpl: public Cmd::CommandTesterComponentBase {
public:
TestCommandSourceImpl(const char* compName);
virtual ~TestCommandSourceImpl();
void init();
void test_TEST_CMD_1(I32 arg1, I32 arg2);
protected:
void cmdStatusPort_handler(NATIVE_INT_TYPE portNum, FwOpcodeType opCode, U32 cmdSeq, const Fw::CmdResponse& response);
void cmdRegPort_handler(NATIVE_INT_TYPE portNum, FwOpcodeType opCode);
private:
void printStatus(const Fw::CmdResponse& response);
};
#endif /* TESTCOMMANDSOURCEIMPL_HPP_ */
| hpp |
fprime | data/projects/fprime/Autocoders/Python/test/stress/TestCommandImpl.cpp | /*
* TestCommand1Impl.cpp
*
* Created on: Mar 28, 2014
* Author: tcanham
*/
#include <Autocoders/Python/test/stress/TestCommandImpl.hpp>
#include <Fw/Types/String.hpp>
#include <cstdio>
TestCommand1Impl::TestCommand1Impl(const char* name) : StressTest::TestCommandComponentBase(name)
{
}
void TestCommand1Impl::init(NATIVE_INT_TYPE queueDepth) {
StressTest::TestCommandComponentBase::init(queueDepth);
}
TestCommand1Impl::~TestCommand1Impl() {
}
void TestCommand1Impl::aport_handler(NATIVE_INT_TYPE portNum, I32 arg4, F32 arg5, U8 arg6) {
printf("Received aport_Test_handler call with %i %f %d\n",arg4,arg5,arg6);
}
void TestCommand1Impl::aport2_handler(NATIVE_INT_TYPE portNum, I32 arg4, F32 arg5, const Ref::Gnc::Quaternion& arg6) {
Fw::String str;
arg6.toString(str);
printf("Received aport2_Test2_handler call with %i %f %s\n",arg4,arg5,str.toChar());
}
void TestCommand1Impl::TEST_CMD_1_cmdHandler(FwOpcodeType opCode, U32 cmdSeq, I32 arg1, StressTest::TestCommandComponentBase::SomeEnum arg2) {
const char *enum_str = "unknown";
switch (arg2) {
case MEMB1:
enum_str = "MEMB1";
break;
case MEMB2:
enum_str = "MEMB2";
break;
case MEMB3:
enum_str = "MEMB3";
break;
default:
enum_str = "INV";
break;
}
printf("Got command args: %d %s\n", arg1, enum_str);
this->cmdResponse_out(opCode,cmdSeq,Fw::CmdResponse::OK);
}
void TestCommand1Impl::TEST_CMD_2_cmdHandler(FwOpcodeType opCode, U32 cmdSeq, I32 arg1, F32 arg2) {
printf("Got command args: %d %f\n", arg1, arg2);
this->cmdResponse_out(opCode,cmdSeq,Fw::CmdResponse::OK);
}
void TestCommand1Impl::printParam() {
Fw::ParamValid valid = Fw::ParamValid::INVALID;
const U32& prmRef = this->paramGet_someparam(valid);
printf("Parameter is: %d %s\n",prmRef,valid==Fw::ParamValid::VALID?"VALID":"INVALID");
}
void TestCommand1Impl::genTlm(Ref::Gnc::Quaternion val) {
this->tlmWrite_AQuat(val);
}
void TestCommand1Impl::sendEvent(I32 arg1, F32 arg2, U8 arg3) {
printf("Sending event args %d, %f, %d\n",arg1, arg2, arg3);
this->log_ACTIVITY_LO_SomeEvent(arg1,arg2,arg3);
}
| cpp |
fprime | data/projects/fprime/Autocoders/Python/test/stress/TestPtSourceImpl.cpp | /*
* TestCommand1Impl.cpp
*
* Created on: Mar 28, 2014
* Author: tcanham
*/
#include <Autocoders/Python/test/stress/TestPtSourceImpl.hpp>
#include <cstdio>
TestPtSourceImpl::TestPtSourceImpl(const char* name) : StressTest::TestPortComponentBase(name)
{
}
TestPtSourceImpl::~TestPtSourceImpl() {
}
void TestPtSourceImpl::init() {
StressTest::TestPortComponentBase::init();
}
void TestPtSourceImpl::aport_Test(I32 arg4, F32 arg5, U8 arg6) {
if (this->isConnected_aport_OutputPort(0)) {
this->aport_out(0,arg4,arg5,arg6);
}
}
void TestPtSourceImpl::aport2_Test2(I32 arg4, F32 arg5, const Ref::Gnc::Quaternion& arg6) {
if (this->isConnected_aport2_OutputPort(0)) {
this->aport2_out(0,arg4,arg5,arg6);
}
}
| cpp |
fprime | data/projects/fprime/Autocoders/Python/test/stress/test/ut/main.cpp | #ifdef FPRIME_CMAKE
#include "Autocoder/GTestBase.hpp"
#else
#include <stressGTestBase.hpp>
#endif
// Very minimal to test autocoder. Some day they'll be actual unit test code
class ATester : public StressTest::TestPortGTestBase {
public:
ATester() : StressTest::TestPortGTestBase("comp",10) {
}
void from_aport_handler(
const NATIVE_INT_TYPE portNum, //!< The port number
I32 arg4, //!< The first argument
F32 arg5, //!< The second argument
U8 arg6 //!< The third argument
);
void from_aport2_handler(
const NATIVE_INT_TYPE portNum, //!< The port number
I32 arg4, //!< The first argument
F32 arg5, //!< The second argument
const Ref::Gnc::Quaternion& arg6 //!< The third argument
);
};
void ATester::from_aport_handler(
const NATIVE_INT_TYPE portNum, //!< The port number
I32 arg4, //!< The first argument
F32 arg5, //!< The second argument
U8 arg6 //!< The third argument
) {
}
void ATester::from_aport2_handler(
const NATIVE_INT_TYPE portNum, //!< The port number
I32 arg4, //!< The first argument
F32 arg5, //!< The second argument
const Ref::Gnc::Quaternion& arg6 //!< The third argument
) {
}
int main(int argc, char* argv[]) {
ATester testBase;
}
| cpp |
fprime | data/projects/fprime/Autocoders/Python/test/tlm_onchange/main.cpp | #include <Autocoders/Python/test/tlm_onchange/TestTelemImpl.hpp>
#include <Autocoders/Python/test/tlm_onchange/TestTelemRecvImpl.hpp>
#include <Autocoders/Python/test/time_tester/TestTimeImpl.hpp>
#include <Fw/Obj/SimpleObjRegistry.hpp>
int main(int argc, char* argv[]) {
#if FW_PORT_TRACING
Fw::PortBase::setTrace(true);
#endif
#if FW_OBJECT_REGISTRATION == 1
Fw::SimpleObjRegistry objReg;
#endif
TestTlmImpl testImpl("TestTlmImpl");
testImpl.init();
TestTelemRecvImpl tlmRecv("TestTlmRecv");
tlmRecv.init();
TestTimeImpl timeSource("TimeComp");
timeSource.init();
testImpl.set_Tlm_OutputPort(0,tlmRecv.get_tlmRecvPort_InputPort(0));
testImpl.set_Time_OutputPort(0,timeSource.get_timeGetPort_InputPort(0));
timeSource.setTime(Fw::Time(TB_NONE,2,3));
#if FW_OBJECT_REGISTRATION == 1
objReg.dump();
#endif
testImpl.genTlm(26);
}
| cpp |
fprime | data/projects/fprime/Autocoders/Python/test/tlm_onchange/TestTelemRecvImpl.cpp | /*
* TestCommand1Impl.cpp
*
* Created on: Mar 28, 2014
* Author: tcanham
*/
#include <Autocoders/Python/test/tlm_onchange/TestTelemRecvImpl.hpp>
#include <cstdio>
TestTelemRecvImpl::TestTelemRecvImpl(const char* name) : Tlm::TelemTesterComponentBase(name)
{
}
TestTelemRecvImpl::~TestTelemRecvImpl() {
}
void TestTelemRecvImpl::tlmRecvPort_handler(NATIVE_INT_TYPE portNum, FwChanIdType id, Fw::Time &timeTag, Fw::TlmBuffer &val) {
U32 tlmVal;
val.deserialize(tlmVal);
printf("ID: %d TLM value is %d. Time is %d:%d base: %d\n",id,tlmVal,timeTag.getSeconds(),timeTag.getUSeconds(),timeTag.getTimeBase());
}
void TestTelemRecvImpl::init() {
Tlm::TelemTesterComponentBase::init();
}
| cpp |
fprime | data/projects/fprime/Autocoders/Python/test/tlm_onchange/TestTelemImpl.cpp | /*
* TestCommand1Impl.cpp
*
* Created on: Mar 28, 2014
* Author: tcanham
*/
#include <Autocoders/Python/test/tlm_onchange/TestTelemImpl.hpp>
#include <cstdio>
TestTlmImpl::TestTlmImpl(const char* name) : Tlm::TestTlmComponentBase(name)
{
}
TestTlmImpl::~TestTlmImpl() {
}
void TestTlmImpl::init() {
Tlm::TestTlmComponentBase::init();
}
void TestTlmImpl::genTlm(U32 val) {
printf("Writing value %d to telemetry.\n",val);
this->tlmWrite_somechan(val);
}
void TestTlmImpl::aport_handler(NATIVE_INT_TYPE portNum, I32 arg4, F32 arg5, U8 arg6) {
}
| cpp |
fprime | data/projects/fprime/Autocoders/Python/test/tlm_onchange/TestTelemRecvImpl.hpp | /*
* TestTelemRecvImpl.hpp
*
* Created on: Mar 28, 2014
* Author: tcanham
*/
#ifndef TESTTELEMRECVIMPL_HPP_
#define TESTTELEMRECVIMPL_HPP_
#include <Autocoders/Python/test/telem_tester/TelemTestComponentAc.hpp>
class TestTelemRecvImpl: public Tlm::TelemTesterComponentBase {
public:
TestTelemRecvImpl(const char* compName);
virtual ~TestTelemRecvImpl();
void init();
protected:
void tlmRecvPort_handler(NATIVE_INT_TYPE portNum, FwChanIdType id, Fw::Time &timeTag, Fw::TlmBuffer &val);
private:
};
#endif /* TESTCOMMANDSOURCEIMPL_HPP_ */
| hpp |
fprime | data/projects/fprime/Autocoders/Python/test/tlm_onchange/TestTelemImpl.hpp | /*
* TestCommand1Impl.hpp
*
* Created on: Mar 28, 2014
* Author: tcanham
*/
#ifndef TESTCOMMAND1IMPL_HPP_
#define TESTCOMMAND1IMPL_HPP_
#include <Autocoders/Python/test/tlm_onchange/TestComponentAc.hpp>
class TestTlmImpl: public Tlm::TestTlmComponentBase {
public:
TestTlmImpl(const char* compName);
void genTlm(U32 val);
virtual ~TestTlmImpl();
void init();
protected:
void aport_handler(NATIVE_INT_TYPE portNum, I32 arg4, F32 arg5, U8 arg6);
};
#endif /* TESTCOMMAND1IMPL_HPP_ */
| hpp |
fprime | data/projects/fprime/Autocoders/Python/test/tlm_onchange/test/ut/main.cpp | #ifdef FPRIME_CMAKE
#include "Autocoder/GTestBase.hpp"
#else
#include <tlm_onchangeGTestBase.hpp>
#endif
// Very minimal to test autocoder. Some day they'll be actual unit test code
class ATester : public Tlm::TestTlmGTestBase {
public:
ATester() : Tlm::TestTlmGTestBase("comp",10) {
}
};
int main(int argc, char* argv[]) {
ATester testBase;
}
| cpp |
fprime | data/projects/fprime/Autocoders/Python/test/comp_diff_namespace/test/ut/main.cpp | #ifdef FPRIME_CMAKE
#include "Autocoder/GTestBase.hpp"
#else
#include <comp_diff_namespaceGTestBase.hpp>
#endif
// Very minimal to test autocoder. Some day they'll be actual unit test code
class ATester : public StressTest::Components::TestCommandGTestBase {
public:
ATester() : StressTest::Components::TestCommandGTestBase("comp",10) {
}
};
int main(int argc, char* argv[]) {
ATester testBase;
}
| cpp |
fprime | data/projects/fprime/Autocoders/Python/test/param_tester/test/ut/main.cpp | #ifdef FPRIME_CMAKE
#include "Autocoder/GTestBase.hpp"
#else
#include <param_testerGTestBase.hpp>
#endif
#include "TesterBase.hpp"
#include <FpConfig.hpp>
// Very minimal to test autocoder. Some day they'll be actual unit test code
class ATester : public Prm::ParamTesterGTestBase {
public:
ATester() : Prm::ParamTesterGTestBase("comp",10) {
}
};
int main(int argc, char* argv[]) {
ATester testBase;
}
| cpp |
fprime | data/projects/fprime/Autocoders/Python/test/param2/test/ut/main.cpp | #ifdef FPRIME_CMAKE
#include "Autocoder/GTestBase.hpp"
#else
#include <param2GTestBase.hpp>
#endif
// Very minimal to test autocoder. Some day they'll be actual unit test code
class ATester : public Tlm::TestPrmGTestBase {
public:
ATester() : Tlm::TestPrmGTestBase("comp",10) {
}
};
int main(int argc, char* argv[]) {
ATester testBase;
}
| cpp |
fprime | data/projects/fprime/Autocoders/Python/test/event2/test/ut/main.cpp | #ifdef FPRIME_CMAKE
#include "Autocoder/GTestBase.hpp"
#else
#include <event2GTestBase.hpp>
#endif
// Very minimal to test autocoder. Some day they'll be actual unit test code
class ATester : public Cmd::TestCommandGTestBase {
public:
ATester() : Cmd::TestCommandGTestBase("comp",10) {
}
};
int main(int argc, char* argv[]) {
ATester testBase;
}
| cpp |
fprime | data/projects/fprime/Autocoders/Python/test/serialize4/main.cpp | #include <Autocoders/Python/test/serialize4/Serial1SerializableAc.hpp>
#include "gtest/gtest.h"
using namespace std;
TEST(DefaultValues, OK) {
Example::Serial1 serial1;
Example::Serial1 serial2;
// Check serializable default values are correctly set
ASSERT_EQ(serial1.getMember1(), 12345);
ASSERT_EQ(serial1.getMember2(), "hello");
ASSERT_EQ(serial1.getMember3(), Example::MEM2);
// Check serializable scalar default for array member is correctly set
NATIVE_INT_TYPE size;
const U32* serial1Member4 = serial1.getMember4(size);
for (NATIVE_INT_TYPE _mem = 0; _mem < size; _mem++) {
ASSERT_EQ(serial1Member4[_mem], 3);
}
}
TEST(Serialize4, ArrayScalarInit) {
Example::Serial1 serial1 (0,"hello",Example::SomeEnum::MEM2,2, "world");
// Check serializable array member values are correctly set
NATIVE_INT_TYPE size;
const U32* serialMember4 = serial1.getMember4(size);
for (NATIVE_INT_TYPE _mem = 0; _mem < size; _mem++) {
ASSERT_EQ(serialMember4[_mem], 2);
}
}
TEST(StringArray, OK) {
Example::Serial1 serial1;
}
int main(int argc, char* argv[]) {
::testing::InitGoogleTest(&argc, argv);
int status = RUN_ALL_TESTS();
cout << "Completed..." << endl;
return status;
}
| cpp |
fprime | data/projects/fprime/Autocoders/Python/test/pass_by_kind/main.cpp | #include <Autocoders/Python/test/pass_by_kind/Component1ComponentAc.hpp>
#include <Autocoders/Python/test/pass_by_kind/Component1.hpp>
#include <Autocoders/Python/test/pass_by_kind/Port1PortAc.hpp>
#include <Autocoders/Python/test/pass_by_kind/AllTypes.hpp>
#include "STest/Random/Random.hpp"
#include "gtest/gtest.h"
#include <iostream>
using namespace std;
// Create the inst1 object
Example::Component1 inst1("inst1");
void constructArchitecture() {
// Instantiate components
inst1.init(100);
}
TEST(PassByTest, OK) {
// Create arguments to test pass-by logic for async and sync cases
cout << "Invoking inst1..." << endl;
Example::AllTypes async_args(true);
Example::AllTypes sync_args(false);
// Invoke sync and async ports and pass arguments
inst1.get_AsyncPort_InputPort(0)->invoke(
&async_args.arg1,
async_args.arg2,
async_args.arg3,
&async_args.arg4,
async_args.arg5,
async_args.arg6,
&async_args.arg7,
async_args.arg8,
async_args.arg9
);
inst1.doDispatch();
inst1.get_SyncPort_InputPort(0)->invoke(
&sync_args.arg1,
sync_args.arg2,
sync_args.arg3,
&sync_args.arg4,
sync_args.arg5,
sync_args.arg6,
&sync_args.arg7,
sync_args.arg8,
sync_args.arg9
);
inst1.doDispatch();
// Check output from ports is expected
async_args.checkAsserts();
sync_args.checkAsserts();
}
int main(int argc, char* argv[]) {
::testing::InitGoogleTest(&argc, argv);
STest::Random::seed();
constructArchitecture();
int status = RUN_ALL_TESTS();
return status;
}
| cpp |
fprime | data/projects/fprime/Autocoders/Python/test/pass_by_kind/AllTypes.cpp | #include "gtest/gtest.h"
#include <Autocoders/Python/test/pass_by_kind/Port1PortAc.hpp>
#include <Autocoders/Python/test/pass_by_kind/AllTypes.hpp>
namespace Example {
AllTypes::AllTypes(bool is_async) {
// Instantiate argument values
arg1 = 0;
arg2 = 0;
arg3 = 0;
arg4.setstate(0);
arg5.setstate(0);
arg6.setstate(0);
arg7 = "zero";
arg8 = "zero";
arg9 = "zero";
// Store whether port is async
this->is_async = is_async;
}
AllTypes::~AllTypes() {
}
void AllTypes::checkAsserts() {
// Check output from port invocations worked
// Declare enum with possible port pass by logic
enum output_options {VALUE = 0, POINTER = 1, CONST_REF = 2, REFERENCE = 3};
// Declare array with expected output for above pass by logic
// Value arguments result in current state being 0
// Pointer arguments result in current state being 1
// Const reference arguments result in current state being 0
// If reference and sync, state will be 1
// If reference and async, state will be 0
int expected_u32_output[] = {0, 1, 0, (this->is_async) ? 0 : 1};
const char *const expected_string_output[] = {
"zero", "one", "zero", (this->is_async) ? "zero" : "one"
};
// Check output values
ASSERT_EQ(this->arg1, expected_u32_output[POINTER]);
ASSERT_EQ(this->arg2, expected_u32_output[REFERENCE]);
ASSERT_EQ(this->arg3, expected_u32_output[VALUE]);
ASSERT_EQ((this->arg4).getstate(), expected_u32_output[POINTER]);
ASSERT_EQ((this->arg5).getstate(), expected_u32_output[REFERENCE]);
ASSERT_EQ((this->arg6).getstate(), expected_u32_output[CONST_REF]);
ASSERT_EQ(this->arg7, expected_string_output[POINTER]);
ASSERT_EQ(this->arg8, expected_string_output[REFERENCE]);
ASSERT_EQ(this->arg9, expected_string_output[CONST_REF]);
}
}
| cpp |
fprime | data/projects/fprime/Autocoders/Python/test/pass_by_kind/AllTypes.hpp | /*
* AllTypes.hpp
*
* Created on: Thursday, 15 July 2021
* Author: dhesikan
*
*/
namespace Example {
class AllTypes {
public:
AllTypes(bool is_async); //!< constructor with argument async/sync boolean flag
virtual ~AllTypes(); //!< destructor
void checkAsserts(); //!< function checks output of arguments is expected
// Declaration of arguments
U32 arg1;
U32 arg2;
U32 arg3;
ExampleType arg4;
ExampleType arg5;
ExampleType arg6;
Arg7String arg7;
Arg8String arg8;
Arg9String arg9;
private:
// Stores whether arguments are passed to async or sync port
bool is_async;
};
} // end namespace Example
| hpp |
fprime | data/projects/fprime/Autocoders/Python/test/pass_by_kind/Component1.cpp | #include <Autocoders/Python/test/pass_by_kind/Component1.hpp>
#include <Autocoders/Python/test/pass_by_kind/ExampleTypeSerializableAc.hpp>
#include <FpConfig.hpp>
#include <Fw/Types/SerialBuffer.hpp>
#include <cstdio>
#include <iostream>
using namespace std;
namespace Example {
Component1::Component1(const char* compName) : Component1ComponentBase(compName) {
}
Component1::~Component1() {
}
void Component1::init(NATIVE_INT_TYPE queueDepth) {
Component1ComponentBase::init(queueDepth);
}
void Component1::AsyncPort_handler(NATIVE_INT_TYPE portNum,U32 *arg1, U32 &arg2, U32 arg3,
ExampleType *arg4, ExampleType &arg5, const ExampleType &arg6,
Arg7String *arg7, Arg8String &arg8, const Arg9String &arg9) {
*arg1 = 1;
arg2 = 1;
// arg3 is a stack variable -- assigning to it has no effect
arg4->set(1);
arg5.set(1);
// arg6 is a const ref -- compiler won't let us modify through it
*arg7 = "one";
arg8 = "one";
// arg9 is a const ref -- compiler won't let us modify through it
}
void Component1::SyncPort_handler(NATIVE_INT_TYPE portNum,U32 *arg1, U32 &arg2, U32 arg3,
ExampleType *arg4, ExampleType &arg5, const ExampleType &arg6,
Arg7String *arg7, Arg8String &arg8, const Arg9String &arg9) {
*arg1 = 1;
arg2 = 1;
// arg3 is a stack variable -- assigning to it has no effect
arg4->set(1);
arg5.set(1);
// arg6 is a const ref -- compiler won't let us modify through it
*arg7 = "one";
arg8 = "one";
// arg9 is a const ref -- compiler won't let us modify through it
}
};
| cpp |
fprime | data/projects/fprime/Autocoders/Python/test/pass_by_kind/Component1.hpp | #ifndef EXAMPLE_ENUM_IMPL_HPP
#define EXAMPLE_ENUM_IMPL_HPP
#include <Autocoders/Python/test/pass_by_kind/Component1ComponentAc.hpp>
namespace Example {
class Component1 : public Component1ComponentBase {
public:
// Only called by derived class
Component1(const char* compName);
~Component1();
void init(NATIVE_INT_TYPE queueDepth);
private:
void AsyncPort_handler(NATIVE_INT_TYPE portNum,U32 *arg1, U32 &arg2, U32 arg3,
ExampleType *arg4, ExampleType &arg5, const ExampleType &arg6,
Arg7String *arg7, Arg8String &arg8, const Arg9String &arg9);
void SyncPort_handler(NATIVE_INT_TYPE portNum,U32 *arg1, U32 &arg2, U32 arg3,
ExampleType *arg4, ExampleType &arg5, const ExampleType &arg6,
Arg7String *arg7, Arg8String &arg8, const Arg9String &arg9);
};
};
#endif
| hpp |
fprime | data/projects/fprime/Autocoders/Python/test/noargport/ExampleComponentImpl.hpp | // ======================================================================
// \title ExampleComponentImpl.hpp
// \author joshuaa
// \brief hpp file for Example component implementation class
//
// \copyright
// Copyright 2009-2015, by the California Institute of Technology.
// ALL RIGHTS RESERVED. United States Government Sponsorship
// acknowledged.
//
// ======================================================================
#ifndef Example_HPP
#define Example_HPP
#include "Autocoders/Python/test/noargport/ExampleComponentAc.hpp"
namespace ExampleComponents {
class ExampleComponentImpl :
public ExampleComponentBase
{
public:
// ----------------------------------------------------------------------
// Construction, initialization, and destruction
// ----------------------------------------------------------------------
//! Construct object Example
//!
ExampleComponentImpl(
const char *const compName /*!< The component name*/
);
//! Initialize object Example
//!
void init(
const NATIVE_INT_TYPE queueDepth, //!< The queue depth
const NATIVE_INT_TYPE instance //!< The instance number
);
//! Destroy object Example
//!
~ExampleComponentImpl();
PRIVATE:
// ----------------------------------------------------------------------
// Handler implementations for user-defined typed input ports
// ----------------------------------------------------------------------
//! Handler implementation for noArgPort
//!
void noArgPort_handler(
const NATIVE_INT_TYPE portNum /*!< The port number*/
);
//! Handler implementation for asyncNoArgPort
//!
void asyncNoArgPort_handler(
const NATIVE_INT_TYPE portNum /*!< The port number*/
);
//! Handler implementation for guardedNoArgPort
//!
void guardedNoArgPort_handler(
const NATIVE_INT_TYPE portNum /*!< The port number*/
);
//! Handler implementation for exampleInput
//!
U32 exampleInput_handler(
const NATIVE_INT_TYPE portNum /*!< The port number*/
);
};
} // end namespace ExampleComponents
#endif
| hpp |
fprime | data/projects/fprime/Autocoders/Python/test/noargport/ExampleComponentImpl.cpp | // ======================================================================
// \title ExampleComponentImpl.cpp
// \author joshuaa
// \brief cpp file for Example component implementation class
//
// \copyright
// Copyright 2009-2015, by the California Institute of Technology.
// ALL RIGHTS RESERVED. United States Government Sponsorship
// acknowledged.
//
// ======================================================================
#include <Autocoders/Python/test/noargport/ExampleComponentImpl.hpp>
#include <FpConfig.hpp>
namespace ExampleComponents {
// ----------------------------------------------------------------------
// Construction, initialization, and destruction
// ----------------------------------------------------------------------
ExampleComponentImpl ::
ExampleComponentImpl(
const char *const compName
) : ExampleComponentBase(compName)
{
}
void ExampleComponentImpl ::
init(
const NATIVE_INT_TYPE queueDepth,
const NATIVE_INT_TYPE instance
)
{
ExampleComponentBase::init(queueDepth, instance);
}
ExampleComponentImpl ::
~ExampleComponentImpl()
{
}
// ----------------------------------------------------------------------
// Handler implementations for user-defined typed input ports
// ----------------------------------------------------------------------
void ExampleComponentImpl ::
noArgPort_handler(
const NATIVE_INT_TYPE portNum
)
{
// TODO
}
void ExampleComponentImpl ::
asyncNoArgPort_handler(
const NATIVE_INT_TYPE portNum
)
{
// TODO
}
void ExampleComponentImpl ::
guardedNoArgPort_handler(
const NATIVE_INT_TYPE portNum
)
{
// TODO
}
U32 ExampleComponentImpl ::
exampleInput_handler(
const NATIVE_INT_TYPE portNum
)
{
return 0;
}
} // end namespace ExampleComponents
| cpp |
fprime | data/projects/fprime/Autocoders/Python/test/noargport/test/ut/noargportTestMain.cpp | // ----------------------------------------------------------------------
// TestMain.cpp
// ----------------------------------------------------------------------
#include "noargportTester.hpp"
TEST(Nominal, TestNoArgs) {
ExampleComponents::noargportTester tester;
tester.testNoArgs();
}
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
| cpp |
fprime | data/projects/fprime/Autocoders/Python/test/noargport/test/ut/noargportTester.cpp | // ======================================================================
// \title Example.hpp
// \author joshuaa
// \brief cpp file for Example test harness implementation class
//
// \copyright
// Copyright 2009-2015, by the California Institute of Technology.
// ALL RIGHTS RESERVED. United States Government Sponsorship
// acknowledged.
//
// ======================================================================
#include "noargportTester.hpp"
#define INSTANCE 0
#define MAX_HISTORY_SIZE 10
#define QUEUE_DEPTH 10
namespace ExampleComponents {
// ----------------------------------------------------------------------
// Construction and destruction
// ----------------------------------------------------------------------
noargportTester ::
noargportTester() :
ExampleGTestBase("Tester", MAX_HISTORY_SIZE),
component("Example")
{
this->initComponents();
this->connectPorts();
}
noargportTester ::
~noargportTester()
{
}
// ----------------------------------------------------------------------
// Tests
// ----------------------------------------------------------------------
void noargportTester ::
testNoArgs()
{
this->invoke_to_noArgPort(0);
this->invoke_to_asyncNoArgPort(0);
this->component.doDispatch(); // Dispatch async port call
this->invoke_to_guardedNoArgPort(0);
ASSERT_EQ(this->invoke_to_exampleInput(0), 0);
}
// ----------------------------------------------------------------------
// Helper methods
// ----------------------------------------------------------------------
void noargportTester ::
connectPorts()
{
// noArgPort
this->connect_to_noArgPort(
0,
this->component.get_noArgPort_InputPort(0)
);
// asyncNoArgPort
this->connect_to_asyncNoArgPort(
0,
this->component.get_asyncNoArgPort_InputPort(0)
);
// guardedNoArgPort
this->connect_to_guardedNoArgPort(
0,
this->component.get_guardedNoArgPort_InputPort(0)
);
// exampleInput
this->connect_to_exampleInput(
0,
this->component.get_exampleInput_InputPort(0)
);
}
void noargportTester ::
initComponents()
{
this->init();
this->component.init(
QUEUE_DEPTH,
INSTANCE
);
}
} // end namespace ExampleComponents
| cpp |
fprime | data/projects/fprime/Autocoders/Python/test/noargport/test/ut/noargportTester.hpp | // ======================================================================
// \title Example/test/ut/Tester.hpp
// \author joshuaa
// \brief hpp file for Example test harness implementation class
//
// \copyright
// Copyright 2009-2015, by the California Institute of Technology.
// ALL RIGHTS RESERVED. United States Government Sponsorship
// acknowledged.
//
// ======================================================================
#ifndef TESTER_HPP
#define TESTER_HPP
#include "noargportGTestBase.hpp"
#include "Autocoders/Python/test/noargport/ExampleComponentImpl.hpp"
namespace ExampleComponents {
class noargportTester :
public ExampleGTestBase
{
// ----------------------------------------------------------------------
// Construction and destruction
// ----------------------------------------------------------------------
public:
//! Construct object noargportTester
//!
noargportTester();
//! Destroy object noargportTester
//!
~noargportTester();
public:
// ----------------------------------------------------------------------
// Tests
// ----------------------------------------------------------------------
//! To do
//!
void testNoArgs();
private:
// ----------------------------------------------------------------------
// Helper methods
// ----------------------------------------------------------------------
//! Connect ports
//!
void connectPorts();
//! Initialize components
//!
void initComponents();
private:
// ----------------------------------------------------------------------
// Variables
// ----------------------------------------------------------------------
//! The component under test
//!
ExampleComponentImpl component;
};
} // end namespace ExampleComponents
#endif
| hpp |
fprime | data/projects/fprime/Autocoders/Python/test/param_multi_inst/TestPrmImpl.cpp | /*
* TestCommand1Impl.cpp
*
* Created on: Mar 28, 2014
* Author: tcanham
*/
#include <Autocoders/Python/test/param_multi_inst/TestPrmImpl.hpp>
#include <cstdio>
TestPrmImpl::TestPrmImpl(const char* name) : Prm::TestPrmComponentBase(name)
{
}
TestPrmImpl::~TestPrmImpl() {
}
void TestPrmImpl::init() {
Prm::TestPrmComponentBase::init();
}
void TestPrmImpl::aport_handler(NATIVE_INT_TYPE portNum, I32 arg4, F32 arg5, U8 arg6) {
}
void TestPrmImpl::printParam() {
Fw::ParamValid valid = Fw::ParamValid::INVALID;
const U32& prmRef = this->paramGet_someparam(valid);
printf("Parameter is: %d %s\n",prmRef,valid==Fw::ParamValid::VALID?"VALID":"INVALID");
}
void TestPrmImpl::parameterUpdated(FwPrmIdType id)
{
printf("Parameter %d was updated\n", id);
}
| cpp |
fprime | data/projects/fprime/Autocoders/Python/test/param_multi_inst/main.cpp | #include <Autocoders/Python/test/param_multi_inst/TestPrmImpl.hpp>
#include <Autocoders/Python/test/param_multi_inst/TestPrmSourceImpl.hpp>
#include <Fw/Obj/SimpleObjRegistry.hpp>
int main(int argc, char* argv[]) {
#if FW_PORT_TRACING
Fw::PortBase::setTrace(true);
#endif
#if FW_OBJECT_REGISTRATION == 1
Fw::SimpleObjRegistry objReg;
#endif
TestPrmImpl testImpl("TestPrmImpl");
testImpl.init();
TestParamSourceImpl prmSrc("TestPrmSrc");
prmSrc.init();
testImpl.set_ParamGet_OutputPort(0,prmSrc.get_paramGetPort_InputPort(0));
testImpl.set_ParamSet_OutputPort(0,prmSrc.get_paramSetPort_InputPort(0));
#if FW_OBJECT_REGISTRATION == 1
objReg.dump();
#endif
prmSrc.setPrm(15);
testImpl.loadParameters();
testImpl.printParam();
}
| cpp |
fprime | data/projects/fprime/Autocoders/Python/test/param_multi_inst/TestPrmSourceImpl.hpp | /*
* TestTelemRecvImpl.hpp
*
* Created on: Mar 28, 2014
* Author: tcanham
*/
#ifndef TESTPARAMRECVIMPL_HPP_
#define TESTPARAMRECVIMPL_HPP_
#include <Autocoders/Python/test/param_tester/ParamTestComponentAc.hpp>
class TestParamSourceImpl: public Prm::ParamTesterComponentBase {
public:
TestParamSourceImpl(const char* compName);
virtual ~TestParamSourceImpl();
void init();
void setPrm(U32 val);
protected:
Fw::ParamValid paramGetPort_handler(NATIVE_INT_TYPE portNum, FwPrmIdType id, Fw::ParamBuffer &val);
void paramSetPort_handler(NATIVE_INT_TYPE portNum, FwPrmIdType id, Fw::ParamBuffer &val);
Fw::ParamBuffer m_prm;
};
#endif /* TESTCOMMANDSOURCEIMPL_HPP_ */
| hpp |
fprime | data/projects/fprime/Autocoders/Python/test/param_multi_inst/TestPrmSourceImpl.cpp | /*
* TestCommand1Impl.cpp
*
* Created on: Mar 28, 2014
* Author: tcanham
*/
#include <Autocoders/Python/test/param_multi_inst/TestPrmSourceImpl.hpp>
#include <cstdio>
TestParamSourceImpl::TestParamSourceImpl(const char* name) : Prm::ParamTesterComponentBase(name)
{
}
TestParamSourceImpl::~TestParamSourceImpl() {
}
Fw::ParamValid TestParamSourceImpl::paramGetPort_handler(NATIVE_INT_TYPE portNum, FwPrmIdType id, Fw::ParamBuffer &val) {
val = this->m_prm;
return Fw::ParamValid::VALID;
}
void TestParamSourceImpl::paramSetPort_handler(NATIVE_INT_TYPE portNum, FwPrmIdType id, Fw::ParamBuffer &val) {
}
void TestParamSourceImpl::init() {
Prm::ParamTesterComponentBase::init();
}
void TestParamSourceImpl::setPrm(U32 val) {
printf("Setting parameter to %d\n",val);
this->m_prm.resetSer();
this->m_prm.serialize(val);
}
| cpp |
fprime | data/projects/fprime/Autocoders/Python/test/param_multi_inst/TestPrmImpl.hpp | /*
* TestPrmImpl.hpp
*
* Created on: Mar 28, 2014
* Author: tcanham
*/
#ifndef TESTPARAMIMPL_HPP_
#define TESTPARAMIMPL_HPP_
#include <Autocoders/Python/test/param_multi_inst/TestComponentAc.hpp>
class TestPrmImpl: public Prm::TestPrmComponentBase {
public:
TestPrmImpl(const char* compName);
void genTlm(U32 val);
virtual ~TestPrmImpl();
void init();
void printParam();
protected:
void aport_handler(NATIVE_INT_TYPE portNum, I32 arg4, F32 arg5, U8 arg6);
void parameterUpdated(FwPrmIdType id);
};
#endif /* TESTPARAMIMPL_HPP_ */
| hpp |
fprime | data/projects/fprime/Autocoders/Python/test/param_multi_inst/test/ut/main.cpp | #ifdef FPRIME_CMAKE
#include "Autocoder/GTestBase.hpp"
#else
#include <param_multi_instGTestBase.hpp>
#endif
#include "TesterBase.hpp"
#include <FpConfig.hpp>
// Very minimal to test autocoder. Some day they'll be actual unit test code
class ATester : public Prm::TestPrmGTestBase {
public:
ATester() : Prm::TestPrmGTestBase("comp",10) {
}
};
int main(int argc, char* argv[]) {
ATester testBase;
}
| cpp |
fprime | data/projects/fprime/Autocoders/Python/test/event1/main.cpp | #include <Autocoders/Python/test/event1/TestLogImpl.hpp>
#include <Autocoders/Python/test/event1/TestLogRecvImpl.hpp>
#include <Autocoders/Python/test/time_tester/TestTimeImpl.hpp>
#include <Fw/Obj/SimpleObjRegistry.hpp>
int main(int argc, char* argv[]) {
#if FW_PORT_TRACING
Fw::PortBase::setTrace(true);
#endif
#if FW_OBJECT_REGISTRATION == 1
Fw::SimpleObjRegistry objReg;
#endif
TestLogImpl testImpl("TestLogImpl");
testImpl.init();
TestLogRecvImpl logRecv("TestLogRecv");
logRecv.init();
TestTimeImpl timeSource("TimeComp");
timeSource.init();
testImpl.set_Log_OutputPort(0,logRecv.get_logRecvPort_InputPort(0));
testImpl.set_Time_OutputPort(0,timeSource.get_timeGetPort_InputPort(0));
testImpl.set_LogText_OutputPort(0,logRecv.get_textLogRecvPort_InputPort(0));
timeSource.setTime(Fw::Time(TB_NONE,2,3));
#if FW_OBJECT_REGISTRATION == 1
objReg.dump();
#endif
testImpl.sendEvent(20,30.0,40);
}
| cpp |
fprime | data/projects/fprime/Autocoders/Python/test/event1/TestLogRecvImpl.cpp | /*
* TestCommand1Impl.cpp
*
* Created on: Mar 28, 2014
* Author: tcanham
*/
#include <Autocoders/Python/test/event1/TestLogRecvImpl.hpp>
#include <cstdio>
TestLogRecvImpl::TestLogRecvImpl(const char* name) : LogTextImpl(name)
{
}
TestLogRecvImpl::~TestLogRecvImpl() {
}
void TestLogRecvImpl::logRecvPort_handler(NATIVE_INT_TYPE portNum, FwEventIdType id, Fw::Time &timeTag, const Fw::LogSeverity& severity, Fw::LogBuffer &args) {
printf("Received log %d, Time (%d,%d:%d) severity %d\n",id,timeTag.getTimeBase(),timeTag.getSeconds(),timeTag.getUSeconds(),severity.e);
I32 arg1;
F32 arg2;
U8 arg3;
// deserialize them in reverse order
args.deserialize(arg3);
args.deserialize(arg2);
args.deserialize(arg1);
printf("Args: %d %f %c\n",arg1,arg2,arg3);
}
void TestLogRecvImpl::init() {
LogTextImpl::init();
}
| cpp |
fprime | data/projects/fprime/Autocoders/Python/test/event1/TestLogRecvImpl.hpp | /*
* TestTelemRecvImpl.hpp
*
* Created on: Mar 28, 2014
* Author: tcanham
*/
#ifndef TESTTELEMRECVIMPL_HPP_
#define TESTTELEMRECVIMPL_HPP_
#include <Autocoders/Python/test/log_tester/TestTextLogImpl.hpp>
class TestLogRecvImpl: public LogTextImpl {
public:
TestLogRecvImpl(const char* compName);
virtual ~TestLogRecvImpl();
void init();
protected:
void logRecvPort_handler(NATIVE_INT_TYPE portNum, FwEventIdType id, Fw::Time &timeTag, const Fw::LogSeverity& severity, Fw::LogBuffer &args);
private:
};
#endif /* TESTCOMMANDSOURCEIMPL_HPP_ */
| hpp |
fprime | data/projects/fprime/Autocoders/Python/test/event1/TestLogImpl.hpp | /*
* TestCommand1Impl.hpp
*
* Created on: Mar 28, 2014
* Author: tcanham
*/
#ifndef TESTCOMMAND1IMPL_HPP_
#define TESTCOMMAND1IMPL_HPP_
#include <Autocoders/Python/test/event1/TestComponentAc.hpp>
class TestLogImpl: public Somewhere::TestLogComponentBase {
public:
TestLogImpl(const char* compName);
virtual ~TestLogImpl();
void init();
void sendEvent(I32 arg1, F32 arg2, U8 arg3);
protected:
void aport_handler(NATIVE_INT_TYPE portNum, I32 arg4, F32 arg5, U8 arg6);
};
#endif /* TESTCOMMAND1IMPL_HPP_ */
| hpp |
fprime | data/projects/fprime/Autocoders/Python/test/event1/TestLogImpl.cpp | /*
* TestCommand1Impl.cpp
*
* Created on: Mar 28, 2014
* Author: tcanham
*/
#include <Autocoders/Python/test/event1/TestLogImpl.hpp>
#include <cstdio>
TestLogImpl::TestLogImpl(const char* name) : Somewhere::TestLogComponentBase(name)
{
}
TestLogImpl::~TestLogImpl() {
}
void TestLogImpl::init() {
Somewhere::TestLogComponentBase::init();
}
void TestLogImpl::aport_handler(NATIVE_INT_TYPE portNum, I32 arg4, F32 arg5, U8 arg6) {
}
void TestLogImpl::sendEvent(I32 arg1, F32 arg2, U8 arg3) {
printf("Sending event args %d, %f, %d\n",arg1, arg2, arg3);
this->log_DIAGNOSTIC_SomeEvent(arg1,arg2,arg3);
}
| cpp |
fprime | data/projects/fprime/Autocoders/Python/test/event1/test/ut/main.cpp | #ifdef FPRIME_CMAKE
#include "Autocoder/GTestBase.hpp"
#else
#include <event1GTestBase.hpp>
#endif
// Very minimal to test autocoder. Some day they'll be actual unit test code
class ATester : public Somewhere::TestLogGTestBase {
public:
ATester() : Somewhere::TestLogGTestBase("comp",10) {
}
};
int main(int argc, char* argv[]) {
ATester testBase;
}
| cpp |
fprime | data/projects/fprime/Autocoders/Python/test/command_string/TestCommandImpl.hpp | /*
* TestCommand1Impl.hpp
*
* Created on: Mar 28, 2014
* Author: tcanham
*/
#ifndef TESTCOMMAND2IMPL_HPP_
#define TESTCOMMAND2IMPL_HPP_
#include <Autocoders/Python/test/command_string/TestComponentAc.hpp>
class TestCommand1Impl: public AcTest::TestCommandComponentBase {
public:
TestCommand1Impl(const char* compName);
void init(NATIVE_INT_TYPE queueDepth);
virtual ~TestCommand1Impl();
void aport_handler(NATIVE_INT_TYPE portNum, I32 arg4, F32 arg5, U8 arg6);
void TEST_CMD_1_cmdHandler(FwOpcodeType opCode, U32 cmdSeq, I32 arg1, const Fw::CmdStringArg& arg2, SomeEnum arg3);
};
#endif /* TESTCOMMAND1IMPL_HPP_ */
| hpp |
fprime | data/projects/fprime/Autocoders/Python/test/command_string/main.cpp | #include <Autocoders/Python/test/command_string/TestCommandImpl.hpp>
#include <Autocoders/Python/test/command_string/TestCommandSourceImpl.hpp>
#include <Fw/Obj/SimpleObjRegistry.hpp>
int main(int argc, char* argv[]) {
#if FW_PORT_TRACING
Fw::PortBase::setTrace(true);
#endif
#if FW_OBJECT_REGISTRATION == 1
Fw::SimpleObjRegistry objReg;
#endif
TestCommand1Impl testImpl("TestCmdImpl");
testImpl.init(10);
testImpl.start();
TestCommandSourceImpl cmdSrc("TestCmdSource");
cmdSrc.init();
testImpl.set_CmdStatus_OutputPort(0,cmdSrc.get_cmdStatusPort_InputPort(0));
testImpl.set_CmdReg_OutputPort(0,cmdSrc.get_cmdRegPort_InputPort(0));
cmdSrc.set_cmdSendPort_OutputPort(0,testImpl.get_CmdDisp_InputPort(0));
testImpl.regCommands();
#if FW_OBJECT_REGISTRATION == 1
objReg.dump();
#endif
Fw::CmdStringArg str("A command string");
cmdSrc.test_TEST_CMD_1(10,str,7);
Os::Task::delay(1000);
testImpl.exit();
}
| cpp |
fprime | data/projects/fprime/Autocoders/Python/test/command_string/TestCommandSourceImpl.cpp | /*
* TestCommand1Impl.cpp
*
* Created on: Mar 28, 2014
* Author: tcanham
*/
#include <Autocoders/Python/test/command_string/TestCommandSourceImpl.hpp>
#include <cstdio>
TestCommandSourceImpl::TestCommandSourceImpl(const char* name) : Cmd::CommandTesterComponentBase(name)
{
}
TestCommandSourceImpl::~TestCommandSourceImpl() {
}
void TestCommandSourceImpl::cmdStatusPort_handler(
NATIVE_INT_TYPE portNum, FwOpcodeType opCode, U32 cmdSeq,
const Fw::CmdResponse& response) {
this->printStatus(response);
}
void TestCommandSourceImpl::cmdRegPort_handler(NATIVE_INT_TYPE portNum, FwOpcodeType opCode) {
printf("Received registration for opcode %d\n",opCode);
}
void TestCommandSourceImpl::init() {
Cmd::CommandTesterComponentBase::init();
}
void TestCommandSourceImpl::printStatus(const Fw::CmdResponse& response) {
switch (response.e) {
case Fw::CmdResponse::OK:
printf("COMMAND OK\n");
break;
case Fw::CmdResponse::INVALID_OPCODE:
printf("INVALID OPCODE\n");
break;
case Fw::CmdResponse::VALIDATION_ERROR:
printf("VALIDATION ERROR\n");
break;
case Fw::CmdResponse::FORMAT_ERROR:
printf("FORMAT ERROR\n");
break;
case Fw::CmdResponse::EXECUTION_ERROR:
printf("EXECUTION ERROR\n");
break;
default:
printf("Unknown status %d\n", response.e);
break;
}
}
void TestCommandSourceImpl::test_TEST_CMD_1(I32 arg1, const Fw::CmdStringArg& arg2, I32 arg3) {
// serialize parameters
if (!this->isConnected_cmdSendPort_OutputPort(0)) {
printf("Test command port not connected.");
return;
}
Fw::CmdArgBuffer argBuff;
// do nominal case
argBuff.serialize(arg1);
argBuff.serialize(arg2);
argBuff.serialize(arg3);
this->cmdSendPort_out(0, 0x100, 1, argBuff);
return;
// wrong value
// argBuff.resetToStart();
// argBuff.serialize(arg1);
// argBuff.serialize(arg2+1);
//
// this->cmdSendPort_FwCmd_out(0, 0x100, 1, argBuff);
//
// // too many arguments
// argBuff.resetToStart();
//
// argBuff.serialize(arg1);
// argBuff.serialize(arg2);
// argBuff.serialize(arg2);
//
// this->cmdSendPort_FwCmd_out(0, 0x100, 1, argBuff);
//
// // too few arguments
// argBuff.resetToStart();
//
// argBuff.serialize(arg1);
//
// this->cmdSendPort_FwCmd_out(0, 0x100, 1, argBuff);
}
| cpp |
fprime | data/projects/fprime/Autocoders/Python/test/command_string/TestCommandSourceImpl.hpp | /*
* TestCommand1Impl.hpp
*
* Created on: Mar 28, 2014
* Author: tcanham
*/
#ifndef TESTCOMMANDSOURCEIMPL_HPP_
#define TESTCOMMANDSOURCEIMPL_HPP_
#include <Autocoders/Python/test/command_tester/CommandTestComponentAc.hpp>
#include <Autocoders/Python/test/command_string/TestComponentAc.hpp>
class TestCommandSourceImpl: public Cmd::CommandTesterComponentBase {
public:
TestCommandSourceImpl(const char* compName);
virtual ~TestCommandSourceImpl();
void init();
void test_TEST_CMD_1(I32 arg1, const Fw::CmdStringArg& arg2, I32 arg3);
protected:
void cmdStatusPort_handler(NATIVE_INT_TYPE portNum, FwOpcodeType opCode, U32 cmdSeq, const Fw::CmdResponse& response);
void cmdRegPort_handler(NATIVE_INT_TYPE portNum, FwOpcodeType opCode);
private:
void printStatus(const Fw::CmdResponse& response);
};
#endif /* TESTCOMMANDSOURCEIMPL_HPP_ */
| hpp |
fprime | data/projects/fprime/Autocoders/Python/test/command_string/TestCommandImpl.cpp | /*
* TestCommand1Impl.cpp
*
* Created on: Mar 28, 2014
* Author: tcanham
*/
#include <Autocoders/Python/test/command_string/TestCommandImpl.hpp>
#include <cstdio>
TestCommand1Impl::TestCommand1Impl(const char* name) : AcTest::TestCommandComponentBase(name)
{
}
void TestCommand1Impl::init(NATIVE_INT_TYPE queueDepth) {
AcTest::TestCommandComponentBase::init(queueDepth);
}
TestCommand1Impl::~TestCommand1Impl() {
}
void TestCommand1Impl::aport_handler(NATIVE_INT_TYPE portNum, I32 arg4, F32 arg5, U8 arg6) {
}
void TestCommand1Impl::TEST_CMD_1_cmdHandler(FwOpcodeType opCode, U32 cmdSeq, I32 arg1, const Fw::CmdStringArg& arg2, SomeEnum arg3) {
const char *enum_str = "unknown";
switch (arg3) {
case MEMB1:
enum_str = "MEMB1";
break;
case MEMB2:
enum_str = "MEMB2";
break;
case MEMB3:
enum_str = "MEMB3";
break;
default:
enum_str = "INV";
break;
}
printf("Got command args: %d \"%s\" %s\n", arg1, arg2.toChar(),enum_str);
this->cmdResponse_out(opCode,cmdSeq,Fw::CmdResponse::OK);
}
| cpp |
fprime | data/projects/fprime/Autocoders/Python/test/command_string/test/ut/main.cpp | #ifdef FPRIME_CMAKE
#include "Autocoder/GTestBase.hpp"
#else
#include <command_stringGTestBase.hpp>
#endif
#include "TesterBase.hpp"
#include <FpConfig.hpp>
// Very minimal to test autocoder. Some day they'll be actual unit test code
class ATester : public AcTest::TestCommandGTestBase {
public:
ATester() : AcTest::TestCommandGTestBase("comp",10) {
}
};
int main(int argc, char* argv[]) {
ATester testBase;
}
| cpp |
fprime | data/projects/fprime/Autocoders/Python/test/serialize3/test/ut/main.cpp | #include <Autocoders/Python/test/serialize3/AlltypesSerializableAc.hpp>
int main(int argc, char* argv[]) {
Ns::Something::Alltypes atypes;
}
| cpp |
fprime | data/projects/fprime/Autocoders/Python/test/tlm_multi_inst/main.cpp | #include <Autocoders/Python/test/tlm_multi_inst/TestTelemImpl.hpp>
#include <Autocoders/Python/test/tlm_multi_inst/TestTelemRecvImpl.hpp>
#include <Autocoders/Python/test/time_tester/TestTimeImpl.hpp>
#include <Fw/Obj/SimpleObjRegistry.hpp>
int main(int argc, char* argv[]) {
#if FW_PORT_TRACING
Fw::PortBase::setTrace(true);
#endif
#if FW_OBJECT_REGISTRATION == 1
Fw::SimpleObjRegistry objReg;
#endif
TestTlmImpl testImpl("TestTlmImpl");
testImpl.init();
TestTelemRecvImpl tlmRecv("TestTlmRecv");
tlmRecv.init();
TestTimeImpl timeSource("TimeComp");
timeSource.init();
testImpl.set_Tlm_OutputPort(0,tlmRecv.get_tlmRecvPort_InputPort(0));
testImpl.set_Time_OutputPort(0,timeSource.get_timeGetPort_InputPort(0));
timeSource.setTime(Fw::Time(TB_NONE,2,3));
#if FW_OBJECT_REGISTRATION == 1
objReg.dump();
#endif
testImpl.genTlm(26);
}
| cpp |