Skip to content

Commit

Permalink
E2E test for stacked sims.
Browse files Browse the repository at this point in the history
Signed-off-by: Timothy Rule (VM/EMT3) <[email protected]>
  • Loading branch information
timrulebosch committed Oct 15, 2024
1 parent 08c70d2 commit 29cc8c7
Show file tree
Hide file tree
Showing 14 changed files with 244 additions and 30 deletions.
13 changes: 10 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ TESTSCRIPT_E2E_FILES = \
$(TESTSCRIPT_E2E_DIR)/ncodec.txtar \
$(TESTSCRIPT_E2E_DIR)/mstep.txtar \
$(TESTSCRIPT_E2E_DIR)/transport.txtar \
$(TESTSCRIPT_E2E_DIR)/stack.txtar \
$(TESTSCRIPT_E2E_DIR)/runtime.txtar \
$(TESTSCRIPT_E2E_DIR)/benchmark.txtar

Expand Down Expand Up @@ -189,15 +190,22 @@ do-test_cmocka-run:
do-test_testscript-e2e:
# Test debug; add '-v' to Testscript command (e.g. $(TESTSCRIPT_IMAGE) -v \).
ifeq ($(PACKAGE_ARCH), linux-amd64)
@-docker kill simer
@set -eu; for t in $(TESTSCRIPT_E2E_FILES) ;\
do \
echo "Running E2E Test: $$t" ;\
export ENTRYWORKDIR=$$(mktemp -d) ;\
docker run -i --rm \
-e ENTRYDIR=$(HOST_DOCKER_WORKSPACE) \
-e ENTRYHOSTDIR=$(HOST_DOCKER_WORKSPACE) \
-e ENTRYWORKDIR=$${ENTRYWORKDIR} \
-v /var/run/docker.sock:/var/run/docker.sock \
-v $(HOST_DOCKER_WORKSPACE):/repo \
-v $${ENTRYWORKDIR}:/workdir \
$(TESTSCRIPT_IMAGE) \
-e ENTRYDIR=$(HOST_DOCKER_WORKSPACE) \
-e ENTRYHOSTDIR=$(HOST_DOCKER_WORKSPACE) \
-e ENTRYWORKDIR=$${ENTRYWORKDIR} \
-e REPODIR=/repo \
-e WORKDIR=/workdir \
-e SIMER=$(SIMER_IMAGE) \
$$t ;\
done;
Expand Down Expand Up @@ -237,4 +245,3 @@ super-linter:
--env VALIDATE_MARKDOWN=true \
--env VALIDATE_YAML=true \
ghcr.io/super-linter/super-linter:slim-v6

19 changes: 10 additions & 9 deletions dse/modelc/examples/simer/model.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ at runtime via environment variables:
*/

typedef struct {
ModelDesc model;
ModelDesc model;
ModelSignalIndex counter;
} ExtendedModelDesc;

Expand All @@ -29,17 +29,18 @@ ModelDesc* model_create(ModelDesc* model)
memcpy(m, model, sizeof(ModelDesc));

/* Identify the counter this model will increment. */
const char* counter_name = "counter";
if (getenv("COUNTER_NAME")) {
counter_name = getenv("COUNTER_NAME");
}
char* counter_name =
model_expand_vars((ModelDesc*)m, "${COUNTER_NAME:-counter_A}");
m->counter = signal_index((ModelDesc*)m, "data", counter_name);
if (m->counter.scalar == NULL) log_fatal("Signal not found (%s)", counter_name);
if (m->counter.scalar == NULL)
log_fatal("Signal not found (%s)", counter_name);
free(counter_name);

/* Set initial values. */
if (getenv("COUNTER_VALUE")) {
*(m->counter.scalar) = atoi(getenv("COUNTER_VALUE"));
}
char* counter_value =
model_expand_vars((ModelDesc*)m, "${COUNTER_VALUE:-0}");
*(m->counter.scalar) = atoi(counter_value);
free(counter_value);

/* Return the extended object. */
return (ModelDesc*)m;
Expand Down
10 changes: 5 additions & 5 deletions extra/tools/simer/build/package/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
# =============
FROM debian:bullseye-slim AS redis

ENV REDIS_VERSION 6.0.20
ENV REDIS_DOWNLOAD_URL http://download.redis.io/releases/redis-6.0.20.tar.gz
ENV REDIS_DOWNLOAD_SHA 173d4c5f44b5d7186da96c4adc5cb20e8018b50ec3a8dfe0d191dbbab53952f0
ENV REDIS_VERSION=6.0.20
ENV REDIS_DOWNLOAD_URL=http://download.redis.io/releases/redis-6.0.20.tar.gz
ENV REDIS_DOWNLOAD_SHA=173d4c5f44b5d7186da96c4adc5cb20e8018b50ec3a8dfe0d191dbbab53952f0


RUN set -eux; \
Expand Down Expand Up @@ -55,7 +55,7 @@ RUN set -eux; \

# Simer Builder
# =============
FROM golang:bullseye as simer
FROM golang:bullseye AS simer
ADD . /src
RUN cd /src && make build

Expand All @@ -66,7 +66,7 @@ RUN cd /src && make build
FROM debian:bullseye-slim
LABEL maintainer="[email protected]"

ENV DEBIAN_FRONTEND noninteractive
ENV DEBIAN_FRONTEND=noninteractive

RUN set -eux; \
groupadd -r -g 999 redis; \
Expand Down
10 changes: 10 additions & 0 deletions extra/tools/simer/internal/app/simer/simer.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,11 @@ func calculateEnv(stack *schema_kind.StackSpec, model *schema_kind.ModelInstance
if model != nil && model.Runtime != nil && model.Runtime.Env != nil {
for k, v := range *model.Runtime.Env {
env[k] = v
if *stack.Runtime.Stacked {
// For stacked models, add additional ENVAR prefixed with Model Name.
key := strings.ToUpper(fmt.Sprintf("%s__%s", model.Name, k))
env[key] = v
}
}
}
// Apply modifications (format MODEL:NAME=VAL).
Expand All @@ -357,6 +362,11 @@ func calculateEnv(stack *schema_kind.StackSpec, model *schema_kind.ModelInstance
}
if model.Name == k[0] {
env[k[1]] = m[1]
if stack.Runtime != nil && *stack.Runtime.Stacked {
// For stacked models, add additional ENVAR prefixed with Model Name.
key := strings.ToUpper(fmt.Sprintf("%s__%s", model.Name, k[1]))
env[key] = m[1]
}
}
}
return env
Expand Down
2 changes: 1 addition & 1 deletion tests/testscript/e2e/benchmark.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ done
-- run_benchmark.sh --
SIMER="${SIMER:-ghcr.io/boschglobal/dse-simer:latest}"
END_TIME="${END_TIME:-${DEFAULT_END_TIME}}"
docker run --name simer -i --rm -v $ENTRYDIR/$SIM:/sim \
docker run --name simer -i --rm -v $ENTRYHOSTDIR/$SIM:/sim \
$SIMER -valgrind $NAME \
-env $NAME:SIMBUS_LOGLEVEL=2 \
-endtime $END_TIME \
Expand Down
2 changes: 1 addition & 1 deletion tests/testscript/e2e/binary.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ stdout 'Message \(message\) : count is 46'

-- test.sh --
SIMER="${SIMER:-ghcr.io/boschglobal/dse-simer:latest}"
docker run --name simer -i --rm -v $ENTRYDIR/$SIM:/sim \
docker run --name simer -i --rm -v $ENTRYHOSTDIR/$SIM:/sim \
$SIMER -valgrind $NAME -env $NAME:SIMBUS_LOGLEVEL=2
2 changes: 1 addition & 1 deletion tests/testscript/e2e/extended.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ stdout 'SignalValue: 3940322353 = 1.000000 \[name=even\]'

-- test.sh --
SIMER="${SIMER:-ghcr.io/boschglobal/dse-simer:latest}"
docker run --name simer -i --rm -v $ENTRYDIR/$SIM:/sim \
docker run --name simer -i --rm -v $ENTRYHOSTDIR/$SIM:/sim \
$SIMER -valgrind $NAME -env $NAME:SIMBUS_LOGLEVEL=2
2 changes: 1 addition & 1 deletion tests/testscript/e2e/gateway.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ stdout '\[0.020000\] scalar\[1\] = 32.000000 \(scalar_bar\)'

-- test.sh --
SIMER="${SIMER:-ghcr.io/boschglobal/dse-simer:latest}"
docker run --name simer -i --rm -v $ENTRYDIR/$SIM:/sim \
docker run --name simer -i --rm -v $ENTRYHOSTDIR/$SIM:/sim \
$SIMER -env simbus:SIMBUS_LOGLEVEL=2 -timeout 5
4 changes: 2 additions & 2 deletions tests/testscript/e2e/minimal.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ stdout 'SignalValue: 2628574755 = 4.000000 \[name=counter\]'

-- test.sh --
SIMER="${SIMER:-ghcr.io/boschglobal/dse-simer:latest}"
docker run --name simer -i --rm -v $ENTRYDIR/$SIM:/sim \
$SIMER -valgrind $NAME -env $NAME:SIMBUS_LOGLEVEL=2
docker run --name simer -i --rm -v $ENTRYHOSTDIR/$SIM:/sim \
$SIMER -valgrind $NAME -env $NAME:SIMBUS_LOGLEVEL=2 -logger 2
6 changes: 3 additions & 3 deletions tests/testscript/e2e/ncodec.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,20 @@ stdout '\(ncodec_inst\) 0.001500 \[1:24:3\] RX 3eb 1 29 :'

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

-- test_trace_wildcard.sh --
SIMER="${SIMER:-ghcr.io/boschglobal/dse-simer:latest}"
docker run --name simer -i --rm -v $ENTRYDIR/$SIM:/sim \
docker run --name simer -i --rm -v $ENTRYHOSTDIR/$SIM:/sim \
$SIMER -valgrind $NAME \
-env $NAME:SIMBUS_LOGLEVEL=4 \
-env $NAME:NCODEC_TRACE_CAN_1=*

-- test_trace_framelist.sh --
SIMER="${SIMER:-ghcr.io/boschglobal/dse-simer:latest}"
docker run --name simer -i --rm -v $ENTRYDIR/$SIM:/sim \
docker run --name simer -i --rm -v $ENTRYHOSTDIR/$SIM:/sim \
$SIMER -valgrind $NAME \
-env $NAME:SIMBUS_LOGLEVEL=4 \
-env $NAME:NCODEC_TRACE_CAN_1=0x3ea,0x3eb
2 changes: 1 addition & 1 deletion tests/testscript/e2e/runtime.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ stdout 'Importer: Calling vtable.destroy\(\)'
-- test.sh --
SIMER="${SIMER:-ghcr.io/boschglobal/dse-simer:latest}"
docker run --name simer -i --rm \
-v $ENTRYDIR/$SIM:/sim \
-v $ENTRYHOSTDIR/$SIM:/sim \
--entrypoint="" $SIMER \
valgrind -q --leak-check=yes --error-exitcode=808 \
bin/importer lib/libruntime.so sim data/simulation.yaml target_inst
196 changes: 196 additions & 0 deletions tests/testscript/e2e/stack.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
# Operate from the WORKDIR (allocated by caller, i.e. docker command).
cd $WORKDIR
env SIM=sim
mkdir $SIM/lib $SIM/data
cp $REPODIR/dse/modelc/build/_out/examples/simer/lib/libcounter.so $SIM/lib/libcounter.so
cp $REPODIR/dse/modelc/build/_out/examples/simer/data/model.yaml $SIM/data/model.yaml
cp $WORK/simulation.yaml $SIM/data/simulation.yaml


# TEST: redispubsub
env SIMBUS_TRANSPORT=redispubsub
env SIMBUS_URI=redis://localhost:6379
env
exec ls -R $SIM
exec ls -R $WORK

exec sh -e $WORK/test.sh

stderr 'Using Valgrind'
stdout 'Transport: redispubsub'
stdout 'URI: redis://localhost:6379'
stdout 'signal_count : 3'
stdout 'uid=182894383, val=204.000000, final_val=204.000000, name=counter_A'
stdout 'uid=199672002, val=304.000000, final_val=304.000000, name=counter_B'
stdout 'uid=216449621, val=404.000000, final_val=404.000000, name=counter_C'
stdout 'counter counter_A = 205.000000'
stdout 'counter counter_B = 305.000000'
stdout 'counter counter_C = 405.000000'


# TEST: redis
env SIMBUS_TRANSPORT=redis
env SIMBUS_URI=redis://localhost:6379
env
exec ls -R $SIM
exec ls -R $WORK

exec sh -e $WORK/test.sh

stderr 'Using Valgrind'
stdout 'Transport: redis'
! stdout 'Transport: redispubsub'
stdout 'URI: redis://localhost:6379'
stdout 'signal_count : 3'
stdout 'uid=182894383, val=204.000000, final_val=204.000000, name=counter_A'
stdout 'uid=199672002, val=304.000000, final_val=304.000000, name=counter_B'
stdout 'uid=216449621, val=404.000000, final_val=404.000000, name=counter_C'
stdout 'counter counter_A = 205.000000'
stdout 'counter counter_B = 305.000000'
stdout 'counter counter_C = 405.000000'


# TEST: redisasync
env SIMBUS_TRANSPORT=redis
env SIMBUS_URI=redisasync://localhost:6379
env
exec ls -R $SIM
exec ls -R $WORK

exec sh -e $WORK/test.sh

stderr 'Using Valgrind'
stdout 'Transport: redis'
! stdout 'Transport: redispubsub'
stdout 'URI: redisasync://localhost:6379'
stdout 'signal_count : 3'
stdout 'uid=182894383, val=204.000000, final_val=204.000000, name=counter_A'
stdout 'uid=199672002, val=304.000000, final_val=304.000000, name=counter_B'
stdout 'uid=216449621, val=404.000000, final_val=404.000000, name=counter_C'
stdout 'counter counter_A = 205.000000'
stdout 'counter counter_B = 305.000000'
stdout 'counter counter_C = 405.000000'


# TEST: loopback
env SIMBUS_TRANSPORT=loopback
env SIMBUS_URI=loopback
env
exec ls -R $SIM
exec ls -R $WORK

exec sh -e $WORK/test-loopback.sh

stderr 'Using Valgrind'
stdout 'Transport: loopback'
stdout 'URI: loopback'
stdout 'signal_count : 3'
stdout 'uid=182894383, val=204.000000, final_val=204.000000, name=counter_A'
stdout 'uid=199672002, val=304.000000, final_val=304.000000, name=counter_B'
stdout 'uid=216449621, val=404.000000, final_val=404.000000, name=counter_C'
stdout 'counter counter_A = 205.000000'
stdout 'counter counter_B = 305.000000'
stdout 'counter counter_C = 405.000000'


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


-- test-loopback.sh --
SIMER="${SIMER:-ghcr.io/boschglobal/dse-simer:latest}"
docker run --name simer -i --rm -v $ENTRYWORKDIR/$SIM:/sim \
$SIMER -valgrind counter_A -simbus="" \
-env counter_A:SIMBUS_TRANSPORT=$SIMBUS_TRANSPORT \
-env counter_A:SIMBUS_URI=$SIMBUS_URI \
-env counter_B:SIMBUS_TRANSPORT=$SIMBUS_TRANSPORT \
-env counter_B:SIMBUS_URI=$SIMBUS_URI \
-env counter_C:SIMBUS_TRANSPORT=$SIMBUS_TRANSPORT \
-env counter_C:SIMBUS_URI=$SIMBUS_URI \
-env counter_C:SIMBUS_LOGLEVEL=2


-- simulation.yaml --
---
kind: Stack
metadata:
name: stacked
spec:
connection:
transport:
redis:
uri: redis://localhost:6379
timeout: 5
runtime:
env:
SIMBUS_LOGLEVEL: 4
stacked: true
models:
- name: simbus
model:
name: simbus
runtime:
env:
SIMBUS_LOGLEVEL: 2
channels:
- name: data_channel
expectedModelCount: 3
- name: counter_A
uid: 42
model:
name: Counter
runtime:
env:
COUNTER_NAME: counter_A
COUNTER_VALUE: 200
channels:
- name: data_channel
alias: data
- name: counter_B
uid: 43
model:
name: Counter
runtime:
env:
COUNTER_NAME: counter_B
COUNTER_VALUE: 300
channels:
- name: data_channel
alias: data
- name: counter_C
uid: 44
model:
name: Counter
runtime:
env:
COUNTER_NAME: counter_C
COUNTER_VALUE: 400
channels:
- name: data_channel
alias: data
---
kind: SignalGroup
metadata:
name: data
labels:
side: data
spec:
signals:
- signal: counter_A
- signal: counter_B
- signal: counter_C
---
kind: Model
metadata:
name: simbus
Loading

0 comments on commit 29cc8c7

Please sign in to comment.