Skip to content

Commit

Permalink
Fix repeated transmission of frames due to stale buffer checksum.
Browse files Browse the repository at this point in the history
  • Loading branch information
timrulebosch committed May 6, 2024
1 parent 5c23174 commit 3b06377
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 4 deletions.
2 changes: 2 additions & 0 deletions dse/network/examples/stub/simulation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ spec:
- signal: temperature
- signal: schedule_signal
- signal: foo_double
- signal: foo
- signal: alive
---
kind: SignalGroup
metadata:
Expand Down
2 changes: 2 additions & 0 deletions dse/network/function.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
89 changes: 85 additions & 4 deletions tests/cmocka/mstep/test_mstep.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
}


Expand All @@ -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);
Expand Down

0 comments on commit 3b06377

Please sign in to comment.