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

조회 수: 6 (최근 30일)
em
em 2022년 6월 20일
답변: Pratyush 2023년 10월 25일
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