Skip to content

Commit

Permalink
enhance example
Browse files Browse the repository at this point in the history
  • Loading branch information
ydaveluy committed Jan 4, 2024
1 parent 4401a98 commit eea68cf
Show file tree
Hide file tree
Showing 29 changed files with 345 additions and 231 deletions.
4 changes: 2 additions & 2 deletions .cproject
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
<storageModule buildDir="_build/Debug" dirtyTs="1693767165288" moduleId="de.marw.cmake4eclipse.mbs.settings">
<options otherArguments="-DCMAKE_CXX_COMPILER=g++&#10;-DXSMP_BUILD_WITH_WARNINGS=ON&#10;-DXSMP_ENABLE_CODECOVERAGE:BOOL=ON"/>
<storageModule buildDir="_build/Debug" dirtyTs="1704361644182" moduleId="de.marw.cmake4eclipse.mbs.settings">
<options otherArguments="-DCMAKE_CXX_COMPILER=g++&#10;-DXSMP_BUILD_WITH_WARNINGS=ON&#10;-DXSMP_ENABLE_CODECOVERAGE:BOOL=ON&#10;-DXSMP_BUILD_EXAMPLES=ON"/>
</storageModule>
</cconfiguration>
<cconfiguration id="cmake4eclipse.mbs.config.release.1009017204">
Expand Down
7 changes: 2 additions & 5 deletions cmake/Pytest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ find_package(Python COMPONENTS Interpreter Development)
function(pytest_discover_tests)
cmake_parse_arguments(
PARSE_ARGV 0 "" ""
"NAME;WORKING_DIRECTORY;TRIM_FROM_NAME;BUNDLE_TESTS"
"NAME;WORKING_DIRECTORY;BUNDLE_TESTS"
"LIBRARY_PATH_PREPEND;PYTHON_PATH_PREPEND;ENVIRONMENT"
)

Expand Down Expand Up @@ -66,9 +66,7 @@ function(pytest_discover_tests)
if (NOT _WORKING_DIRECTORY)
set(_WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/python)
endif()
if (NOT _TRIM_FROM_NAME)
set(_TRIM_FROM_NAME "^test_")
endif()

# Override option by environment variable if available.
if (DEFINED ENV{BUNDLE_PYTHON_TESTS})
set(_BUNDLE_TESTS $ENV{BUNDLE_PYTHON_TESTS})
Expand Down Expand Up @@ -97,7 +95,6 @@ function(pytest_discover_tests)
" LIB_ENV_PATH" " [==[" "${LIB_ENV_PATH}" "]==]" "\n"
" LIBRARY_PATH" " [==[" "${libpath}" "]==]" "\n"
" PYTHON_PATH" " [==[" "${pythonpath}" "]==]" "\n"
" TRIM_FROM_NAME" " [==[" "${_TRIM_FROM_NAME}" "]==]" "\n"
" WORKING_DIRECTORY" " [==[" "${_WORKING_DIRECTORY}" "]==]" "\n"
" ENVIRONMENT" " [==[" "${_ENVIRONMENT}" "]==]" "\n"
" CTEST_FILE" " [==[" "${ctest_tests_file}" "]==]" "\n"
Expand Down
12 changes: 6 additions & 6 deletions cmake/PytestAddTests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function(pytest_discover_tests_impl)
cmake_parse_arguments(
""
""
"PYTHON_EXECUTABLE;TEST_GROUP_NAME;BUNDLE_TESTS;LIB_ENV_PATH;LIBRARY_PATH;PYTHON_PATH;TRIM_FROM_NAME;WORKING_DIRECTORY;ENVIRONMENT;CTEST_FILE"
"PYTHON_EXECUTABLE;TEST_GROUP_NAME;BUNDLE_TESTS;LIB_ENV_PATH;LIBRARY_PATH;PYTHON_PATH;WORKING_DIRECTORY;ENVIRONMENT;CTEST_FILE"
""
${ARGN}
)
Expand Down Expand Up @@ -73,16 +73,17 @@ function(pytest_discover_tests_impl)
set(_class ${CMAKE_MATCH_3})
set(_func ${CMAKE_MATCH_4})


string(REGEX REPLACE "^test_?" "" _func "${_func}")

if (_class)
#string(REGEX REPLACE "^Test|Test$" "" _class "${_class}")
set(test_name "${_class}.${_func}")
else()
set(test_name "${_func}")
endif()

if (_TRIM_FROM_NAME)
string(REGEX REPLACE
"${_TRIM_FROM_NAME}" "" test_name "${test_name}")
endif()


set(test_name "${_TEST_GROUP_NAME}/${test_name}")
set(test_case "${_WORKING_DIRECTORY}/${test_case}")
Expand Down Expand Up @@ -128,7 +129,6 @@ if(CMAKE_SCRIPT_MODE_FILE)
LIB_ENV_PATH ${LIB_ENV_PATH}
LIBRARY_PATH ${LIBRARY_PATH}
PYTHON_PATH ${PYTHON_PATH}
TRIM_FROM_NAME ${TRIM_FROM_NAME}
WORKING_DIRECTORY ${WORKING_DIRECTORY}
ENVIRONMENT ${ENVIRONMENT}
CTEST_FILE ${CTEST_FILE}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import ecss_smp

class M1:
class Counter:
uuid: ecss_smp.Smp.Uuid = ecss_smp.Smp.Uuid("2386045d-5cff-46b5-b6da-3ff6e2cfd792")

del ecss_smp
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,18 @@ class __XsmpScheduler(ecss_smp.Smp.Services.IScheduler, ecss_smp.Smp.IDynamicInv

_Models: ecss_smp.Smp.IContainer

class __name(ecss_smp.Smp.IModel, ecss_smp.Smp.IDynamicInvocation, ecss_smp.Smp.ILinkingComponent, ecss_smp.Smp.IComposite, ):
class __integer1(ecss_smp.Smp.ISimpleField, ):
pass

integer1: __integer1
class __counter(ecss_smp.Smp.IModel, ecss_smp.Smp.IDynamicInvocation, ecss_smp.Smp.IEventConsumer, ecss_smp.Smp.ILinkingComponent, ecss_smp.Smp.IEntryPointPublisher, ):
def ResetCount(self, ): ...
Add: ecss_smp.Smp.IEventSink

class __integer2(ecss_smp.Smp.ISimpleField, ):
class __count(ecss_smp.Smp.ISimpleField, ):
pass

integer2: __integer2

_subModels: ecss_smp.Smp.IContainer
count: __count

IncrementCount: ecss_smp.Smp.IEntryPoint

name: __name
counter: __counter



36 changes: 36 additions & 0 deletions examples/project1/python/xsmp_example_project1/test_Counter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import ecss_smp
import xsmp
import xsmp_example_project1


class TestCounter(xsmp.unittest.TestCase):
try:
sim: xsmp_example_project1._test_xsmp_example_project1.Simulator
except AttributeError:
pass

def loadAssembly(self, sim: ecss_smp.Smp.ISimulator):
sim.LoadLibrary("xsmp_example_project1")
sim.AddModel(sim.CreateInstance(xsmp_example_project1.Example.Counter.uuid, "counter", "", sim))

def test_Init(self):
self.assertEqual(self.sim.counter.count, 0, "Initial value of count is 0")

def test_IncrementCount(self):
self.sim.counter.IncrementCount()
self.assertEqual(self.sim.counter.count, 1, "Count incremented")

def test_ScheduleIncrementCount(self):
self.sim.GetScheduler().AddSimulationTimeEvent(self.sim.counter.IncrementCount, 0, 1_000_000_000, 5)
self.sim.Run(seconds=10)
self.assertEqual(self.sim.counter.count, 6, "Count incremented 6 times")

def test_ResetCount(self):
self.sim.counter.count = 10
self.sim.counter.ResetCount()
self.assertEqual(self.sim.counter.count, 0, "Count is reseted")

def test_Add(self):
self.sim.counter.Add(arg=10)
self.assertEqual(self.sim.counter.count, 10, "Add 10 to count")

This file was deleted.

29 changes: 18 additions & 11 deletions examples/project1/smdl-gen/xsmp_example_project1.smpcat
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
<?xml version="1.0" encoding="ASCII"?>
<Catalogue:Catalogue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:Catalogue="http://www.ecss.nl/smp/2019/Smdl/Catalogue" xmlns:xlink="http://www.w3.org/1999/xlink" Id="_xsmp_example_project1" Name="xsmp_example_project1" Date="2023-06-02T15:08:16.000Z" Creator="Y.Daveluy">
<Catalogue:Catalogue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:Catalogue="http://www.ecss.nl/smp/2019/Smdl/Catalogue" xmlns:Types="http://www.ecss.nl/smp/2019/Core/Types" xmlns:xlink="http://www.w3.org/1999/xlink" Id="_xsmp_example_project1" Name="xsmp_example_project1" Date="2024-01-04T09:37:00.000Z" Creator="Y.Daveluy">
<Description>Catalogue xsmp_example_project1</Description>
<Namespace Id="Example" Name="Example">
<Description></Description>
<Type xsi:type="Catalogue:Model" Id="Example.M1" Name="M1" Uuid="2386045d-5cff-46b5-b6da-3ff6e2cfd792">
<Type xsi:type="Catalogue:EventType" Id="Example.CountEvent" Name="CountEvent" Uuid="f80c5d8e-deb4-492a-a5c0-4d37eadebe24">
<Description></Description>
<Field Id="Example.M1.integer1" Name="integer1" State="true" Input="false" Output="false">
<EventArgs xlink:title="Int32" xlink:href="http://www.ecss.nl/smp/2019/Smdl#Smp.Int32"/>
</Type>
<Type xsi:type="Catalogue:Model" Id="Example.Counter" Name="Counter" Uuid="2386045d-5cff-46b5-b6da-3ff6e2cfd792">
<Description></Description>
<Operation Id="Example.Counter.ResetCount" Name="ResetCount">
<Description></Description>
<Type xlink:title="Int8" xlink:href="http://www.ecss.nl/smp/2019/Smdl#Smp.Int8"/>
</Field>
<Field Id="Example.M1.integer2" Name="integer2" State="true" Input="false" Output="false">
</Operation>
<EntryPoint Id="Example.Counter.IncrementCount" Name="IncrementCount">
<Description></Description>
<Type xlink:title="Int16" xlink:href="http://www.ecss.nl/smp/2019/Smdl#Smp.Int16"/>
</Field>
<Container Id="Example.M1.subModels" Name="subModels" Lower="0" Upper="-1">
</EntryPoint>
<EventSink Id="Example.Counter.Add" Name="Add">
<Description></Description>
<Type xlink:title="CountEvent" xlink:href="#Example.CountEvent"/>
</EventSink>
<Field Id="Example.Counter.count" Name="count" State="true" Input="false" Output="false">
<Description></Description>
<Type xlink:title="M1" xlink:href="#Example.M1"/>
</Container>
<Type xlink:title="Int32" xlink:href="http://www.ecss.nl/smp/2019/Smdl#Smp.Int32"/>
<Default xsi:type="Types:Int32Value" Value="0"/>
</Field>
</Type>
</Namespace>
</Catalogue:Catalogue>
5 changes: 3 additions & 2 deletions examples/project1/smdl-gen/xsmp_example_project1.smppkg
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="ASCII"?>
<Package:Package xmlns:Catalogue="http://www.ecss.nl/smp/2019/Smdl/Catalogue" xmlns:Package="http://www.ecss.nl/smp/2019/Smdl/Package" xmlns:xlink="http://www.w3.org/1999/xlink" Id="_xsmp_example_project1" Name="xsmp_example_project1" Date="2023-06-02T15:08:16.000Z" Creator="Y.Daveluy">
<Package:Package xmlns:Catalogue="http://www.ecss.nl/smp/2019/Smdl/Catalogue" xmlns:Package="http://www.ecss.nl/smp/2019/Smdl/Package" xmlns:xlink="http://www.w3.org/1999/xlink" Id="_xsmp_example_project1" Name="xsmp_example_project1" Date="2024-01-04T09:37:00.000Z" Creator="Y.Daveluy">
<Description>Catalogue xsmp_example_project1</Description>
<Implementation xlink:title="M1" xlink:href="Catalogue:Model xsmp_example_project1.smpcat#Example.M1"/>
<Implementation xlink:title="CountEvent" xlink:href="Catalogue:EventType xsmp_example_project1.smpcat#Example.CountEvent"/>
<Implementation xlink:title="Counter" xlink:href="Catalogue:Model xsmp_example_project1.smpcat#Example.Counter"/>
</Package:Package>
14 changes: 9 additions & 5 deletions examples/project1/smdl/xsmp_example_project1.xsmpcat
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,24 @@
* Catalogue xsmp_example_project1
*
* @creator Y.Daveluy
* @date 2023-06-02T17:08:16.000+0200
* @date 2024-01-04T10:37:00.000+0100
*/
catalogue xsmp_example_project1


namespace Example
{
/** @uuid f80c5d8e-deb4-492a-a5c0-4d37eadebe24 */
event CountEvent extends Int32

/** @uuid 2386045d-5cff-46b5-b6da-3ff6e2cfd792 */
model M1
model Counter
{
field Int8 integer1
field Int16 integer2
field Int32 count = 0

container M1[*] subModels
entrypoint IncrementCount
def void ResetCount ()
eventsink CountEvent Add
}
}

121 changes: 121 additions & 0 deletions examples/project1/src-gen/Example/CounterGen.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
// Copyright 2023 YOUR ORGANIZATION. All rights reserved.
//
// YOUR NOTICE

// -----------------------------------------------------------------------------
// File Name : CounterGen.cpp
// Generated by : XsmpSdkGenerator-${qualifiedVersion}
// -----------------------------------------------------------------------------
/// @file Example/CounterGen.cpp
// This file is auto-generated, Do not edit otherwise your changes will be lost

// ----------------------------------------------------------------------------
// ---------------------------- Include Header Files --------------------
// ----------------------------------------------------------------------------

#include <Example/Counter.h>
#include <Smp/IPublication.h>
#include <Xsmp/ComponentHelper.h>
#include <Xsmp/EntryPoint.h>
#include <Xsmp/EventSink.h>
#include <Xsmp/Request.h>

namespace Example {
//--------------------------- Constructor -------------------------
CounterGen::CounterGen(::Smp::String8 name, ::Smp::String8 description,
::Smp::IObject *parent, ::Smp::ISimulator *simulator) :
// Base class initialization
::Xsmp::Model(name, description, parent, simulator),
// EntryPoint: IncrementCount
IncrementCount { new ::Xsmp::EntryPoint("IncrementCount", "", this,
std::bind(&CounterGen::_IncrementCount, this)) },
// Event Sink: Add
Add { new ::Xsmp::EventSink<::Smp::Int32>("Add", "", this,
std::bind(&CounterGen::_Add, this, std::placeholders::_1,
std::placeholders::_2),
::Smp::PrimitiveTypeKind::PTK_Int32) },
// count initialization
count { 0 } {
}

/// Virtual destructor that is called by inherited classes as well.
CounterGen::~CounterGen() {
delete IncrementCount;
IncrementCount = nullptr;
delete Add;
Add = nullptr;
}

void CounterGen::Publish(::Smp::IPublication *receiver) {
// Call parent class implementation first
::Xsmp::Model::Publish(receiver);

// Publish field count
receiver->PublishField("count", "", &count, ::Smp::ViewKind::VK_None, true,
false, false);
{
// Publish operation ResetCount
receiver->PublishOperation("ResetCount", "", ::Smp::ViewKind::VK_None);
}
// Call user DoPublish if any
::Xsmp::Component::Helper::Publish < ::Example::Counter > (this, receiver);
}

void CounterGen::Configure(::Smp::Services::ILogger *logger,
::Smp::Services::ILinkRegistry *linkRegistry) {
// Call parent implementation first
::Xsmp::Model::Configure(logger, linkRegistry);

// Call user DoConfigure if any
::Xsmp::Component::Helper::Configure < ::Example::Counter
> (this, logger, linkRegistry);
}

void CounterGen::Connect(::Smp::ISimulator *simulator) {
// Call parent implementation first
::Xsmp::Model::Connect(simulator);

// Call user DoConnect if any
::Xsmp::Component::Helper::Connect < ::Example::Counter > (this, simulator);
}

void CounterGen::Disconnect() {
// Call user DoDisconnect if any
::Xsmp::Component::Helper::Disconnect < ::Example::Counter > (this);

// Call parent implementation last, to remove references to the Simulator and its services
::Xsmp::Model::Disconnect();
}

CounterGen::RequestHandlers CounterGen::requestHandlers = InitRequestHandlers();

CounterGen::RequestHandlers CounterGen::InitRequestHandlers() {
RequestHandlers handlers;
if (handlers.find("ResetCount") == handlers.end()) {
handlers["ResetCount"] = [](CounterGen *cmp, ::Smp::IRequest*) {

/// Invoke ResetCount
cmp->ResetCount();

};
}
return handlers;
}

void CounterGen::Invoke(::Smp::IRequest *request) {
if (request == nullptr) {
return;
}
auto handler = requestHandlers.find(request->GetOperationName());
if (handler != requestHandlers.end()) {
handler->second(this, request);
} else {
// pass the request down to the base model
::Xsmp::Model::Invoke(request);
}
}

const Smp::Uuid& CounterGen::GetUuid() const {
return Uuid_Counter;
}
} // namespace Example
Loading

0 comments on commit eea68cf

Please sign in to comment.