function LoadTest(case_name) evalin('base', 'clear all'); caseFile = [case_name '_Case.json']; test_case = jsondecode(fileread(caseFile)); %读取测试用例文件 target_model = test_case.Model.name; connectionFile = test_case.Model.connection_file; % 初始化模型 load_system(target_model); % scopes = find_system(target_model, 'FindAll', 'on', 'BlockType', 'Scope'); % CommentBlocks(scopes, 1); evalin('base', test_case.Model.init); % 获取模型测试接口 ports = LoadModelPorts(target_model); % 初始化注入信号 % 默认物理信号为0,使能直通 for i = 1:length(ports.Physical) SetPortSignal(ports.Physical(i), 0); SetPortThrough(ports.Physical(i), 1); SetPortEnable(ports.Physical(i), 1); end % 默认软件信号为0,关闭直通 for i = 1:length(ports.Software) SetPortSignal(ports.Software(i), 0); SetPortThrough(ports.Software(i), 0); SetPortEnable(ports.Software(i), 0); end % 加载注入信号 test_connection = jsondecode(fileread(connectionFile)); %读取连接文件 % 应用模型注入信号 for i = 1:length(test_case.Injections) ApplyInjection(test_case.Injections(i), test_connection, ports); end % 应用模型初始化信号 for i = 1:length(test_case.Initializations) ApplyInit(test_case.Initializations(i), test_connection) end %% 运行模型 if isfield(test_case.Model, 'config') for i = 1:length(test_case.Model.config) set_param(target_model, test_case.Model.config(i).name, test_case.Model.config(i).value); end end end