Skip to content

Commit

Permalink
Transform example and E2E test.
Browse files Browse the repository at this point in the history
Signed-off-by: Rule Timothy (VM/EMT3) <Timothy.Rule@de.bosch.com>
  • Loading branch information
timrulebosch committed May 15, 2024
1 parent d98e0a9 commit ca15ec3
Show file tree
Hide file tree
Showing 8 changed files with 228 additions and 4 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export TESTSCRIPT_E2E_DIR ?= tests/testscript/e2e
TESTSCRIPT_E2E_FILES = \
$(TESTSCRIPT_E2E_DIR)/minimal.txtar \
$(TESTSCRIPT_E2E_DIR)/extended.txtar \
$(TESTSCRIPT_E2E_DIR)/transform.txtar \
$(TESTSCRIPT_E2E_DIR)/binary.txtar \
$(TESTSCRIPT_E2E_DIR)/ncodec.txtar \
$(TESTSCRIPT_E2E_DIR)/mstep.txtar \
Expand Down
9 changes: 5 additions & 4 deletions dse/modelc/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@


# Example Models.
add_subdirectory(minimal)
add_subdirectory(extended)
add_subdirectory(binary)
add_subdirectory(ncodec)
add_subdirectory(simer)
add_subdirectory(extended)
add_subdirectory(gateway)
add_subdirectory(gdb)
add_subdirectory(minimal)
add_subdirectory(ncodec)
add_subdirectory(simer)
add_subdirectory(transform)
if(UNIX)
add_subdirectory(benchmark)
endif()
Expand Down
56 changes: 56 additions & 0 deletions dse/modelc/examples/transform/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Copyright 2024 Robert Bosch GmbH
#
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.21)

project(Transform)
set(MODEL_PATH "examples/transform")

add_library(ponger SHARED
ponger.c
)
target_include_directories(ponger
PRIVATE
../../../..
)
target_link_libraries(ponger
PRIVATE
$<$<BOOL:${WIN32}>:${modelc_link_lib}>
)
install(TARGETS ponger
LIBRARY DESTINATION
${MODEL_PATH}/lib
RUNTIME DESTINATION
${MODEL_PATH}/lib
COMPONENT
transform
)
add_library(pingit SHARED
pingit.c
)
target_include_directories(pingit
PRIVATE
../../../..
)
target_link_libraries(pingit
PRIVATE
$<$<BOOL:${WIN32}>:${modelc_link_lib}>
)
install(TARGETS pingit
LIBRARY DESTINATION
${MODEL_PATH}/lib
RUNTIME DESTINATION
${MODEL_PATH}/lib
COMPONENT
transform
)
install(
FILES
model.yaml
simulation.yaml
DESTINATION
${MODEL_PATH}/data
COMPONENT
transform
)
50 changes: 50 additions & 0 deletions dse/modelc/examples/transform/model.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Copyright 2024 Robert Bosch GmbH
#
# SPDX-License-Identifier: Apache-2.0

---
kind: Model
metadata:
name: Ponger
spec:
runtime:
dynlib:
- os: linux
arch: amd64
path: lib/libponger.so
- os: linux
arch: x86
path: lib/libponger.so
- os: windows
arch: x64
path: lib/libponger.dll
- os: windows
arch: x86
path: lib/libponger.dll
channels:
- alias: data
selectors:
side: data
---
kind: Model
metadata:
name: Pingit
spec:
runtime:
dynlib:
- os: linux
arch: amd64
path: lib/libpingit.so
- os: linux
arch: x86
path: lib/libpingit.so
- os: windows
arch: x64
path: lib/libpingit.dll
- os: windows
arch: x86
path: lib/libpingit.dll
channels:
- alias: data
selectors:
side: data
20 changes: 20 additions & 0 deletions dse/modelc/examples/transform/pingit.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2024 Robert Bosch GmbH
//
// SPDX-License-Identifier: Apache-2.0

#include <errno.h>
#include <stddef.h>
#include <dse/modelc/model.h>

int model_step(ModelDesc* m, double* model_time, double stop_time)
{
ModelSignalIndex ping = m->index(m, "data", "ping");
if (ping.scalar == NULL) return -EINVAL;

double val = *(ping.scalar);
val = (val == 100) ? -100 : 100;

*(ping.scalar) = val;
*model_time = stop_time;
return 0;
}
20 changes: 20 additions & 0 deletions dse/modelc/examples/transform/ponger.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2024 Robert Bosch GmbH
//
// SPDX-License-Identifier: Apache-2.0

#include <errno.h>
#include <stddef.h>
#include <dse/modelc/model.h>

int model_step(ModelDesc* m, double* model_time, double stop_time)
{
ModelSignalIndex ping = m->index(m, "data", "ping");
ModelSignalIndex pong = m->index(m, "data", "pong");
if (ping.scalar == NULL) return -EINVAL;
if (pong.scalar == NULL) return -EINVAL;

*(pong.scalar) = *(ping.scalar);

*model_time = stop_time;
return 0;
}
53 changes: 53 additions & 0 deletions dse/modelc/examples/transform/simulation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Copyright 2024 Robert Bosch GmbH
#
# SPDX-License-Identifier: Apache-2.0

---
kind: Stack
metadata:
name: transform_stack
spec:
connection:
transport:
redispubsub:
uri: redis://localhost:6379
timeout: 60
models:
- name: simbus
model:
name: simbus
channels:
- name: data_channel
expectedModelCount: 2
- name: ponger_inst
uid: 42
model:
name: Ponger
channels:
- name: data_channel
alias: data
- name: pingit_inst
uid: 24
model:
name: Pingit
channels:
- name: data_channel
alias: data
---
kind: Model
metadata:
name: simbus
---
kind: SignalGroup
metadata:
name: data
labels:
side: data
spec:
signals:
- signal: ping
- signal: pong
transform:
linear:
factor: 20
offset: -100
23 changes: 23 additions & 0 deletions tests/testscript/e2e/transform.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
env NAME=transform_inst
env SIM=dse/modelc/build/_out/examples/transform


# TEST: transform example model
exec sh -e $WORK/test.sh

stdout 'Load YAML File: data/simulation.yaml'
stdout 'Loading symbol: model_create ... not found'
stdout 'Loading symbol: model_step ... ok'
stdout 'Loading symbol: model_destroy ... not found'
stdout 'Run the Simulation ...'
stdout 'Controller exit ...'
stdout 'SignalValue: 2061178551 = 0.000000 \[name=pong\]'
stdout 'SignalValue: 2061178551 = 10.000000 \[name=pong\]'
stdout 'uid=2061178551, val=10.000000, final_val=10.000000, name=pong'
stdout 'uid=375255177, val=-100.000000, final_val=-100.000000, name=ping'
stdout 'model_time=0.002000'

-- test.sh --
SIMER="${SIMER:-ghcr.io/boschglobal/dse-simer:latest}"
docker run --name simer -i --rm -v $ENTRYDIR/$SIM:/sim \
$SIMER -valgrind $NAME -env simbus:SIMBUS_LOGLEVEL=2

0 comments on commit ca15ec3

Please sign in to comment.