Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auto-generate connect ports option. Fixes #934 #1786

Merged
merged 4 commits into from
Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Autocoders/Python/bin/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,7 @@ def generate_component(
cpp_instance_gtest_name = base + "_GTest_Cpp"
h_instance_test_impl_name = base + "_TestImpl_H"
cpp_instance_test_impl_name = base + "_TestImpl_Cpp"
cpp_instance_test_impl_helpers_name = base + "_TestImplHelpers_Cpp"
test_main_name = base + "_TestMain_Cpp"
else:
PRINT.info("Missing Ai at end of file name...")
Expand Down Expand Up @@ -753,6 +754,9 @@ def generate_component(
generator.configureVisitor(
cpp_instance_test_impl_name, "TestImplCppVisitor", True, True
)
generator.configureVisitor(
cpp_instance_test_impl_helpers_name, "TestImplCppHelpersVisitor", True, True
)
generator.configureVisitor(test_main_name, "TestMainVisitor", True, True)
else:
generator.configureVisitor(h_instance_name, "ComponentHVisitor", True, True)
Expand Down
3 changes: 3 additions & 0 deletions Autocoders/Python/src/fprime_ac/generators/GenFactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
SerialHVisitor,
SerializableVisitor,
TestImplCppVisitor,
TestImplCppHelpersVisitor,
TestImplHVisitor,
TestMainVisitor,
TopologyCppVisitor,
Expand Down Expand Up @@ -147,6 +148,8 @@ def Instance(self):
inst = ImplHVisitor.ImplHVisitor()
elif self.__type == "TestImplCppVisitor":
inst = TestImplCppVisitor.TestImplCppVisitor()
elif self.__type == "TestImplCppHelpersVisitor":
inst = TestImplCppHelpersVisitor.TestImplCppHelpersVisitor()
elif self.__type == "TestImplHVisitor":
inst = TestImplHVisitor.TestImplHVisitor()
elif self.__type == "TestMainVisitor":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ include(autocoder/ai-shared)
set(CHEETAH_TEMPLATES
"${CMAKE_CURRENT_LIST_DIR}/cpp.tmpl"
"${CMAKE_CURRENT_LIST_DIR}/hpp.tmpl"
"${CMAKE_CURRENT_LIST_DIR}/test_helpers.tmpl"
"${CMAKE_CURRENT_LIST_DIR}/test_main.tmpl"
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
// ======================================================================
// \title $name/test/ut/TesterHelpers.cpp
// \author Auto-generated
// \brief cpp file for ${name} component test harness base class
//
// NOTE: this file was automatically generated
//
// ======================================================================
\#include "Tester.hpp"

#if $namespace_list != None
#for $namespace in $namespace_list
namespace ${namespace} {
#end for
#end if
// ----------------------------------------------------------------------
// Helper methods
// ----------------------------------------------------------------------

void Tester ::
connectPorts()
{

#for $instance, $type, $sync, $priority, $full, $role, $max_num in $typed_input_ports:
// $instance
#if $max_num == 1 or $max_num == "1":
this->connect_to_${instance}(
0,
this->component.get_${instance}_InputPort(0)
);
#else
#set LT = "<"
for (NATIVE_INT_TYPE i = 0; i $LT $max_num; ++i) {
this->connect_to_${instance}(
i,
this->component.get_${instance}_InputPort(i)
);
}
#end if

#end for
#for $instance, $type, $sync, $priority, $role, $max_num in $typed_output_ports:
// $instance
#if $max_num == 1 or $max_num == "1":
this->component.set_${instance}_OutputPort(
0,
this->get_from_${instance}(0)
);
#else
#set LT = "<"
for (NATIVE_INT_TYPE i = 0; i $LT $max_num; ++i) {
this->component.set_${instance}_OutputPort(
i,
this->get_from_${instance}(i)
);
}
#end if

#end for

#if len($serial_output_ports) > 0:
// ----------------------------------------------------------------------
// Connect serial output ports
// ----------------------------------------------------------------------
#for $instance, $sync, $priority, $max_num in $serial_output_ports:
#if $max_num == 1 or $max_num == "1":
this->component.set_${instance}_OutputPort(
0,
this->get_from_${instance}(0)
);
#else
#set LT = "<"
for (NATIVE_INT_TYPE i = 0; i $LT $max_num; ++i) {
this->component.set_${instance}_OutputPort(
i,
this->get_from_${instance}(i)
);
}
#end if

#end for
#end if

#if len($serial_input_ports) > 0:
// ----------------------------------------------------------------------
// Connect serial input ports
// ----------------------------------------------------------------------
#for $instance, $sync, $priority, $full, $max_num in $serial_input_ports:
// $instance
#if $max_num == 1 or $max_num == "1":
this->connect_to_${instance}(
0,
this->component.get_${instance}_InputPort(0)
);
#else
#set LT = "<"
for (NATIVE_INT_TYPE i = 0; i $LT $max_num; ++i) {
this->connect_to_${instance}(
i,
this->component.get_${instance}_InputPort(i)
);
}
#end if

#end for
#end if

}

void Tester ::
initComponents()
{
this->init();
this->component.init(
#if $kind == "passive"
Tester::TEST_INSTANCE_ID
#else
Tester::TEST_INSTANCE_QUEUE_DEPTH, Tester::TEST_INSTANCE_ID
#end if
);
}

#if $namespace_list != None
#for $namespace in $reversed($namespace_list)
} // end namespace $namespace
#end for
#end if
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@

\#include "Tester.hpp"

\#define INSTANCE 0
\#define MAX_HISTORY_SIZE 10
#if $kind != "passive":
\#define QUEUE_DEPTH 10
#end if

#if $namespace_list != None
#for $namespace in $namespace_list
namespace ${namespace} {
Expand All @@ -24,7 +18,7 @@ namespace ${namespace} {

Tester ::
Tester() :
${gtest_base}("Tester", MAX_HISTORY_SIZE),
${gtest_base}("Tester", Tester::MAX_HISTORY_SIZE),
component("${name}")
{
this->initComponents();
Expand Down Expand Up @@ -85,112 +79,6 @@ $emit_port_params([ $param_portNum ] + $port_params[$instance])

#end for
#end if
// ----------------------------------------------------------------------
// Helper methods
// ----------------------------------------------------------------------

void Tester ::
connectPorts()
{

#for $instance, $type, $sync, $priority, $full, $role, $max_num in $typed_input_ports:
// $instance
#if $max_num == 1 or $max_num == "1":
this->connect_to_${instance}(
0,
this->component.get_${instance}_InputPort(0)
);
#else
#set LT = "<"
for (NATIVE_INT_TYPE i = 0; i $LT $max_num; ++i) {
this->connect_to_${instance}(
i,
this->component.get_${instance}_InputPort(i)
);
}
#end if

#end for
#for $instance, $type, $sync, $priority, $role, $max_num in $typed_output_ports:
// $instance
#if $max_num == 1 or $max_num == "1":
this->component.set_${instance}_OutputPort(
0,
this->get_from_${instance}(0)
);
#else
#set LT = "<"
for (NATIVE_INT_TYPE i = 0; i $LT $max_num; ++i) {
this->component.set_${instance}_OutputPort(
i,
this->get_from_${instance}(i)
);
}
#end if

#end for

#if len($serial_output_ports) > 0:
// ----------------------------------------------------------------------
// Connect serial output ports
// ----------------------------------------------------------------------
#for $instance, $sync, $priority, $max_num in $serial_output_ports:
#if $max_num == 1 or $max_num == "1":
this->component.set_${instance}_OutputPort(
0,
this->get_from_${instance}(0)
);
#else
#set LT = "<"
for (NATIVE_INT_TYPE i = 0; i $LT $max_num; ++i) {
this->component.set_${instance}_OutputPort(
i,
this->get_from_${instance}(i)
);
}
#end if

#end for
#end if

#if len($serial_input_ports) > 0:
// ----------------------------------------------------------------------
// Connect serial input ports
// ----------------------------------------------------------------------
#for $instance, $sync, $priority, $full, $max_num in $serial_input_ports:
// $instance
#if $max_num == 1 or $max_num == "1":
this->connect_to_${instance}(
0,
this->component.get_${instance}_InputPort(0)
);
#else
#set LT = "<"
for (NATIVE_INT_TYPE i = 0; i $LT $max_num; ++i) {
this->connect_to_${instance}(
i,
this->component.get_${instance}_InputPort(i)
);
}
#end if

#end for
#end if

}

void Tester ::
initComponents()
{
this->init();
this->component.init(
#if $kind == "passive"
INSTANCE
#else
QUEUE_DEPTH, INSTANCE
#end if
);
}

#if $namespace_list != None
#for $namespace in $reversed($namespace_list)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ namespace ${namespace} {
// ----------------------------------------------------------------------

public:
// Maximum size of histories storing events, telemetry, and port outputs
static const NATIVE_INT_TYPE MAX_HISTORY_SIZE = 10;
// Instance ID supplied to the component instance under test
static const NATIVE_INT_TYPE TEST_INSTANCE_ID = 0;
#if $kind != "passive":
// Queue depth supplied to component instance under test
static const NATIVE_INT_TYPE TEST_INSTANCE_QUEUE_DEPTH = 10;
#end if

//! Construct object Tester
//!
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# ===============================================================================
# NAME: TestImplCppHelpersVisitor.py
#
# DESCRIPTION: A visitor class for generating test implementation cpp files.
#
# AUTHOR: lestarch
# DATE CREATED: November 28, 2022
#
# Copyright 2015, California Institute of Technology.
# ALL RIGHTS RESERVED. U.S. Government Sponsorship acknowledged.
# ===============================================================================
import sys

from fprime_ac.generators.visitors import TestImplVisitorBase

try:
from fprime_ac.generators.templates.test import test_helpers
except ImportError:
print("ERROR: must generate python templates first.")

Check notice

Code scanning / CodeQL

Use of a print statement at module level

Print statement may execute during import.
sys.exit(-1)


class TestImplCppHelpersVisitor(TestImplVisitorBase.TestImplVisitorBase):
"""
A visitor class for generating test implementation cpp files.
"""

def __init__(self):
super().__init__()
self.initBase("TestImplCpp")

def emitPortParams(self, params):
return self.emitPortParamsCpp(8, params)

def emitNonPortParams(self, params):
return self.emitNonPortParamsCpp(8, params)

def initFilesVisit(self, obj):
self.openFile("TesterHelpers.cpp")

def startSourceFilesVisit(self, obj):
c = test_helpers.test_helpers()
self.init(obj, c)
self.initTestImpl(obj, c)
c.emit_port_params = self.emitPortParams
c.emit_non_port_params = self.emitNonPortParams
self._writeTmpl(c, "startSourceFilesVisit")
1 change: 1 addition & 0 deletions Ref/SignalGen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ set(UT_SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/test/ut/Tester.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/TestMain.cpp"
)
set(UT_AUTO_HELPERS ON)
register_fprime_ut()
Loading