Bläddra i källkod

feat:删除复制的子模块

CN\guohui27 2 år sedan
förälder
incheckning
bb6222b4c1

+ 0 - 0
tests/sim/automation/.gitignore


+ 0 - 7
tests/sim/automation/ApplyInit.m

@@ -1,7 +0,0 @@
-function ApplyInit(initvars, connections)
-% 设置模型初始化变量
-    [t, n] = SelectConnection(initvars.tag, connections);
-    if (t == 'v')
-        assignin('base', n, initvars.value);
-    end
-end

+ 0 - 34
tests/sim/automation/ApplyInjection.m

@@ -1,34 +0,0 @@
-function ApplyInjection(injection, connection, modelPorts)
-%SET_INJ 设置注入信号
-%   
-    [conn_type, conn_name] = SelectConnection(injection.tag, connection);
-    if conn_type == 's' || conn_type == 'p'
-        if conn_type == 's'
-            ch = SelectPort(modelPorts.Software, conn_name);
-        elseif conn_type == 'p'
-            ch = SelectPort(modelPorts.Physical, conn_name);
-        end
-        SetPortSignal(ch, ConstructSignal(injection.time, injection.value));
-        SetPortEnable(ch, injection.enable');
-        if isfield(injection.option, 'through')
-            SetPortThrough(ch, injection.option.through);
-        end
-        if isfield(injection.option, 'interpolation')
-            SetPortInterpolation(ch, injection.option.interpolation);
-        end
-    end
-end
-
-function Signal = ConstructSignal(time, value)
-    if length(time) == 1
-        if time == 0
-            Signal = value;
-        else
-           Signal = [0 0; time value]; 
-        end
-    else
-        Signal = [time value];
-    end
-end
-
-

BIN
tests/sim/automation/AutomationPortLib.slx


+ 0 - 13
tests/sim/automation/CommentBlocks.m

@@ -1,13 +0,0 @@
-function CommentBlocks(handles, out)
-%COMMENTOUTBLOCKS 此处显示有关此函数的摘要
-%   此处显示详细说明
-for i = 1:length(handles)
-    if out == 1
-        set_param(handles(i), 'Commented', 'on');
-    else
-        set_param(handles(i), 'Commented', 'off');
-    end
-end
-
-end
-

+ 0 - 100
tests/sim/automation/ConditionCheck.m

@@ -1,100 +0,0 @@
-function [result, msg] = ConditionCheck(check)
-
-result = 0;
-msg = '';
-
-if check.fdb.Length < 2
-    msg = 'Not enough data to verify condition';
-    return;
-end
-
-if check.tolerance <= 0
-    msg = 'Invalid tolerance setting';
-    return;
-end
-
-if check.ref.Time(1) > 0
-    check.ref = addsample(check.ref, 'Data', 0, 'Time', 0);
-end
-
-if check.ref.Time(end) < check.fdb.Time(end)
-    check.ref = addsample(check.ref, 'Data', check.ref.Data(end), 'Time', check.fdb.Time(end));
-end
-
-if check.preprocess == 0
-    % 不需要对数据进行预处理
-    if isa(check.time, 'double') || isa(check.time, 'char')
-        if isa(check.time, 'char')
-            test_time = check.fdb.Time(end);
-        else
-            test_time = check.time;
-        end
-        
-        if max(test_time) > check.fdb.Time(end)
-            msg = 'Check time out of range';
-            return;
-        end
-        if check.refIntp
-            check.ref_cmp = resample(check.ref, test_time);
-        else
-            check.ref_cmp = resample(check.ref, test_time, 'zoh');
-        end
-        if check.fdbIntp
-            check.fdb_cmp = resample(check.fdb, test_time);
-        else
-            check.fdb_cmp = resample(check.fdb, test_time, 'zoh');
-        end
-        res = check.condition.Test(check.ref_cmp.Data, check.fdb_cmp.Data, check.tolerance);
-        if all(res)
-            result = 1;
-            msg = sprintf('[%s]: [%s] [%s] check passed', check.tag, check.fdb_name, check.condition.Name);
-            return;
-        else
-            fail = not(res);
-            fail_index = find(fail);
-            result = 0;
-            msg = sprintf('[%s]: [%s] [%s] check failed at time {%s}: Expected {%s}; Get {%s}', check.tag, check.fdb_name, check.condition.Name, mat2str(test_time(fail_index)), mat2str(check.ref_cmp.Data(fail_index)),  mat2str(check.fdb_cmp.Data(fail_index)));
-            return;
-        end
-    else
-        result = 0;
-        msg = 'Invalid check time setting';
-        return;
-    end
-else
-    % 需要对数据进行预处理,即检查时间段内的情况
-    test_time = check.fdb.time(find(and(check.fdb.Time > check.time(1), check.fdb.Time > check.time(1))));
-    if check.refIntp
-        check.ref_cmp = resample(check.ref, test_time);
-    else
-        check.ref_cmp = resample(check.ref, test_time, 'zoh');
-    end
-    if check.fdbIntp
-        check.fdb_cmp = resample(check.fdb, test_time);
-    else
-        check.fdb_cmp = resample(check.fdb, test_time, 'zoh');
-    end
-    switch (check.adv)
-        case {'A', 'Always'}
-            res = check.condition.Test(check.ref_cmp.Data, check.fdb_cmp.Data, check.tolerance);
-        case {'R', 'RMS'}
-        case {'M', 'Mean'}
-            res = check.condition.Test(mean(check.ref_cmp), mean(check.fdb_cmp), check.tolerance);
-        case {'P', 'Peak2Peak'}
-            res = check.condition.Test(check.ref_cmp.Data(1), max(check.fdb_cmp) - min(check.fdb_cmp), check.tolerance);
-    end
-    if all(res)
-        result = 1;
-        msg = sprintf('[%s]: [%s] [%s] check passed', check.tag, check.fdb_name, check.condition.Name);
-        return;
-    else
-        fail = not(res);
-        fail_index = find(fail);
-        result = 0;
-        msg = sprintf('[%s]: [%s] [%s-%s] check failed in duration {%s}: Expected {%s}; Get {%s}', check.tag, check.fdb_name, check.adv, check.condition.Name, mat2str(check.time), mat2str(check.ref_cmp.Data(fail_index(1))),  mat2str(check.fdb_cmp.Data(fail_index(1))));
-        return;
-    end     
-end
-
-
-end

+ 0 - 18
tests/sim/automation/LoadModelPorts.m

@@ -1,18 +0,0 @@
-function ModelPorts = LoadModelPorts(model)
-%LOADMODELPORT 此处显示有关此函数的摘要
-%   此处显示详细说明
-ModelPorts.Physical = get_phy_channels(model);
-ModelPorts.Software = get_sw_channels(model);
-end
-
-function channels = get_sw_channels(model)
-% 获取模型的软件信号注入接口
-% 返回注入接口模型句柄
-    channels = find_system(model, 'FindAll', 'on', 'MaskType', 'InjectionChannel', 'InjectionType', 'Software');
-end
-
-function channels = get_phy_channels(model)
-% 获取模型的物理信号注入接口
-% 返回注入接口模型句柄
-    channels = find_system(model, 'FindAll', 'on', 'MaskType', 'InjectionChannel', 'InjectionType', 'Physical');
-end

+ 0 - 54
tests/sim/automation/LoadTest.m

@@ -1,54 +0,0 @@
-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

+ 0 - 138
tests/sim/automation/ParseCheck.m

@@ -1,138 +0,0 @@
-function check = ParseCheck(check_in, case_in, connections)
-%PARSE_CASE 此处显示有关此函数的摘要
-%   此处显示详细说明
-check.id = check_in.id;
-check.tag = check_in.tag;
-check.condition_str = check_in.condition;
-check.condition.Name = '';
-check.condition.Test = @() 0;
-check.ref_name = '';
-check.ref = timeseries(0, 0);
-check.refIntp = 1;  %默认使能插值
-check.fdb_name = '';
-check.fdb = timeseries(0, 0);
-check.fdbIntp = 1;  %默认使能插值
-
-tmp.ref.time = 0;
-tmp.ref.value = 0;
-tmp.fdb.time = 0;
-tmp.fdb.value = 0;
-
-if isa(check_in.time, 'struct')
-    check.preprocess = 1;
-    check.time = check_in.time.duration;
-    check.adv = check_in.time.adv;
-else
-    check.preprocess = 0;
-    check.time = check_in.time;
-    check.adv = 'None';
-end
-
-check.tolerance = check_in.tolerance;
-if check.tolerance == 0
-    check.tolerance = 1e-10;
-end
-check.test = @() 0;
-
-if isa(check_in.ref, 'char')
-    check.ref_name = check_in.ref;
-    [tmp.ref.time, tmp.ref.value, check.refIntp] = GetSignal(check_in.ref, case_in, connections);
-elseif isa(check_in.ref, 'double')
-    tmp.ref.time = check.time;
-    if (check.preprocess == 1)  
-        tmp.ref.value = [check_in.ref; check_in.ref];
-    else
-        tmp.ref.value = check_in.ref;
-    end
-end
-
-if isa(check_in.fdb, 'char')
-    check.fdb_name = check_in.fdb;
-    [tmp.fdb.time, tmp.fdb.value, check.fdbIntp] = GetSignal(check_in.fdb, case_in, connections);
-elseif isa(check_in.fdb, 'double')
-    tmp.fdb.time = check.time;
-    if (check.preprocess == 1)   
-        tmp.fdb.value = [check_in.fdb; check_in.fdb];
-    else
-        tmp.fdb.value = check_in.fdb;
-    end
-end
-
-check.ref = timeseries(tmp.ref.value, tmp.ref.time);
-check.fdb = timeseries(tmp.fdb.value, tmp.fdb.time);
-
-switch(check_in.condition)
-    case 'eq'
-        check.condition.Name = 'Equal';
-        check.condition.Test = @(ref, fdb, tor) and(fdb <= ref + tor, fdb >= ref - tor);
-    case 'ne'
-        check.condition.Name = 'NotEqual';
-        check.condition.Test = @(ref, fdb, tor) or(fdb > ref + tor, fdb < ref - tor);
-    case 'gt'
-        check.condition.Name = 'GreaterThan';
-        check.condition.Test = @(ref, fdb, tor) (fdb > ref);
-    case 'ge'
-        check.condition.Name = 'GreaterOrEqual';
-        check.condition.Test = @(ref, fdb, tor) (fdb >= ref);
-    case 'lt'
-        check.condition.Name = 'LessThan';
-        check.condition.Test = @(ref, fdb, tor) (fdb >= ref);
-    case 'le'
-        check.condition.Name = 'LessOrEqual';
-        check.condition.Test = @(ref, fdb, tor) (fdb >= ref);
-    case 'EqAngle'
-        check.condition.Name = 'EqualAngle';
-        check.condition.Test = @(ref, fdb, tor) ((mod(fdb - ref, 2*pi) < tor) || (mod(fdb - ref, 2*pi) > (2*pi - tor)));
-    case 'In'
-        check.condition.Name = 'In';
-        check.condition.Test = @(ref, fdb, tor) and(fdb <= ref + tor, fdb >= ref - tor);
-    case 'NotIn'
-        check.condition.Name = 'NotIn';
-        check.condition.Test = @(ref, fdb, tor) or(fdb > ref + tor, fdb < ref - tor);
-end
-check.test = @ConditionCheck;
-
-end
-
-function [time, value, intp] = GetSignal(tag, test, connections)
-
-time = 0;
-value = 0;
-intp = 0;
-
-for i = 1:length(test.Initializations)
-    if strcmp(tag, test.Initializations(i).tag)
-        time = 0;
-        value = test.Initializations(i).value;
-        return;
-    end
-end
-
-for i = 1:length(test.Injections)
-    if strcmp(tag, test.Injections(i).tag)
-        time = test.Injections(i).time;
-        value = test.Injections(i).value;
-        if isfield(test.Injections(i), 'option')
-            if isfield(test.Injections(i).option, 'interpolation')
-                if test.Injections(i).option.interpolation
-                    intp = 1;
-                end
-            end
-        end
-        return;
-    end
-end
-
-for i = 1:length(test.Feedbacks)
-    if strcmp(tag, test.Feedbacks(i).tag)
-        [t, n, c] = SelectConnection(test.Feedbacks(i).tag, connections);
-        if t == 'v' || t == 'a'
-            time = evalin('base', n).Time;
-            value = evalin('base', n).Data(:,c + 1);
-            return;
-        end
-    end
-end
-
-end
-

+ 0 - 75
tests/sim/automation/RunTest.m

@@ -1,75 +0,0 @@
-function result = RunTest(case_name)
-%RUNTEST 运行测试用例
-
-%% 初始化/加载
-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
-out = sim(target_model);
-assignin('base', 'out', out); 
-% s = load('matlab.mat');
-% assignin('base', 'out', s.out); 
-close_system(target_model, 0); %仿真完成后必须关闭模型,否则在Accelerator模式下再次仿真将导致Matlab崩溃,原因暂时不明
-
-%% 获取模型输出
-
-%% 验证测试结果
-test_check = test_case.Checks;
-check_result = {};
-for i = 1:length(test_check)
-    check = ParseCheck(test_check(i), test_case, test_connection);
-    [res, msg] = ConditionCheck(check);
-    check_result{i} = {check.id, check.tag, res, msg};
-end
-
-result = check_result;
-
-end
-

+ 0 - 35
tests/sim/automation/SelectConnection.m

@@ -1,35 +0,0 @@
-function [Type, Name, Column] = SelectConnection(tag, map)
-%GET_CONNECTION 读取信号连接信息
-%   type为信号连接类型:
-%   's'-连接至软件注入点
-%   'p'-连接至物理注入点
-%   'v'-连接至变量
-%   'a'-连接至数组
-%   'n'-无效连接
-Type = 'n';
-Name = '';
-Column = 0;
-for i = 1:length(map)
-    if strcmp(tag, map(i).from)
-        if isa(map(i).to, 'char')
-            Type = 'v';
-            Name = map(i).to;
-        elseif isa(map(i).to, 'struct')
-            if strcmp(map(i).to.type, 'port')
-                if strcmp(map(i).to.spec, 'software')
-                    Type = 's';
-                    Name = map(i).to.channel;
-                elseif strcmp(map(i).to.spec, 'physical')
-                    Type = 'p';
-                    Name = map(i).to.channel;
-                end
-            elseif strcmp(map(i).to.type, "array")
-                Type = 'a';
-                Name = map(i).to.name;
-                Column = map(i).to.column;
-            end
-        end
-        break;
-    end
-end
-

+ 0 - 20
tests/sim/automation/SelectPort.m

@@ -1,20 +0,0 @@
-function Port = SelectPort(handles, hints)
-%SELECTPORT 根据序号选择端口,接受字符串或者数字
-%   此处显示详细说明
-Port = 0;    
-if isa(hints, 'char')
-    for i = 1:length(handles)
-        if strcmp(get_param(handles(i), 'Index'), hints)
-            Port = handles(i);
-        end
-    end 
-elseif isa(hints, 'double')
-    for i = 1:length(handles)
-        if str2double(get_param(handles(i), 'Index')) == hints
-            Port = handles(i);
-        end
-    end
-end
-
-end
-

+ 0 - 16
tests/sim/automation/SetPortEnable.m

@@ -1,16 +0,0 @@
-function SetPortEnable(handle, en)
-% 使能或关闭注入信号
-% handle 信号注入模块句柄或全名
-% en 使能
-    if en == 0
-        set_param(handle, 'enableVar', '[0 0]');
-    elseif en == 1
-        set_param(handle, 'enableVar', '[0 1]');  
-    else
-        if length(inputname(2)) > 0
-            set_param(handle, 'enableVar', inputname(2));
-        else
-            set_param(handle, 'enableVar', mat2str(en));
-        end
-    end
-end

+ 0 - 8
tests/sim/automation/SetPortInterpolation.m

@@ -1,8 +0,0 @@
-function SetPortInterpolation(handle, en)
-% 使能或关闭注入信号曲线插值
-    if en
-        set_param(handle, 'interpolation', 1);
-    else
-        set_param(handle, 'interpolation', 0);
-    end
-end

+ 0 - 12
tests/sim/automation/SetPortSignal.m

@@ -1,12 +0,0 @@
-function SetPortSignal(handle, sig)
-% 设置注入信号
-    if length(sig) == 1
-        set_param(handle, 'dataVar', mat2str([0, sig]));
-    else
-        if length(inputname(2)) > 0
-            set_param(handle, 'dataVar', inputname(2));
-        else
-            set_param(handle, 'dataVar', mat2str(sig));
-        end
-    end
-end

+ 0 - 4
tests/sim/automation/SetPortThrough.m

@@ -1,4 +0,0 @@
-function SetPortThrough(handle, en)
-% 使能或关闭注入信号直通
-    set_param(handle, 'through', double(en));
-end

BIN
tests/sim/automation/injection_dtype.mat


+ 0 - 25
tests/sim/automation/slblocks.m

@@ -1,25 +0,0 @@
-function blkStruct = slblocks
-
-% This function specifies that the library should appear
-
-% in the Library Browser
-
-% and be cached in the browser repository
-
-
-
-Browser.Library = 'AutomationPortLib';
-
-% 'mylib' is the name of the library
-
-
-
-Browser.Name = 'AutomationMidea';
-
-% 'My Library' is the library name that appears
-
-% in the Library Browser
-
-
-
-blkStruct.Browser = Browser;

+ 0 - 2
tests/sim/pytest/.gitignore

@@ -1,2 +0,0 @@
-__pycache__
-.pytest_cache

+ 0 - 17
tests/sim/pytest/base_case.py

@@ -1,17 +0,0 @@
-import pytest
-from matlab_wrapper import *
-
-class TestBase:
-    case_name = ''
-    res = 0
-
-    @pytest.fixture(scope='class')
-    def Sim(self):
-        res = run_sim(self.case_name)
-        return res
-
-    def test_Sim(self, Sim):
-        assert Sim != None
-
-    def test_Result(self, Sim, index):
-        assert Sim[index][2] == 1, Sim[index][3]

+ 0 - 11
tests/sim/pytest/conftest.py

@@ -1,11 +0,0 @@
-import matlab_wrapper as mw
-
-def pytest_generate_tests(metafunc):
-    if "index" in metafunc.fixturenames:
-        case_name = metafunc.cls.case_name
-        if case_name == '':
-            case_name = metafunc.cls.__name__[4:]
-            metafunc.cls.case_name = case_name
-        print(case_name)
-        checks_name = mw.load_checks(case_name)
-        metafunc.parametrize("index", range(len(checks_name)), ids=checks_name)

+ 0 - 28
tests/sim/pytest/matlab_wrapper.py

@@ -1,28 +0,0 @@
-import os
-import matlab.engine
-import json
-from pathlib import Path
-
-def load_checks(case_name):
-    tmp = []
-    print('Load Check of Case [{0}]'.format(case_name))
-    case_path = '../test_cases/'+case_name+'_Case.json'
-    if (os.path.exists(case_path)):
-        fo = open(case_path)
-        checks_data = fo.read()
-        checks = json.loads(checks_data)['Checks']
-        for check in checks:
-            tmp.append(check['tag'])
-        print('{0} Checks Loaded'.format(len(tmp)))
-    else:
-        print('Case File Not Found')
-    return tmp
-
-def run_sim(case_name):
-    eng = matlab.engine.start_matlab()
-    eng.cd(Path().absolute().parent.as_posix())
-    eng.prepare_test(nargout=0)
-    res = eng.RunTest(case_name)
-    eng.quit()
-    return res
-

+ 0 - 15
tests/sim/pytest/test_Sim.py

@@ -1,15 +0,0 @@
-import base_case as base
-import os
-import re
-
-exist_testcases_path = os.path.exists("../test_cases")
-
-if exist_testcases_path:
-    var_dict = locals()
-    for dirpath, dnames, fnames in os.walk("../test_cases"):
-        for fname in fnames:
-            m = re.match('^(.+)_Case.json$', fname)
-            if m != None:
-                var_dict['Test'+m.group(1)] = type('Test'+m.group(1),(base.TestBase,),{})
-else:
-    print("No Test Cases Found!")