Skip to content

Commit

Permalink
Add support for signal with annotation 'internal' which are skipped b…
Browse files Browse the repository at this point in the history
…y framework.

Signed-off-by: Timothy Rule (VM/EMT3) <[email protected]>
  • Loading branch information
timrulebosch committed Oct 10, 2024
1 parent 8637bab commit 77cb20f
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 0 deletions.
8 changes: 8 additions & 0 deletions dse/modelc/model/model.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@ static int _signal_group_match_handler(
&index, schema_signal_object_generator);
if (so == NULL) break;
if (so->signal) {
/* Internal signals are skipped. */
bool internal = false;
dse_yaml_get_bool(so->data, "internal", &internal);
if (internal) {
free(so);
continue;
}

/* Signals are taken in parsing order. */
hashlist_append(&__handler_signal_list, (void*)so->signal);

Expand Down
1 change: 1 addition & 0 deletions tests/cmocka/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ install(TARGETS test_model)
install(
FILES
model/gateway.yaml
model/internal.yaml
model/ncodec.yaml
model/signal.yaml
model/transform.yaml
Expand Down
56 changes: 56 additions & 0 deletions tests/cmocka/model/internal.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
kind: Stack
metadata:
name: stack
spec:
connection:
transport:
redispubsub:
uri: redis://redis:6379
timeout: 60
models:
- name: internal
uid: 42
model:
name: Internal
channels:
- name: scalar
alias: scalar_vector
---
kind: Model
metadata:
name: Internal
spec:
runtime:
dynlib:
- os: linux
arch: amd64
path: lib/model.so
channels:
- alias: scalar_vector
selectors:
channel: scalar
---
kind: SignalGroup
metadata:
name: test_signal_internal
labels:
channel: scalar
spec:
signals:
- signal: one
- signal: two
internal: false
- signal: three
internal: 0
- signal: four
internal: true
- signal: five
internal: 1
- signal: six
internal: on
- signal: seven
internal: two
- signal: eight
internal: off

83 changes: 83 additions & 0 deletions tests/cmocka/model/test_signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,36 @@ static int test_setup(void** state)
}


static int test_setup_internal(void** state)
{
ModelCMock* mock = calloc(1, sizeof(ModelCMock));
assert_non_null(mock);

int rc;
ModelCArguments args;
char* argv[] = {
(char*)"test_internal",
(char*)"--name=internal",
(char*)"resources/model/internal.yaml",
};

modelc_set_default_args(&args, "test", 0.005, 0.005);
args.log_level = __log_level__;
modelc_parse_arguments(&args, ARRAY_SIZE(argv), argv, "Signal");
rc = modelc_configure(&args, &mock->sim);
assert_int_equal(rc, 0);
mock->mi = modelc_get_model_instance(&mock->sim, args.name);
assert_non_null(mock->mi);
ModelVTable vtable = { .step = _sv_nop };
rc = modelc_model_create(&mock->sim, mock->mi, &vtable);
assert_int_equal(rc, 0);

/* Return the mock. */
*state = mock;
return 0;
}


static int test_teardown(void** state)
{
ModelCMock* mock = *state;
Expand Down Expand Up @@ -458,6 +488,58 @@ void test_signal__binary_echo(void** state)
}


typedef struct InternalTC {
const char* s;
bool internal;
} InternalTC;

void test_signal__internal(void** state)
{
ModelCMock* mock = *state;
ModelDesc* m = mock->mi->model_desc;
SignalVector* sv_save = mock->mi->model_desc->sv;

assert_non_null(m);
assert_non_null(m->index);

/* find the indexes. */
SignalVector* sv = sv_save;
while (sv && sv->name) {
if (strcmp(sv->name, "scalar") == 0) break;
/* Next signal vector. */
sv++;
}

InternalTC tc[] = {
{ .s = "one", .internal = false, },
{ .s = "two", .internal = false, },
{ .s = "three", .internal = false, },
{ .s = "four", .internal = true, },
{ .s = "five", .internal = false, },
{ .s = "six", .internal = true, },
{ .s = "seven", .internal = false, },
{ .s = "eight", .internal = false, },
};
// Check the test cases.
for (size_t i = 0; i < ARRAY_SIZE(tc); i++) {
ModelSignalIndex msi = signal_index(m, "scalar_vector", tc[i].s);
if (tc[i].internal == false) {
/* Signal should exist. */
if (msi.sv == NULL) assert_string_equal(tc[i].s, "should NOT be internal");
assert_non_null(msi.sv);
assert_non_null(msi.scalar);
assert_null(msi.binary);
} else {
/* Signal should NOT exist. */
if (msi.sv) assert_string_equal(tc[i].s, "should be internal");
assert_null(msi.sv);
assert_null(msi.scalar);
assert_null(msi.binary);
}
}
}


int run_signal_tests(void)
{
void* s = test_setup;
Expand All @@ -470,6 +552,7 @@ int run_signal_tests(void)
cmocka_unit_test_setup_teardown(test_signal__annotations, s, t),
cmocka_unit_test_setup_teardown(test_signal__group_annotations, s, t),
cmocka_unit_test_setup_teardown(test_signal__binary_echo, s, t),
cmocka_unit_test_setup_teardown(test_signal__internal, test_setup_internal, t),
};

return cmocka_run_group_tests_name("SIGNAL", tests, NULL, NULL);
Expand Down

0 comments on commit 77cb20f

Please sign in to comment.