[go: up one dir, main page]

CN104375932B - Method and device for analyzing code coverage rate of Java card - Google Patents

Method and device for analyzing code coverage rate of Java card Download PDF

Info

Publication number
CN104375932B
CN104375932B CN201410427514.5A CN201410427514A CN104375932B CN 104375932 B CN104375932 B CN 104375932B CN 201410427514 A CN201410427514 A CN 201410427514A CN 104375932 B CN104375932 B CN 104375932B
Authority
CN
China
Prior art keywords
java card
coverage rate
coverage
java
virtual machine
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201410427514.5A
Other languages
Chinese (zh)
Other versions
CN104375932A (en
Inventor
巫瑞
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing CEC Huada Electronic Design Co Ltd
Original Assignee
Beijing CEC Huada Electronic Design Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing CEC Huada Electronic Design Co Ltd filed Critical Beijing CEC Huada Electronic Design Co Ltd
Priority to CN201410427514.5A priority Critical patent/CN104375932B/en
Publication of CN104375932A publication Critical patent/CN104375932A/en
Application granted granted Critical
Publication of CN104375932B publication Critical patent/CN104375932B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Landscapes

  • Devices For Executing Special Programs (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The invention provides a method and device for analyzing the Java code (including a Java card platform and an application) coverage rate of a Java card. The method comprises the steps that syllable codes for marking coverage are inserted in a class file, wherein coverage marking data are Native data stored in a JCVM, a Converter of the Java card is adjusted without prejudice to JCVM standards, the coverage marking data store the operation situation of the codes in the operation process of a card simulator, the JCVM outputs the coverage marking data according to a certain format after the testing is finished, the class file is analyzed to correspond to the data, and the percentage of the coverage rate can be obtained. A provided system interacts with a user in the two modes of an Eclipse plugin and an Ant task. According to the method, the syllable code instrumentation technology is adopted on the Java card, the influence on the codes and the speed of the JCVM is little, analysis without source codes is supported, and statement coverage and branch coverage are supported.

Description

A kind of Java card code coverage rate analysis method and apparatus
Technical field
The present invention relates to field of intelligent cards, illustrates a kind of Java card code coverage rate analysis method and apparatus.
Background technology
Code coverage statistical technique includes two big class, and a class is to be tracked note to code operation by Java Virtual Machine Record, a class is to carry out pitching pile (Instrumentation) to source code or bytecode i.e. class files, is inserted in key position Enter code or bytecode, (referring to accompanying drawing 3) whether is run for record.To the method for class file pitching piles without using Source code, it is adaptable to the situation of source code cannot be obtained.
There is more commercial and Open Source Code coverage rate analysis instrument currently for the Java on PC, and be directed to the generation of Java card Code coverage rate analysis instrument is then little.Java card, is compiled on PC using Java card virtual machine for the equipment of resource-constrained To class file bytecodes need by Java card Converter change after use.Existing code cannot directly be utilized Coverage rate instrument.
It is domestic at present to track the skill that code runs using the first kind in code coverage statistical technique in Java Virtual Machine Art is realized (referring to master thesis to Java card code coverage instrument《JAVA card code coverage data source machine The research of system and calculating》, author open it is dripping,《The research of Java card code coverage measurement technology and realization》, author Zhao Pan Peak), the program needs to do extensive work in Java card virtual machine (JCVM), does and sentence during including to operation at each instruction It is disconnected, bytecode controlling stream is analyzed according to CAP bags content, by log and the concrete bytecode of apoplexy due to endogenous wind, code line position Carry out correspondence.Need to increase larger code space in JCVM, while bytecode analysis is carried out when running for JCVM and judgement can also be dropped Low execution speed.
The content of the invention
The present invention uses Instrumentation code coverage statistical techniques on Java card, inserts in class files Enter bytecode needed for coverage rate statistics, the parsing of class pitching piles and class all can be done on PC, mitigate the code space of JCVM Bearing, and insert bytecode only carries out assignment to overlay marks data in ad-hoc location, without entering at per bar instruction Row analysis and judgement, the impact very little to speed.
Difficult point be Java card virtual machine not on PC, overlay marks record cannot be stored on PC, and compiled on PC To bytecode need Java card Converter conversion after use, whether pitching pile class files can be by the inspections of Converter Look into and change, can normally run on JCVM after conversion, can or can not be destroyed after pitching pile Content Transformation, and class files Whether analysis and the overlay marks record after changing correctly can also correspond to etc..
For achieving the above object, the technical solution used in the present invention step is as follows:
A. coverage rate analysis bytecode is inserted to Java card class files, including being called to obtain to Native methods Native overlay marks data are obtained, each pitching pile point is marked in overlay marks data relevant position.By JCVM to coverage rate Data are stored.
B. Java card Converter is partially adjusted on the premise of without prejudice to JCVM specifications, using should Converter is changed to inserting the class files after bytecode.To ensure that the class files after pitching pile can pass through Converter is checked, and can normally be run and be used.
C., after needing to carry out terminating such as testing results when coverage rate is counted, notify that JCVM exports all kinds of correspondences by certain format Coverage rate flag data.
D. it is by class files before the software analysis pitching pile of PC ends, corresponding with the coverage rate flag data of step c output, step a In class pitching piles and parsing now parse code using same set of class, ensure to lose in the transformation process of step b Fall pitching pile content, thus during parsing the position of each can it is corresponding with former class on.Can be calculated sentence to cover and branch's covering As a result, and by debug information in class obtain the coverage condition that correspondence source code is often gone.
The technical solution used in the present invention concrete operations are as follows:
Step 1:Java source code is compiled, class files are obtained;
Step 2:To bytecode needed for class files insertion coverage rate analysis;
Step 3:Java card bytecode conversion is carried out to class files after pitching pile, JCA files are obtained;
Step 4:JCA files are converted to into mask.c files;
Step 5:Mask.c files are placed in Java card virtual machine engineering and are recompilated;
Step 6:Java card virtual machine engineering operation card simulator;
Step 7:Operation will check the test that test completeness is included;
Step 8:Notify JCVM output coverage rate flag datas;
Step 9:Output coverage rate statistical report.
In technical scheme steps a, control flow analysis is run by class files bytecode, it is (same in each instruction block Or bytecode is all performed and is all not carried out in block) in pitching pile, be marked in relevant position, such as by boolean's array pair Element is answered to put 1.Pitching pile position and content are limited according to Java card virtual machine specification and are adjusted, and pitching pile is realized should be noted Details, such as:
JCVM pair<clinit>In bytecode have strict restriction, it is therefore right<clinit>The pitching pile of method adjusts.
Some Java characteristics that JCVM is not supported can not be used, such as serializing mechanism, TRANSIENT key words etc..
In stepb, the inspection and flow path switch to Java card Converter is adjusted, it is considered to newly insert bytecode Impact (different according to the different correspondence virtual machine specification of Java card version and Converter, realization may be slightly changed), Such as:
Narrow examination in adjustment Converter, the variable of new insertion do not correspond to line number and do not need Debugging message, therefore need Error is such as changed to warning by the inspection of adjustment Converter.
When instruction conversion is carried out in Converter, in obtaining class, local variable table content calculates local variable Startpc, needs Adjustable calculation method, it is considered to the length of pitching pile bytecode.
By above scheme, the invention provides the Instrumentation coverage ratio analysis methods of complete Java card, And combined with Ant with Eclipse in embodiment respectively, can greatly facilitate Java card exploration project to pass through code coverage Evaluation test level of coverage and inspection redundant code.
Description of the drawings
Fig. 1 is covering under the Eclipse environment realized according to Java card Java code coverage ratio analysis method in the present invention Lid rate analysis system.
Fig. 2 is that the Ant tasks provided according to Java card Java code coverage rate analysis system in the present invention are write The flow of task of build.xml, completes from the complete procedure for being compiled into test to output coverage rate report.
Fig. 3 be present invention uses Java code Instrumentation pitching pile technologies, the figure derives from《EclEmma on JaCoCo》, Marc R.Hoffmann, 28.03.2012, during wherein probearray has used JCVM in the present invention Native data.
Specific embodiment
With reference to embodiments and accompanying drawing is described in further detail.
The present invention provides a kind of coverage rate analysis system with Eclipse card formats and user mutual, referring to Fig. 1, bag Include following device:
Device A:Eclipse plug-in units:In providing graphic user interface, including source code editor, different colours are highlighted Whether cover, coverage rate View shows and covers statistics percentage ratio etc., and similar to the another of " run " in Eclipse and " debug " A kind of " Coverage " engineering startup mode.
Device B:Coverage rate analysis are acted on behalf of:The core of the system, realizes the pitching pile to class, class files point Analysis, output coverage rate statistical result etc., and the various Ant tasks of coverage rate analysis operation are provided, such as to class file pitching piles " instrument ", notifies JCVM outputs coverage data " jcexport ", obtains coverage rate statistical report " report ".
Device C:JCVM:Native methods are provided, the coverage rate labelling result of each class is stored in Native data, All kinds of corresponding coverage rate flag datas are exported by agreement form after notified message.
Device D:Java card Converter:The class files that java compilings are obtained are by Java card virtual machine specification requirement It is supplied to Java card to use after conversion, byte digital content is inserted according to coverage rate the inspection of Converter and calculation process are done It is corresponding to adjust.
Operate under Java card code development environment using the system user on Eclipse, operating process is simple, Referring to Fig. 1, comprise the following steps:
Early-stage preparations:Java card developer adds pitching pile task in original building process, carries out bytecode conversion, The Java card simulator after coverage rate analysis pitching pile is obtained after recompilating in JCVM.Needs are transferred to be covered in simulator The personnel of rate statistics are counted.In following steps, User step 1 and 2 orders of User step are commutative.
User step 1:Java card Java code engineering is started in " Coverage " mode.
User step 2:Operation card simulator, to card simulator testing results.
User step 3:Stop " Coverage " mode in Eclipse to run, or click " dump " button is interim Current results are checked, coverage rate analysis statistical result all can be seen in the interface of Eclipse, if source code can be See that every line code different colours show cover, do not cover, partly covering, and show in Coverage View in Editor Coverage rate percentage ratio situation.
The system additionally provide coverage rate analysis operation needed for each Ant tasks, user only need to by Java card code compilation, Coverage rate pitching pile, Converter conversions, testing results, notify output coverage data, obtain coverage rate report etc. task write on In build.xml, can Ant perform and then complete all of structure, test and obtain coverage rate report.It is referring to Fig. 2, concrete to walk It is rapid as follows:
Step 21:Call the Ant tasks that Java is provided to be compiled Java source code, obtain class files.
Step 22:The Ant tasks " instrument " for calling present system to provide, insert coverage rate to class files Bytecode needed for analysis.
Step 23:The Ant tasks " Convert " for calling Java card developing instrument external member to provide, after present invention modification Converter, Java card bytecode conversion is carried out to class files after pitching pile, JCA files are obtained.
Step 24:The Ant tasks " Maskgen " for calling Java card developing instrument external member to provide, JCA files are converted to Mask.c files.
Step 25:Mask.c files are placed in JCVM engineerings and are compiled.Because C exploitation IDE such as VS Studio can be provided Local command, Ant can be called to local command, therefore the task of calling local command can be write in build.xml.
Step 26:JCVM engineering operation card simulators, the step can call local command in Ant similar to step 25.
Step 27:Operation will check the test that test completeness is included, such as JUnit tests, test of testing tool etc., There is provided Ant tasks, testing tool test can according to circumstances use the local command of its offer for JUnit tests.
Step 28:The Ant tasks " jcexport " for calling present system to provide, notify JCVM output overlay marks numbers According to.
Step 29:The Ant tasks " report " for calling present system to provide, export coverage rate statistical report.
Above-mentioned steps are included from Java compilings, the operation of coverage rate analysis pitching pile, Java card simulator, test, output to be covered The overall process of lid rate report, whole process can be completed in an Ant flow process, and user's once-through operation can be covered all steps and be obtained To coverage rate statistical report, regression test was carried out in can greatly facilitating project and count coverage rate, in the development phase of project Efficiency can all be improved with test phase.
From the point of view of above-mentioned two embodiment, implemented according to the Java card Java code coverage ratio analysis method that the present invention is provided System, can combine closely with code development environment Eclipse, it is possible to use Ant automatically perform needed for each task, practicality By force, motility is high.
The Java card Java code coverage ratio analysis method that the present invention is provided is also not limited to above-mentioned two embodiment, can It is applied in other embodiments according to the method that the present invention is provided.Therefore, any those familiar with the art is at this In the technical scope that invention is disclosed, the change or replacement that can be readily occurred in should all be included within the scope of the present invention.

Claims (4)

1. a kind of method of analysis Java card Java code coverage rate, is applied to following device, including Eclipse card modules, Coverage rate analysis proxy module, Java card virtual machine and Java card transducer, wherein:
Eclipse card modules provide graphic user interface;
Coverage rate analysis proxy module realizes the pitching pile to class, and class file analyses export coverage rate statistical result, and carry For the various Ant tasks of coverage rate analysis operation;
Java card virtual machine provides Native data structures, stores the overlay marks data of each class in Native data, carries For Native methods, called for inserting bytecode to obtain Native data, by agreement form output after notified message All kinds of corresponding overlay marks data;
Java card transducer is supplied to after the class files that java compilings are obtained are changed by the requirement of Java card virtual machine specification Java card is used, and inserts byte digital content according to coverage rate and the inspection of Java card transducer and calculation process are adjusted accordingly;
Comprise the following steps:
A. coverage rate analysis bytecode is inserted to Java card class files, including calling with acquisition to Native methods Native overlay marks data, each insertion point are marked in Native overlay marks data relevant position;
B. Java card transducer is partially adjusted on the premise of without prejudice to Java card virtual machine specification, using the transducer Change to inserting the class files after coverage rate analysis bytecode;
When c. needing to carry out coverage rate statistics, notify that Java card virtual machine exports all kinds of corresponding overlay marks numbers by certain format According to;
D. class files are analyzed simultaneously corresponding with overlay marks data, is calculated coverage rate percentage ratio, by class files Debug information can obtain the coverage condition that correspondence source code is often gone.
2. the method for claim 1, it is characterised in that step a is further included:
1) the coverage rate analysis bytecode for inserting can store all insertion point flag datas by calling Native methods to obtain Native data structures;
2) control flow analysis is run by class files bytecode, coverage rate analysis byte is inserted in each sequential instructions block Code, overlay marks data relevant position is marked;
3) insert coverage rate analysis bytecode scope and content to be adjusted according to the restriction of Java card virtual machine specification.
3. the method for claim 1, it is characterised in that in step c, PC ends coverage rate analysis instrument and Java card are virtual Machine engineering is communicated, and needs every time to send messages to Java card virtual machine when obtaining coverage data, and Java card virtual machine is pressed The form of agreement exports all kinds of corresponding overlay marks data.
4. the method for claim 1, it is characterised in that in step d, is covered by the coverage rate analysis tool analysis insertion of PC ends Class files before lid rate analysis bytecode, it is corresponding with the coverage rate flag data of Java card virtual machine output.
CN201410427514.5A 2014-08-27 2014-08-27 Method and device for analyzing code coverage rate of Java card Active CN104375932B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201410427514.5A CN104375932B (en) 2014-08-27 2014-08-27 Method and device for analyzing code coverage rate of Java card

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201410427514.5A CN104375932B (en) 2014-08-27 2014-08-27 Method and device for analyzing code coverage rate of Java card

Publications (2)

Publication Number Publication Date
CN104375932A CN104375932A (en) 2015-02-25
CN104375932B true CN104375932B (en) 2017-04-19

Family

ID=52554867

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201410427514.5A Active CN104375932B (en) 2014-08-27 2014-08-27 Method and device for analyzing code coverage rate of Java card

Country Status (1)

Country Link
CN (1) CN104375932B (en)

Families Citing this family (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106326118B (en) * 2016-08-19 2019-03-15 东软集团股份有限公司 Code tester coverage rate determines method and apparatus
CN106844209A (en) * 2017-01-18 2017-06-13 广州唯品会信息科技有限公司 Code coverage method of testing and system
CN108874656A (en) * 2017-05-16 2018-11-23 北京京东尚科信息技术有限公司 Code test method, device, readable storage medium storing program for executing and computer equipment
CN109542789B (en) * 2018-11-26 2022-03-25 泰康保险集团股份有限公司 Code coverage rate statistical method and device
CN113806231B (en) * 2021-09-29 2024-03-19 锐捷网络股份有限公司 Code coverage rate analysis method, device, equipment and medium

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102253889A (en) * 2011-08-07 2011-11-23 南京大学 Method for dividing priorities of test cases in regression test based on distribution
CN102736980A (en) * 2012-06-29 2012-10-17 南京大学 Random test case generation method facing Java program

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8479159B2 (en) * 2006-10-20 2013-07-02 International Business Machines Corporation System and method for automatically determining relationships between software artifacts using multiple evidence sources

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102253889A (en) * 2011-08-07 2011-11-23 南京大学 Method for dividing priorities of test cases in regression test based on distribution
CN102736980A (en) * 2012-06-29 2012-10-17 南京大学 Random test case generation method facing Java program

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
Java卡代码覆盖率度量技术的研究与实现;赵攀峰;《中国优秀硕士学位论文全文数据库》;20121015(第10期);第32-45页 *

Also Published As

Publication number Publication date
CN104375932A (en) 2015-02-25

Similar Documents

Publication Publication Date Title
CN104375932B (en) Method and device for analyzing code coverage rate of Java card
CN106681912A (en) Method and device for automatic testing of code coverage rate, applied to Android system
US8924937B1 (en) Method and system for generating verification information and tests for software
CN107704393B (en) Data test method, apparatus and electronic equipment
CN108073400A (en) Software automation construction method, server and storage medium
CN109426516A (en) Software version management method and device
US20110197098A1 (en) Method and apparatus for test coverage analysis
US20180173610A1 (en) Method for performing cared-zone code coverage evaluation with no source code modification
CN104407980A (en) Mobile application automated testing device and method
CN106933609A (en) The generation method and device of Android application program installation kits
CN103885341B (en) Performance analysis system based on automotive performance simulator and method
CN103530209A (en) Automated testing method for code keyboard
CN101008962A (en) Verification method for configurable and replaceable reference model used by network chip
US20080127061A1 (en) Method and system for editing code
CN102520949B (en) Formalized computer interlocking realization method
CN111767232A (en) Equipment test program set verification system
Lee et al. A New Integrated Software Development Environment Based on SDL, MSC, and CHILL for Large‐scale Switching Systems
Kim Mobile applications software testing methodology
CN112099453B (en) Function verification system of nuclear power plant safety level instrument control system
CN115688644A (en) Verification method for solving problem of poor consistency between rtl simulation design and chip algorithm
CN104569650B (en) A kind of instrument driving implementation method based on signal
CN102567187B (en) A kind of method utilizing C++test to perform SCADE tested object
CN114327403A (en) Development method and device of intelligent contract and electronic equipment
CN101281479A (en) A method for dynamic memory allocation of wireless sensor network node operating system
CN105446866A (en) Cross-platform testing device

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
CB02 Change of applicant information

Address after: 102209 Beijing, Beiqijia, the future of science and technology in the south area of China electronic network security and information technology industry base C building,

Applicant after: Beijing CEC Huada Electronic Design Co., Ltd.

Address before: 100102 Beijing City, Chaoyang District Lize two Road No. 2, Wangjing science and Technology Park A block five layer

Applicant before: Beijing CEC Huada Electronic Design Co., Ltd.

COR Change of bibliographic data
GR01 Patent grant
GR01 Patent grant