CN111026630B - 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
CN111026630B
CN111026630B CN201811173609.3A CN201811173609A CN111026630B CN 111026630 B CN111026630 B CN 111026630B CN 201811173609 A CN201811173609 A CN 201811173609A CN 111026630 B CN111026630 B CN 111026630B
Authority
CN
China
Prior art keywords
statistical
file
code
data packet
statistics
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201811173609.3A
Other languages
Chinese (zh)
Other versions
CN111026630A (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, device and 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, setting a function statistical code for an executable file in the data packet file; running the data packet file, and executing 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 triggering condition in the function statistical code. The invention solves the technical problem that the prior art can not realize multi-user sampling of the online 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, device and system of code coverage rate.
Background
Code coverage is an important criterion for measuring the quality of codes of a product, and particularly for large projects, a plurality of teams are required to cooperatively develop and complete. At this time, the statistics of the code coverage rate is very important, and if a set of good code coverage rate statistics tools are provided, at least developers can be assisted to know that the first is the proportion of effective code execution after the application is released; second, which functions are hot spot functions and which functions are not substantially invoked; thirdly, counting the time consumption of the function call frequency; the information has great reference value for the developer to optimize self application and reduce volume, and especially has urgent business requirement for large projects.
However, the code coverage rate statistics scheme used by the traditional android application is based on inserting an instruction into a jar packet, and then compiling the jar packet into a dex file by using a dx compiling tool provided by google, so that the purpose of realizing code coverage rate statistics is achieved. This solution has the following problems: firstly, converting jar packet processing into dex, which is complicated in process and meanwhile has the risk of compiling errors; secondly, the jar pile inserting treatment is completed and then dex is turned, so that the volume is overlarge; third, the jar packet modification mode may cause performance degradation during statistics recording because there is no constant pool that depends on dex itself. Because of the above drawbacks, for large applications, they can only be used in the test phase and cannot be applied to online multi-user sampling of applications.
Aiming at the problem that the prior art cannot realize multi-user sampling of online application programs in the process of counting the code coverage rate, no effective solution is proposed at present.
Disclosure of Invention
The embodiment of the invention provides a statistical method, device and system of code coverage rate, which at least solve the technical problem that the prior art cannot realize multi-user sampling of online application programs in the process of counting the code coverage rate.
According to an aspect of the 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, setting a function statistical code for an executable file in the data packet file; running the data packet file, and executing 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 triggering 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, in the case that the function statistics code includes a trigger intercept statistics code, a statistics code, and a instrumentation statistics instruction, setting the function statistics code for the executable file in the data packet file includes: setting a trigger interception statistical code in an executable file, wherein the trigger interception statistical code is used for intercepting codes of a 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; a kind of electronic device with high-pressure air-conditioning system; the pile inserting statistical instruction is used for recording the calling times of each statistical 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 into the executable file for modifying the method reference number, wherein the initial statistical file is used for recording the times of each function call when the data packet file runs, and storing the statistical result.
Further, optionally, after setting the trigger interception statistic code in the executable file, the method further includes: setting a statistical duration, wherein the statistical duration is used for recording the times of function call in the executable file in a unit time interval.
Optionally, setting the statistic code and the instrumentation statistic instruction in the executable file according to the triggering interception statistic 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 number of method references 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 comprises: and under the condition that the data packet file does not meet the preset pile inserting condition, the data packet file is not processed.
Optionally, performing code coverage statistics on the data packet file according to the function statistical code, where obtaining the statistical file includes: intercepting the times of calling 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.
Optionally, determining whether to upload the statistics file according to the triggering condition in the function statistics code includes: and uploading the statistical file generated in the statistical time length to a server under the condition that the triggering condition comprises the statistical time length, so that the server can generate a statistical result according to the statistical file uploaded each time.
According to another aspect of the embodiment of the present invention, there is also provided a device for counting code coverage, including: the analysis module is used for analyzing the received data packet file; the setting module is used for setting a function statistical code for an executable file in the data packet file if the data packet file meets a preset pile inserting condition; the statistics module is used for running the data packet file, and executing code coverage rate statistics on the data packet file according to the function statistics code to obtain a statistics 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.
According to still another aspect of the embodiment of the present invention, there is also provided a statistical system of code coverage, including: the system comprises a terminal and a server, wherein the terminal is used for analyzing a received data packet file, and setting a function statistical code for an executable file in the data packet file if the data packet file meets a preset pile inserting condition; running the data packet file, and executing 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 the triggering condition in the function statistical code; and the server is connected with the terminal and is used for generating a statistical result according to the statistical file uploaded each time.
According to still another aspect of the embodiment of the present invention, there is further provided a storage medium, where the storage medium includes a stored program, and when the program runs, the device where the storage medium is controlled to execute the above statistical method of code coverage.
In the embodiment of the invention, the method of modifying the dex file and inserting the stub in the android application program is adopted, statistics is carried out during program operation, the mode of code function operation is counted, and the received data packet file is analyzed; if the data packet file meets the preset pile inserting condition, setting a function statistical code for an executable file in the data packet file; running the data packet file, and executing code coverage rate statistics on the data packet file according to the function statistical code to obtain a statistical file; whether the statistical file is uploaded is judged according to the triggering condition in the function statistical code, the purposes of overcoming the overlarge file volume and serious statistical performance loss are achieved, the technical effect of reducing the statistical performance loss in running is achieved, and the technical problem that the multi-user sampling of the 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 embodiments of the invention and together with the description serve to explain the invention and do not constitute a limitation on the invention. In the drawings:
FIG. 1 is a block diagram of the hardware architecture of a computer terminal of a statistical method of code coverage according to an embodiment of the present invention;
FIG. 2 is a flow chart of a method of statistics 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 execution logic of a statistical system of code coverage according to the third embodiment of the present invention.
Detailed Description
In order that those skilled in the art will better understand the present invention, a technical solution in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in which it is apparent that the described embodiments are only some embodiments of the present invention, not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the present invention without making any inventive effort, shall fall within the scope of the present invention.
It should be noted that the terms "first," "second," and the like in the description and the claims of the present invention and the above figures are used for distinguishing between similar objects and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used may be interchanged where appropriate such that the embodiments of the invention described herein may be implemented in sequences other than those illustrated or otherwise 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 referred to in this application are:
dex: dalvik executable file format;
coco: abbreviation for code coverage code overlay.
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 shown in the flowchart of the figures may be performed in a computer system, such as a set of computer executable instructions, and that, although a logical sequence is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than what is shown or described herein.
The method embodiment provided in 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 the hardware structure of the computer terminal of a statistical method of code coverage rate according to an embodiment of the present invention. As shown in fig. 1, the computer terminal 10 may include one or more (only one is shown in the figure) processors 102 (the processors 102 may include, but are not limited to, a microprocessor MCU or a processing device such as a programmable logic device FPGA), a memory 104 for storing data, and a transmission module 106 for communication functions. It will be appreciated by those of ordinary skill in the art that the configuration shown in fig. 1 is merely illustrative and is not intended to limit the configuration of the electronic device described above. 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 the software programs and modules stored in the memory 104 to perform various functional applications and data processing, that is, implement the statistical method of code coverage of application programs. 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 module 106 is used to receive or transmit data via a network. The 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 module 106 includes a network adapter (Network Interface Controller, NIC) that can connect to other network devices through a base station to communicate with the internet. In one example, the transmission module 106 may be a Radio Frequency (RF) module for communicating with the internet wirelessly.
In the above-described 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 rate, the received data packet file needs to be parsed, and in the method for counting the code coverage rate provided in the embodiment of the present application, description is given by taking a dex file suitable for modification of an android application program as an example, where determining whether the data packet file is damaged is included in a preset instrumentation condition; 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 pile inserting condition, namely judging whether the data packet file is damaged; or, whether the packet file is legal or not is determined, and if yes, step S204 is executed, and if no, execution is refused.
Step S204, if the data packet file meets the preset pile-inserting condition, setting a function statistical code for an executable file in the data packet file;
in step S204, based on the analysis in step S202, if the packet file meets the preset instrumentation condition, a function statistical code is set for an executable file in the packet file, and in this embodiment, the executable file may be a Dex file, so the setting of the function statistical code for the Dex file includes: setting pre-buried statistical codes and pile inserting statistical instructions;
specifically, the function statistics code is set for the executable file in the data packet file as follows:
(1) The statistics interception codes are pre-embedded, so that codes of the foreground and background page switching logic of the android system are intercepted, and in order to ensure the accuracy of statistics, the interception of the foreground and background page switching is mainly used for knowing that a user is actually using the application to perform statistics, and the statistics is not performed when the application runs in the background. And setting statistical time length, and counting information such as recording frequency.
(2) The pre-buried statistical code and the pile inserting statistical instruction comprise: when the counted application program is running and after the interception code is triggered, when the counting condition is met, counting the number of times of function call is needed, and the code logic is needed to be embedded in advance, namely, the code logic is realized through an embedded counting code, and the embedded counting code counts the number of times through the function call.
In order to improve the execution efficiency, the pile inserting statistical instruction is embedded in advance, and different functions are distinguished according to the method reference number, so that statistics of function call times is achieved.
(3) The method reference number of the method requiring statistics in the Dex file is calculated.
(4) The method reference number in the instrumentation instruction is modified.
(5) A pre-installed initial statistics file is generated.
Because the times of each function call are required to be recorded continuously when the program runs, and the statistical result is stored in a file, in order to improve the running efficiency, a statistical file is required to be generated in advance, and all the times of the function call are 0, so that IO burden can be reduced when the program runs, and the statistical efficiency is improved.
Step S206, running the data packet file, and executing code coverage rate statistics on the data packet file according to the function statistical code to obtain a statistical file;
in step S206, based on the function statistical code obtained in step S204, code coverage statistics is performed on the Apk file, and finally, the statistical result is stored in the pre-installed statistical file in step S204.
Step S208, judging whether to upload the statistical file according to the triggering condition in the function statistical code.
In step S208, when the trigger condition is based on the statistical duration set in step S204, and the statistical duration timer is finished, the statistical file is uploaded to the server, so that the server performs sampling analysis according to the statistical results in the plurality of statistical files.
In summary, in combination with step S202 to step S208, the statistical method of code coverage provided in the embodiment of the present application first analyzes the Apk file, and determines whether a preset pile-inserting condition can be satisfied; under the condition that the preset pile inserting condition is met, directly embedding a statistical code and a pile inserting statistical instruction into a Dex file in the Apk file; executing a code coverage function when the program runs, and counting the functions; and judging whether to report the statistical file to the server according to the triggering condition in the embedded code, and finally analyzing by the server, sampling and analyzing and outputting the result.
In the embodiment of the invention, the method of modifying the dex file and inserting the stub in the android application program is adopted, statistics is carried out during program operation, the mode of code function operation is counted, and the received data packet file is analyzed; if the data packet file meets the preset pile inserting condition, setting a function statistical code for an executable file in the data packet file; running the data packet file, and executing code coverage rate statistics on the data packet file according to the function statistical code to obtain a statistical file; whether the statistical file is uploaded is judged according to the triggering condition in the function statistical code, the purposes of overcoming the overlarge file volume and serious statistical performance loss are achieved, the technical effect of reducing the statistical performance loss in running is achieved, and the technical problem that the multi-user sampling of the 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 the trigger interception statistics code, the statistics code, and the instrumentation statistics instruction, the setting the function statistics code for the executable file in the data packet file in step S204 includes:
step S2041, setting a trigger interception statistical code in an executable file, wherein the trigger interception statistical code is used for intercepting codes of a foreground and background page switching logic of an application system;
step S2042, 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; a kind of electronic device with high-pressure air-conditioning system; the pile inserting statistical instruction is used for recording the calling times of each statistical 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 statistics file in the executable file for modifying the method reference number, wherein the initial statistics file is used for recording the times of each function call when the data packet file runs, and storing the statistics result.
Specifically, in combination with step S2041 to step S2044, the function statistics code is set for the executable file in the data packet file as follows:
(1) The statistics interception codes are pre-embedded, so that codes of the foreground and background page switching logic of the android system are intercepted, and in order to ensure the accuracy of statistics, the interception of the foreground and background page switching is mainly used for knowing that a user is actually using the application to perform statistics, and the statistics is not performed when the application runs in the background. And setting statistical time length, and counting information such as recording frequency.
(2) The pre-buried statistical code and the pile inserting statistical instruction comprise: when the counted application program is running and after the interception code is triggered, when the counting condition is met, counting the number of times of function call is needed, and the code logic is needed to be embedded in advance, namely, the code logic is realized through an embedded counting code, and the embedded counting code counts the number of times through the function call.
In order to improve the execution efficiency, the pile inserting statistical instruction is embedded in advance, and different functions are distinguished according to the method reference number, so that statistics of function call times is achieved.
(3) Calculating the method reference number of a method needing statistics in the Dex file; the method reference number in the instrumentation instruction is modified.
(4) A pre-installed initial statistics file is generated.
Because the times of each function call are required to be recorded continuously when the program runs, and the statistical result is stored in a file, in order to improve the running efficiency, a statistical file is required to be generated in advance, and all the times of the function call are 0, so that IO burden can be reduced when the program runs, and the statistical efficiency is improved.
Further, optionally, after setting the trigger interception statistical code in the executable file in step S2041, the statistical method of code coverage provided in the embodiment of the present application further includes:
step S2045, setting a statistical duration, wherein the statistical duration is used for recording the times of function call in the executable file in a unit time interval.
Optionally, setting the statistic code and the instrumentation statistic instruction in the executable file according to the trigger interception statistic code in step S2042 includes:
step S20421, setting pile inserting statistical instructions according to functions corresponding to the method reference numbers in the executable files;
in step S20422, a statistical code is set in the executable file provided with the instrumentation statistical instruction.
Specifically, in combination with step S20421 and step S20422, when the counted application program is running, after the interception of the statistic code is triggered, when the statistic condition is satisfied, the statistics of the number of times of function execution is called according to the statistic code. In order to improve the execution efficiency, the instrumentation statistics instruction distinguishes different functions according to the method reference number, and further statistics of function call times is achieved.
Optionally, in step S2043, modifying the method reference number in the set executable file to obtain an executable file with the modified method reference number includes:
step S20431, counting the number of method references in the set executable file;
step S20432, the counted method reference number is configured in the instrumentation statistics instruction, and an executable file for modifying the method reference number is obtained.
Specifically, in combination with step S20431 and step S20432, since the original Dex file has been modified, and meanwhile, the relevant code is added to the Dex file, the method number of the original Dex file and the method reference number are changed, and the method reference number of the new Dex file needs to be recalculated.
Optionally, the statistical method for code coverage rate provided in the embodiment of the present application further includes: and if the judgment result is negative, not processing the data packet file.
Optionally, in step S206, performing code coverage statistics on the data packet file according to the function statistical code, where obtaining the statistical file includes:
step S2061, intercepting the times of calling 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;
in step S2062, the number of times is counted into the initial statistics file in the executable file to obtain the statistics file.
Specifically, in combination of step S2061 and step S2062, since the function statistical code has been set in advance in step S204, that is, the function statistical code includes: intercepting statistical codes, statistical codes and instrumentation statistical instructions, directly running corresponding codes when running, and recording the call times of functions in the application by continuously modifying an initial statistical file.
Optionally, in step S208, determining whether to upload the statistics file according to the triggering condition in the function statistics code includes:
in step S2081, in the case that the trigger condition includes a statistical duration, the statistical file generated in the statistical duration is uploaded to the server, so that the server can generate a statistical result according to the statistical file uploaded each time.
Specifically, since the interception statistical code, the instrumentation statistical instruction and the triggering condition are already preset in step 204, if the triggering condition, such as the statistical duration, is reached in the running process, the pre-installed statistical file is reported to the server, and meanwhile, the statistics is stopped; so that the server outputs the result after analyzing the post-analysis sampling.
Because different users have different using habits, the method has significance in that a certain number of samples are required to be averaged for code statistics, so that a server needs to sample a certain number of statistical files, and an average result is output after analysis.
It should be noted that, for simplicity of description, the foregoing method embodiments are all described as a series of acts, but it should be understood by those skilled in the art that the present invention is not limited by the order of acts described, as some steps may be performed in other orders or concurrently in accordance with the present invention. Further, those skilled in the art will also appreciate that the embodiments described in the specification are all preferred embodiments, and that the acts and modules referred to are not necessarily required for the present invention.
From the above description of the embodiments, it will be clear to those skilled in the art that the statistical method of code coverage according to the above embodiments may be implemented by means of software plus a necessary general hardware platform, but of course also by means of hardware, but in many cases the former is a preferred embodiment. Based on such understanding, the technical solution of the present invention may be embodied essentially or in a part contributing to the prior art in the form of a software product stored in a storage medium (e.g. ROM/RAM, magnetic disk, optical disk) comprising instructions for causing a terminal device (which may be a mobile phone, a computer, a server, or a network device, etc.) to perform the method according to the embodiments of the present invention.
Example 2
According to an embodiment of the present invention, there is further provided an apparatus for implementing the above-mentioned statistical method of code coverage, as shown in fig. 3, fig. 3 is a block diagram of a statistical apparatus of code coverage according to a second embodiment of the present invention, where the apparatus includes:
a parsing module 32, configured to parse the received packet file; the setting module 34 is configured to set a function statistical code for an executable file in the data packet file if the data packet file meets a preset instrumentation condition; the statistics module 36 is configured to run the data packet file, perform code coverage statistics on the data packet file according to the function statistics code, and obtain a statistics file; and a sending module 38, configured to determine whether to upload the statistics file according to the triggering condition in the function statistics code.
Example 3
According to still another aspect of the embodiment of the present invention, there is further provided a system for statistics of code coverage, as shown in fig. 4, fig. 4 is a schematic diagram of execution logic of the system for statistics of code coverage according to the third embodiment of the present invention, including: the terminal 42 and the server 44, wherein the terminal 42 is configured to parse the received data packet file, and if the data packet file meets a preset instrumentation condition, set a function statistical code for an executable file in the data packet file; running the data packet file, and executing 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 the triggering condition in the function statistical code; and the server 44 is connected with the terminal 42 and is used for generating a statistical result according to the statistical file uploaded each time.
Example 4
According to still another aspect of the embodiment of the present invention, there is further provided a storage medium, where the storage medium includes a stored program, and when the program runs, the device where the storage medium is controlled to execute the above statistical method of code coverage.
Example 5
The embodiment of the invention also provides a storage medium. Alternatively, in this embodiment, the storage medium may be used to store the program code executed by the statistical method of code coverage provided in the first embodiment.
Alternatively, in this embodiment, the storage medium may be located in any one of the computer terminals in the computer terminal group in the computer network, or in any one of the mobile terminals in the mobile terminal group.
Alternatively, in the present embodiment, the storage medium is configured to store program code for performing the steps of: analyzing the received data packet file; if the data packet file meets the preset pile inserting condition, setting a function statistical code for an executable file in the data packet file; running the data packet file, and executing 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 triggering condition in the function statistical code.
Alternatively, in the present embodiment, the storage medium is configured to store program code for performing the steps of: 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.
Alternatively, in the present embodiment, the storage medium is configured to store program code for performing the steps of: in the case that the function statistics code includes trigger intercept statistics code, and instrumentation statistics instructions, setting the function statistics code for the executable file in the data packet file includes: setting a trigger interception statistical code in an executable file, wherein the trigger interception statistical code is used for intercepting codes of a 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; a kind of electronic device with high-pressure air-conditioning system; the pile inserting statistical instruction is used for recording the calling times of each statistical 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 into the executable file for modifying the method reference number, wherein the initial statistical file is used for recording the times of each function call when the data packet file runs, and storing the statistical result.
Further optionally, in the present embodiment, the storage medium is configured to store program code for performing the steps of: after setting a trigger interception statistical code in the executable file, setting a statistical duration, wherein the statistical duration is used for recording the times of function call in the executable file in a unit time interval.
Alternatively, in the present embodiment, the storage medium is configured to store program code for performing the steps of: setting the statistic code and the instrumentation statistic instruction in the executable file according to the triggering interception statistic 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.
Alternatively, in the present embodiment, the storage medium is configured to store program code for performing the steps of: modifying the method reference number in the set executable file to obtain the executable file with the modified method reference number, wherein the method reference number comprises the following steps: counting the number of method references 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.
Alternatively, in the present embodiment, the storage medium is configured to store program code for performing the steps of: and under the condition that the data packet file does not meet the preset pile inserting condition, the data packet file is not processed.
Alternatively, in the present embodiment, the storage medium is configured to store program code for performing the steps of: executing code coverage statistics on the data packet file according to the function statistical code, wherein obtaining the statistical file comprises: intercepting the times of calling 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.
Alternatively, in the present embodiment, the storage medium is configured to store program code for performing the steps of: 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 file generated in the statistical time length to a server under the condition that the triggering condition comprises the statistical time length, so that the server can generate a statistical result according to the statistical file uploaded each time.
The foregoing embodiment numbers of the present invention are merely for the purpose of description, and do not represent the advantages or disadvantages of the embodiments.
In the foregoing embodiments of the present invention, the descriptions of the embodiments are emphasized, and for a portion of this disclosure that is not described in detail in this embodiment, reference is made to the related descriptions of other embodiments.
In the several embodiments provided in the present application, it should be understood that the disclosed technology content may be implemented in other manners. The above-described embodiments of the apparatus are merely exemplary, and the division of the units, such as the division of the units, is merely a logical function division, and may be implemented in another manner, for example, multiple units or components may be combined or may be integrated into another system, or some features may be omitted, or not performed. Alternatively, the coupling or direct coupling or communication connection shown or discussed with each other may be through some interfaces, units or modules, or may be in electrical or other forms.
The units described as separate units may or may not be physically separate, and units shown 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 may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
In addition, each functional unit in the embodiments of the present invention may be integrated in one processing unit, or each unit may exist alone physically, or two or more units may be integrated in one unit. The integrated units may be implemented in hardware or in software functional units.
The integrated units, if implemented in the form of software functional units and sold or used as stand-alone products, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present invention may be embodied essentially or in part or all of the technical solution or in part in the form of a software product stored in a storage medium, including instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to perform 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, random Access Memory), a removable hard disk, a magnetic disk, or an optical disk, or other various media capable of storing program codes.
The foregoing is merely a preferred embodiment of the present invention and it should be noted that modifications and adaptations to those skilled in the art may be made without departing from the principles of the present invention, which are intended to be comprehended within the scope of the present invention.

Claims (11)

1. A statistical method of code coverage, comprising:
analyzing the received data packet file;
if the data packet file meets the preset pile inserting condition, setting a function statistical code for an executable file in the data packet file;
operating the data packet file, and executing 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 the triggering condition in the function statistical code;
wherein, in the case that the function statistics code includes a trigger interception statistics code, a statistics code, and a instrumentation statistics instruction, the setting the function statistics code for the executable file in the data packet file includes:
setting the trigger interception statistical code in the executable file, wherein the trigger interception statistical code is used for intercepting codes of a 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; a kind of electronic device with high-pressure air-conditioning system; the pile inserting statistical instruction is used for recording the calling times of each statistical function;
modifying the set method reference number in the executable file to obtain an executable file for modifying the method reference number;
and adding an initial statistical file into the executable file for modifying the method reference number, wherein the initial statistical file is used for recording the times of each function call when the data packet file runs, and storing a statistical result.
2. The statistical method of code coverage according to claim 1, wherein the preset instrumentation condition comprises:
judging whether the data packet file is damaged or not; or alternatively, the first and second heat exchangers may be,
and judging whether the data packet file is legal or not.
3. The statistical method of code coverage according to claim 1, wherein after the setting of the trigger intercept statistical code in the executable file, the method further comprises:
setting a statistical time length, wherein the statistical time length is used for recording the times of function call in the executable file in a unit time interval.
4. The method for counting code coverage according to claim 1, wherein the setting the statistics codes and the instrumentation statistics instructions in the executable file according to the trigger interception statistics codes comprises:
setting the instrumentation statistics 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.
5. The statistical method of code coverage according to claim 1, wherein the modifying the set method reference number in the executable file to obtain the executable file with the modified method reference number includes:
counting the number of method references in the executable file after setting;
and configuring the counted method reference number in the instrumentation statistics instruction to obtain an executable file for modifying the method reference number.
6. The statistical method of code coverage according to claim 1, wherein the method further comprises:
and under the condition that the data packet file does not meet the preset pile inserting condition, the data packet file is not processed.
7. The method of code coverage statistics according to any one of claims 1 to 6, wherein performing code coverage statistics on the data packet file in accordance with the function statistics code, obtaining a statistics file comprises:
intercepting the times of calling 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.
8. The method for counting code coverage according to claim 1, wherein the determining whether to upload the statistics file according to the trigger condition in the function statistics code comprises:
and uploading the statistical file generated in the statistical time length to a server under the condition that the triggering condition comprises the statistical time length, so that the server can generate a statistical result according to the statistical file uploaded each time.
9. 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 a function statistical code for the executable file in the data packet file if the data packet file meets the preset pile inserting condition;
the statistics module is used for running the data packet file, and executing code coverage rate statistics on the data packet file according to the function statistics code to obtain a statistics file;
the sending module is used for judging whether to upload the statistical file according to the triggering condition in the function statistical code;
wherein, in the case that the function statistics code includes a trigger interception statistics code, a statistics code, and a instrumentation statistics instruction, the setting module is further configured to: setting the trigger interception statistical code in the executable file, wherein the trigger interception statistical code is used for intercepting codes of a 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; a kind of electronic device with high-pressure air-conditioning system; the pile inserting statistical instruction is used for recording the calling times of each statistical function; modifying the set method reference number in the executable file to obtain an executable file for modifying the method reference number; and adding an initial statistical file into the executable file for modifying the method reference number, wherein the initial statistical file is used for recording the times of each function call when the data packet file runs, and storing a statistical result.
10. 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 an executable file in the data packet file if the data packet file meets a preset pile inserting condition; operating the data packet file, and executing 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 the triggering condition in the function statistical code;
the server is connected with the terminal and used for generating a statistical result according to the statistical file uploaded each time;
wherein, under the condition that the function statistical code comprises a trigger interception statistical code, a statistical code and a pile-inserting statistical instruction, the terminal is further used for: setting the trigger interception statistical code in the executable file, wherein the trigger interception statistical code is used for intercepting codes of a 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; a kind of electronic device with high-pressure air-conditioning system; the pile inserting statistical instruction is used for recording the calling times of each statistical function; modifying the set method reference number in the executable file to obtain an executable file for modifying the method reference number; and adding an initial statistical file into the executable file for modifying the method reference number, wherein the initial statistical file is used for recording the times of each function call when the data packet file runs, and storing a statistical result.
11. A storage medium comprising a stored program, wherein the program, when run, controls a device in which the storage medium resides to perform: the statistical method of code coverage of 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 CN111026630A (en) 2020-04-17
CN111026630B true 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 (9)

* 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
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
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

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20120167057A1 (en) * 2010-12-22 2012-06-28 Microsoft Corporation Dynamic instrumentation of software code
US8769512B2 (en) * 2011-03-24 2014-07-01 International Business Machines Corporation Adding instrumentation to a body of code to enable generation of code coverage data
CN103246602B (en) * 2012-02-14 2017-03-01 阿里巴巴集团控股有限公司 Code coverage determines method and system, code coverage detection method and system
US9703677B2 (en) * 2015-09-22 2017-07-11 Red Hat Israel, Ltd. Code coverage plugin

Patent Citations (9)

* 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
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
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.2016 IEEE 23rd International Conference on Software Analysis, Evolution, and Reengineering (SANER).2016,全文. *
刘利枚 ; 周鲜成 ; 石彪 ; .嵌入式软件测试系统的设计与实现.国外电子测量技术.2008,(第01期),全文. *
姜文 ; 刘立康 ; .基于持续集成的C/C++软件覆盖率测试.计算机技术与发展.2017,(第03期),全文. *
张荣 ; 王曙燕 ; .基于插桩技术的动态测试研究与实现.现代电子技术.2011,(第04期),全文. *

Also Published As

Publication number Publication date
CN111026630A (en) 2020-04-17

Similar Documents

Publication Publication Date Title
CN109949062B (en) Application software promotion platform confirmation method and device, storage medium and electronic equipment
CN109002424B (en) File format conversion method and device, computer equipment and storage medium
CN109672580A (en) Full link monitoring method, apparatus, terminal device and storage medium
CN109002457A (en) Downloading channel statistical processing methods, device and the electronic equipment of application program
CN111767211A (en) Test method and device of alliance chain, storage medium and electronic device
CN112422557A (en) Attack testing method and device for industrial control network
CN110727697A (en) Data processing method and device, storage medium and electronic device
CN111654879B (en) Business push method, device, control equipment and storage medium
CN103686821A (en) Control method for application program traffic statistics according to unique identification of mobile terminal
CN105553770B (en) Data acquisition control method and device
CN106487602B (en) Application program release version monitoring method and monitoring device
CN110851339A (en) Method and device for reporting buried point data, storage medium and terminal equipment
EP2741449B1 (en) Processing of call data records
CN108595178B (en) Hook-based data acquisition method, device and equipment
CN112422604B (en) File uploading method, device and system and computer equipment
CN110308954A (en) Click event interception method, device and mobile terminal
CN111026630B (en) Statistical method, device and system for code coverage rate
CN108616870B (en) Method and device for identifying terminal customized preferentially
CN111641959A (en) Method and device for detecting network environment information
CN114090074A (en) Method and device for configuring operating environment, storage medium and electronic device
CN107888772A (en) A kind of method, apparatus and storage medium for determining configuration information
CN111953796A (en) In-band management file transmission method, device and equipment and readable storage medium
CN110971644A (en) Page access monitoring method and device
CN111399839B (en) VNF registration method, device, medium and equipment
CN111314184B (en) Control method and system based on transparent transmission mechanism

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