diff --git a/dse/network/examples/stub/simulation.yaml b/dse/network/examples/stub/simulation.yaml index 6b5f2a5..f1f21e9 100644 --- a/dse/network/examples/stub/simulation.yaml +++ b/dse/network/examples/stub/simulation.yaml @@ -49,6 +49,8 @@ spec: - signal: temperature - signal: schedule_signal - signal: foo_double + - signal: foo + - signal: alive --- kind: SignalGroup metadata: diff --git a/dse/network/function.c b/dse/network/function.c index 743c7b1..9e2debf 100644 --- a/dse/network/function.c +++ b/dse/network/function.c @@ -41,6 +41,8 @@ int network_function_apply_encode(Network* network) /* Trigger update of signals based on changed payload. */ nm_p->update_signals = true; nm_p->unpack_func(nm_p->buffer, nm_p->payload, nm_p->payload_len); + /* Set the buffer checksum to prevent subsequent Tx. */ + nm_p->buffer_checksum = simbus_generate_uid_hash(nm_p->buffer, nm_p->buffer_len); } } diff --git a/tests/cmocka/mstep/test_mstep.c b/tests/cmocka/mstep/test_mstep.c index aaaebe8..e884080 100644 --- a/tests/cmocka/mstep/test_mstep.c +++ b/tests/cmocka/mstep/test_mstep.c @@ -63,7 +63,7 @@ void test_mstep(void** state) assert_non_null(model->sv_signal); assert_string_equal(model->sv_signal->name, "signal"); - assert_int_equal(model->sv_signal->count, 5); + assert_int_equal(model->sv_signal->count, 7); assert_non_null(model->sv_signal->scalar); assert_non_null(model->sv_network); assert_string_equal(model->sv_network->name, "network"); @@ -111,7 +111,7 @@ void test_mstep(void** state) %02x %02x %02x\n", buffer[i+0], buffer[i+1], buffer[i+2], buffer[i+3], buffer[i+4], buffer[i+5], buffer[i+6], buffer[i+7]); }*/ - size_t C_len = 0x62; + size_t C_len = 0x62; uint8_t C_buf[0x62]; memcpy(C_buf, model->sv_network->binary[0], C_len); C_buf[53] = 0x42; @@ -144,8 +144,88 @@ void test_mstep(void** state) void test_mstep_message_function(void** state) { - UNUSED(state); - skip(); +#define MSG_NF_NAME "function_example" +#define MSG_NF_FRAME_ID 0x1f2 +#define MSG_NF_FRAME_SIG_OFFSET 2 +#define MSG_NF_SIG_NAME "foo" // uint8_t +#define MSG_NF_SIG_IDX 5 +#define MSG_NF_ALIVE_NAME "alive" // uint8_t +#define MSG_NF_ALIVE_IDX 6 +#define NETWORK_NAME "stub_inst" +#define NETWORK_SIG "can" + + SimMock* mock = *state; + ModelMock* network_model = &mock->model[0]; + assert_non_null(network_model); + assert_true(MSG_NF_SIG_IDX < mock->sv_signal->count); + assert_true(MSG_NF_ALIVE_IDX < mock->sv_signal->count); + + /* 0-5ms */ + { + for (uint32_t i = 0; i < 10; i++) { + assert_int_equal(simmock_step(mock, true), 0); + assert_int_equal(network_model->sv_network->length[0] > 0, + false); // can_bus has no data. + } + } + /* 5.5ms - Set a signal value. */ + { + mock->sv_signal->scalar[MSG_NF_SIG_IDX] = 4; + assert_int_equal(simmock_step(mock, true), 0); + assert_int_equal(network_model->sv_network->length[0] > 0, + true); // can_bus has data. + SignalCheck s_checks[] = { + { .index = MSG_NF_SIG_IDX, .value = 4.0 }, + { .index = MSG_NF_ALIVE_IDX, .value = 1.0 }, + }; + simmock_print_scalar_signals(mock, LOG_DEBUG); + simmock_signal_check( + mock, NETWORK_NAME, s_checks, ARRAY_SIZE(s_checks), NULL); + } + /* 5.5-10ms - stable, no value change, no Tx*/ + { + for (uint32_t i = 0; i < 9; i++) { + assert_int_equal(simmock_step(mock, true), 0); + assert_int_equal(network_model->sv_network->length[0] > 0, + false); // can_bus has no data. + SignalCheck s_checks[] = { + { .index = MSG_NF_SIG_IDX, .value = 4.0 }, + { .index = MSG_NF_ALIVE_IDX, .value = 1.0 }, + }; + simmock_print_scalar_signals(mock, LOG_DEBUG); + simmock_signal_check( + mock, NETWORK_NAME, s_checks, ARRAY_SIZE(s_checks), NULL); + } + } + /* 10.5ms - Set a signal value. */ + { + mock->sv_signal->scalar[MSG_NF_SIG_IDX] = 6; + assert_int_equal(simmock_step(mock, true), 0); + assert_int_equal(network_model->sv_network->length[0] > 0, + true); // can_bus has data. + SignalCheck s_checks[] = { + { .index = MSG_NF_SIG_IDX, .value = 6.0 }, + { .index = MSG_NF_ALIVE_IDX, .value = 2.0 }, + }; + simmock_print_scalar_signals(mock, LOG_DEBUG); + simmock_signal_check( + mock, NETWORK_NAME, s_checks, ARRAY_SIZE(s_checks), NULL); + } + /* 10.5-15ms - stable, no value change, no Tx*/ + { + for (uint32_t i = 0; i < 9; i++) { + assert_int_equal(simmock_step(mock, true), 0); + assert_int_equal(network_model->sv_network->length[0] > 0, + false); // can_bus has no data. + SignalCheck s_checks[] = { + { .index = MSG_NF_SIG_IDX, .value = 6.0 }, + { .index = MSG_NF_ALIVE_IDX, .value = 2.0 }, + }; + simmock_print_scalar_signals(mock, LOG_DEBUG); + simmock_signal_check( + mock, NETWORK_NAME, s_checks, ARRAY_SIZE(s_checks), NULL); + } + } } @@ -162,6 +242,7 @@ int run_mstep_tests(void) const struct CMUnitTest tests[] = { cmocka_unit_test_setup_teardown(test_mstep, s, t), + cmocka_unit_test_setup_teardown(test_mstep_message_function, s, t), }; return cmocka_run_group_tests_name("MSTEP", tests, NULL, NULL);