How to Assert Simulink S-Function Called from Test Harness?

6 次查看(过去 30 天)
Hi, I am using Simulink Test to test a Simulink model. Within the model, it calls external functions using S-Functions. Is there a way to verify that the function was called, and with which parameters?
For example, if I had an S-Function with the inputs int8, and boolean, within Simulink test I would love to have a function such as:
assertCalled('externalFunction', 8, true);
Which would return true if the externalFunction mask was called with the parameters 8 and true. Otherwise it would return false.
I'm aware that within the Matlab Mock library, there is a similar fuction. However, I am unsure of how to use this in conjunction with Simulink tests. (It seems to be intended for matlab only). Is there any way to use this, or a similar function to see if the S-Function is called?

回答(1 个)

Pratyush
Pratyush 2023-10-25
Hi em,
I understand that you want a way to verify the external function called and the parameters passed to it, in Simulink Test.
Although the MATLAB Mock library is primarily intended for MATLAB functions, you can still use it to mock the external function and verify its calls through MATLAB Function Block. You can refer to the following documentation for more details on MATLAB function block: https://in.mathworks.com/help/simulink/ug/what-is-a-matlab-function-block.html
Here's how you can do it:
  1. Create a MATLAB function that wraps the external function you want to test. Let's call it myExternalFunctionWrapper. This function takes the same inputs as the external function and calls it internally.
  2. In your Simulink model, replace the S-Function block that calls the external function with a MATLAB Function block. Inside this block, call the "myExternalFunctionWrapper" function instead.
  3. In your Simulink Test test case, you can use the MATLAB Mock library to mock the "myExternalFunctionWrapper" function. This allows you to verify if it was called with the expected parameters.
Hope this workaround helps.

类别

Help CenterFile Exchange 中查找有关 Test Execution 的更多信息

产品


版本

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by