Creating Boundary Value Tests for Simulink Models with MATLAB Scripts

In model validation, boundary value testing is crucial for ensuring system robustness. Automating the generation of boundary value test cases using MATLAB scripts can efficiently uncover abnormal behaviors of the model under extreme parameter conditions, especially suitable for control system design and embedded code generation. This article will systematically introduce the technical implementation and engineering practices.

📌 1. Core Concepts of Boundary Value Testing

Boundary value testing focuses on critical conditions of input/output parameters, including:

– Input signal boundaries: Minimum/maximum values of sensor signals, moments of step changes.

– Parameter boundaries: Extreme values of controller gain, integral limits, filter cutoff frequencies, etc.

– State variable boundaries: Saturation constraints of system states (e.g., integrator outputs).

– Output signal boundaries: Physical limits of actuator commands or logical output enumeration extremes.

🚀 2. Script Process for Creating Boundary Value Test Cases

1. Establish the test framework and test harness

harnessName = 'boundaryTestHarness';
sltest.harness.create('modelName', 'HarnessName', harnessName, ...
    'Source', 'Inport', 'Sink', 'Outport');

Key parameters:

– Source / Sink: Bind input/output ports to isolate the model under test.

2. Define the boundary value data set

% Input signal boundaries
inputBounds.signal1 = [-10, 0, 10]; % Minimum, typical, maximum values
% Model parameter boundaries
paramBounds.gain = [0.1, 1, 10];

3. Configure parameter overrides

testCase = sltest.testmanager.TestCase('boundaryTest');
testCase.ParameterOverrides = {'gain = 0.1'}; % Set minimum gain

4. Set baseline criteria and tolerances

baseline = testCase.BaselineCriteria;
baseline.addSignal('modelName/Outport', 'AbsTol', 0.01, 'RelTol', 0.001);

5. Execute tests and collect results

resultSet = sltest.testmanager.run();
sltest.testmanager.report(resultSet, 'BoundaryTestReport.pdf', ...
    'IncludeSimulationSignalPlots', true);

💡 3. Advanced Techniques and Applications

1. Integrate with Simulink Design Verifier

[dvResults, ~] = sldvrun('modelName', 'Auto', 'on');
sltest.testmanager.import('DataFile', 'sldv_output.mat');

Value: Automatically generate supplementary test cases to enhance boundary coverage completeness.

2. Manage test cases with Excel templates

sltest.testmanager.createSpreadsheetTemplate('boundaryTestTemplate.xlsx', ...
    'Model', 'modelName', 'Harness', harnessName);
testCase = sltest.testmanager.importTestCases('boundaryTestTemplate.xlsx');

Advantage: Facilitates version management and team sharing.

3. Stability verification

[outputData, time] = getSimulationOutput(resultSet, 1);
overshoot = max(outputData) - steadyStateValue;
outOfBounds = any(outputData > upperLimit | outputData < lowerLimit);

Focus: Oscillation, integral saturation, logical jitter.

⚠️ 4. Practical Recommendations and Common Issues

1. Atomic subsystem settings: Ensure the subsystem under test is set to “Atomic” to generate standalone code.

2. Floating-point precision: Use tolerance comparisons (AbsTol / RelTol) to avoid false positives.

3. Requirement traceability: Link test cases to requirement IDs to comply with standards such as ISO 26262.

4. Continuous integration: Integrate into CI/CD pipelines for automatic testing of model changes.

🌟 Summary

Automating boundary value testing with MATLAB scripts can significantly enhance model reliability:

– Process automation: Full scripting of test harness creation, parameter overrides, and result analysis;

– Coverage improvement: Combining Design Verifier and Excel templates to enhance boundary coverage;

– Engineering value: Ensuring robustness of control systems, providing assurance for code generation and system integration.

Leave a Comment