CN111026630A - Statistical method, device and system for code coverage rate - Google Patents

Statistical method, device and system for code coverage rate Download PDF

Info

Publication number
CN111026630A
CN111026630A CN201811173609.3A CN201811173609A CN111026630A CN 111026630 A CN111026630 A CN 111026630A CN 201811173609 A CN201811173609 A CN 201811173609A CN 111026630 A CN111026630 A CN 111026630A
Authority
CN
China
Prior art keywords
statistical
file
code
data packet
function
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.)
Granted
Application number
CN201811173609.3A
Other languages
Chinese (zh)
Other versions
CN111026630B (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.)
Alibaba Group Holding Ltd
Original Assignee
Alibaba Group Holding 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 Alibaba Group Holding Ltd filed Critical Alibaba Group Holding Ltd
Priority to CN201811173609.3A priority Critical patent/CN111026630B/en
Publication of CN111026630A publication Critical patent/CN111026630A/en
Application granted granted Critical
Publication of CN111026630B publication Critical patent/CN111026630B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3604Software analysis for verifying properties of programs
    • G06F11/3612Software analysis for verifying properties of programs by runtime analysis
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3604Software analysis for verifying properties of programs
    • G06F11/3616Software analysis for verifying properties of programs using software metrics

Abstract

The invention discloses a statistical method, a device and a system for code coverage rate. Wherein, the method comprises the following steps: analyzing the received data packet file; if the data packet file meets the preset pile inserting condition, function statistical codes are set for executable files in the data packet file; running the data packet file, and performing code coverage rate statistics on the data packet file according to the function statistical codes to obtain a statistical file; and judging whether to upload the statistical file according to the trigger condition in the function statistical code. The invention solves the technical problem that the prior art can not realize multi-user sampling of the on-line application program in the process of counting the code coverage rate.

Description

Statistical method, device and system for code coverage rate
Technical Field
The invention relates to the field of Internet technology application, in particular to a statistical method, a statistical device and a statistical system for code coverage rate.
Background
Code coverage is an important criterion for measuring the quality of codes of a product, and particularly for large projects, multiple teams are required to develop and complete cooperatively. At the moment, the statistics of the code coverage rate is very important, and if a set of good code coverage rate statistics tool is provided, developers can be at least assisted to know the execution proportion of effective codes after the application is released; second, which functions are hotspot functions and which are not substantially called; thirdly, counting the time consumed by function calling frequency; the information has great reference value for optimizing self application of developers and reducing volume, and particularly has urgent business requirements for large projects.
However, the traditional code coverage rate statistical scheme used by android applications is based on the steps that instructions are inserted into jar packages firstly, and then the dx compiling tool provided by google is used for compiling the jar packages into dex files, so that the purpose of realizing code coverage rate statistics is achieved. This solution has the following problems: firstly, a process is complicated by converting jar packet processing into dex, and meanwhile, the risk of compiling errors exists; secondly, the socket pile inserting treatment is completed and then dex is converted, so that the size is overlarge; third, the modified pattern of jar packets does not depend on the constant pool of dex itself, which results in slow performance during statistical recording. Due to the defects, the method can only be used in a test stage for large-scale application, and cannot be applied to online sampling of multiple users of an application program.
Aiming at the problem that multi-user sampling of an online application program cannot be realized in the process of counting the code coverage rate in the prior art, an effective solution is not provided at present.
Disclosure of Invention
The embodiment of the invention provides a statistical method, a statistical device and a statistical system of code coverage rate, which at least solve the technical problem that multi-user sampling of an online application program cannot be realized in the process of carrying out statistics on the code coverage rate in the prior art.
According to an aspect of an embodiment of the present invention, there is provided a statistical method of code coverage, including: analyzing the received data packet file; if the data packet file meets the preset pile inserting condition, function statistical codes are set for executable files in the data packet file; running the data packet file, and performing code coverage rate statistics on the data packet file according to the function statistical codes to obtain a statistical file; and judging whether to upload the statistical file according to the trigger condition in the function statistical code.
Optionally, the preset pile inserting conditions include: judging whether the data packet file is damaged or not; or judging whether the data packet file is legal or not.
Optionally, under the condition that the function statistics code includes a triggering interception statistics code, a statistics code, and an instrumentation statistics instruction, setting the function statistics code for the executable file in the data packet file includes: setting a triggering interception statistical code in an executable file, wherein the triggering interception statistical code is used for intercepting a code of foreground and background page switching logic of an application system; setting a statistical code and a pile-inserting statistical instruction in an executable file according to the triggering interception statistical code, wherein the statistical code is used for calling a statistical function; and; a pile-inserting counting instruction is used for recording the calling times of each counting function; modifying the method reference number in the set executable file to obtain an executable file with the modified method reference number; and adding an initial statistical file in the executable file of the reference number of the modification method, wherein the initial statistical file is used for recording the times of calling each function when the data packet file runs and storing a statistical result.
Further, optionally, after setting the triggered interception statistical code in the executable file, the method further includes: and setting a statistical time length, wherein the statistical time length is used for recording the function calling times in the executable file in a unit time interval.
Optionally, the setting of the statistical code and the instrumentation statistical instruction in the executable file according to the triggered interception statistical code includes: setting a pile-inserting statistical instruction according to a function corresponding to the method reference number in the executable file; and setting a statistical code in the executable file provided with the instrumentation statistical instruction.
Optionally, modifying the method reference number in the set executable file to obtain the executable file with the modified method reference number includes: counting the method reference number in the set executable file; and configuring the counted method reference number in the instrumentation statistics instruction to obtain an executable file for modifying the method reference number.
Optionally, the method further includes: and under the condition that the data packet file does not meet the preset instrumentation condition, the data packet file is not processed.
Optionally, performing code coverage rate statistics on the data packet file according to the function statistical code to obtain a statistical file includes: calling times of each function in the data packet file according to the triggering interception statistical code, the statistical code and the instrumentation statistical instruction in the function statistical code; and counting the times into an initial statistical file in the executable file to obtain a statistical file.
Optionally, judging whether to upload the statistical file according to the trigger condition in the function statistical code includes: and uploading the statistical files generated in the statistical duration to the server under the condition that the triggering condition comprises the statistical duration, so that the server can generate a statistical result according to the statistical files uploaded each time.
According to another aspect of the embodiments of the present invention, there is also provided a statistical apparatus for code coverage, including: the analysis module is used for analyzing the received data packet file; the setting module is used for setting function statistical codes for executable files in the data package file if the data package file meets the preset instrumentation conditions; the statistical module is used for operating the data packet file, performing code coverage rate statistics on the data packet file according to the function statistical code, and obtaining a statistical file; and the sending module is used for judging whether the statistical file is uploaded or not according to the triggering condition in the function statistical code.
According to another aspect of the embodiments of the present invention, there is also provided a statistical system of code coverage, including: the terminal is used for analyzing the received data packet file, and setting a function statistical code for the executable file in the data packet file if the data packet file meets a preset instrumentation condition; running the data packet file, and performing code coverage rate statistics on the data packet file according to the function statistical codes to obtain a statistical file; judging whether to upload the statistical file according to the triggering condition in the function statistical code; and the server is connected with the terminal and used for generating a statistical result according to the statistical file uploaded each time.
According to still another aspect of the embodiments of the present invention, there is provided a storage medium including a stored program, wherein when the program runs, a device on which the storage medium is located is controlled to execute the statistical method for code coverage.
In the embodiment of the invention, a method of modifying dex files and inserting piles in an android application program is adopted, a method of counting when the program runs and counting code function runs is adopted, and a received data packet file is analyzed; if the data packet file meets the preset pile inserting condition, function statistical codes are set for executable files in the data packet file; running the data packet file, and performing code coverage rate statistics on the data packet file according to the function statistical codes to obtain a statistical file; whether the statistical file is uploaded is judged according to the trigger condition in the function statistical code, the purposes of overcoming overlarge file volume and serious statistical performance loss are achieved, the technical effect of reducing the performance loss of the statistics in operation is achieved, and the technical problem that multi-user sampling of an online application program cannot be achieved in the process of counting the code coverage rate in the prior art is solved.
Drawings
The accompanying drawings, which are included to provide a further understanding of the invention and are incorporated in and constitute a part of this application, illustrate embodiment(s) of the invention and together with the description serve to explain the invention without limiting the invention. In the drawings:
fig. 1 is a block diagram of a hardware structure of a computer terminal of a statistical method of code coverage according to an embodiment of the present invention;
FIG. 2 is a flowchart of a statistical method of code coverage according to a first embodiment of the present invention;
FIG. 3 is a block diagram of a statistical apparatus of code coverage according to a second embodiment of the present invention;
fig. 4 is a schematic diagram of an execution logic of a statistical system of code coverage according to a third embodiment of the present invention.
Detailed Description
In order to make the technical solutions of the present invention better understood, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
It should be noted that the terms "first," "second," and the like in the description and claims of the present invention and in the drawings described above are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used is interchangeable under appropriate circumstances such that the embodiments of the invention described herein are capable of operation in sequences other than those illustrated or described herein. Furthermore, the terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed, but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.
The technical terms related to the present application are:
dex: dalvik executable file format;
coco: code coverage code.
Example 1
There is also provided, in accordance with an embodiment of the present invention, an embodiment of a statistical method of code coverage, it being noted that the steps illustrated in the flowchart of the figure may be performed in a computer system such as a set of computer-executable instructions and that, although a logical order is illustrated in the flowchart, in some cases the steps illustrated or described may be performed in an order different than here.
The method provided by the first embodiment of the present application may be executed in a mobile terminal, a computer terminal, or a similar computing device. Taking the example of running on a computer terminal, fig. 1 is a block diagram of a hardware structure of the computer terminal of a statistical method of code coverage according to an embodiment of the present invention. As shown in fig. 1, the computer terminal 10 may include one or more (only one shown) processors 102 (the processor 102 may include, but is not limited to, a processing device such as a microprocessor MCU or a programmable logic device FPGA), a memory 104 for storing data, and a transmission module 106 for communication functions. It will be understood by those skilled in the art that the structure shown in fig. 1 is only an illustration and is not intended to limit the structure of the electronic device. For example, the computer terminal 10 may also include more or fewer components than shown in FIG. 1, or have a different configuration than shown in FIG. 1.
The memory 104 may be used to store software programs and modules of application software, such as program instructions/modules corresponding to the statistical method of code coverage in the embodiment of the present invention, and the processor 102 executes various functional applications and data processing by running the software programs and modules stored in the memory 104, that is, implementing the statistical method of code coverage of the application program. The memory 104 may include high speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include memory located remotely from the processor 102, which may be connected to the computer terminal 10 via a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
The transmission device 106 is used for receiving or transmitting data via a network. Specific examples of the network described above may include a wireless network provided by a communication provider of the computer terminal 10. In one example, the transmission device 106 includes a Network Interface Controller (NIC) that can be connected to other Network devices through a base station to communicate with the internet. In one example, the transmission device 106 can be a Radio Frequency (RF) module, which is used to communicate with the internet in a wireless manner.
Under the above operating environment, the present application provides a statistical method of code coverage as shown in fig. 2. Fig. 2 is a flowchart of a statistical method of code coverage according to a first embodiment of the present invention.
Step S202, analyzing the received data packet file;
in step S202, before counting the code coverage, the received data packet file needs to be analyzed, and in the code coverage counting method provided in the embodiment of the present application, a description is given by taking an example of being applicable to an android application to modify a dex file, where the predetermined instrumentation condition includes determining whether the data packet file is damaged; or, under the condition of judging whether the data packet file is legal, analyzing the received data packet file comprises detecting whether the data packet file meets the preset instrumentation condition, namely, judging whether the data packet file is damaged; or, whether the data packet file is legal or not is judged, if the judgment result is yes, the step S204 is executed, and if the judgment result is no, the execution is refused.
Step S204, if the data packet file meets the preset instrumentation condition, function statistical codes are set for executable files in the data packet file;
in step S204, based on the analysis in step S202, when the data package file meets the preset instrumentation condition, a function statistic code is set for an executable file in the data package file, where the executable file may be a Dex file in this embodiment, and thus setting the function statistic code for the Dex file includes: setting pre-buried statistical codes and pile inserting statistical instructions;
specifically, the function statistical code set for the executable file in the data packet file is specifically as follows:
(1) and embedding a triggering statistic interception code so as to intercept a code of a foreground and background page switching logic of the android system, wherein the purpose of intercepting foreground and background page switching is mainly to know that a user really uses the application for counting instead of counting when the application runs in the background in order to ensure the correctness of counting. And setting the statistical duration, and counting the recording frequency and other information.
(2) Pre-embedding statistical codes and instrumentation statistical instructions comprises: when the application program to be counted runs, after the interception code is triggered, when the counting condition is met, the counting of the function calling times is needed, the logic of the code needs to be embedded in advance, namely, the counting is realized by embedding the counting code, and the embedding counting code carries out the time counting through the function calling.
In order to improve execution efficiency, pre-embedding of the instrumentation statistical instruction distinguishes different functions according to the method reference number, and further statistics of function calling times is achieved.
(3) And calculating the method reference number of the method needing statistics in the Dex file.
(4) Modifying method reference numbers in the instrumented instructions.
(5) And generating a pre-installed initial statistical file.
Because the times of calling each function need to be continuously recorded during the running of the program, and the statistical result is stored in a file, a statistical file needs to be generated in advance for improving the running efficiency, and all the times of calling the functions are all 0, so that the IO load can be reduced during the running, and the statistical efficiency is improved.
Step S206, operating the data packet file, and performing code coverage rate statistics on the data packet file according to the function statistical code to obtain a statistical file;
in step S206, code coverage statistics is performed on the Apk file based on the function statistical code obtained in step S204, and the statistical result is finally stored in the statistical file pre-installed in step S204.
Step S208, judging whether to upload the statistical file according to the trigger condition in the function statistical code.
In step S208, when the trigger condition is based on the statistical duration set in step S204, when the timing of the statistical duration is over, the statistical file is uploaded to the server, so that the server performs sampling analysis according to the statistical result in the plurality of statistical files.
In summary, with reference to steps S202 to S208, the statistical method for code coverage provided in the embodiment of the present application first analyzes the Apk file, and determines whether a preset instrumentation condition can be met; under the condition that a preset pile inserting condition is met, directly embedding a statistical code and a pile inserting statistical instruction into a Dex file in an Apk file; executing a code coverage function when the program runs, and counting functions; and judging whether to report the statistical file to the server according to a trigger condition in the embedded code, and finally outputting a result after the statistical file is analyzed by the server and sampled and analyzed.
In the embodiment of the invention, a method of modifying dex files and inserting piles in an android application program is adopted, a method of counting when the program runs and counting code function runs is adopted, and a received data packet file is analyzed; if the data packet file meets the preset pile inserting condition, function statistical codes are set for executable files in the data packet file; running the data packet file, and performing code coverage rate statistics on the data packet file according to the function statistical codes to obtain a statistical file; whether the statistical file is uploaded is judged according to the trigger condition in the function statistical code, the purposes of overcoming overlarge file volume and serious statistical performance loss are achieved, the technical effect of reducing the performance loss of the statistics in operation is achieved, and the technical problem that multi-user sampling of an online application program cannot be achieved in the process of counting the code coverage rate in the prior art is solved.
Optionally, in the case that the function statistics code includes a triggering interception statistics code, a statistics code, and an instrumentation statistics instruction, the setting of the function statistics code for the executable file in the data packet file in step S204 includes:
step S2041, setting a triggering interception statistical code in the executable file, wherein the triggering interception statistical code is used for intercepting a code of foreground and background page switching logic of the application system;
step S2042, setting a statistical code and a pile-inserting statistical instruction in the executable file according to the triggered interception statistical code, wherein the statistical code is used for calling a statistical function; and; a pile-inserting counting instruction is used for recording the calling times of each counting function;
step S2043, modifying the method reference number in the set executable file to obtain an executable file with the modified method reference number;
step S2044, adding an initial statistical file to the executable file of the modification method reference number, where the initial statistical file is used to record the number of times of each function call when the data package file runs, and store the statistical result.
Specifically, with reference to steps S2041 to S2044, the function statistical code is specifically set for the executable file in the data package file as follows:
(1) and embedding a triggering statistic interception code so as to intercept a code of a foreground and background page switching logic of the android system, wherein the purpose of intercepting foreground and background page switching is mainly to know that a user really uses the application for counting instead of counting when the application runs in the background in order to ensure the correctness of counting. And setting the statistical duration, and counting the recording frequency and other information.
(2) Pre-embedding statistical codes and instrumentation statistical instructions comprises: when the application program to be counted runs, after the interception code is triggered, when the counting condition is met, the counting of the function calling times is needed, the logic of the code needs to be embedded in advance, namely, the counting is realized by embedding the counting code, and the embedding counting code carries out the time counting through the function calling.
In order to improve execution efficiency, pre-embedding of the instrumentation statistical instruction distinguishes different functions according to the method reference number, and further statistics of function calling times is achieved.
(3) Calculating the method reference number of the method needing statistics in the Dex file; modifying method reference numbers in the instrumented instructions.
(4) And generating a pre-installed initial statistical file.
Because the times of calling each function need to be continuously recorded during the running of the program, and the statistical result is stored in a file, a statistical file needs to be generated in advance for improving the running efficiency, and all the times of calling the functions are all 0, so that the IO load can be reduced during the running, and the statistical efficiency is improved.
Further, optionally, after the triggering interception statistic code is set in the executable file in step S2041, the statistical method for code coverage provided in the embodiment of the present application further includes:
step S2045, setting a statistical time length, wherein the statistical time length is used for recording the function calling times in the executable file in a unit time interval.
Optionally, the step S2042 of setting the statistical code and the instrumentation statistical instruction in the executable file according to the triggered interception statistical code includes:
step S20421, setting a pile insertion statistical instruction according to a function corresponding to the method reference number in the executable file;
step S20422, a statistical code is set in the executable file with the instrumentation statistical instruction.
Specifically, with reference to step S20421 and step S20422, when the application program to be counted runs, after the statistical code is triggered to be intercepted, when the statistical condition is satisfied, the function is called according to the statistical code to count the times. In order to improve execution efficiency, the instrumentation statistical instruction distinguishes different functions according to the method reference number, and statistics of function calling times is further achieved.
Optionally, in step S2043, modifying the method reference number in the set executable file, and obtaining the executable file with the modified method reference number includes:
step S20431, counting the number of method references in the set executable file;
step S20432, configure the counted method reference number in the instrumentation statistics instruction, and obtain an executable file for modifying the method reference number.
Specifically, in combination with step S20431 and step S20432, since the original Dex file has been modified and the related code is added to the Dex file, the number of methods and the number of references of the original Dex file are changed, and the number of references of methods of a new Dex file needs to be recalculated here.
Optionally, the statistical method for code coverage provided in the embodiment of the present application further includes: and under the condition that the judgment result is negative, the data packet file is not processed.
Optionally, in step S206, performing code coverage rate statistics on the data packet file according to the function statistical code, and obtaining a statistical file includes:
step S2061, according to the times of calling each function in the data packet file by the triggering interception statistical code, the statistical code and the instrumentation statistical instruction in the function statistical code;
step S2062, count the number of times into the initial statistical file in the executable file to obtain a statistical file.
Specifically, in combination with step S2061 and step S2062, since the function statistic code has been previously set in step S204, that is, the function statistic code includes: intercepting the statistical codes, counting the codes and inserting the statistical instructions, directly running the corresponding codes during running, and recording the calling times of the functions in the application by continuously modifying the initial statistical files.
Optionally, the step S208 of determining whether to upload the statistical file according to the trigger condition in the function statistical code includes:
step S2081, uploading the statistical files generated in the statistical duration to the server under the condition that the triggering condition includes the statistical duration, so that the server can generate a statistical result according to the statistical files uploaded each time.
Specifically, since the interception statistical code, the instrumentation statistical instruction, and the trigger condition are preset in step 204, if it is determined during the operation that the trigger condition, such as the statistical duration, is reached, the pre-installed statistical file is reported to the server, and the statistics is stopped; so that the server outputs the result after analyzing the sample.
Because different users have different use habits, the code statistics needs to have a certain sample number for averaging, so that the server needs to sample a certain number of statistical files, analyze the statistical files and output an average result.
It should be noted that, for simplicity of description, the above-mentioned method embodiments are described as a series of acts or combination of acts, but those skilled in the art will recognize that the present invention is not limited by the order of acts, as some steps may occur in other orders or concurrently in accordance with the invention. Further, those skilled in the art should also appreciate that the embodiments described in the specification are preferred embodiments and that the acts and modules referred to are not necessarily required by the invention.
Through the above description of the embodiments, those skilled in the art can clearly understand that the statistical method of code coverage according to the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but the former is a better implementation mode in many cases. Based on such understanding, the technical solutions of the present invention may be embodied in the form of a software product, which is stored in a storage medium (e.g., ROM/RAM, magnetic disk, optical disk) and includes instructions for enabling a terminal device (e.g., a mobile phone, a computer, a server, or a network device) to execute the method according to the embodiments of the present invention.
Example 2
According to an embodiment of the present invention, there is also provided an apparatus for implementing the statistical method of code coverage, as shown in fig. 3, fig. 3 is a structural diagram of a statistical apparatus of code coverage according to a second embodiment of the present invention, the apparatus including:
the analysis module 32 is used for analyzing the received data packet file; a setting module 34, configured to set a function statistic code for the executable file in the data package file if the data package file meets a preset instrumentation condition; the statistical module 36 is configured to run the data package file, perform code coverage statistics on the data package file according to the function statistical code, and obtain a statistical file; and the sending module 38 is configured to determine whether to upload the statistical file according to the trigger condition in the function statistical code.
Example 3
According to another aspect of the embodiment of the present invention, there is further provided a statistical system of code coverage, as shown in fig. 4, fig. 4 is a schematic diagram of an execution logic of the statistical system of code coverage according to a third embodiment of the present invention, including: the terminal 42 is used for analyzing the received data packet file, and if the data packet file meets a preset instrumentation condition, setting a function statistical code for an executable file in the data packet file; running the data packet file, and performing code coverage rate statistics on the data packet file according to the function statistical codes to obtain a statistical file; judging whether to upload the statistical file according to the triggering condition in the function statistical code; and the server 44 is connected with the terminal 42 and used for generating a statistical result according to the statistical file uploaded each time.
Example 4
According to still another aspect of the embodiments of the present invention, there is provided a storage medium including a stored program, wherein when the program runs, a device on which the storage medium is located is controlled to execute the statistical method for code coverage.
Example 5
The embodiment of the invention also provides a storage medium. Optionally, in this embodiment, the storage medium may be configured to store program codes executed by the statistical method for code coverage provided in the first embodiment.
Optionally, in this embodiment, the storage medium may be located in any one of computer terminals in a computer terminal group in a computer network, or in any one of mobile terminals in a mobile terminal group.
Optionally, in this embodiment, the storage medium is configured to store program code for performing the following steps: analyzing the received data packet file; if the data packet file meets the preset pile inserting condition, function statistical codes are set for executable files in the data packet file; running the data packet file, and performing code coverage rate statistics on the data packet file according to the function statistical codes to obtain a statistical file; and judging whether to upload the statistical file according to the trigger condition in the function statistical code.
Optionally, in this embodiment, the storage medium is configured to store program code for performing the following steps: the preset pile inserting conditions comprise: judging whether the data packet file is damaged or not; or judging whether the data packet file is legal or not.
Optionally, in this embodiment, the storage medium is configured to store program code for performing the following steps: under the condition that the function statistic code comprises a triggering interception statistic code, a statistic code and an instrumentation statistic instruction, setting the function statistic code for the executable file in the data packet file comprises the following steps: setting a triggering interception statistical code in an executable file, wherein the triggering interception statistical code is used for intercepting a code of foreground and background page switching logic of an application system; setting a statistical code and a pile-inserting statistical instruction in an executable file according to the triggering interception statistical code, wherein the statistical code is used for calling a statistical function; and; a pile-inserting counting instruction is used for recording the calling times of each counting function; modifying the method reference number in the set executable file to obtain an executable file with the modified method reference number; and adding an initial statistical file in the executable file of the reference number of the modification method, wherein the initial statistical file is used for recording the times of calling each function when the data packet file runs and storing a statistical result.
Further, optionally, in the present embodiment, the storage medium is configured to store program code for performing the following steps: and after the trigger interception counting code is set in the executable file, setting counting time length, wherein the counting time length is used for recording the function calling times in the executable file in a unit time interval.
Optionally, in this embodiment, the storage medium is configured to store program code for performing the following steps: the step of setting a statistical code and a instrumentation statistical instruction in the executable file according to the triggered interception statistical code comprises the following steps: setting a pile-inserting statistical instruction according to a function corresponding to the method reference number in the executable file; and setting a statistical code in the executable file provided with the instrumentation statistical instruction.
Optionally, in this embodiment, the storage medium is configured to store program code for performing the following steps: modifying the method reference number in the set executable file to obtain the executable file with the modified method reference number, wherein the step of modifying the method reference number comprises the following steps: counting the method reference number in the set executable file; and configuring the counted method reference number in the instrumentation statistics instruction to obtain an executable file for modifying the method reference number.
Optionally, in this embodiment, the storage medium is configured to store program code for performing the following steps: and under the condition that the data packet file does not meet the preset instrumentation condition, the data packet file is not processed.
Optionally, in this embodiment, the storage medium is configured to store program code for performing the following steps: performing code coverage rate statistics on the data packet file according to the function statistical codes to obtain a statistical file, wherein the statistical file comprises the following steps: calling times of each function in the data packet file according to the triggering interception statistical code, the statistical code and the instrumentation statistical instruction in the function statistical code; and counting the times into an initial statistical file in the executable file to obtain a statistical file.
Optionally, in this embodiment, the storage medium is configured to store program code for performing the following steps: judging whether to upload the statistical file according to the triggering condition in the function statistical code comprises the following steps: and uploading the statistical files generated in the statistical duration to the server under the condition that the triggering condition comprises the statistical duration, so that the server can generate a statistical result according to the statistical files uploaded each time.
The above-mentioned serial numbers of the embodiments of the present invention are merely for description and do not represent the merits of the embodiments.
In the above embodiments of the present invention, the descriptions of the respective embodiments have respective emphasis, and for parts that are not described in detail in a certain embodiment, reference may be made to related descriptions of other embodiments.
In the embodiments provided in the present application, it should be understood that the disclosed technology can be implemented in other ways. The above-described embodiments of the apparatus are merely illustrative, and for example, the division of the units is only one type of division of logical functions, and there may be other divisions when actually implemented, for example, a plurality of units or components may be combined or may be integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, units or modules, and may be in an electrical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit.
The integrated unit, if implemented in the form of a software functional unit and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a removable hard disk, a magnetic or optical disk, and other various media capable of storing program codes.
The foregoing is only a preferred embodiment of the present invention, and it should be noted that, for those skilled in the art, various modifications and decorations can be made without departing from the principle of the present invention, and these modifications and decorations should also be regarded as the protection scope of the present invention.

Claims (12)

1. A statistical method of code coverage, comprising:
analyzing the received data packet file;
if the data packet file meets a preset pile inserting condition, function statistical codes are set for executable files in the data packet file;
running the data packet file, and performing code coverage rate statistics on the data packet file according to the function statistical code to obtain a statistical file;
and judging whether to upload the statistical file according to the trigger condition in the function statistical code.
2. The statistical method of code coverage according to claim 1, wherein the preset instrumentation conditions include:
judging whether the data packet file is damaged or not; or the like, or, alternatively,
and judging whether the data packet file is legal or not.
3. The code coverage rate statistical method according to claim 1, wherein in a case that the function statistic code includes a trigger interception statistic code, a statistic code and an instrumentation statistic instruction, the setting of the function statistic code on the executable file in the data packet file includes:
setting the triggering interception statistical code in the executable file, wherein the triggering interception statistical code is used for intercepting a code of foreground and background page switching logic of an application system;
setting the statistical code and the instrumentation statistical instruction in the executable file according to the triggering interception statistical code, wherein the statistical code is used for calling a statistical function; and; the pile-inserting counting instruction is used for recording the calling times of each counting function;
modifying the method reference number in the set executable file to obtain an executable file for modifying the method reference number;
and adding an initial statistical file in the executable file for modifying the reference number of the method, wherein the initial statistical file is used for recording the times of calling each function when the data packet file runs and storing a statistical result.
4. The statistical method of code coverage according to claim 3, wherein after the setting the trigger intercept statistics code in the executable file, the method further comprises:
and setting a statistical time length, wherein the statistical time length is used for recording the function calling times in the executable file in a unit time interval.
5. The statistical method of code coverage according to claim 3, wherein the setting the statistical code and the instrumentation statistical instruction in the executable file according to the triggering interception statistical code comprises:
setting the instrumentation statistical instruction according to a function corresponding to the method reference number in the executable file;
and setting the statistical code in the executable file provided with the instrumentation statistical instruction.
6. The method for counting code coverage according to claim 3, wherein the modifying the method reference number in the set executable file to obtain the executable file with the modified method reference number comprises:
counting the method reference number in the executable file after setting;
and configuring the counted method reference number in the instrumentation statistical instruction to obtain an executable file for modifying the method reference number.
7. The statistical method of code coverage according to claim 1, wherein the method further comprises:
and under the condition that the data package file does not meet the preset instrumentation condition, the data package file is not processed.
8. The method for counting code coverage according to any one of claims 1 to 7, wherein performing code coverage counting on the data packet file according to the function counting code to obtain a counting file comprises:
calling times of each function in the data packet file according to the triggering interception statistical code, the statistical code and the instrumentation statistical instruction in the function statistical code;
and counting the times into an initial statistical file in the executable file to obtain the statistical file.
9. The method for counting code coverage rate according to claim 1, wherein the determining whether to upload the statistical file according to the trigger condition in the function statistical code comprises:
and uploading the statistical files generated in the statistical duration to a server under the condition that the triggering condition comprises the statistical duration, so that the server can generate a statistical result according to the statistical files uploaded each time.
10. A statistical apparatus of code coverage, comprising:
the analysis module is used for analyzing the received data packet file;
the setting module is used for setting function statistical codes for the executable files in the data package file if the data package file meets the preset instrumentation conditions;
the statistical module is used for operating the data packet file, performing code coverage rate statistics on the data packet file according to the function statistical code, and obtaining a statistical file;
and the sending module is used for judging whether to upload the statistical file according to the triggering condition in the function statistical code.
11. A statistical system of code coverage comprising: a terminal and a server, wherein,
the terminal is used for analyzing the received data packet file, and setting a function statistical code for the executable file in the data packet file if the data packet file meets a preset instrumentation condition; running the data packet file, and performing code coverage rate statistics on the data packet file according to the function statistical code to obtain a statistical file; judging whether to upload the statistical file according to a trigger condition in the function statistical code;
and the server is connected with the terminal and used for generating a statistical result according to the statistical file uploaded each time.
12. A storage medium comprising a stored program, wherein the program, when executed, controls an apparatus on which the storage medium is located to perform: a statistical method of code coverage as recited in claim 1.
CN201811173609.3A 2018-10-09 2018-10-09 Statistical method, device and system for code coverage rate Active CN111026630B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201811173609.3A CN111026630B (en) 2018-10-09 2018-10-09 Statistical method, device and system for code coverage rate

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201811173609.3A CN111026630B (en) 2018-10-09 2018-10-09 Statistical method, device and system for code coverage rate

Publications (2)

Publication Number Publication Date
CN111026630A true CN111026630A (en) 2020-04-17
CN111026630B CN111026630B (en) 2023-05-02

Family

ID=70190671

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201811173609.3A Active CN111026630B (en) 2018-10-09 2018-10-09 Statistical method, device and system for code coverage rate

Country Status (1)

Country Link
CN (1) CN111026630B (en)

Citations (13)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6581191B1 (en) * 1999-11-30 2003-06-17 Synplicity, Inc. Hardware debugging in a hardware description language
CN1517876A (en) * 2003-01-17 2004-08-04 华为技术有限公司 Statistical method for covering rate of embedded system
US20120167057A1 (en) * 2010-12-22 2012-06-28 Microsoft Corporation Dynamic instrumentation of software code
US20120246627A1 (en) * 2011-03-24 2012-09-27 International Business Machines Corporation Adding Instrumentation to a Body of Code to Enable Generation of Code Coverage Data
US20130212564A1 (en) * 2012-02-14 2013-08-15 Alibaba Group Holding Limited Code coverage rate determination method and system
CN104199773A (en) * 2014-09-03 2014-12-10 腾讯科技(深圳)有限公司 Method and device for obtaining code coverage information
CN104598274A (en) * 2015-01-13 2015-05-06 北京京东尚科信息技术有限公司 Automatic instrumentation, compiling and installing method and system
CN104834859A (en) * 2015-04-24 2015-08-12 南京邮电大学 Method for dynamically detecting malicious behavior in Android App (Application)
CN105446884A (en) * 2015-12-16 2016-03-30 北京奇虎科技有限公司 Code coverage rate test method and apparatus
CN105573915A (en) * 2015-12-16 2016-05-11 北京奇虎科技有限公司 Test method and device based on code coverage rate
US20170083430A1 (en) * 2015-09-22 2017-03-23 Red Hat Israel, Ltd. Code coverage plugin
CN106547680A (en) * 2015-09-17 2017-03-29 腾讯科技(深圳)有限公司 Data processing method and device in coverage rate test
CN106681912A (en) * 2016-12-08 2017-05-17 武汉斗鱼网络科技有限公司 Method and device for automatic testing of code coverage rate, applied to Android system

Patent Citations (13)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6581191B1 (en) * 1999-11-30 2003-06-17 Synplicity, Inc. Hardware debugging in a hardware description language
CN1517876A (en) * 2003-01-17 2004-08-04 华为技术有限公司 Statistical method for covering rate of embedded system
US20120167057A1 (en) * 2010-12-22 2012-06-28 Microsoft Corporation Dynamic instrumentation of software code
US20120246627A1 (en) * 2011-03-24 2012-09-27 International Business Machines Corporation Adding Instrumentation to a Body of Code to Enable Generation of Code Coverage Data
US20130212564A1 (en) * 2012-02-14 2013-08-15 Alibaba Group Holding Limited Code coverage rate determination method and system
CN104199773A (en) * 2014-09-03 2014-12-10 腾讯科技(深圳)有限公司 Method and device for obtaining code coverage information
CN104598274A (en) * 2015-01-13 2015-05-06 北京京东尚科信息技术有限公司 Automatic instrumentation, compiling and installing method and system
CN104834859A (en) * 2015-04-24 2015-08-12 南京邮电大学 Method for dynamically detecting malicious behavior in Android App (Application)
CN106547680A (en) * 2015-09-17 2017-03-29 腾讯科技(深圳)有限公司 Data processing method and device in coverage rate test
US20170083430A1 (en) * 2015-09-22 2017-03-23 Red Hat Israel, Ltd. Code coverage plugin
CN105446884A (en) * 2015-12-16 2016-03-30 北京奇虎科技有限公司 Code coverage rate test method and apparatus
CN105573915A (en) * 2015-12-16 2016-05-11 北京奇虎科技有限公司 Test method and device based on code coverage rate
CN106681912A (en) * 2016-12-08 2017-05-17 武汉斗鱼网络科技有限公司 Method and device for automatic testing of code coverage rate, applied to Android system

Non-Patent Citations (4)

* Cited by examiner, † Cited by third party
Title
DÁVID TENGERI ET AL.: "Negative Effects of Bytecode Instrumentation on Java Source Code Coverage" *
刘利枚;周鲜成;石彪;: "嵌入式软件测试系统的设计与实现" *
姜文;刘立康;: "基于持续集成的C/C++软件覆盖率测试" *
张荣;王曙燕;: "基于插桩技术的动态测试研究与实现" *

Also Published As

Publication number Publication date
CN111026630B (en) 2023-05-02

Similar Documents

Publication Publication Date Title
US8874736B2 (en) Event extractor
CN104978263A (en) Mobile terminal application program test method and mobile terminal application program test system
CN105052076B (en) Network element management system and network element management method based on cloud computing
CN105487966A (en) Program testing method, device and system
AU2014359172B2 (en) Network server system, client device, computer program product and computer-implemented method
CN110727697A (en) Data processing method and device, storage medium and electronic device
CN103986788A (en) Data fetching method and device of OTT (over the top) application
CN112422557A (en) Attack testing method and device for industrial control network
CN103686821A (en) Control method for application program traffic statistics according to unique identification of mobile terminal
EP2741449B1 (en) Processing of call data records
CN111858113B (en) Application program repairing method and device, service system and storage medium
CN108170600A (en) The coverage rate statistical method of front-end code test, apparatus and system
CN105843740B (en) Method and device for detecting code compiling result
CN111026630A (en) Statistical method, device and system for code coverage rate
CN108400901B (en) Application testing method, terminal device and computer readable storage medium
CN104182331A (en) Browser performance test method, browser performance test system and terminal
CN108924840B (en) Blacklist management method and device and terminal
CN112364267B (en) Front-end data acquisition method and device
Cai et al. Delaydroid: reducing tail-time energy by refactoring android apps
CN111641959A (en) Method and device for detecting network environment information
CN105357272A (en) OTA (Over the Air) upgrading method and device
CN113687870B (en) Terminal operation optimization method and device, storage medium and terminal
CN103444214A (en) Method, apparatus and computer program product for security configuration coordination during a cell update procedure
CN112817536B (en) Data packet capturing method and related device
CN113434417B (en) Regression testing method and device for loopholes, storage medium and electronic device

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
GR01 Patent grant
GR01 Patent grant