You typically end up being to sensitive to floating-point roundoff errors. This time, when the test finishes, SDI shows us how different the signals are:Īs we all know, doing bit-to-bit comparison with floating-point signals is usually a bad idea. We add the following function to our test file exampleTest.m to launch SDI and display a comparison in case the test fails.Īnd we specify this function as additional argument to verifyEqual
Let’s create a diagnostic that can help us visualize these signal mismatches rather than looking at a bunch of numbers. It could be a string or character array, function handle or object. So, how can we have better diagnostics? Luckily, qualification methods accept a user diagnostics for additional diagnosis. But as they say, an image is worth a thousand words. The failure diagnostics show a table with numerical mismatches. In case you were not aware, there are various math libraries implementing trigonometric functions in different ways, giving slightly different results.
To make this story more interesting, I purposely configured the generated code to link against a math library where the implementation of sin is slightly different than the one used by Simulink in normal mode. When ready, use the runtests function to run all the tests in exampleTest.m.Īs you can see, our test failed. We use verifyEqual from the MATLAB Unit Test qualification library to compare the results.In this case, this means closing the model. We use addTeardown to do the cleanup once the test is completed.
The function testEquivalence is our main test, it simulates the model in normal and SIL mode, and compares the results.