The method of testing and device of embedded Control algorithmTechnical field
The present embodiments relate to the method for testing and device of technical field of measurement and test, more particularly to embedded Control algorithm.
Background technology
Embedded system is developed, it is applied as one of presently the most popular field with the speed advanced by leaps and boundsField covers Industry Control, communication, instrument, instrument, automobile, ship, Aeronautics and Astronautics, military equipment, consumer electronics etc..TogetherWhen, embedded Control equipment is also more and more intelligent, information-based, networking and precision, so that the control purchased whereinAlgorithm processed becomes to become increasingly complex, and the difficulty for testing these control algolithms is consequently increased, regression test it is less efficient.
At present, the more universal method of testing to embedded Control algorithm is typically:First, using the skill of white-box testingArt means enter the unit testing of line function level to control algolithm;And then embedded Control algorithm is downloaded to real embeddedSystem level testing is carried out in the controller of system, with the various parameters of testing and control algorithm repeatedly, until reaching satisfied controlEffect.
But inventor has found that prior art has following defect:
When entering the test of line function level early stage, for iterating, the excitation of multicycle input, the correlation function such as output, needVery important person increases the workload of test to write a large amount of test codes, generating test data to build test environment;
During later stage system level testing, on the one hand, dependence of the tested control algolithm to hardware is largely increased,Precision, the stability factor of such as executing agency and sensor, govern the correctness and accuracy of control algolithm operation result;On the other hand, because test job intervention is later, it is necessary to which the middle and later periods to project development can just be controlled the system-level of algorithmTest, so as to increase the cost of reparation problem.
The content of the invention
The embodiment of the present invention provides a kind of method of testing and device of embedded Control algorithm, to realize to embedded ControlThe automatic test of algorithm, testing efficiency is improved, ensure the accuracy of test, reduce problem rehabilitation cost.
In a first aspect, the embodiments of the invention provide a kind of method of testing of embedded Control algorithm, this method includes:
System testing engineering is created, to load embedded system model, is obtained corresponding with the embedded system modelThe test data item that preserves of at least one test case, test judgement criterion and the needs that pre-set;
By running the system testing engineering, emulation testing is carried out to the embedded system model;
Wherein, the embedded system model for created in MATLAB Visual Simulation Tools Simulink byModel corresponding to User Defined S-Function modules and the embedded system of standard module composition;The User DefinedS-Function modules include passing through the system function S-Function in MATLAB, and embedded Control algorithm packaging is obtainedS-Function control modules.
Second aspect, the embodiment of the present invention additionally provide a kind of test device of embedded Control algorithm, and the device includes:
System testing engineering creating unit, for creating system testing engineering, to load embedded system model, obtain withWhat the corresponding at least one test case of the embedded system model, test judgement criterion and the needs that pre-set preservedTest data item;
System testing engineering operation unit, for by running the system testing engineering, to the embedded system mouldType carries out emulation testing;
Wherein, the embedded system model for created in MATLAB Visual Simulation Tools Simulink byModel corresponding to User Defined S-Function modules and the embedded system of standard module composition;The User DefinedS-Function modules include passing through the system function S-Function in MATLAB, and embedded Control algorithm packaging is obtainedS-Function control modules.
In technical scheme provided in an embodiment of the present invention, the S-Function in MATLAB is advanced with, will be embeddedControl algolithm is packaged into S-Function control modules, and creates the embedded system model for including the control module, finallyThe system testing engineering of the embedded system model is loaded with by operation, to realize that the automation to embedded Control algorithm is surveyedIt examination, can so greatly reduce the workload spent because artificially writing test code and test data, improve testing efficiency, dropLow problem rehabilitation cost.
Brief description of the drawings
Fig. 1 is a kind of flow chart of the method for testing for embedded Control algorithm that the embodiment of the present invention one provides;
Fig. 2 is a kind of flow chart of the method for testing for embedded Control algorithm that the embodiment of the present invention two provides;
Fig. 3 is a kind of flow chart of the method for testing for embedded Control algorithm that the embodiment of the present invention three provides;
Fig. 4 is a kind of structural representation of the test device for embedded Control algorithm that the embodiment of the present invention four provides.
Embodiment
The present invention is described in further detail with reference to the accompanying drawings and examples.It is understood that this place is retouchedThe specific embodiment stated is used only for explaining the present invention, rather than limitation of the invention.It also should be noted that in order to justPart related to the present invention rather than entire infrastructure are illustrate only in description, accompanying drawing.
Embodiment one
A kind of flow chart of the method for testing for embedded Control algorithm that Fig. 1 provides for the embodiment of the present invention one, this methodIt can be performed by the test device of embedded Control algorithm, described device can be soft on MATLAB platforms by that can run onPart is realized.Referring to Fig. 1, the method for testing for the embedded Control algorithm that the present embodiment provides specifically comprises the following steps:
Step 110, system testing engineering is created, to load embedded system model, obtained and embedded system model phaseThe test data item that corresponding at least one test case, test judgement criterion and the needs that pre-set preserve.
Simulink is a kind of for the more of dynamical system and embedded system as one of most important components of MATLABField emulates and the design tool based on model.The system model created in Simulink can by multiple different modules withThe connected mode of setting links together composition, and module can be as the elementary cell of system model.Each mould in system modelBlock can be one or more standard modules selected from the module library that Simulink is carried or pass through MATLABIn system function S-Function can be established the link to call with standard module obtained from the source code that user designsCustom block.The present embodiment can create embedded system model based on the Simulink in MATLAB, and the model includes tuneWith the custom block of embedded Control algorithm, and then by carrying out emulation testing to the model to complete to embedded ControlThe test of algorithm.
, can the new established model text in MATLAB system emulation instrument Simulink in advance specifically, in the present embodimentPart, to create the embedded system model that embedded Control algorithm is applicable.Under normal circumstances, embedded system is mainly by controllingDevice processed and other multiple hardware device compositions, the system is by the embedded Control algorithm in controller of purchasing to embedded systemSystem other hardware devices be controlled by, therefore the embedded system model should be by User Defined S-Function modules withAnd model corresponding to the embedded system of multiple standard module compositions.Wherein, User Defined S-Function modules are to pass throughS-Function in MATLAB, and the custom block for being used to build embedded system model created, the number of modules canThink one or more, but the S-Function passed through in MATLAB should be comprised at least, embedded Control algorithm packaging is obtainedS-Function control modules.
In a kind of embodiment of the present embodiment, by the S-Function in MATLAB, by embedded ControlAlgorithm packaging obtains S-Function control modules, it may include:
(1) the C MEX S file templates for utilizing the S-Function in MATLAB to be included, are called for being stored in insertionThe embedded Control algorithm of controller in formula system, to generate the target C MEX S file corresponding with embedded Control algorithm,This document includes embedded Control algorithm source file, to the relation between inputting, export, export and inputting, original state and completeThe setting of office's variable, and be stored in extending entitled .c under setting file;
(2) successively by inputting mex-setup, configuration MATLAB MEX orders and input in MATLAB command windowsMex C MEX S filename .c, C MEX S filename .mexw32 files are generated in file is set, with to embedded ControlAlgorithm source file is compiled and by embedded Control algorithm packaging into corresponding S-Function modules, wherein the filenameFor the title of target C MEX S files.
, can be by creating system testing engineering in MATLAB after establishment finishes embedded system modelSystemTest, to load embedded system model, obtain at least one test case corresponding with the model, test judgementThe test data item that criterion and the needs pre-set preserve.Wherein, test case is in the simulated survey of embedded system modelInput during examination;Test judgement criterion be judge after emulation testing test case by whether when used commentSentence standard.It should be noted that test case and test judgement criterion can be that user is pre-designed according to demand.
Step 120, by runtime testing engineering, emulation testing is carried out to embedded system model.
After establishment finishes system testing engineering, the system testing engineering is run using SystemTest instruments, withThe emulation testing to embedded system model is completed, and then realizes the automatic test to embedded Control algorithm.UtilizeSystemTest instruments can carry out any possible test, including input combined test, the arbitrary parameter of any system make a variationTest, the test of any system interference, the test data item that can be preserved according to the needs pre-set got before, to preserveTest obtained corresponding data items.After system testing engineering operation, preserved test data is can obtain, for eachThe situation whether situation and test that test case performs pass through.User can enter according to these situations to embedded Control algorithmRow modification and tuning.
In the technical scheme that the present embodiment provides, the S-Function in MATLAB is advanced with, by embedded ControlAlgorithm packaging creates the embedded system model for including the control module into S-Function control modules, finally byOperation is loaded with the system testing engineering of the embedded system model, to realize the automatic test to embedded Control algorithm,It is advantageous in that:The workload spent because artificially writing test code and test data can not only be greatly reduced, improve and surveyTry efficiency, and need not until the later stage control algolithm being downloaded to real embedded system hardware, just to be testedEmbedded Control algorithm carries out system level testing, and causes the control algolithm to need not rely upon hardware, so as to ensure to testThe degree of accuracy, facilitate user in time according to test result carry out algorithm modification and tuning, reduce to control algolithm problemRehabilitation cost.
Embodiment two
A kind of flow chart of the method for testing for embedded Control algorithm that Fig. 2 provides for the embodiment of the present invention two, this implementationExample is on the basis of the various embodiments described above, the step of further increasing test result analysis and regression test.Referring to Fig. 2,The method of testing for the embedded Control algorithm that the present embodiment provides specifically comprises the following steps:
Step 210, system testing engineering is created, to load embedded system model, obtained and embedded system model phaseThe test data item that corresponding at least one test case, test judgement criterion and the needs that pre-set preserve;Wherein, it is embeddedFormula system model is is created by User Defined S-Function in MATLAB Visual Simulation Tools SimulinkModel corresponding to module and the embedded system of standard module composition;User Defined S-Function modules include passing throughSystem function S-Function in MATLAB, the S-Function control modules that embedded Control algorithm packaging is obtained;
Step 220, by runtime testing engineering, emulation testing is carried out to embedded system model;
Step 230, according to the simulation results, calculate in this test setting for embedded Control algorithm under each test caseDetermine the actual value of index;
Step 240, the standard value of the actual value calculated and the default setting index to embedded Control algorithm enteredRow compare, according to comparison result and the test judgement criterion judge each test case by whether;
Step 250, obtain the S-Function controls new S-Function control modules replaced in embedded system modelThe new embedded system model that molding block obtains, wherein new S-Function control modules are by by S-Function, by basisThe new embedded Control algorithm that each test case is changed to obtain by whether judged result to the embedded Control algorithm sealsDress obtains;
Step 260, system testing engineering is reruned, emulation testing is carried out again to new embedded system model, with realityNow to the regression test of embedded Control algorithm.
In the present embodiment, when the simulation results is input response curve, when the setting index may include to riseBetween, overshoot and/or steady-state error etc..
The technical scheme that the present embodiment provides, when carrying out regression test, compared to prior art without building survey againTest ring border, user need to only replace with the lower source file for realizing embedded Control algorithm of corresponding document folder new embedding for realizingEnter the source file of formula control algolithm, triggering system testing engineering is run, can be automatically performed to new embedded system model againEmulation testing, and then realize test to new embedded Control algorithm, so as to greatly improve regression test efficiency, reduce and returnTesting cost.
On the basis of above-mentioned technical proposal, the method for testing of embedded Control algorithm provided in an embodiment of the present invention canStill further comprise:
By the interface with third party's Tool integration pre-set, code coverage point is carried out to embedded Control algorithmAnalysis, uncovered test case is determined with binding analysis result and at least one test case;
By identified uncovered test case, added at least one survey corresponding with embedded system modelIn example on probation.
At present, the interface of third party's instrument is integrated with MATLAB, by the access to the interface, third party can be obtainedThe code coverage rate analysis to embedded Control algorithm of instrument generation is reported.Report accordingly, current system engineering can be addedThe unlapped test case of test institute so that test is more abundant.
Specifically, the interface with third party's Tool integration, Ke Yishi are set:In embedded system model file, selectionSimulation>Configuration Parameters>Code Generation, in System target file, choosingIt is ert.tlc to select file destination, while SIL and PIL Verification options are chosen, in Code Coverage ToolBullseyeCoverage or LDRA Testbed are selected in combobox, Configure Coverage is clicked on, enters line code and coverThe setting of lid rate test.
In embodiments of the present invention, if the Profiler options of embedded system model are arranged to effective status, thisThe method of testing for the embedded Control algorithm that inventive embodiments provide also includes:In runtime testing engineering, record insertionThe time that each function in formula system model corresponding to S-Function control modules is spent when performing itself function, with lifeReported into function level Analysis of operation efficiency.The function level operational efficiency data reporting that can be so provided according to Profiler is rightEmbedded Control algorithm quality is analyzed, and the function for needing to optimize can be conveniently navigated in embedded Control algorithm, so as to carryThe efficiency of high algorithm performance tuning.When performing step 250, new S-Function control modules are by by S-Function, inciting somebody to actionAccording to each test case by whether judged result and the report of function level Analysis of operation efficiency to the embedded Control algorithmObtained new embedded Control algorithm packaging is changed to obtain.
Embodiment three
Fig. 3 is a kind of schematic flow sheet of the method for testing for embedded Control algorithm that the embodiment of the present invention three provides.ThisEmbodiment can be based on above-described embodiment, there is provided a kind of preferred embodiment.Referring to Fig. 3, the present embodiment provides embeddedThe method of testing of control algolithm comprises the following steps:
Step 310, the C MEX S file templates included using the S-Function in MATLAB, call for storingThe embedded Control algorithm of controller in embedded systems, to generate the target C MEX corresponding with embedded Control algorithmS files, this document includes embedded Control algorithm source file, to the relation between inputting, export, export and inputting, initial shapeThe setting of state and global variable, and be stored in extending entitled .c under setting file.
In the present embodiment, in C MEX S file templates, using #include " xxxx.c ", embedded Control is calculatedThe source file of method is declared at the beginning of C MEX S file templates, and the source file of embedded Control algorithm is included inTarget C MEX S files are generated in the template.Wherein, " xxxx " is the source filename of embedded Control algorithm.Wherein, it is embeddedThe source file of control algolithm can be the file being made up of C code.
The number or dimension of input and the output of target C MEX S files, and in embedded Control algorithm source file codeInput it is consistent with output number or dimension, can be utilized respectively ssSetNumInputPorts (S, n) in template,SsSetNumOutputPorts (S, n) function is realized;
The initialization function or setup code of embedded Control algorithm, it is necessary to C MEX S file templates staticIt is called in void mdlInitializeConditions (SimStruct*S) function;
If it is related to global variable in embedded Control algorithm C code, it is necessary in static void mdlTerminate(SimStruct*S) in function, the value of global variable is changed into initial value or is entered as 0, avoids next runtime engineering from enteringProduce and add up during row emulation testing, if without global variable in embedded Control algorithm, without considering;
The output of embedded Control algorithm C code needs the static void in C MEX S file templatesIt is called in mdlOutputs (SimStruct*S, int_T tid) function, including the relation between input.
Step 320, in MATLAB command windows successively by input mex-setup, configuration MATLAB MEX orders withAnd input mex C MEX S filename .c, C MEX S filename .mexw32 files are generated in file is set, with to insertionFormula control algolithm source file is compiled and by embedded Control algorithm packaging into corresponding S-Function modules.
Wherein, the title of the entitled target C MEX S files of the file.
Step 330, the newly-built model file in Simulink, to create the embedded system that embedded Control algorithm is applicableSystem model, and set and code coverage rate analysis is carried out to embedded Control algorithm with the interface of third party's Tool integration, wherein shouldEmbedded system model includes the S- for obtaining embedded Control algorithm packaging by the S-Function in MATLABFunction control modules, the Profiler options of model are effective status.
Step 340, system testing engineering is created, to load embedded system model, obtained and embedded system model phaseThe test data item that corresponding at least one test case, test judgement criterion and the needs that pre-set preserve, and pass through fortuneRow system testing engineering, emulation testing is carried out to embedded system model.
Step 350, generation the simulation results, to analyze the simulation results.
In the present embodiment, the simulation results include:The test data preserved, performed for each test caseThe situation whether situation and test pass through, the report of function level operational efficiency, code coverage rate analysis report.Wherein, function level is transportedLine efficiency report according to S-Function in embedded system models of the Profiler recorded in emulation testing process by controllingThe time data composition that each function corresponding to molding block is spent when performing itself function, accordingly report can be embedded inThe good and bad analysis of formula control algolithm, the function that the algorithm needs to optimize can be easily navigated to, improve the efficiency of Performance tuning;RootUnlapped test case can be added according to code coverage rate analysis report, makes test more abundant.
Step 360, obtain the S-Function controls new S-Function control modules replaced in embedded system modelThe new embedded system model that molding block obtains, wherein new S-Function control modules are by by S-Function, by basisThe new embedded Control algorithm packaging for changing to obtain to the embedded Control algorithm to the analysis result of the simulation results obtainsArrive.
Step 370, system testing engineering is reruned, emulation testing is carried out again to new embedded system model, with realityNow to the regression test of embedded Control algorithm.
The method of testing for the embedded Control algorithm that the present embodiment provides, functionally, pays close attention to embedded on the wholeThe operational effect of control algolithm, is easy to interpretation of result;In aspect of performance, there is provided the operational efficiency data of function level, be easy to performanceAnalysis and tuning;In regression test, the source code of embedded Control algorithm need to be only changed, you can the recurrence automated is surveyedExamination, so as to improve efficiency.
The present embodiment calls the source code of embedded Control algorithm in S-Function functions, builds Simulink modelsEmulation testing is carried out, comprehensive method of testing and approach can be provided for the embedded Control algorithm of complexity, reduction is artificially writeTest the workload of code and test data;Integrated third party's instrument carries out code coverage rate analysis, according to code coverage pointAnalysis report, carries out the addition of test case, makes test more abundant;For the function in algorithm, there is provided reliable run time, sideJust algorithm performance tuning and positioning;For regression test, need to only carry out by the replacement of method of determining and calculating source program, you can automatedTest, without building test environment again, testing cost is saved, improves testing efficiency.
Example IV
Fig. 4 is a kind of structural representation of the test device for embedded Control algorithm that the embodiment of the present invention four provides.GinsengSee Fig. 4, the concrete structure for the device that the present embodiment provides is as follows:
System testing engineering creating unit 410, for creating system testing engineering, to load embedded system model, obtainTake at least one test case corresponding with the embedded system model, test judgement criterion and what is pre-set need to protectThe test data item deposited;
System testing engineering operation unit 420, for by running the system testing engineering, to the embedded systemModel carries out emulation testing;
Wherein, the embedded system model for created in MATLAB Visual Simulation Tools Simulink byModel corresponding to User Defined S-Function modules and the embedded system of standard module composition;The User DefinedS-Function modules include passing through the system function S-Function in MATLAB, and embedded Control algorithm packaging is obtainedS-Function control modules.
Further, the device that the present embodiment provides also includes test case covering analyzing unit 400, is used for:
By the interface with third party's Tool integration pre-set, code coverage is carried out to the embedded Control algorithmRate is analyzed, and uncovered test case is determined with binding analysis result and at least one test case;
By identified uncovered test case, added to corresponding with the embedded system model at least oneIn individual test case.
Further, the Profiler options of the embedded system model are arranged to effective status;
The device that the present embodiment provides also includes:
Module performance detection unit 430, for when running the system testing engineering, recording the embedded system mouldThe time that each function corresponding to S-Function control modules described in type is spent when performing itself function, to generate letterSeveral levels Analysis of operation efficiency is reported.
Further, the device that the present embodiment provides also includes:
Test index computing unit 440, in the system testing engineering operation unit 420 by running the systemTesting engineering, after carrying out emulation testing to the embedded system model, according to the simulation results, calculate in this testThe actual value of the setting index of the embedded Control algorithm under each test case;
Test result analysis unit 450, for the actual value for being calculated the test result calculations unit 440 and presetThe standard value of the setting index to the embedded Control algorithm be compared, it is accurate according to comparison result and the test judgementThen judge each test case by whether.
Further, the device that the present embodiment provides also includes regression test unit 460, is used for:
Each test case is judged according to comparison result and the test judgement criterion in the test result analysis unit 450By whether after, obtain the S-Function replaced new S-Function control modules in the embedded system model and controlThe new embedded system model that molding block obtains, wherein the new S-Function control modules are by passing through the system function S-Function, it will be reported according to each test case by whether judged result and function level Analysis of operation efficiency to the insertionThe new embedded Control algorithm packaging that formula control algolithm is changed to obtain obtains;
The system testing engineering is reruned, emulation testing is carried out again to the new embedded system model, with realityNow to the regression test of the embedded Control algorithm.
The said goods can perform the method that any embodiment of the present invention is provided, and belong to same invention structure with methods describedThink, possess the corresponding functional module of execution method and beneficial effect.
It should be appreciated by those skilled in the art that:The test device for the embedded Control algorithm that the present embodiment provides is being heldDuring the operation of the method for testing of row embedded Control algorithm, it is illustrated with the division of above-mentioned each functional unit;Among practical application, it can be completed as needed and by above-mentioned function distribution by different units, i.e., by embedded Control algorithmThe internal structure of test device be divided into different functional units, to complete all or part of function described above.
Pay attention to, above are only presently preferred embodiments of the present invention and institute's application technology principle.It will be appreciated by those skilled in the art thatThe invention is not restricted to specific embodiment described here, can carry out for a person skilled in the art various obvious changes,Readjust and substitute without departing from protection scope of the present invention.Therefore, although being carried out by above example to the present inventionIt is described in further detail, but the present invention is not limited only to above example, without departing from the inventive concept, alsoOther more equivalent embodiments can be included, and the scope of the present invention is determined by scope of the appended claims.