CN115840692A - Code overlay method, apparatus, device, computer readable medium and program product - Google Patents

Code overlay method, apparatus, device, computer readable medium and program product Download PDF

Info

Publication number
CN115840692A
CN115840692A CN202211255774.XA CN202211255774A CN115840692A CN 115840692 A CN115840692 A CN 115840692A CN 202211255774 A CN202211255774 A CN 202211255774A CN 115840692 A CN115840692 A CN 115840692A
Authority
CN
China
Prior art keywords
class
code
modified
code coverage
coverage information
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.)
Pending
Application number
CN202211255774.XA
Other languages
Chinese (zh)
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 Jingdong Century Trading Co Ltd
Beijing Wodong Tianjun Information Technology Co Ltd
Original Assignee
Beijing Jingdong Century Trading Co Ltd
Beijing Wodong Tianjun Information Technology 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 Jingdong Century Trading Co Ltd, Beijing Wodong Tianjun Information Technology Co Ltd filed Critical Beijing Jingdong Century Trading Co Ltd
Priority to CN202211255774.XA priority Critical patent/CN115840692A/en
Publication of CN115840692A publication Critical patent/CN115840692A/en
Pending legal-status Critical Current

Links

Images

Abstract

Embodiments of the present disclosure disclose code overlay methods, apparatus, devices, computer readable media and program products. One embodiment of the method comprises: selecting classes meeting preset filtering conditions from a class set of a target application to be run as classes to be modified to obtain a class set to be modified; for each class to be modified in the class set to be modified, responding to the class file loaded with the class to be modified, and performing code covering and instrumentation on the class file; and running the target application to be run to obtain at least one code coverage information. The embodiment is related to code testing, and code coverage related information can be acquired in real time without code invasion.

Description

Code overlay method, apparatus, device, computer readable medium and program product
Technical Field
Embodiments of the present disclosure relate to the field of computer technology, and in particular, to a code overlay method, apparatus, device, computer-readable medium, and program product.
Background
Code coverage is a measure in software testing that describes the proportion and extent to which source code in a program is tested. At present, when acquiring code coverage related information, the method generally adopted is as follows: the code coverage is obtained in a static manner.
However, the inventors have found that when the code coverage related information is acquired in the above manner, there are often technical problems as follows: the static mode cannot realize that the code coverage related information can be acquired in real time without code invasion when the application program is operated.
The above information disclosed in this background section is only for enhancement of understanding of the background of the inventive concept and, therefore, it may contain information that does not form the prior art that is already known to a person of ordinary skill in the art in this country.
Disclosure of Invention
This summary is provided to introduce a selection of concepts in a simplified form that are further described below in the detailed description. This summary is not intended to identify key features or essential features of the claimed subject matter, nor is it intended to be used to limit the scope of the claimed subject matter.
Some embodiments of the present disclosure propose code overlay methods, apparatuses, electronic devices, computer readable media and computer program products to address one or more of the technical problems noted in the background section above.
In a first aspect, some embodiments of the present disclosure provide a code overlay method, the method comprising: selecting classes meeting preset filtering conditions from a class set of a target application to be run as classes to be modified to obtain a class set to be modified; for each class to be modified in the class set to be modified, responding to the class file loaded with the class to be modified, and performing code covering and instrumentation on the class file; and running the target application to be run to obtain at least one code coverage information.
Optionally, the performing code coverage instrumentation on the class file includes: adding class probes in the class files; and adding at least one method probe in the class file.
Optionally, the performing code coverage instrumentation on the class file includes: a row probe is added to each row of the class file.
Optionally, the performing code coverage instrumentation on the class file includes: adding a method row probe to each row of each method block in at least one method block of the class file.
Optionally, the performing code coverage instrumentation on the class file includes: and adding an ending probe before the returning method block and/or the abnormal exiting method block of the class file.
Optionally, the running the target application to be run further includes: and issuing the at least one piece of code coverage information.
Optionally, the issuing the at least one piece of code coverage information includes: adding each obtained code coverage information to a code coverage information queue; and storing each code coverage information in the code coverage information queue to a storage terminal.
Optionally, the method further comprises: acquiring a code coverage information set corresponding to the target application to be run from the storage end; and carrying out visualization processing on the code coverage information set.
In a second aspect, some embodiments of the present disclosure provide a code overlay apparatus, the apparatus comprising: the selection unit is configured to select a class meeting a preset filtering condition from a class set of a target application to be run as a class to be modified, so as to obtain a class set to be modified; the instrumentation unit is configured to respond to the detection of loading of the class file of the class to be modified and perform code coverage instrumentation on the class file for each class to be modified in the class set to be modified; and the running unit is configured to run the target application to be run to obtain at least one piece of code coverage information.
Optionally, the pile inserting unit is further configured to: adding a class probe in the class file; and adding at least one method probe in the class file.
Optionally, the pile inserting unit is further configured to: a row probe is added to each row of the class file.
Optionally, the pile inserting unit is further configured to: adding a method line probe to each line of each method block in at least one method block of the class file.
Optionally, the pile inserting unit is further configured to: and adding an ending probe before the returning method block and/or the abnormal exiting method block of the class file.
Optionally, the operation unit comprises: and the issuing unit is configured to issue the at least one piece of code coverage information.
Optionally, the publication unit is further configured to: adding each obtained code coverage information to a code coverage information queue; and storing each code coverage information in the code coverage information queue to a storage terminal.
Optionally, the apparatus further comprises: an acquisition unit and a visualization unit. The obtaining unit is configured to obtain a code coverage information set corresponding to the target application to be run from the storage terminal. The visualization unit is configured to perform visualization processing on the code coverage information set.
In a third aspect, some embodiments of the present disclosure provide an electronic device, comprising: one or more processors; a storage device, on which one or more programs are stored, which when executed by one or more processors cause the one or more processors to implement the method described in any implementation of the first aspect.
In a fourth aspect, some embodiments of the present disclosure provide a computer readable medium on which a computer program is stored, wherein the program, when executed by a processor, implements the method described in any of the implementations of the first aspect.
In a fifth aspect, some embodiments of the present disclosure provide a computer program product comprising a computer program that, when executed by a processor, implements the method described in any of the implementations of the first aspect above.
The above embodiments of the present disclosure have the following advantages: by the code coverage method of some embodiments of the disclosure, code coverage related information can be acquired in real time without code invasion. Specifically, the reason why the real-time acquisition of the code coverage related information without code intrusion when the application is running cannot be realized is that: the static mode cannot realize that the code coverage related information can be acquired in real time without code invasion when the application program is operated. Based on this, in the code coverage method of some embodiments of the present disclosure, first, a class meeting a preset filtering condition is selected from a class set of a target application to be run as a class to be modified, so as to obtain a class set to be modified. Therefore, each class to be modified in the class set to be modified can represent the class file to be modified so as to be used for code coverage. And then, for each class to be modified in the class set to be modified, responding to the class file loaded with the class to be modified, and performing code covering and instrumentation on the class file. Therefore, when the class file of the class to be modified is loaded, the pile can be inserted in the class file in advance for acquiring the code coverage related information. And finally, running the target application to be run to obtain at least one code coverage information. Therefore, when the target application to be run is run, the code coverage information can be acquired in real time. And the code coverage instrumentation processing is executed when the class file of the class to be modified is loaded, so that the running of the target application to be run is not influenced, and the code coverage related information can be acquired in real time without code invasion.
Drawings
The above and other features, advantages and aspects of various embodiments of the present disclosure will become more apparent by referring to the following detailed description when taken in conjunction with the accompanying drawings. Throughout the drawings, the same or similar reference numbers refer to the same or similar elements. It should be understood that the drawings are schematic and that elements and elements are not necessarily drawn to scale.
FIG. 1 is an architectural diagram of an exemplary system in which some embodiments of the present disclosure may be applied;
FIG. 2 is a schematic diagram of one application scenario of a code overlay method according to some embodiments of the present disclosure;
FIG. 3 is a flow diagram of some embodiments of a code overlay method according to the present disclosure;
FIG. 4 is a flow diagram of further embodiments of a code overlay method according to the present disclosure;
FIG. 5 is a flow diagram of still further embodiments of a code overlay method according to the present disclosure;
FIG. 6 is a schematic structural diagram of some embodiments of a code overlay apparatus according to the present disclosure;
FIG. 7 is a schematic block diagram of an electronic device suitable for use in implementing some embodiments of the present disclosure.
Detailed Description
Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. While certain embodiments of the present disclosure are shown in the drawings, it is to be understood that the disclosure may be embodied in various forms and should not be construed as limited to the embodiments set forth herein. Rather, these embodiments are provided for a more thorough and complete understanding of the present disclosure. It should be understood that the drawings and embodiments of the disclosure are for illustration purposes only and are not intended to limit the scope of the disclosure.
It should be noted that, for convenience of description, only the portions related to the present invention are shown in the drawings. The embodiments and features of the embodiments in the present disclosure may be combined with each other without conflict.
It should be noted that the terms "first", "second", and the like in the present disclosure are only used for distinguishing different devices, modules or units, and are not used for limiting the order or interdependence relationship of the functions performed by the devices, modules or units.
It is noted that references to "a", "an", and "the" modifications in this disclosure are intended to be illustrative rather than limiting, and that those skilled in the art will recognize that "one or more" may be used unless the context clearly dictates otherwise.
The names of messages or information exchanged between devices in the embodiments of the present disclosure are for illustrative purposes only, and are not intended to limit the scope of the messages or information.
The present disclosure will be described in detail below with reference to the accompanying drawings in conjunction with embodiments.
Fig. 1 illustrates an exemplary system architecture 100 to which a code overlay method or code overlay apparatus of some embodiments of the present disclosure may be applied.
As shown in fig. 1, the system architecture 100 may include terminal devices 101, 102, 103, a network 104, and a server 105. The network 104 serves as a medium for providing communication links between the terminal devices 101, 102, 103 and the server 105. Network 104 may include various connection types, such as wired, wireless communication links, or fiber optic cables, to name a few.
The user may use the terminal devices 101, 102, 103 to interact with the server 105 via the network 104 to receive or send messages or the like. The terminal devices 101, 102, 103 may have various communication client applications installed thereon, such as a web browser application, a search-type application, an instant messaging tool, a mailbox client, social platform software, and the like.
The terminal devices 101, 102, 103 may be hardware or software. When the terminal devices 101, 102, 103 are hardware, they may be various electronic devices having a display screen and supporting information display, including but not limited to smart phones, tablet computers, e-book readers, laptop portable computers, desktop computers, and the like. When the terminal apparatuses 101, 102, 103 are software, they can be installed in the electronic apparatuses listed above. It may be implemented, for example, as multiple software or software modules to provide distributed services, or as a single software or software module. And is not particularly limited herein.
The server 105 may be a server providing various services, such as a background server providing support for information displayed on the terminal devices 101, 102, 103. The background server can analyze and process the received data such as the request and feed back the processing result to the terminal equipment.
It should be noted that the code coverage method provided by the embodiments of the present disclosure may be executed by the terminal devices 101, 102, 103. Accordingly, the code overlay means may be provided in the terminal device 101, 102, 103.
The server may be hardware or software. When the server is hardware, it may be implemented as a distributed server cluster formed by multiple servers, or may be implemented as a single server. When the server is software, it may be implemented as multiple pieces of software or software modules, for example, to provide distributed services, or as a single piece of software or software module. And is not particularly limited herein.
It should be understood that the number of terminal devices, networks, and servers in fig. 1 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
Fig. 2 is a schematic diagram of one application scenario of the code coverage method of some embodiments of the present disclosure.
In the application scenario of fig. 2, first, the computing device 201 may select a class satisfying a preset filtering condition from the class set 203 of the target application 202 to be run as a class to be modified, and obtain a class set 204 to be modified. Then, for each class to be modified (for example, the class to be modified 2041) in the class to be modified set 204, the computing device 201 may perform code coverage instrumentation on the class file 205 in response to detecting that the class file 205 of the class to be modified 2041 is loaded. Finally, the computing device 201 may run the target application to be run 202, resulting in at least one code coverage information 206. For example, the at least one code overlay information 206 may include "[ class name: name ], [ class name: age ] ".
The computing device 201 may be hardware or software. When the computing device is hardware, it may be implemented as a distributed cluster composed of multiple servers or terminal devices, or may be implemented as a single server or a single terminal device. When the computing device is embodied as software, it may be installed in the hardware devices enumerated above. It may be implemented, for example, as multiple software or software modules to provide distributed services, or as a single software or software module. And is not particularly limited herein.
It should be understood that the number of computing devices in FIG. 2 is merely illustrative. There may be any number of computing devices, as the implementation requires.
With continued reference to fig. 3, a flow 300 of some embodiments of a code overlay method according to the present disclosure is shown. The code covering method comprises the following steps:
step 301, selecting a class meeting a preset filtering condition from the class set of the target application to be run as a class to be modified, and obtaining a class set to be modified.
In some embodiments, an execution subject of the code coverage method (for example, the computing device 201 shown in fig. 2) may select a class satisfying a preset filtering condition from a class set of a target application to be run as a class to be modified, resulting in a class set to be modified. The target application to be run may be an application that needs to be tested and is not run currently, and may be represented by an application program code. For example, the target application to be executed may be code written in JAVA programming language. The class set may be a respective reference data type of the target application to be run. Here, a class may be the basis for object-oriented programming to implement information encapsulation. The preset filtering condition may be a condition preset by a tester for selecting a class of a class file to be modified. For example, the preset filtering condition may be "the package name corresponding to the class includes a preset character string". Here, the specific setting of the preset character string is not limited.
It is to be understood that the execution subject may be a computing device storing application program code of the target application to be executed for execution.
Step 302, for each class to be modified in the class set to be modified, in response to detecting that the class file of the class to be modified is loaded, performing code coverage instrumentation on the class file.
In some embodiments, for each class to be modified in the set of classes to be modified, the execution main body may perform code coverage instrumentation on the class file in response to detecting that the class file of the class to be modified is loaded. The class file may be in a binary representation of the application program. For example, the class file may be a Java class file, i.e., a class file. The class file of the application to be executed may be loaded by a JVM (Java Virtual Machine). When the JVM loads the class binary file, the loaded class file can be dynamically modified. In practice, first, the execution body may add a class name acquisition probe to the class file. The above-mentioned class name acquisition probe may be a probe inserted into program code to acquire a class name. The class name acquisition probe is used for acquiring a class name corresponding to a method, and storing variables corresponding to the class name. The class name storage variable may be a variable for storing the class name acquired by the class name acquisition probe. Thus, the class name of the current class can be acquired by the class name acquisition probe. The acquired class name may be stored by the class name storage variable of the above-described class name acquisition probe.
In some optional implementations of some embodiments, the execution agent may add a class probe to the class file. Wherein the class probe may be a class name acquisition probe. Then, at least one method probe may be added to the class file. Among them, the method probe may be a method name acquisition probe. The above-mentioned method name acquisition probe may be a probe inserted into program code to acquire a method name. Each of the at least one method probe corresponds to a method. The respective method to which at least one method probe corresponds may be determined by the tester. The method names of the above methods to be executed are acquired. The method name acquisition probe is used for acquiring a method name (namely, a function for acquiring the method name) and storing a variable corresponding to the method name. The method name storage variable may be a variable for storing a method name acquired by the method name acquisition probe. Thus, the class name and method name of the executed class file can be acquired.
Optionally, the execution agent may add an end probe before the return method block and/or the exception exit method block of the class file. The return method block may be a code block of a return method in the class file. The exception exit method block may be a code block of an exception exit method in the class file. The end probe may be a probe for generating method end information for characterizing the end of execution of the method. The end probe corresponds to a method for generating method end information, and stores a variable corresponding to the method end information. The method end information storage variable may be a variable for storing the method end information generated by the end probe. In practice, the execution body may add an end probe immediately before the return method block and the abnormal exit method block, respectively. Thereby, the method end information can be acquired by ending the probe.
Step 303, running the target application to be run to obtain at least one code coverage information.
In some embodiments, the execution subject may execute the target application to be executed, and obtain at least one code coverage information. In practice, the execution subject may use each class file after the code coverage instrumentation process as an updated class file, and run the target application to be run. Then, the information stored by each information storage variable may be determined as code coverage information. The above-mentioned information storage variable may be a variable for storing information acquired by the added probe. Each probe added corresponds to an information storage variable. The above information storage variables may include, but are not limited to: class name storage variables and method name storage variables. It is to be understood that the at least one code coverage information may include code coverage information acquired by the probe added in each class file after the code coverage instrumentation process.
Optionally, the execution subject may issue the at least one code coverage information. In practice, the execution body may send the at least one code coverage information to the server. Here, the server may be a computing device for storing code coverage information. The execution agent may obtain each piece of code coverage information, and then issue the obtained code coverage information. Thereby, the resulting code coverage information may be automatically transmitted to the respective storage device.
In some optional implementations of some embodiments, first, the execution body may add each of the obtained code coverage information to a code coverage information queue. The code coverage information queue may be a message queue for storing code coverage information. In practice, the execution body may add the code coverage information to an end position of the code coverage information queue. Then, the code coverage information in the code coverage information queue may be stored in a storage. The storage terminal may be a computing device or a distributed computing device for storing the code coverage information. For example, the storage end may be an Elasticsearch cluster. Therefore, the code coverage information can be stored in the code coverage information queue firstly, and then each code coverage information in the code coverage information queue is stored in the storage end, so that the storage pressure and the network pressure when the data volume is large can be buffered.
Optionally, the execution main body may obtain, from the storage end, a code coverage information set corresponding to the target application to be run. In practice, the execution main body may obtain, from the storage end, each piece of code coverage information that a corresponding application identifier is the same as an application identifier of the target application to be executed and a corresponding execution time is within a preset time period, as a code coverage information set. The execution time may be a time when the probe acquires code coverage information. The respective code coverage information may include execution time. The code coverage information set may then be visualized. In practice, for each piece of code coverage information in the code coverage information set, the execution subject may render a page area corresponding to the code coverage information in a visualization page by using a visualization template corresponding to the code coverage information. As an example, when the code coverage information is code coverage information acquired by a class probe, the execution subject may display a class name included in the code coverage information in text style information included in a class name visualization template in a page area corresponding to the class name. When the code coverage information is obtained by the method probe, the execution subject may display the method name included in the code coverage information in text style information included in the method name visualization template in a page area corresponding to the method name. Here, the text style information may include, but is not limited to, at least one of: text font size, text font, text style, text color, text background color. When the code coverage information is obtained through a line probe, the execution subject may display, in a page area corresponding to a line dimension, an execution line number and a code coverage rate included in the code coverage information in a visualization chart corresponding to a line visualization template. For example, the visualization chart corresponding to the line visualization template may be a pie chart. The number of execution lines may be displayed in a caption module of the pie chart. Code coverage can be visually displayed in a graphic display module of the pie chart.
It should be noted that, the data acquired by each added probe may be corresponding to a unique thread identifier, so as to ensure the uniqueness of the acquired data.
The above embodiments of the present disclosure have the following advantages: by the code coverage method of some embodiments of the disclosure, code coverage related information can be acquired in real time without code invasion. Specifically, the reason why the real-time acquisition of the code coverage related information without code intrusion when the application is running cannot be realized is that: the static mode cannot realize that the code coverage related information can be acquired in real time without code invasion when the application program is operated. Based on this, in the code coverage method of some embodiments of the present disclosure, first, a class meeting a preset filtering condition is selected from a class set of a target application to be run as a class to be modified, so as to obtain a class set to be modified. Therefore, each class to be modified in the class set to be modified can represent the class file to be modified for code coverage. And then, for each class to be modified in the class set to be modified, responding to the class file loaded with the class to be modified, and performing code covering and instrumentation on the class file. Therefore, when the class file of the class to be modified is loaded, the pile can be inserted in the class file in advance for acquiring the code coverage related information. And finally, running the target application to be run to obtain at least one code coverage information. Therefore, when the target application to be run is run, the code coverage information can be obtained in real time. And the code coverage instrumentation processing is executed when the class file of the class to be modified is loaded, so that the running of the target application to be run is not influenced, and the code coverage related information can be acquired in real time without code invasion.
With further reference to FIG. 4, a flow 400 of further embodiments of a code overlay method is illustrated. The flow 400 of the code overlay method includes the following steps:
step 401, selecting a class meeting a preset filtering condition from a class set of a target application to be run as a class to be modified, and obtaining a class set to be modified.
In some embodiments, the specific implementation of step 401 and the technical effect brought by the implementation may refer to step 301 in those embodiments corresponding to fig. 3, which are not described herein again.
Step 402, for each class to be modified in the class set to be modified, in response to detecting that the class file of the class to be modified is loaded, adding a line probe to each line of the class file.
In some embodiments, for each class to be modified in the set of classes to be modified, an execution subject of the code overlay method (e.g., the computing device 201 shown in fig. 2) may add a line probe to each line of the class file in response to detecting that the class file of the class to be modified is loaded. The line probe may be a probe for acquiring code coverage information of a line dimension. Here, the code coverage information of the line dimension may include the number of execution lines. The code coverage information of the line dimension may further include a ratio of the number of execution lines to the total number of lines of the class file, i.e., a code coverage. The number of execution lines may be the number of lines already executed in the class file. The line probe can correspond to a method for acquiring the number of execution lines and a line dimension code coverage information storage variable. The line probe may also correspond to a method of acquiring code coverage. The row dimension code coverage information storage variable may be a variable for storing code coverage information of a row dimension acquired by the row probe. As an example, a line probe may be added based on jacoco, and here, a method of acquiring the number of execution lines may be a method of rewriting.
And step 403, running the target application to be run to obtain at least one code coverage information.
In some embodiments, the specific implementation of step 403 and the technical effect brought by the implementation may refer to step 303 in those embodiments corresponding to fig. 3, and are not described herein again.
As can be seen from fig. 4, the flow 400 of the code overlay method in some embodiments corresponding to fig. 4 embodies the step of extending the add line probe compared to the description of some embodiments corresponding to fig. 3. Thus, the schemes described in these embodiments may be instrumented from the dimensions of the rows of the class file to obtain code coverage information for the dimensions of the rows executed in the class file.
With further reference to FIG. 5, a flow 500 of still further embodiments of a code overlay method is illustrated. The process 500 of the code overlay method includes the following steps:
step 501, selecting a class meeting a preset filtering condition from a class set of a target application to be run as a class to be modified, and obtaining a class set to be modified.
In some embodiments, the specific implementation of step 501 and the technical effect brought by the implementation may refer to step 301 in those embodiments corresponding to fig. 3, which are not described herein again.
Step 502, for each class to be modified in the class set to be modified, in response to detecting that the class file of the class to be modified is loaded, adding a method row probe to each row of each method block in at least one method block of the class file.
In some embodiments, for each class to be modified in the set of classes to be modified, an execution subject of the code overlay method (e.g., the computing device 201 shown in fig. 2) may add a method row probe in each row of each method block in at least one method block of the class file in response to detecting that the class file of the class to be modified is loaded. The at least one method block may be a method block of a method to be tested determined by a tester. The method block may be a code block of a method in a class file. The method line probe may be a probe for acquiring code coverage information of a line dimension in a method block. Here, the code coverage information of the line dimension in the method block may include the number of execution lines of the method. The code coverage information of the line dimension in the method block may further include a ratio of the number of execution lines of the method to the total number of lines of the method block, i.e., the code coverage of the method block. The number of execution rows of a method may be the number of rows already executed in a method block. The method line probe can correspond to a method for acquiring the execution line number of the method and a method block line dimension code coverage information storage variable. The method line probe may also correspond to a method of obtaining code coverage of a method block. The method block line dimension code coverage information storage variable may be a variable for storing code coverage information acquired by the method line probe. As an example, a method line probe may be added based on jacoco, where the method of obtaining the number of execution lines of the method may be a newly added method.
Step 503, running the target application to be run to obtain at least one code coverage information.
In some embodiments, the specific implementation of step 503 and the technical effect brought by the implementation may refer to step 303 in those embodiments corresponding to fig. 3, and are not described herein again.
As can be seen from fig. 5, compared with the description of some embodiments corresponding to fig. 3, the flow 500 of the code overlay method in some embodiments corresponding to fig. 5 represents a step of expanding the add method line probe. Thus, the schemes described by these embodiments may be instrumented from the dimensions of the rows of the methods of the class file, with code coverage information for the row dimensions of the method blocks.
With further reference to fig. 6, as an implementation of the methods illustrated in the above figures, the present disclosure provides some embodiments of a code overlay apparatus, which correspond to those illustrated in fig. 3, and which may be particularly applicable in various electronic devices.
As shown in FIG. 6, the code overlay apparatus 600 of some embodiments comprises: a selection unit 601, a peg inserting unit 602 and a running unit 603. The selecting unit 601 is configured to select a class meeting a preset filtering condition from a class set of a target application to be run as a class to be modified, so as to obtain a class set to be modified; the instrumentation unit 602 is configured to perform, for each class to be modified in the class to be modified set, code coverage instrumentation on a class file in response to detecting that the class file of the class to be modified is loaded; the execution unit 603 is configured to execute the target application to be executed, and obtain at least one piece of code coverage information.
Optionally, the staking unit 602 may be further configured to: adding class probes in the class files; and adding at least one method probe in the class file.
Optionally, the staking unit 602 may be further configured to: a row probe is added to each row of the class file.
Optionally, the staking unit 602 may be further configured to: adding a method line probe to each line of each method block in at least one method block of the class file.
Optionally, the staking unit 602 may be further configured to: and adding an ending probe before the returning method block and/or the abnormal exiting method block of the class file.
Alternatively, the operation unit 603 may include: and an issuing unit (not shown) configured to perform an issuing process on the at least one code coverage information.
Optionally, the publication unit may be further configured to: adding each obtained code coverage information to a code coverage information queue; and storing each code coverage information in the code coverage information queue to a storage terminal.
Optionally, the code overlay apparatus 600 may further include: an acquisition unit and a visualization unit (not shown in the figure). The obtaining unit is configured to obtain a code coverage information set corresponding to the target application to be run from the storage terminal. The visualization unit is configured to perform visualization processing on the code coverage information set.
It will be understood that the elements described in the apparatus 600 correspond to various steps in the method described with reference to fig. 3. Thus, the operations, features and resulting advantages described above with respect to the method are also applicable to the apparatus 600 and the units included therein, and are not described herein again.
Referring now to FIG. 7, a block diagram of an electronic device (e.g., computing device 201 of FIG. 2) 700 suitable for use in implementing some embodiments of the present disclosure is shown. The electronic device shown in fig. 7 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present disclosure.
As shown in fig. 7, electronic device 700 may include a processing means (e.g., central processing unit, graphics processor, etc.) 701 that may perform various appropriate actions and processes in accordance with a program stored in a Read Only Memory (ROM) 702 or a program loaded from storage 708 into a Random Access Memory (RAM) 703. In the RAM 703, various programs and data necessary for the operation of the electronic apparatus 700 are also stored. The processing device 701, the ROM 702, and the RAM 703 are connected to each other by a bus 704. An input/output (I/O) interface 705 is also connected to bus 704.
Generally, the following devices may be connected to the I/O interface 705: input devices 706 including, for example, a touch screen, touch pad, keyboard, mouse, camera, microphone, accelerometer, gyroscope, or the like; an output device 707 including, for example, a Liquid Crystal Display (LCD), a speaker, a vibrator, and the like; storage 708 including, for example, magnetic tape, hard disk, etc.; and a communication device 709. The communication means 709 may allow the electronic device 700 to communicate wirelessly or by wire with other devices to exchange data. While fig. 7 illustrates an electronic device 700 having various means, it is to be understood that not all illustrated means are required to be implemented or provided. More or fewer devices may alternatively be implemented or provided. Each block shown in fig. 7 may represent one device or may represent multiple devices as desired.
In particular, according to some embodiments of the present disclosure, the processes described above with reference to the flow diagrams may be implemented as computer software programs. For example, some embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer-readable medium, the computer program comprising program code for performing the method illustrated by the flow chart. In some such embodiments, the computer program may be downloaded and installed from a network via communications means 709, or may be installed from storage 708, or may be installed from ROM 702. The computer program, when executed by the processing device 701, performs the above-described functions defined in the methods of some embodiments of the present disclosure.
It should be noted that the computer readable medium described in some embodiments of the present disclosure may be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In some embodiments of the disclosure, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In some embodiments of the present disclosure, however, a computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: electrical wires, optical cables, RF (radio frequency), etc., or any suitable combination of the foregoing.
In some embodiments, the clients, servers may communicate using any currently known or future developed network Protocol, such as HTTP (HyperText Transfer Protocol), and may interconnect with any form or medium of digital data communication (e.g., a communications network). Examples of communication networks include a local area network ("LAN"), a wide area network ("WAN"), the Internet (e.g., the Internet), and peer-to-peer networks (e.g., ad hoc peer-to-peer networks), as well as any currently known or future developed network.
The computer readable medium may be embodied in the electronic device; or may exist separately without being assembled into the electronic device. The computer readable medium carries one or more programs which, when executed by the electronic device, cause the electronic device to: selecting classes meeting preset filtering conditions from a class set of a target application to be run as classes to be modified to obtain a class set to be modified; for each class to be modified in the class set to be modified, responding to the class file loaded with the class to be modified, and performing code covering and instrumentation on the class file; and running the target application to be run to obtain at least one code coverage information.
Computer program code for carrying out operations for embodiments of the present disclosure may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, smalltalk, C + +, and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider).
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems that perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The units described in some embodiments of the present disclosure may be implemented by software or hardware. The described units may also be provided in a processor, and may be described as: a processor includes a selection unit, a instrumentation unit, and an execution unit. For example, the selection unit may also be described as "selecting a class satisfying a preset filtering condition from a class set of the target application to be run as a class to be modified, resulting in a unit of the class set to be modified".
The functions described herein above may be performed, at least in part, by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field Programmable Gate Arrays (FPGAs), application Specific Integrated Circuits (ASICs), application Specific Standard Products (ASSPs), systems on a chip (SOCs), complex Programmable Logic Devices (CPLDs), and the like.
Some embodiments of the present disclosure also provide a computer program product comprising a computer program that, when executed by a processor, implements any of the code coverage methods described above.
The foregoing description is only exemplary of the preferred embodiments of the disclosure and is illustrative of the principles of the technology employed. It will be appreciated by those skilled in the art that the scope of the invention in the embodiments of the present disclosure is not limited to the specific combination of the above-mentioned features, but also encompasses other embodiments in which any combination of the above-mentioned features or their equivalents is made without departing from the inventive concept as defined above. For example, the above features and (but not limited to) technical features with similar functions disclosed in the embodiments of the present disclosure are mutually replaced to form the technical solution.

Claims (12)

1. A code overlay method comprising:
selecting classes meeting preset filtering conditions from a class set of a target application to be run as classes to be modified to obtain a class set to be modified;
for each class to be modified in the class set to be modified, responding to the class file loaded with the class to be modified, and performing code covering and instrumentation on the class file;
and running the target application to be run to obtain at least one code coverage information.
2. The method of claim 1, wherein the code overlay instrumentation of the class file comprises:
adding class probes in the class file;
adding at least one method probe to the class file.
3. The method of claim 1, wherein the code overlay instrumentation of the class file comprises:
adding a row probe to each row of the class file.
4. The method of claim 1, wherein the code overlay instrumentation of the class file comprises:
adding a method row probe to each row of each method block in at least one method block of the class file.
5. The method of claim 1, wherein the code overlay instrumentation of the class file comprises:
adding an end probe before a return method block and/or an exception exit method block of the class file.
6. The method of any of claims 1-5, wherein the running the target application-to-be-run further comprises:
and issuing the at least one code coverage information.
7. The method of claim 6, wherein said publishing the at least one code coverage information comprises:
adding each obtained code coverage information to a code coverage information queue;
and storing each piece of code coverage information in the code coverage information queue to a storage terminal.
8. The method of claim 7, wherein the method further comprises:
acquiring a code coverage information set corresponding to the target application to be run from the storage terminal;
and carrying out visualization processing on the code coverage information set.
9. A code overlay apparatus comprising:
the selection unit is configured to select a class meeting a preset filtering condition from a class set of a target application to be run as a class to be modified, so as to obtain a class set to be modified;
the instrumentation unit is configured to perform code coverage instrumentation on each class to be modified in the class set to be modified in response to detecting that a class file of the class to be modified is loaded;
and the running unit is configured to run the target application to be run to obtain at least one piece of code coverage information.
10. An electronic device, comprising:
one or more processors;
a storage device having one or more programs stored thereon,
when executed by the one or more processors, cause the one or more processors to implement the method of any one of claims 1-8.
11. A computer-readable medium, on which a computer program is stored, wherein the program, when executed by a processor, implements the method of any one of claims 1-8.
12. A computer program product comprising a computer program which, when executed by a processor, implements the method according to any one of claims 1-8.
CN202211255774.XA 2022-10-13 2022-10-13 Code overlay method, apparatus, device, computer readable medium and program product Pending CN115840692A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211255774.XA CN115840692A (en) 2022-10-13 2022-10-13 Code overlay method, apparatus, device, computer readable medium and program product

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211255774.XA CN115840692A (en) 2022-10-13 2022-10-13 Code overlay method, apparatus, device, computer readable medium and program product

Publications (1)

Publication Number Publication Date
CN115840692A true CN115840692A (en) 2023-03-24

Family

ID=85575593

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211255774.XA Pending CN115840692A (en) 2022-10-13 2022-10-13 Code overlay method, apparatus, device, computer readable medium and program product

Country Status (1)

Country Link
CN (1) CN115840692A (en)

Similar Documents

Publication Publication Date Title
CN109684188B (en) Test method and device
CN112631590B (en) Component library generation method, device, electronic equipment and computer readable medium
CN111459364B (en) Icon updating method and device and electronic equipment
CN109582317B (en) Method and apparatus for debugging hosted applications
CN113505302A (en) Method, device and system for supporting dynamic acquisition of buried point data and electronic equipment
CN109656799B (en) Test method and device
CN111273830A (en) Data display method and device, electronic equipment and computer readable medium
CN112954056B (en) Method and device for processing monitoring data, electronic equipment and storage medium
CN111596992B (en) Navigation bar display method and device and electronic equipment
CN112800363A (en) Page display method and device, electronic equipment and computer readable medium
CN115454956A (en) Log generation method and device, electronic equipment and storage medium
CN114840379A (en) Log generation method, device, server and storage medium
CN115840692A (en) Code overlay method, apparatus, device, computer readable medium and program product
CN109889402B (en) Method and apparatus for generating information
CN112464039A (en) Data display method and device of tree structure, electronic equipment and medium
CN113704079A (en) Interface testing method and device based on Protobuf
CN108459890B (en) Interface display method and device for application
CN111767486A (en) Method, device, electronic equipment and computer readable medium for displaying page
CN112579428A (en) Interface testing method and device, electronic equipment and storage medium
CN113407229B (en) Method and device for generating offline scripts
CN113760706B (en) Webpage debugging method and device
CN114428823B (en) Data linkage method, device, equipment and medium based on multidimensional variable expression
CN115062022B (en) Aircraft manual splitting method, device, electronic equipment and computer readable medium
CN116185521A (en) Data driving method, apparatus, device, computer readable medium, and program product
CN113867827A (en) Method and device for loading webpage

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination