Skip to content

Commit

Permalink
Update the SimMock objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
timrulebosch committed Feb 5, 2024
1 parent 27d1bfe commit 47f447a
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 10 deletions.
4 changes: 2 additions & 2 deletions dse/mocks/examples/network/test_network.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static int test_setup(void** state)
static int test_teardown(void** state)
{
SimMock* mock = *state;
simmock_exit(mock);
simmock_exit(mock, false);
simmock_free(mock);
return 0;
}
Expand Down Expand Up @@ -74,7 +74,7 @@ void test_network__network2target2network(void** state)
}
/* Inject a message carrying the reset_counters signal. */
uint8_t buffer[8] = { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
simmock_write_frame(mock->sv_network_tx, "can_bus", buffer, 8, 0x1f0u);
simmock_write_frame(mock->sv_network_tx, "can_bus", buffer, 8, 0x1f0u, 0);
assert_int_equal(simmock_step(mock, true), 0);
/* 20ms */
{
Expand Down
23 changes: 19 additions & 4 deletions dse/mocks/simmock.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,16 +426,27 @@ int simmock_step(SimMock* mock, bool assert_rc)
simmock_exit
============
Call `model_exit()` for each model.
Call `model_destroy()` for each model.
Parameters
----------
mock (SimMock*)
: A SimMock object.
call_destroy (bool)
: Indicate that model_destroy() should be explicitly called. Set to `true` when
using the SimMock library outside of the ModelC repo (which has its own mock
object representing the controller).
*/
void simmock_exit(SimMock* mock)
void simmock_exit(SimMock* mock, bool call_destroy)
{
assert_non_null(mock);

if (call_destroy) {
for (ModelMock* model = mock->model; model->name; model++) {
modelc_destroy(model->mi);
}
}
modelc_exit(&mock->sim);
}

Expand Down Expand Up @@ -667,9 +678,12 @@ len (size_t)
frame_id (uint32_t)
: The Frame ID associated with the data.
frame_type (uint8_t)
: The Frame Type associated with the frame.
*/
void simmock_write_frame(SignalVector* sv, const char* sig_name, uint8_t* data,
size_t len, uint32_t frame_id)
size_t len, uint32_t frame_id, uint8_t frame_type)
{
assert_non_null(sv);
assert_true(sv->is_binary);
Expand All @@ -686,7 +700,8 @@ void simmock_write_frame(SignalVector* sv, const char* sig_name, uint8_t* data,
char* node_id_save = __get_ncodec_node_id(nc);
__set_ncodec_node_id(nc, (char*)"42");
ncodec_write(nc, &(struct NCodecCanMessage){
.frame_id = frame_id, .len = len, .buffer = data });
.frame_id = frame_id, .frame_type = frame_type,
.len = len, .buffer = data });
ncodec_flush(nc);
__set_ncodec_node_id(nc, node_id_save);
free(node_id_save);
Expand Down
4 changes: 2 additions & 2 deletions dse/mocks/simmock.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ void simmock_load_model_check(ModelMock* model, bool expect_create_func,
bool expect_step_func, bool expect_destroy_func);
void simmock_setup(SimMock* mock, const char* sig_name, const char* net_name);
int simmock_step(SimMock* mock, bool assert_rc);
void simmock_exit(SimMock* mock);
void simmock_exit(SimMock* mock, bool call_destroy);
ModelMock* simmock_find_model(SimMock* mock, const char* name);
void simmock_write_frame(SignalVector* sv, const char* sig_name, uint8_t* data,
size_t len, uint32_t frame_id);
size_t len, uint32_t frame_id, uint8_t frame_type);
uint32_t simmock_read_frame(
SignalVector* sv, const char* sig_name, uint8_t* data, size_t len);
void simmock_free(SimMock* mock);
Expand Down
20 changes: 20 additions & 0 deletions dse/modelc/controller/modelc_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,23 @@ int modelc_step(ModelInstanceSpec* model_instance, double step_size)
double model_time = 0.0;
return step_model(model_instance, &model_time);
}


/**
* modelc_destroy
*
* Bypass the controller and call model_destroy() directly.
*
* Parameters
* ----------
* model_instance : ModelInstanceSpec (pointer to)
* The model instance, which holds references to the registered channels
* and model functions. step_size : double The duration simulation step to be
* performed (in seconds).
*/
void modelc_destroy(ModelInstanceSpec* mi)
{
if (mi->model_desc->vtable.destroy == NULL) return;
mi->model_desc->vtable.destroy(mi->model_desc);
mi->model_desc->vtable.destroy = NULL;
}
3 changes: 2 additions & 1 deletion dse/modelc/runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ DLL_PUBLIC int modelc_model_create(


/* modelc_debug.c - Debug Interface. */
DLL_PUBLIC int modelc_step(ModelInstanceSpec* model_instance, double step_size);
DLL_PUBLIC int modelc_step(ModelInstanceSpec* mi, double step_size);
DLL_PUBLIC void modelc_destroy(ModelInstanceSpec* mi);


/* modelc_args.c - CLI argument parsing routines. */
Expand Down
2 changes: 1 addition & 1 deletion tests/cmocka/model/interface/test_model_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ static int test_teardown(void** state)
{
SimMock* mock = *state;

simmock_exit(mock);
simmock_exit(mock, false);
simmock_free(mock);

chdir(__entry_path__);
Expand Down

0 comments on commit 47f447a

Please sign in to comment.