Skip to content

Commit

Permalink
New SimMock code library for Model developers.
Browse files Browse the repository at this point in the history
Code library for developing integration test cases.

Signed-off-by: Rule Timothy (CC/EMT2) <[email protected]>
  • Loading branch information
timrulebosch committed Nov 29, 2023
1 parent 34f5cab commit 9352943
Show file tree
Hide file tree
Showing 22 changed files with 1,735 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
PACKAGE_ARCH: ${{ matrix.package_arch }}
run: |
make test_cmocka
- name: Stats
run: |
ccache -s -v || true
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export DSE_SCHEMA_URL ?= $(DSE_SCHEMA_REPO)/releases/download/v$(DSE_SCHEMA_VERS
###############
## DSE C Library.
DSE_CLIB_REPO ?= https://github.com/boschglobal/dse.clib
DSE_CLIB_VERSION ?= 1.0.4
DSE_CLIB_VERSION ?= 1.0.5
export DSE_CLIB_URL ?= $(DSE_CLIB_REPO)/archive/refs/tags/v$(DSE_CLIB_VERSION).zip


Expand Down
9 changes: 8 additions & 1 deletion doc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,16 @@ DOC_OUTPUT_schema := doc/content/apis/modelc/schema/index.md
DOC_LINKTITLE_schema := Schema
DOC_TITLE_schema := "Schema API Reference"

# Module "simmock"
DOC_INPUT_simmock := dse/modelc/mocks/simmock.h
DOC_CDIR_simmock := dse/modelc/mocks/simmock.c
DOC_OUTPUT_simmock := doc/content/apis/modelc/simmock/index.md
DOC_LINKTITLE_simmock := SimMock
DOC_TITLE_simmock := "SimMock API Reference"


# Targets
DOC_C_MODULES := gateway mcl model schema
DOC_C_MODULES := gateway mcl model schema simmock
#DOC_C_MODULES := model

.PHONY: examples
Expand Down
28 changes: 28 additions & 0 deletions doc/content/apis/modelc/examples/simmock_configure.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <dse/testing.h>
#include <dse/modelc/mocks/simmock.h>

int test_setup(void** state)
{
const char* inst_names[] = {
"target_inst",
"network_inst",
};
char* argv[] = {
(char*)"test_runnable",
(char*)"--name=target_inst;network_inst",
(char*)"--logger=5", // 1=debug, 5=QUIET (commit with 5!)
(char*)"../../../../tests/cmocka/network/stack.yaml",
(char*)"../../../../tests/cmocka/network/signalgroup.yaml",
(char*)"../../../../tests/cmocka/network/network.yaml",
(char*)"../../../../tests/cmocka/network/model.yaml",
(char*)"../../../../tests/cmocka/network/runnable.yaml",
};
SimMock* mock = simmock_alloc(inst_names, ARRAY_SIZE(inst_names));
simmock_configure(mock, argv, ARRAY_SIZE(argv), ARRAY_SIZE(inst_names));
simmock_load(mock, true);
simmock_setup(mock, "signal", "network");

/* Return the mock. */
*state = mock;
return 0;
}
21 changes: 21 additions & 0 deletions doc/content/apis/modelc/examples/simmock_frame_check.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <dse/testing.h>
#include <dse/modelc/mocks/simmock.h>

void test_network__frame_check(void** state)
{
SimMock* mock = *state;

/* 0ms - initial tick, Rx consumed, Tx of initial content. */
{
for (uint32_t i = 0; i < 1; i++) {
assert_int_equal(simmock_step(mock, true), 0);
}
FrameCheck f_checks[] = {
{ .frame_id = 0x1f3u, .offset = 0, .value = 0x01 },
{ .frame_id = 0x1f4u, .offset = 1, .value = 0x02 },
{ .frame_id = 0x1f5u, .offset = 4, .value = 0x02 },
};
simmock_print_network_frames(mock, LOG_DEBUG);
simmock_frame_check(mock, "network_inst", "can_bus", f_checks, ARRAY_SIZE(f_checks));
}
}
25 changes: 25 additions & 0 deletions doc/content/apis/modelc/examples/simmock_signal_check.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <dse/testing.h>
#include <dse/modelc/mocks/simmock.h>

#define SIG_task_init_done 1
#define SIG_task_5_active 2
#define SIG_task_5_counter 6

void test_network__signal_check(void** state)
{
SimMock* mock = *state;

/* 0ms - initial tick, Rx consumed, Tx of initial content. */
{
for (uint32_t i = 0; i < 1; i++) {
assert_int_equal(simmock_step(mock, true), 0);
}
SignalCheck s_checks[] = {
{ .index = SIG_task_init_done, .value = 1.0 },
{ .index = SIG_task_5_active, .value = 0.0 },
{ .index = SIG_task_5_counter, .value = 0.0 },
};
simmock_print_scalar_signals(mock, LOG_DEBUG);
simmock_signal_check(mock, "network_inst", s_checks, ARRAY_SIZE(s_checks), NULL);
}
}
2 changes: 2 additions & 0 deletions doc/content/apis/modelc/model/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ typedef struct SignalVector {
BinarySignalResetFunc reset;
BinarySignalReleaseFunc release;
SignalAnnotationGetFunc annotation;
BinarySignalCodecFunc codec;
ModelInstanceSpec * mi;
}
```
Expand All @@ -229,6 +230,7 @@ typedef struct SignalVectorVTable {
BinarySignalResetFunc reset;
BinarySignalReleaseFunc release;
SignalAnnotationGetFunc annotation;
BinarySignalCodecFunc codec;
}
```

Expand Down
Loading

0 comments on commit 9352943

Please sign in to comment.