matlab/agent-skills-playground / demos/requirements-based-verification/skills/simulink-test-sequence-from-ears
simulink-test-sequence-from-ears
VerifiedGenerate Simulink Test Sequence blocks and harnesses from EARS requirements. Use when asked to create a test case from a requirement, generate tests from a .slreqx file, or verify a Simulink model with requirement-based tests.
| File | Kind | Size |
|---|---|---|
| LICENSE.md | markdown | 1.4 KB |
| SKILL.md | skill md | 5.6 KB |
| references/workflow-details.md | markdown | 15.1 KB |
| scripts/addPreconditionSteps.m | other | 1.4 KB |
| scripts/analizeRequirements.m | other | 2.9 KB |
| scripts/analyzeRequirements.m | other | 279 B |
| scripts/buildHarnessesFromApprovedYaml.m | other | 6.7 KB |
| scripts/collectSkillContext.m | other | 29.7 KB |
| scripts/compileHarnessModel.m | other | 326 B |
| scripts/configureEventDriven.m | other | 1.8 KB |
| scripts/configureStateDriven.m | other | 1.9 KB |
| scripts/configureTestSequence.m | other | 1.6 KB |
| scripts/configureUbiquitous.m | other | 1.5 KB |
| scripts/configureUnwantedBehavior.m | other | 1.9 KB |
| scripts/generateMappingReviewFromRequirements.m | other | 29.7 KB |
| scripts/generateSignalMappingsFromYaml.m | other | 4.3 KB |
| scripts/generateTestSequencesFromRequirements.m | other | 4.7 KB |
| scripts/parseEARSPattern.m | other | 2.3 KB |
| scripts/prepareWritableBuildWorkspace.m | other | 1.5 KB |
| scripts/readMappingReviewYaml.m | other | 6.6 KB |
| scripts/writeMappingReviewYaml.m | other | 9.2 KB |
scripts/generateTestSequencesFromRequirements.m
View on GitHubfunction generateTestSequencesFromRequirements(modelName, signalMappings, varargin)
%GENERATETESTSEQUENCESFROMREQUIREMENTS Create test harnesses from approved signal mappings
%
% generateTestSequencesFromRequirements(MODELNAME, SIGNALMAPPINGS)
% generateTestSequencesFromRequirements(..., 'OutputFolder', PATH)
%
% Called in Phase 2 of the simulink-test-sequence-from-ears skill after
% the user approves the signal mapping summary from Phase 1.
%
% Inputs:
% modelName - Simulink model name (without .slx extension)
% signalMappings - Array of structs, one per requirement, with fields:
% .reqId - Requirement ID string (e.g., '17')
% .pattern - EARS pattern: 'Event-Driven', 'State-Driven',
% 'Unwanted Behavior', 'Ubiquitous', or 'Optional'
% .trigger - Trigger/condition text from requirement (used in comments)
% .behavior - Expected behavior text from requirement (used in comments)
% .init - MATLAB code string: signal initializations (preconditions)
% .preconditionSteps - Optional struct array with fields:
% .name, .action, .duration for multi-step state entry
% .stimulus - MATLAB code string: signal changes activating the requirement
% (empty string is accepted for Ubiquitous pattern)
% .verify - MATLAB code string: verify() statements checking outputs
%
% Outputs:
% Creates externally-saved test harness .slx files in a 'test_harnesses/'
% subfolder of the current directory, one per entry in signalMappings.
% When the owner model is writable, the harness association metadata is
% saved on the model under test.
%
% Example:
% signalMappings(1).reqId = '17';
% signalMappings(1).pattern = 'Event-Driven';
% signalMappings(1).trigger = 'the flight control system powers up';
% signalMappings(1).behavior = 'enter the Establish Communications mode';
% signalMappings(1).init = 'GCSCmds.WIFIconnected = false;';
% signalMappings(1).stimulus = '% power-up state — no comms yet';
% signalMappings(1).verify = 'verify(Logic.Mode == modeEnum.WaitForComms);';
% generateTestSequencesFromRequirements('ModeLogic', signalMappings);
parser = inputParser;
addParameter(parser, 'OutputFolder', fullfile(pwd, 'test_harnesses'), @(x) ischar(x) || isstring(x));
parse(parser, varargin{:});
outputFolder = char(parser.Results.OutputFolder);
modelFile = fullfile(pwd, [modelName '.slx']);
if ~exist(modelFile, 'file')
error('Model %s.slx not found. Add the model directory to the MATLAB path.', modelName);
end
if ~exist(outputFolder, 'dir')
mkdir(outputFolder);
end
if bdIsLoaded(modelName)
loadedFile = string(get_param(modelName, 'FileName'));
if loadedFile ~= string(modelFile)
close_system(modelName, 0);
end
end
load_system(modelFile);
for i = 1:numel(signalMappings)
sm = signalMappings(i);
reqId = sm.reqId;
pattern = sm.pattern;
fprintf('Processing REQ-%s (%s pattern)...\n', reqId, pattern);
harnessName = sprintf('%s_REQ%s_Harness', modelName, reqId);
harnessFile = fullfile(outputFolder, [harnessName '.slx']);
try
if bdIsLoaded(harnessName)
close_system(harnessName, 0);
end
sltest.harness.create(modelName, ...
'Name', harnessName, ...
'Source', 'Test Sequence', ...
'SaveExternally', true, ...
'HarnessPath', outputFolder);
% Harness must be open before sltest.testsequence APIs work
sltest.harness.open(modelName, harnessName);
tsBlockPath = [harnessName '/Test Sequence'];
configureTestSequence(tsBlockPath, reqId, pattern, sm.trigger, sm.behavior, sm);
save_system(harnessName);
fprintf(' Compiling harness model...\n');
compileHarnessModel(harnessName);
fprintf(' Harness compile check passed.\n');
sltest.harness.close(modelName, harnessName);
if strcmp(get_param(modelName, 'Dirty'), 'on')
save_system(modelName);
end
fprintf(' Created: %s\n', harnessFile);
catch ME
warning('Failed to create harness for REQ-%s: %s', reqId, ME.message);
try
sltest.harness.close(modelName, harnessName);
catch %#ok<CTCH>
end
end
end
if strcmp(get_param(modelName, 'Dirty'), 'on')
save_system(modelName);
end
fprintf('\nTest harness generation complete.\n');
fprintf('Output folder: %s\n', outputFolder);
end
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the work | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixes | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation code | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |