WO2020244445A1 - 一种覆盖信息获取方法及装置 - Google Patents

一种覆盖信息获取方法及装置 Download PDF

Info

Publication number
WO2020244445A1
WO2020244445A1 PCT/CN2020/093025 CN2020093025W WO2020244445A1 WO 2020244445 A1 WO2020244445 A1 WO 2020244445A1 CN 2020093025 W CN2020093025 W CN 2020093025W WO 2020244445 A1 WO2020244445 A1 WO 2020244445A1
Authority
WO
WIPO (PCT)
Prior art keywords
code
version
coverage information
line
executed
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.)
Ceased
Application number
PCT/CN2020/093025
Other languages
English (en)
French (fr)
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.)
WeBank Co Ltd
Original Assignee
WeBank Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by WeBank Co Ltd filed Critical WeBank Co Ltd
Publication of WO2020244445A1 publication Critical patent/WO2020244445A1/zh
Anticipated expiration legal-status Critical
Ceased legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Prevention of errors by analysis, debugging or testing of software
    • G06F11/3668Testing of software
    • G06F11/3672Test management
    • G06F11/3676Test management for coverage analysis

Definitions

  • the present invention relates to the field of financial technology (Fintech), and in particular to a method and device for obtaining coverage information.
  • the embodiments of the present application provide a method and device for obtaining coverage information, which solves the problem that in the prior art, the amount of calculation is huge when obtaining coverage information, which is prone to errors, and will lead to a long entire process, and the efficiency of obtaining coverage information of different codes between versions Lower question.
  • an embodiment of the present application provides a method for obtaining coverage information, including: obtaining first coverage information; the first coverage information is used to indicate whether each line of code corresponding to line numbers 1 to K is executed, where: When a line of code corresponding to line number i is executed in N versions of the code, it means that the line of code corresponding to line number i is executed, otherwise, it means that the line of code corresponding to line number i has not been executed; K is the first version code The number of lines of code included; i is an integer greater than or equal to 1 and less than or equal to K; the first version code is the last submitted code among the N version codes; according to the first version code and the first version code The second version code, which determines the difference code in the first version code that is different from the second version code; the second version code is the code submitted for the first time among the N version codes; according to the difference code And the first coverage information determines the second coverage information; the second coverage information is used to indicate whether each line of code in the difference code is executed in
  • the first coverage information is obtained, and the first coverage information indicates whether each line of code corresponding to the line number 1 to K is executed.
  • This method does not need to frequently pull each of the N version codes to determine each After submitting the version code for the second time, the difference code directly based on the first version code and the second version code can determine the difference code in the second version code that is different from the first version code, thereby The amount of calculation and error rate are greatly reduced, thereby reducing the entire process time.
  • the second coverage information is obtained, that is, each line of code in the difference code is in the first
  • the obtaining of the first coverage information includes: obtaining N sets of third coverage information; wherein, each set of third coverage information of the N sets of third coverage information is identical to the N versions One version code in the code uniquely corresponds, and the set of third coverage information is used to indicate whether each line of code in the version code is executed; the N sets of third coverage information are merged into the first coverage information.
  • each set of third coverage information and the first coverage information of the N sets of third coverage information is an array, and for the value of any subscript of the array, if the value is the first A preset value indicates that the code corresponding to the subscript has been executed in the version code corresponding to the group of coverage information, and if the value is the second preset value, it indicates that the code corresponding to the subscript is not in the group Is executed in the version code corresponding to the coverage information; the merging of the N groups of third coverage information into the first coverage information includes: according to each subscript in the array of the first coverage information, the The value of the subscript in the N arrays of the N sets of third coverage information is operated according to a preset operation rule, and the operation result is used as the value of the subscript in the array of the first coverage information.
  • the determination of a difference code in the first version code that is different from the second version code according to the first version code and the second version code includes: If there is a new code in the first version code relative to the second version code, the newly added code is taken as the first code set; if the first version code has a code block that is deleted relative to the second version code, In the second version of the code, the line of code before the first line of the deleted code block and the line of code after the end line of the deleted code block are taken as the second code set; if the first version of the code exists relative to the second version The code block whose code annotation changes, then the code block whose annotation changes are used as the third code set; the first code set, the third code set, and all the codes in the third code set, As the difference code.
  • the determining second coverage information according to the difference code and the first coverage information includes: for each line of code in the difference code, if it is in the first coverage information Indicates that the line of code is executed, then it is determined that the line of code is executed in the first version code; otherwise, it is determined that the line of code is not executed in the first version code; according to each line in the difference code Determine whether the code is executed in the first version code, and determine the second coverage information.
  • an embodiment of the present application provides a coverage information obtaining device, including: an obtaining module, configured to obtain first coverage information; and the first coverage information is used to indicate whether each line of code corresponding to line numbers 1 to K is Is executed, where, when a line of code corresponding to line number i is executed in N versions of code, it means that the line of code corresponding to line number i is executed, otherwise, it means that the line of code corresponding to line number i has not been executed; K Is the number of lines of code included in the first version code; i is an integer greater than or equal to 1 and less than or equal to K; the first version code is the last submitted code among the N version codes; the processing module uses According to the first version code and the second version code, determine the difference code in the first version code that is different from the second version code; the second version code is among the N version codes The code submitted for the first time; determine the second coverage information according to the difference code and the first coverage information; the second coverage information is used to indicate whether each line of code in
  • the obtaining module is specifically configured to: obtain N sets of third coverage information; wherein, each set of third coverage information of the N sets of third coverage information is compared with the N version codes A version code of is uniquely corresponding, and the set of third coverage information is used to indicate whether each line of code in the version code is executed; the N sets of third coverage information are merged into the first coverage information.
  • each set of third coverage information and the first coverage information of the N sets of third coverage information is an array, and for the value of any subscript of the array, if the value is the first A preset value indicates that the code corresponding to the subscript has been executed in the version code corresponding to the group of coverage information, and if the value is the second preset value, it indicates that the code corresponding to the subscript is not in the group Is executed in the version code corresponding to the coverage information; the acquisition module is specifically configured to: according to each subscript in the array of the first coverage information, perform a calculation of the subscript in the N arrays of the N sets of third coverage information The value is calculated according to a preset operation rule, and the operation result is used as the value of the subscript in the array of the first coverage information.
  • the processing module is specifically configured to: if the first version code has a new code relative to the second version code, use the newly added code as the first code set; if If the first version code has a code block that is deleted relative to the second version code, then in the second version code, a line of code before the first line of the deleted code block and a line of code after the end line are taken as the first A second code set; if there is a code block in the first version code that changes with respect to the second version code annotation, the code block with the annotation changed is used as the third code set; and the first code The set, the third code set, and all codes in the third code set are used as the difference code.
  • the processing module is specifically configured to: for each line of code in the difference code, if the line of code is indicated in the first coverage information, it is determined that the line of code is Is executed in the first version code; otherwise, it is determined that this line of code is not executed in the first version code; according to whether each line of code in the difference code is executed in the first version code, it is determined that all The second coverage information.
  • an embodiment of the present application provides a computer device, including:
  • At least one processor and,
  • a memory communicatively connected with the at least one processor; wherein,
  • the memory stores a program executable by the at least one processor, and the program is executed by the at least one processor, so that the at least one processor can execute the coverage information obtaining method as described above.
  • an embodiment of the present application provides a non-transitory computer-readable storage medium, the non-transitory computer-readable storage medium stores a computer program, and the computer program is used to make the computer execute the above-mentioned overlay Information acquisition method.
  • the embodiments of the present invention also provide a computer program product.
  • the computer program product includes a computer program stored on a non-transitory computer-readable storage medium.
  • the computer program When the computer program is executed by a computer, the computer program The computer executes the coverage information acquisition method described above.
  • FIG. 1 is a schematic diagram of the flow of steps of a method for obtaining coverage information in an embodiment of this application;
  • Figure 2 is a system architecture diagram to which a method for obtaining coverage information in an embodiment of the application can be applied;
  • FIG. 3 is a flowchart of steps for automatically injecting coverage information agents into a system architecture diagram to which a coverage information acquisition method in an embodiment of the application is applicable;
  • FIG. 4 is a schematic structural diagram of an apparatus for obtaining coverage information in an embodiment of this application.
  • FIG. 5 is a schematic structural diagram of an electronic device provided by an embodiment of the present invention.
  • the coverage information of the difference code between versions that is, the execution of the code in the difference code during the running process of the newer version of the code, such as the number of lines executed by the difference code during the running process, and the number of lines executed by the difference code account for the total lines of the difference code The proportion of the number, etc.
  • an embodiment of the present application provides a method for obtaining first coverage information, and a step flowchart of the method is shown in FIG. 1.
  • Step 101 Obtain first coverage information.
  • the coverage information refers to the information that the code in the program file is executed at runtime. During the execution of a program file, each line of code in the program file may have been executed from the beginning to the end of the execution of the program file, or it may have never been executed. If a line of code is executed, it is said that this line of code is covered, otherwise, it is said that this line of code is not covered.
  • the coverage information may be ratio information, line number information, etc. of the code covered in the program file, which is not limited in the embodiment of the present application.
  • Blank line when editing the code in the program file, there are some blank lines without code in the program file. The deletion or non-deleting of these blank lines does not affect the operation of the program. These are not considered when obtaining coverage information. Blank line.
  • the first coverage information is used to indicate whether each line of code corresponding to line number 1 to K is executed.
  • a line of code corresponding to line number i is executed in N version codes, it means that line number i corresponds to A line of code is executed, otherwise, it means that the line of code corresponding to line number i has not been executed;
  • K is the number of lines of code included in the first version code;
  • i is an integer greater than or equal to 1 and less than or equal to K
  • the first A version code is the last submitted code among the N version codes.
  • Step 102 According to the first version code and the second version code, determine a difference code in the first version code that is different from the second version code.
  • the second version code is the code submitted for the first time among the N version codes.
  • Step 103 Determine second coverage information according to the difference code and the first coverage information.
  • the second coverage information is used to indicate whether each line of code in the difference code is executed in the first version code.
  • step 101 an optional implementation manner for obtaining the first coverage information is as follows:
  • each set of third coverage information of the N sets of third coverage information uniquely corresponds to one of the N version codes, and the set of third coverage information is used to indicate Whether each line of code in the version code is executed; combining the N groups of third coverage information into the first coverage information.
  • the forms of the N sets of third coverage information and the first coverage information are not limited.
  • each set of third coverage information of the N sets of third coverage information the The first coverage information is an array.
  • the value of any subscript of the array if the value is the first preset value, it indicates that the code corresponding to the subscript has been executed in the version code corresponding to the set of coverage information . If the value is the second preset value, it indicates that the code corresponding to the subscript is not executed in the version code corresponding to the set of coverage information.
  • the N sets of third coverage information can be changed in the following manner Merged into the first coverage information:
  • the value of the subscript in the N arrays of the N sets of third coverage information is operated according to a preset operation rule, and the operation result is taken as the first The value of the subscript in an array of coverage information.
  • each of the N arrays is a Boolean array
  • the first preset value is 0, the second preset value is 1, and the preset operation rule is AND operation.
  • the result of the AND operation on N Boolean arrays is also a Boolean array, and this Boolean array is used as the first coverage information.
  • the difference code refers to codes that have differences between versions.
  • the embodiment of the present application only exemplifies the determination rules of the difference codes, and the determination rules of the difference codes can be adjusted according to specific implementation scenarios. This is not limited, and the specific determination rules as follows:
  • the difference code is divided into file difference and file content difference.
  • File difference If the file path or file name changes, it means that there is a file difference;
  • File content difference The file path and file name are not sent, but the file content is sent.
  • files refer to program files.
  • the content of the code can be changed by adding or subtracting a series of files, as well as adding or subtracting certain lines of a file, as follows:
  • the first version of the code has a new file. For the newly added file, all the code lines of the entire file are included in the difference code. For files whose codes in the first version are reduced compared to the codes in the second version, the reduced codes are not included in the difference code.
  • the code line refers to the edit line of the code in the file, such as a blank line, is not regarded as a code line.
  • the first case some lines of code are added. For newly added lines of code, they are directly included in the difference code.
  • the reduced file lines may affect the function of the upper and lower code lines, so the upper and lower lines of the deleted code block are included in the difference code.
  • the code block refers to a group of consecutive lines of code, and the line before the first line of the deleted code block and the line after the end line are included in the difference code.
  • the program file of the second version code has lines 1 to 10 in total
  • the program file of the first version code has lines 1 to 8
  • the program file of the first version code has lines 1 to 6
  • the lines are the same as lines 1 to 6 of program file 1 of the second version code
  • lines 7 to 8 of program file 1 of the first version code are the same as lines 9 to 10 of program file 1 of the second version code.
  • the program file 1 of the first version code is relative to the program file 1 of the second version code.
  • the 7th to 8th lines in the program file 1 of the second version code are deleted, which is the deleted code block, so it will be deleted.
  • the line before the first line of the code block, which is the 6th line in the program file 1 of the first version code, and the line after the end line of the deleted code block, which is the 7th line in the program file 1 of the first version code Line (corresponding to the 9th line in the program file 1 of the second version code), including the difference code.
  • annotations may affect the execution of the annotated code block, so here for the same code block in the same file, if the annotation of the code block occurs Modification, the code line set by the entire code block can be included in the difference code.
  • annotations are a mechanism provided in the Java programming language, which allows programmers to write metadata directly while writing code. The annotated code will not be directly affected by the annotation, it will only provide the third system with information about itself for different needs.
  • an optional implementation manner for determining the difference code in step 102 is as follows:
  • the newly added code is taken as the first code set; if the first version code has a code that is deleted relative to the second version code Code block, in the second version code, a line of code before the first line and a line of code after the end line of the deleted code block are taken as the second code set; if the first version code exists relative to the The code block whose annotations of the second version have changed is used as the third code set; the first code set, the third code set, and the third code set are All codes, as the difference code.
  • blank lines in the program file are not included in the difference code.
  • the first line in the program file A is 1, the second line is 2, the third line is 3, and the first line in the program file B is 1 , The second line is empty, the third line is 2, and the fourth line is 3. It is considered that there is no difference between program file A and program file B.
  • Step 102 obtains the difference code in the first version code that is different from the second version code
  • step 103 further obtains the second coverage information according to the difference code obtained in step 102.
  • the second coverage information is the information about whether each line of code in the difference code is executed during the execution of the first version of the code.
  • step 103 an optional implementation manner for obtaining the second coverage information is as follows:
  • the second coverage information is determined according to whether each line of code in the difference code is executed in the first version code.
  • the executed code line recorded in the difference code and recorded in the first coverage information is taken as the code line covered in the second coverage information.
  • the submission information of git can be automatically collected, the coverage information of the N version codes are merged in advance, the first coverage information is obtained, and the first version code is combined with The difference code of the second version code, so as to quickly obtain the second coverage information.
  • Jenkins is deployed on the application machine, and git is deployed on the server.
  • the application machine is the machine for project development, and the application machine submits each modified code to the server.
  • git commit which is a modification submission in git
  • git tag is a snapshot of the git repository, pointing to a pointer to a modification submission
  • git commit id which is used in git A unique string that identifies each modification submitted. You can use git commit to record the file differences between each modification submission of Jenkins, and use git tag to point to each commit modification of Jenkins, and use git commit id to identify each commit modification of Jenkins.
  • Each module is introduced below:
  • the commit id information collection module is a module in the application machine.
  • the commit id information collection module will automatically collect the commit id of the current version code and output the result to the application release material package.
  • the application is when the program is written Software applications.
  • the application release material package is a software package that is used to load when instrumentation is used to add additional functions. In this system architecture, the release material package is Jenkins. After the version is compiled, the version information is output to the specified directory and the specified file name under the application package. Version information includes: git branch name, git commit id corresponding to the build and release of the material package.
  • the coverage information agent injection module will automatically access the coverage information agent to avoid misoperation and operation delay caused by manual access. This module monitors the application name of the current application and its corresponding process identification (pid) relationship on the machine where the application is running, and determines whether the application has been connected to the coverage information agent by judging whether the pid of the application exists. Automatically connect the coverage information agent to the application. Among them, pid refers to the process identification number in the operating system, that is, the process identifier. A pid is created every time a program is opened in the operating system. The module will also combine the output results of the commit id information collection module. After accessing the coverage information agent, it will send a heartbeat to the coverage information collection module through the network for data synchronization, and will also send the coverage information collection module the application from startup to the current time. Coverage information over a period of time.
  • the coverage information collection module is used to regularly receive the heartbeat information of the coverage agent, determine the online status of the coverage information agent, and also periodically or manually send the coverage information collection instructions to the online coverage information agent to collect application information Overwrite information.
  • the collected coverage information is combined with the previously existing coverage information. For example, N groups of third coverage information are combined to obtain the first coverage information accumulated over a period of time and store it on a local disk.
  • the coverage information agent injection module provided in this embodiment of the application automatically injects the step flow chart of the coverage information agent, taking Application A as an example.
  • Step 301 Obtain pid_1 of application A through a command called Process Status (ps).
  • the ps command is used to list the processes currently running in the system.
  • the ps command lists the snapshots of the current processes, which are the processes at the moment when the ps command is executed.
  • Step 302 Request the coverage information collection module to obtain the pid_2 reported by the application A.
  • Step 303 Determine whether pid1 of application A does not exist or pid_1 and pid_2 are not equal.
  • step 304 If yes, go to step 304.
  • Step 304 Inject the coverage information agent.
  • Step 304 uses the application program interface of instrumentation provided by java to inject the coverage proxy.
  • Step 305 Report pid_1.
  • Difference code comparison module When receiving an instruction to generate coverage information, the difference code comparison module will obtain the latest tag and the version code corresponding to the current commit id from git through the network, and compare and obtain the difference files between the two and between the files The difference line, output the difference result of the corresponding code line.
  • the instruction that triggers the source code comparison can be automatic trigger or manual trigger.
  • the coverage information output module is used to combine the first coverage information and the difference code to generate second coverage information.
  • the first coverage information is obtained, and the first coverage information indicates whether each line of code corresponding to the line number 1 to K is executed.
  • This method does not need to frequently pull each of the N version codes to determine each After submitting the version code for the second time, the difference code directly based on the first version code and the second version code can determine the difference code in the second version code that is different from the first version code, thereby The amount of calculation and error rate are greatly reduced, thereby reducing the entire process time.
  • the second coverage information is obtained, that is, each line of code in the difference code is in the first
  • FIG. 4 it is a schematic structural diagram of an apparatus for obtaining coverage information in an embodiment of this application.
  • An embodiment of the present application provides an apparatus for obtaining coverage information, including: an obtaining module 401, configured to obtain first coverage information; the first coverage information is used to indicate whether each line of code corresponding to line numbers 1 to K is executed, Among them, when a line of code corresponding to line number i is executed in N versions of code, it means that the line of code corresponding to line number i is executed, otherwise, it means that the line of code corresponding to line number i has not been executed; K is the first The number of lines of code included in the version code; i is an integer greater than or equal to 1 and less than or equal to K; the first version code is the last submitted code among the N version codes; the processing module 402 is configured to The first version code and the second version code determine the difference code of the first version code that is different from the second version code; the second version code is the first submission among the N version codes The code; according to the difference code and the first coverage information, determine second coverage information; the second coverage information is used to indicate whether each line of code in the difference code is executed
  • the obtaining module 401 is specifically configured to: obtain N sets of third coverage information; wherein, each set of third coverage information of the N sets of third coverage information is associated with the N version codes One of the version codes in is uniquely corresponding, and the set of third coverage information is used to indicate whether each line of code in the version code is executed; the N sets of third coverage information are merged into the first coverage information.
  • each set of third coverage information and the first coverage information of the N sets of third coverage information is an array, and for the value of any subscript of the array, if the value is the first A preset value indicates that the code corresponding to the subscript has been executed in the version code corresponding to the group of coverage information, and if the value is the second preset value, it indicates that the code corresponding to the subscript is not in the group Is executed in the version code corresponding to the coverage information; the acquiring module 401 is specifically configured to: according to each subscript in the array of the first coverage information, perform the following operations in the N arrays of the N sets of third coverage information. The value of the subscript is calculated according to a preset operation rule, and the result of the operation is used as the value of the subscript in the array of the first coverage information.
  • the processing module 402 is specifically configured to: if the first version code has a new code relative to the second version code, use the newly added code as the first code set; If the first version code has a code block that is deleted relative to the second version code, then in the second version code, a line of code before the first line of the deleted code block and a line of code after the end line are taken as A second code set; if there is a code block in the first version code that changes with respect to the second version code annotation, the code block with the annotation changed is taken as the third code set; The code set, the third code set, and all codes in the third code set are used as the difference code.
  • the processing module 402 is specifically configured to: for each line of code in the difference code, if the line of code is indicated in the first coverage information, determine that the line of code is Is executed in the first version code; otherwise, it is determined that this line of code is not executed in the first version code; according to whether each line of code in the difference code is executed in the first version code, it is determined The second coverage information.
  • the present invention also provides a computer device, as shown in FIG. 5, including:
  • processor 501 Including a processor 501, a memory 502, a transceiver 503, and a bus interface 504, wherein the processor 501, the memory 502 and the transceiver 503 are connected through the bus interface 504;
  • the processor 501 is configured to read a program in the memory 502 and execute the voting method in the above-mentioned blockchain, and the method includes:
  • the first coverage information is used to indicate whether each line of code corresponding to line number 1 to K is executed, wherein, when a line of code corresponding to line number i is executed in N version codes, It means that the line of code corresponding to line number i is executed, otherwise, it means that the line of code corresponding to line number i is not executed; K is the number of lines of code included in the first version code; i is greater than or equal to 1 and less than or equal to K An integer of; the first version code is the last submitted code among the N version codes;
  • the first version code and the second version code determine the difference code in the first version code that is different from the second version code; the second version code is the first in the N version codes Submitted code;
  • the second coverage information is used to indicate whether each line of code in the difference code is executed in the first version code.
  • the processor 501 may be a central processing unit (CPU for short), a network processor (NP for short), or a combination of CPU and NP. It can also be a hardware chip.
  • the aforementioned hardware chip may be an application-specific integrated circuit (ASIC for short), a programmable logic device (PLD for short), or a combination thereof.
  • ASIC application-specific integrated circuit
  • PLD programmable logic device
  • the above-mentioned PLD can be a complex programmable logic device (complex programmable logic device, CPLD), a field-programmable gate array (FPGA), a generic array logic (generic array logic, GAL), or any of them combination.
  • the memory 502 is configured to store one or more executable programs, and can store data used by the processor 501 when performing operations.
  • the program may include program code, and the program code includes computer operation instructions.
  • the memory 502 may include a volatile memory (volatile memory), such as random-access memory (RAM for short); the memory 502 may also include a non-volatile memory (non-volatile memory), such as flash memory ( flash memory, hard disk drive (HDD for short) or solid-state drive (SSD for short); the memory 502 may also include a combination of the foregoing types of memory.
  • volatile memory volatile memory
  • RAM random-access memory
  • non-volatile memory non-volatile memory
  • flash memory flash memory, hard disk drive (HDD for short) or solid-state drive (SSD for short
  • SSD solid-state drive
  • the memory 502 stores the following elements, executable modules or data structures, or their subsets, or their extended sets:
  • Operating instructions including various operating instructions, used to implement various operations.
  • Operating system including various system programs, used to implement various basic services and process hardware-based tasks.
  • the bus interface 504 may be a wired communication access port, a wireless bus interface or a combination thereof, where the wired bus interface may be, for example, an Ethernet interface.
  • the Ethernet interface can be an optical interface, an electrical interface or a combination thereof.
  • the wireless bus interface may be a WLAN interface.
  • the embodiments of the present invention also provide a non-transitory computer-readable storage medium, the non-transitory computer-readable storage medium stores a computer program, and the computer program is used to make the computer execute the above-mentioned coverage information Obtaining method.
  • embodiments of the present invention also provide a computer program product.
  • the computer program product includes a computer program stored on a non-transitory computer-readable storage medium.
  • the computer program When the computer program is executed by a computer, the computer program The computer executes the coverage information obtaining method.
  • the embodiments of the present application can be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, this application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, optical storage, etc.) containing computer-usable program codes.
  • a computer-usable storage media including but not limited to disk storage, optical storage, etc.
  • These computer program instructions can also be stored in a computer-readable memory that can guide a computer or other programmable data processing equipment to work in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture including the instruction device.
  • the device implements the functions specified in one process or multiple processes in the flowchart and/or one block or multiple blocks in the block diagram.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)
  • Debugging And Monitoring (AREA)

Abstract

本发明公开了一种覆盖信息获取方法及装置, 其中方法为:获取第一覆盖信息;所述第一覆盖信息用于指示行号为1至K对应的每行代码是否被执行, 其中, 当行号i对应的一行代码, 在N个版本代码中均被执行, 则表示行号i对应的一行代码被执行, 否则,表示行号i对应的一行代码未被执行; K为第一版本代码包括的代码的行数; 根据所述第一版本代码与第二版本代码, 确定所述第一版本代码中, 与所述第二版本代码存在差异的差异代码; 根据所述差异代码以及所述第一覆盖信息, 确定第二覆盖信息; 所述第二覆盖信息用于指示所述差异代码中每行代码在所述第一版本代码中是否被执行, 该方法可应用于金融科技(Fintech)。

Description

一种覆盖信息获取方法及装置
相关申请的交叉引用
本申请要求在2019年06月03日提交中国专利局、申请号为201910477036.1、申请名称为“一种覆盖信息获取方法及装置”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本发明涉及金融科技(Fintech)领域,尤其涉及一种覆盖信息获取方法及装置。
背景技术
随着计算机技术的发展,越来越多的技术(大数据、分布式、区块链(Blockchain)、人工智能等)应用在金融领域,传统金融业正在逐步向金融科技(Fintech)转变。目前,金融科技领域中,一个软件项目在一个开发周期内,代码会进行频繁的修改,因此一个软件项目在一个开发周期内会产生多个版本,为了表征不同版本代码间的变动情况、以及代码变动后的优化情况,常常需要获取两个不同版本之间差异代码的覆盖信息,也就是较新版本的代码在运行过程中,差异代码中代码的执行情况,如运行过程中差异代码执行的行数、差异代码执行的行数占差异代码总行数的比例等。
现有技术中,在需要获取软件项目在一个开发周期内的两个不同版本之间差异代码的覆盖信息时,依次获取两个不同版本之间所有版本中,每两个相邻版本代码之间差异代码的覆盖信息、代码变动信息,再一个一个版本推导下去,直至得出两个不同版本之间差异代码的覆盖信息。
显然,现有技术中的方法需要频繁拉取各个版本代码,计算量巨大,容易出错,而且会导致整个流程较长,两个不同版本间差异代码的覆盖信息的获取效率较低,这是一个亟待解决的问题。
发明内容
本申请实施例提供一种覆盖信息获取方法及装置,解决了现有技术中,覆盖信息获取时计算量巨大,容易出错,而且会导致整个流程较长,版本间差异代码的覆盖信息的获取效率较低的问题。
第一方面,本申请实施例提供一种覆盖信息获取方法,包括:获取第一 覆盖信息;所述第一覆盖信息用于指示行号为1至K对应的每行代码是否被执行,其中,当行号i对应的一行代码,在N个版本代码中均被执行,则表示行号i对应的一行代码被执行,否则,表示行号i对应的一行代码未被执行;K为第一版本代码包括的代码的行数;i为大于或等于1且小于或等于K的整数;所述第一版本代码为所述N个版本代码中最后一次提交的代码;根据所述第一版本代码与第二版本代码,确定所述第一版本代码中,与所述第二版本代码存在差异的差异代码;所述第二版本代码为所述N个版本代码中首次提交的代码;根据所述差异代码以及所述第一覆盖信息,确定第二覆盖信息;所述第二覆盖信息用于指示所述差异代码中每行代码在所述第一版本代码中是否被执行。
上述方法中,获取了第一覆盖信息,第一覆盖信息指示了行号为1至K对应的每行代码是否被执行,该方法并不需要频繁拉取N个版本代码中各个版本代码确定每次提交版本代码后的差异代码,直接根据所述第一版本代码与所述第二版本代码,便能确定所述第二版本代码中,与所述第一版本代码存在差异的差异代码,从而大幅度降低了计算量和错误率,从而降低了整个流程时间,再根据所述差异代码以及所述第一覆盖信息,获取所述第二覆盖信息,即差异代码中每行代码在所述第二版本代码运行时是否被执行的标记信息,因此该方法提升了版本间差异代码的覆盖信息的获取效率。
一种可选实施方式中,所述获取第一覆盖信息,包括:获取N组第三覆盖信息;其中,所述N组第三覆盖信息的每组第三覆盖信息,与所述N个版本代码中的一个版本代码唯一对应,该组第三覆盖信息用于指示该版本代码中每行代码是否被执行;将所述N组第三覆盖信息合并为所述第一覆盖信息。
一种可选实施方式中,所述N组第三覆盖信息的每组第三覆盖信息、所述第一覆盖信息均为一个数组,对于该数组任一下标的取值,若该取值为第一预设值,则指示该下标对应的代码已在该组覆盖信息对应的版本代码中被执行,若该取值为第二预设值,则指示该下标对应的代码未在该组覆盖信息对应的版本代码中被执行;所述将所述N组第三覆盖信息合并为所述第一覆盖信息,包括:按照所述第一覆盖信息的数组中每个下标,对所述N组第三覆盖信息的N个数组中该下标的取值按预设运算规则做运算,将该运算结果作为所述第一覆盖信息的数组中该下标的取值。
一种可选实施方式中,所述根据所述第一版本代码与第二版本代码,确定所述第一版本代码中,与所述第二版本代码存在差异的差异代码,包括:若所述第一版本代码存在相对所述第二版本代码的新增代码,则将所述新增 代码作为第一代码集合;若所述第一版本代码存在相对所述第二版本代码删除的代码块,则将在所述第二版本代码中,删除的代码块首行之前的一行代码和末尾行之后的一行代码,作为第二代码集合;若所述第一版本代码中存在相对所述第二版本代码注解发生变化的代码块,则将所述注解发生变化的代码块,作为第三代码集合;将所述第一代码集合、所述第三代码集合以及所述第三代码集合中所有代码,作为所述差异代码。
一种可选实施方式中,所述根据所述差异代码以及所述第一覆盖信息,确定第二覆盖信息,包括:针对所述差异代码中每一行代码,若在所述第一覆盖信息中指示了该行代码被执行,则确定该行代码在所述第一版本代码中被执行;否则,确定该行代码在所述第一版本代码中未被执行;根据所述差异代码中每一行代码在所述第一版本代码中是否被执行,确定所述第二覆盖信息。
第二方面,本申请实施例提供一种覆盖信息获取装置,包括:获取模块,用于获取第一覆盖信息;所述第一覆盖信息用于指示行号为1至K对应的每行代码是否被执行,其中,当行号i对应的一行代码,在N个版本代码中均被执行,则表示行号i对应的一行代码被执行,否则,表示行号i对应的一行代码未被执行;K为第一版本代码包括的代码的行数;i为大于或等于1且小于或等于K的整数;所述第一版本代码为所述N个版本代码中最后一次提交的代码;处理模块,用于根据所述第一版本代码与第二版本代码,确定所述第一版本代码中,与所述第二版本代码存在差异的差异代码;所述第二版本代码为所述N个版本代码中首次提交的代码;根据所述差异代码以及所述第一覆盖信息,确定第二覆盖信息;所述第二覆盖信息用于指示所述差异代码中每行代码在所述第一版本代码中是否被执行。
一种可选实施方式中,所述获取模块具体用于:获取N组第三覆盖信息;其中,所述N组第三覆盖信息的每组第三覆盖信息,与所述N个版本代码中的一个版本代码唯一对应,该组第三覆盖信息用于指示该版本代码中每行代码是否被执行;将所述N组第三覆盖信息合并为所述第一覆盖信息。
一种可选实施方式中,所述N组第三覆盖信息的每组第三覆盖信息、所述第一覆盖信息均为一个数组,对于该数组任一下标的取值,若该取值为第一预设值,则指示该下标对应的代码已在该组覆盖信息对应的版本代码中被执行,若该取值为第二预设值,则指示该下标对应的代码未在该组覆盖信息对应的版本代码中被执行;所述获取模块具体用于:按照所述第一覆盖信息的数组中每个下标,对所述N组第三覆盖信息的N个数组中该下标的取值按 预设运算规则做运算,将该运算结果作为所述第一覆盖信息的数组中该下标的取值。
一种可选实施方式中,所述处理模块具体用于:若所述第一版本代码存在相对所述第二版本代码的新增代码,则将所述新增代码作为第一代码集合;若所述第一版本代码存在相对所述第二版本代码删除的代码块,则将在所述第二版本代码中,删除的代码块首行之前的一行代码和末尾行之后的一行代码,作为第二代码集合;若所述第一版本代码中存在相对所述第二版本代码注解发生变化的代码块,则将所述注解发生变化的代码块,作为第三代码集合;将所述第一代码集合、所述第三代码集合以及所述第三代码集合中所有代码,作为所述差异代码。
一种可选实施方式中,所述处理模块具体用于:针对所述差异代码中每一行代码,若在所述第一覆盖信息中指示了该行代码被执行,则确定该行代码在所述第一版本代码中被执行;否则,确定该行代码在所述第一版本代码中未被执行;根据所述差异代码中每一行代码在所述第一版本代码中是否被执行,确定所述第二覆盖信息。
第三方面,本申请实施例提供一种计算机设备,包括:
至少一个处理器;以及,
与所述至少一个处理器通信连接的存储器;其中,
所述存储器存储有可被所述至少一个处理器执行的程序,所述程序被所述至少一个处理器执行,以使所述至少一个处理器能够执行如上所述的覆盖信息获取方法。
第四方面,本申请实施例提供一种非暂态计算机可读存储介质,所述非暂态计算机可读存储介质存储计算机程序,所述计算机程序用于使所述计算机执行如上所述的覆盖信息获取方法。
第五方面,本发明实施例还提供一种计算机程序产品,所述计算机程序产品包括存储在非暂态计算机可读存储介质上的计算机程序,当所述计算机程序被计算机执行时,使所述计算机执行如上所述的覆盖信息获取方法。
附图说明
图1为本申请实施例中一种覆盖信息获取方法的步骤流程示意图;
图2为本申请实施例中一种覆盖信息获取方法可应用的系统架构图;
图3为本申请实施例中一种覆盖信息获取方法可应用的系统架构图中自动注入覆盖信息代理的步骤流程图;
图4为本申请实施例中一种覆盖信息获取装置的结构示意图;
图5为本发明实施例提供的电子设备的结构示意图。
具体实施方式
为了更好的理解上述技术方案,下面将结合说明书附图及具体的实施方式对上述技术方案进行详细的说明,应当理解本申请实施例以及实施例中的具体特征是对本申请技术方案的详细的说明,而不是对本申请技术方案的限定,在不冲突的情况下,本申请实施例以及实施例中的技术特征可以相互结合。
随着计算机技术的发展,越来越多的技术(大数据、分布式、区块链(Blockchain)、人工智能等)应用在金融领域,传统金融业正在逐步向金融科技(Fintech)转变。目前,金融科技领域中,经常需要开发软件项目,一个软件项目在一个开发周期内,会对代码进行频繁的修改,可以将每次修改的代码提交到一个开源分布式版本控制系统中存储起来。举例来说,Jenkins是一个开源软件项目,是基于Java开发的一种持续集成工具,用于监控持续重复的工作,旨在提供一个开放易用的软件平台,使软件的持续集成变成可能。git为一个开源分布式版本控制系统,git旨在快速高效地处理从小型到大型项目的所有事务。
由于一个软件项目代码会进行频繁的修改,因此一个软件项目在一个开发周期内会产生多个版本,为了表征不同版本代码间的变动情况、以及代码变动后的优化情况,常常需要获取两个不同版本之间差异代码的覆盖信息,也就是较新版本的代码在运行过程中,差异代码中代码的执行情况,如运行过程中差异代码执行的行数、差异代码执行的行数占差异代码总行数的比例等。
现有技术中,在金融机构(银行机构、保险机构或证券机构)在进行业务(如银行的贷款业务、存款业务等)开发过程中,需要获取软件项目在一个开发周期内的两个不同版本之间差异代码的覆盖信息时,依次获取两个不同版本之间所有版本中,每两个相邻版本代码之间差异代码的覆盖信息、代码变动信息,再一个一个版本推导下去,直至得出两个不同版本之间差异代码的覆盖信息。显然,现有技术中的方法需要频繁拉取各个版本代码,计算量巨大,容易出错,而且会导致整个流程较长,两个不同版本间差异代码的覆盖信息的获取效率较低,这种情况不符合银行等金融机构的需求,无法保证各项业务的高效运行。
为此,本申请实施例提供获取第一覆盖信息的方法,该方法的步骤流程图如图1所示。
步骤101:获取第一覆盖信息。
需要说明的是,覆盖信息指运行时程序文件中的代码被执行的信息。一个程序文件在执行过程中,程序文件中每一行代码可能从程序文件执行开始到执行结束过程中,被执行过,也可能从未被执行过。如果一行代码被执行了就称这行代码被覆盖了,否则,就称这行代码未被覆盖。覆盖信息可以为程序文件中被覆盖的代码的比例信息、行数信息等,本申请实施例不做限定。另外,在一些编程环境中,对程序文件中代码进行编辑时,程序文件中有一些没有代码的空行,这些空行删除或不删除并不影响程序运行,在获取覆盖信息时并不考虑这些空行。
所述第一覆盖信息用于指示行号为1至K对应的每行代码是否被执行,其中,当行号i对应的一行代码,在N个版本代码中均被执行,则表示行号i对应的一行代码被执行,否则,表示行号i对应的一行代码未被执行;K为第一版本代码包括的代码的行数;i为大于或等于1且小于或等于K的整数,所述第一版本代码为所述N个版本代码中最后一次提交的代码。所述N个版本代码为,一个开发周期中按预设顺序提交的代码中连续N次提交的代码,举例来说,一个软件项目,按照时间先后顺序提交了10次代码,N个版本代码为第4~8次提交的代码,此时N=5。
步骤102:根据所述第一版本代码与第二版本代码,确定所述第一版本代码中,与所述第二版本代码存在差异的差异代码。
所述第二版本代码为所述N个版本代码中首次提交的代码。
步骤103:根据所述差异代码以及所述第一覆盖信息,确定第二覆盖信息。所述第二覆盖信息用于指示所述差异代码中每行代码在所述第一版本代码中是否被执行。
步骤101中,获取第一覆盖信息的一种可选实施方式如下:
获取N组第三覆盖信息;其中,所述N组第三覆盖信息的每组第三覆盖信息,与所述N个版本代码中的一个版本代码唯一对应,该组第三覆盖信息用于指示该版本代码中每行代码是否被执行;将所述N组第三覆盖信息合并为所述第一覆盖信息。
在该可选实施方式中,对N组第三覆盖信息以及所述第一覆盖信息的形式不做限定,举例来说,所述N组第三覆盖信息的每组第三覆盖信息、所述第一覆盖信息均为一个数组,对于该数组任一下标的取值,若该取值为第一 预设值,则指示该下标对应的代码已在该组覆盖信息对应的版本代码中被执行,若该取值为第二预设值,则指示该下标对应的代码未在该组覆盖信息对应的版本代码中被执行,基于此,可按照以下方式将所述N组第三覆盖信息合并为所述第一覆盖信息:
按照所述第一覆盖信息的数组中每个下标,对所述N组第三覆盖信息的N个数组中该下标的取值按预设运算规则做运算,将该运算结果作为所述第一覆盖信息的数组中该下标的取值。
举例来说,N个数组的每个数组均为布尔型数组,第一预设值为0,第二预设值为1,预设运算规则为与运算。对N个布尔型数组做与运算的结果,也是一个布尔型数组,将这个布尔型数组作为所述第一覆盖信息。
步骤102中,差异代码指版本之间存在差异的代码,本申请实施例仅举例说明差异代码的判定规则,可根据具体实施场景来调整差异代码的判定规则,对此不做限定,具体判定规则如下:
差异代码分为文件差异和文件内容差异,文件差异:如果文件路径或者文件名发生了改变,就指存在文件差异;文件内容差异:文件路径和文件名没有发送改变,但是文件内容发送了改变。在以下叙述中,文件指程序文件。可以通过增加或者减少一系列文件,以及对一个文件增加或者减少某些行内容,从而变更代码的内容,表现为:
(1)第一版本代码相比第二版本代码新增了文件,对于新增的文件,将整个文件的所有代码行纳入差异代码中。对于第一版本代码相比第二版本代码减少的文件,不将减少的代码纳入差异代码。需要说明的是,代码行指文件中为代码的编辑行,如空行,并不作为代码行。
(2)第一版本代码相比第二版本代码,文件名和文件的存储路径相同,但是文件内容不同的,分为以下情形:
第一种情形:新增了某些代码行。对于新增的代码行,直接纳入差异代码中。
第二种情形:但减少的文件行,由于可能会影响上下代码行功能,所以这里将删除的代码块上下两行纳入差异代码中。对于删除的代码块,代码块指一组连续行数的代码行,将删除的代码块首行之前的一行和末尾行之后的一行纳入差异代码中。举例来说,第二版本代码的程序文件一中共有第1~10行,第一版本代码的程序文件一中共有第1~8行,其中第一版本代码的程序文件一的第1~6行与第二版本代码的程序文件一的第1~6行相同,第一版本代码的程序文件一的第7~8行与第二版本代码的程序文件一的第9~10行相同, 也就是说,第一版本代码的程序文件一相对于第二版本代码的程序文件一,删除了第二版本代码的程序文件一中的第7~8行,即为删除的代码块,因此将删除的代码块首行之前的一行,也就是第一版本代码的程序文件一中的第6行,以及删除的代码块末尾行之后的一行,也就是第一版本代码的程序文件一中的第7行(对应第二版本代码的程序文件一中的第9行),纳入差异代码。
第三种情形,对于文件中的代码注解,由于注解本身没有覆盖信息,但是注解却有可能影响注解的代码块的执行,所以这里对于相同文件中的相同代码块,如果代码块的注解发生了修改,可以将整个代码块设置的代码行纳入差异代码中。需要说明的是,注解为Java编程语言中提供的一种机制,这种机制允许程序员在编写代码的同时可以直接编写元数据。被注解的代码并不会直接被注解影响,这只会向第三系统提供关于自己的信息以用于不同的需求。
综合以上情形,步骤102中确定差异代码一种可选实施方式如下:
若所述第一版本代码存在相对所述第二版本代码的新增代码,则将所述新增代码作为第一代码集合;若所述第一版本代码存在相对所述第二版本代码删除的代码块,则将在所述第二版本代码中,删除的代码块首行之前的一行代码和末尾行之后的一行代码,作为第二代码集合;若所述第一版本代码中存在相对所述第二版本代码注解发生变化的代码块,则将所述注解发生变化的代码块,作为第三代码集合;将所述第一代码集合、所述第三代码集合以及所述第三代码集合中所有代码,作为所述差异代码。
另外,需要说明的是,程序文件中的空行不计入差异代码,举例来说,程序文件A中第一行为1,第二行为2,第三行为3,程序文件B中第一行为1,第二行为空,第三行为2,第四行为3,认为程序文件A和程序文件B没有差异。
步骤102获取了第一版本代码中与所述第二版本代码存在差异的差异代码,步骤103即根据步骤102获取的所述差异代码,进一步获取第二覆盖信息。第二覆盖信息也就是,第一版本代码在执行过程中,差异代码中每行代码是否被执行的信息。
步骤103中,获取第二覆盖信息的一种可选实施方式如下:
针对所述差异代码中每一行代码,若在所述第一覆盖信息中指示了该行代码被执行,则确定该行代码在所述第一版本代码中被执行;否则,确定该行代码在所述第一版本代码中未被执行;根据所述差异代码中每一行代码在所述第一版本代码中是否被执行,确定所述第二覆盖信息。
上述实施方式也就是,将在差异代码中,且在第一覆盖信息中记录的被执行的代码行,作为第二覆盖信息中被覆盖的代码行。
下面以Jenkins和git结合为例,根据图2进一步说明本申请实施例提出的一种覆盖信息获取方法,如图2所示,为本申请实施例提出的一种覆盖信息获取方法可应用的系统架构图。
在图2示出的系统架构图中,通过Jenkins和git结合,可自动收集git的提交信息,提前将N个版本代码的覆盖信息进行合并,获取第一覆盖信息,并结合第一版本代码与第二版本代码的差异代码,从而快速的获取所述第二覆盖信息。其中,Jenkins部署在应用机器,git部署在服务器。应用机器即进行项目开发的机器,应用机器将每次修改的代码提交至服务器。git中有几个常用工具标记如下:git commit,为git中的某次修改提交;git tag,是git版本库的一个快照,指向某次修改提交的指针;git commit id,为git中用于标识每一次提交修改的唯一字符串。可通过git commit记录Jenkins的每次修改提交之间文件差异,并用git tag指向Jenkins的每次提交修改,以及用git commit id标识Jenkins的每一次提交修改。下面分别介绍各个模块:
commit id信息收集模块:commit id信息收集模块为应用机器中的模块,commit id信息收集模块将自动采集当前版本代码的commit id,将结果输出到应用的发布物料包中,应用即为编写程序时的软件应用。应用的发布物料包是一个软件包,用于运用插桩技术(instrumentation)插桩时进行加载,从而进行额外功能的添加。该系统架构中,发布物料包为Jenkins,在版本编译后,将版本信息输出到应用包下的指定目录和指定文件名中。版本信息包括:git分支名,构建发布物料包时对应的git commit id。
覆盖信息代理注入模块:覆盖信息代理注入模块将自动接入覆盖信息代理,避免人工接入导致的误操作以及操作延迟。该模块会在应用运行的机器上监听当前应用的应用名及其对应的进程标识符(process identification,pid)关系,通过判断应用的pid是否存在,确定应用是否已经接入了覆盖信息代理,从而自动将覆盖信息代理接入应用。其中,pid在操作系统里指进程识别号,也就是进程标识符,操作系统里每打开一个程序都会创建一个pid。该模块还会结合commit id信息收集模块的输出结果,在接入覆盖信息代理后,通过网络给覆盖信息收集模块发送心跳以进行数据同步,也会给覆盖信息收集模块发送应用从启动到当前这段时间内的覆盖信息。
覆盖信息收集模块:覆盖信息收集模块用于定时接收覆盖率代理的心跳信息,判断覆盖信息代理的在线情况,同时也会定时或者手动给在线的覆盖 信息代理发送采集覆盖信息的指令,采集应用的覆盖信息。采集到覆盖信息会同之前已经存在的覆盖信息进行合并,举例来说,将N组第三覆盖信息进行合并,得到一段时间内累积的第一覆盖信息,并将其存储在本地磁盘。
如图3所示,为本申请实施例提供的覆盖信息代理注入模块自动注入覆盖信息代理的步骤流程图,以应用A举例说明。
步骤301:通过一个称为过程状态(Process Status,ps)的命令获取应用A的pid_1。
需要说明的是,ps命令用来列出系统中当前运行的那些进程。ps命令列出的是当前那些进程的快照,就是执行ps命令的那个时刻的那些进程。
步骤302:请求覆盖信息采集模块获取应用A上报的pid_2。
步骤303:确定是否应用A的pid1不存在或pid_1与pid_2不相等。
若是,则执行步骤304。
若应用A没有上报过pid1或者查询回来的pid2同当前的pid1不一致,则确定应用未接入覆盖信息代理。
步骤304:注入覆盖信息代理。
步骤304使用java提供的instrumentation的应用程序接口,注入覆盖率代理。
步骤305:上报pid_1。
在应用A成功注入覆盖率代理后,会将应用A自身的pid_1上报给覆盖信息收集模块,更新其之前存储的值。
差异代码比较模块:在收到生成覆盖信息的指令时,差异代码比较模块会通过网络从git获取最近一次tag以及当前commit id对应的版本代码,比较获取两者之间的差异文件和文件之间的差异行,输出对应的代码行差异结果。触发源码比较的指令可以是自动触发也可以是手动触发。
覆盖信息输出模块:覆盖信息输出模块用于将结合第一覆盖信息以及差异代码,生成第二覆盖信息。
上述方法中,获取了第一覆盖信息,第一覆盖信息指示了行号为1至K对应的每行代码是否被执行,该方法并不需要频繁拉取N个版本代码中各个版本代码确定每次提交版本代码后的差异代码,直接根据所述第一版本代码与所述第二版本代码,便能确定所述第二版本代码中,与所述第一版本代码存在差异的差异代码,从而大幅度降低了计算量和错误率,从而降低了整个流程时间,再根据所述差异代码以及所述第一覆盖信息,获取所述第二覆盖信息,即差异代码中每行代码在所述第二版本代码运行时是否被执行的标记 信息,因此该方法提升了版本间差异代码的覆盖信息的获取效率。
如图4所示,为本申请实施例中一种覆盖信息获取装置的结构示意图。
本申请实施例提供一种覆盖信息获取装置,包括:获取模块401,用于获取第一覆盖信息;所述第一覆盖信息用于指示行号为1至K对应的每行代码是否被执行,其中,当行号i对应的一行代码,在N个版本代码中均被执行,则表示行号i对应的一行代码被执行,否则,表示行号i对应的一行代码未被执行;K为第一版本代码包括的代码的行数;i为大于或等于1且小于或等于K的整数;所述第一版本代码为所述N个版本代码中最后一次提交的代码;处理模块402,用于根据所述第一版本代码与第二版本代码,确定所述第一版本代码中,与所述第二版本代码存在差异的差异代码;所述第二版本代码为所述N个版本代码中首次提交的代码;根据所述差异代码以及所述第一覆盖信息,确定第二覆盖信息;所述第二覆盖信息用于指示所述差异代码中每行代码在所述第一版本代码中是否被执行。
一种可选实施方式中,所述获取模块401具体用于:获取N组第三覆盖信息;其中,所述N组第三覆盖信息的每组第三覆盖信息,与所述N个版本代码中的一个版本代码唯一对应,该组第三覆盖信息用于指示该版本代码中每行代码是否被执行;将所述N组第三覆盖信息合并为所述第一覆盖信息。
一种可选实施方式中,所述N组第三覆盖信息的每组第三覆盖信息、所述第一覆盖信息均为一个数组,对于该数组任一下标的取值,若该取值为第一预设值,则指示该下标对应的代码已在该组覆盖信息对应的版本代码中被执行,若该取值为第二预设值,则指示该下标对应的代码未在该组覆盖信息对应的版本代码中被执行;所述获取模块401具体用于:按照所述第一覆盖信息的数组中每个下标,对所述N组第三覆盖信息的N个数组中该下标的取值按预设运算规则做运算,将该运算结果作为所述第一覆盖信息的数组中该下标的取值。
一种可选实施方式中,所述处理模块402具体用于:若所述第一版本代码存在相对所述第二版本代码的新增代码,则将所述新增代码作为第一代码集合;若所述第一版本代码存在相对所述第二版本代码删除的代码块,则将在所述第二版本代码中,删除的代码块首行之前的一行代码和末尾行之后的一行代码,作为第二代码集合;若所述第一版本代码中存在相对所述第二版本代码注解发生变化的代码块,则将所述注解发生变化的代码块,作为第三代码集合;将所述第一代码集合、所述第三代码集合以及所述第三代码集合 中所有代码,作为所述差异代码。
一种可选实施方式中,所述处理模块402具体用于:针对所述差异代码中每一行代码,若在所述第一覆盖信息中指示了该行代码被执行,则确定该行代码在所述第一版本代码中被执行;否则,确定该行代码在所述第一版本代码中未被执行;根据所述差异代码中每一行代码在所述第一版本代码中是否被执行,确定所述第二覆盖信息。
基于相同的原理,本发明还提供一种计算机设备,如图5所示,包括:
包括处理器501、存储器502、收发机503、总线接口504,其中处理器501、存储器502与收发机503之间通过总线接口504连接;
所述处理器501,用于读取所述存储器502中的程序,执行上述区块链中的投票方法,所述方法包括:
获取第一覆盖信息;所述第一覆盖信息用于指示行号为1至K对应的每行代码是否被执行,其中,当行号i对应的一行代码,在N个版本代码中均被执行,则表示行号i对应的一行代码被执行,否则,表示行号i对应的一行代码未被执行;K为第一版本代码包括的代码的行数;i为大于或等于1且小于或等于K的整数;所述第一版本代码为所述N个版本代码中最后一次提交的代码;
根据所述第一版本代码与第二版本代码,确定所述第一版本代码中,与所述第二版本代码存在差异的差异代码;所述第二版本代码为所述N个版本代码中首次提交的代码;
根据所述差异代码以及所述第一覆盖信息,确定第二覆盖信息;所述第二覆盖信息用于指示所述差异代码中每行代码在所述第一版本代码中是否被执行。
所述处理器501可以是中央处理器(central processing unit,简称CPU),网络处理器(network processor,简称NP)或者CPU和NP的组合。还可以是硬件芯片。上述硬件芯片可以是专用集成电路(application-specific integrated circuit,简称ASIC),可编程逻辑器件(programmable logic device,简称PLD)或其组合。上述PLD可以是复杂可编程逻辑器件(complex programmable logic device,简称CPLD),现场可编程逻辑门阵列(field-programmable gate array,简称FPGA),通用阵列逻辑(generic array logic,简称GAL)或其任意组合。
所述存储器502,用于存储一个或多个可执行程序,可以存储所述处理器501在执行操作时所使用的数据。
具体地,程序可以包括程序代码,程序代码包括计算机操作指令。存储 器502可以包括易失性存储器(volatile memory),例如随机存取存储器(random-access memory,简称RAM);存储器502也可以包括非易失性存储器(non-volatile memory),例如快闪存储器(flash memory),硬盘(hard disk drive,简称HDD)或固态硬盘(solid-state drive,简称SSD);存储器502还可以包括上述种类的存储器的组合。
存储器502存储了如下的元素,可执行模块或者数据结构,或者它们的子集,或者它们的扩展集:
操作指令:包括各种操作指令,用于实现各种操作。
操作系统:包括各种系统程序,用于实现各种基础业务以及处理基于硬件的任务。
总线接口504可以为有线通信接入口,无线总线接口或其组合,其中,有线总线接口例如可以为以太网接口。以太网接口可以是光接口,电接口或其组合。无线总线接口可以为WLAN接口。
基于相同的原理,本发明实施例还提供一种非暂态计算机可读存储介质,所述非暂态计算机可读存储介质存储计算机程序,所述计算机程序用于使所述计算机执行上述覆盖信息获取方法。
基于相同的原理,本发明实施例还提供一种计算机程序产品,所述计算机程序产品包括存储在非暂态计算机可读存储介质上的计算机程序,当所述计算机程序被计算机执行时,使所述计算机执行上述覆盖信息获取方法。
最后应说明的是:本领域内的技术人员应明白,本申请的实施例可提供为方法、系统、或计算机程序产品。因此,本申请可采用完全硬件实施例、完全软件实施例、或结合软件和硬件方面的实施例的形式。而且,本申请可采用在一个或多个其中包含有计算机可用程序代码的计算机可用存储介质(包括但不限于磁盘存储器、光学存储器等)上实施的计算机程序产品的形式。
本申请是参照根据本申请的方法、设备(系统)、和计算机程序产品的流程图和/或方框图来描述的。应理解可由计算机程序指令实现流程图和/或方框图中的每一流程和/或方框、以及流程图和/或方框图中的流程和/或方框的结合。可提供这些计算机程序指令到通用计算机、专用计算机、嵌入式处理机或其他可编程数据处理设备的处理器以产生一个机器,使得通过计算机或其他可编程数据处理设备的处理器执行的指令产生用于实现在流程图一个流程或多个和/或方框图一个方框或多个方框中指定的功能的装置。
这些计算机程序指令也可存储在能引导计算机或其他可编程数据处理设 备以特定方式工作的计算机可读存储器中,使得存储在该计算机可读存储器中的指令产生包括指令装置的制造品,该指令装置实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能。
显然,本领域的技术人员可以对本申请进行各种改动和变型而不脱离本申请的范围。这样,倘若本申请的这些修改和变型属于本申请权利要求及其等同技术的范围之内,则本申请也意图包含这些改动和变型在内。

Claims (13)

  1. 一种覆盖信息获取方法,其特征在于,包括:
    获取第一覆盖信息;所述第一覆盖信息用于指示行号为1至K对应的每行代码是否被执行,其中,当行号i对应的一行代码,在N个版本代码中均被执行,则表示行号i对应的一行代码被执行,否则,表示行号i对应的一行代码未被执行;K为第一版本代码包括的代码的行数;i为大于或等于1且小于或等于K的整数;所述第一版本代码为所述N个版本代码中最后一次提交的代码;
    根据所述第一版本代码与第二版本代码,确定所述第一版本代码中,与所述第二版本代码存在差异的差异代码;所述第二版本代码为所述N个版本代码中首次提交的代码;
    根据所述差异代码以及所述第一覆盖信息,确定第二覆盖信息;所述第二覆盖信息用于指示所述差异代码中每行代码在所述第一版本代码中是否被执行。
  2. 如权利要求1所述的方法,其特征在于,所述获取第一覆盖信息,包括:
    获取N组第三覆盖信息;其中,所述N组第三覆盖信息的每组第三覆盖信息,与所述N个版本代码中的一个版本代码唯一对应,该组第三覆盖信息用于指示该版本代码中每行代码是否被执行;
    将所述N组第三覆盖信息合并为所述第一覆盖信息。
  3. 如权利要求2所述的方法,其特征在于,所述N组第三覆盖信息的每组第三覆盖信息、所述第一覆盖信息均为一个数组,对于该数组任一下标的取值,若该取值为第一预设值,则指示该下标对应的代码已在该组覆盖信息对应的版本代码中被执行,若该取值为第二预设值,则指示该下标对应的代码未在该组覆盖信息对应的版本代码中被执行;所述将所述N组第三覆盖信息合并为所述第一覆盖信息,包括:
    按照所述第一覆盖信息的数组中每个下标,对所述N组第三覆盖信息的N个数组中该下标的取值按预设运算规则做运算,将该运算结果作为所述第一覆盖信息的数组中该下标的取值。
  4. 如权利要求1-3任一所述的方法,其特征在于,所述根据所述第一版本代码与第二版本代码,确定所述第一版本代码中,与所述第二版本代码存在差异的差异代码,包括:
    若所述第一版本代码存在相对所述第二版本代码的新增代码,则将所述新增代码作为第一代码集合;
    若所述第一版本代码存在相对所述第二版本代码删除的代码块,则将在所述第二版本代码中,删除的代码块首行之前的一行代码和末尾行之后的一行代码,作为第二代码集合;
    若所述第一版本代码中存在相对所述第二版本代码注解发生变化的代码块,则将所述注解发生变化的代码块,作为第三代码集合;
    将所述第一代码集合、所述第三代码集合以及所述第三代码集合中所有代码,作为所述差异代码。
  5. 如权利要求1-3任一所述的方法,其特征在于,所述根据所述差异代码以及所述第一覆盖信息,确定第二覆盖信息,包括:
    针对所述差异代码中每一行代码,若在所述第一覆盖信息中指示了该行代码被执行,则确定该行代码在所述第一版本代码中被执行;否则,确定该行代码在所述第一版本代码中未被执行;
    根据所述差异代码中每一行代码在所述第一版本代码中是否被执行,确定所述第二覆盖信息。
  6. 一种覆盖信息获取装置,其特征在于,包括:
    获取模块,用于获取第一覆盖信息;所述第一覆盖信息用于指示行号为1至K对应的每行代码是否被执行,其中,当行号i对应的一行代码,在N个版本代码中均被执行,则表示行号i对应的一行代码被执行,否则,表示行号i对应的一行代码未被执行;K为第一版本代码包括的代码的行数;i为大于或等于1且小于或等于K的整数;所述第一版本代码为所述N个版本代码中最后一次提交的代码;
    处理模块,用于根据所述第一版本代码与第二版本代码,确定所述第一版本代码中,与所述第二版本代码存在差异的差异代码;所述第二版本代码为所述N个版本代码中首次提交的代码;根据所述差异代码以及所述第一覆盖信息,确定第二覆盖信息;所述第二覆盖信息用于指示所述差异代码中每行代码在所述第一版本代码中是否被执行。
  7. 如权利要求6所述的装置,其特征在于,所述获取模块具体用于:
    获取N组第三覆盖信息;其中,所述N组第三覆盖信息的每组第三覆盖信息,与所述N个版本代码中的一个版本代码唯一对应,该组第三覆盖信息用于指示该版本代码中每行代码是否被执行;将所述N组第三覆盖信息合并为所述第一覆盖信息。
  8. 如权利要求7所述的装置,其特征在于,所述N组第三覆盖信息的每组第三覆盖信息、所述第一覆盖信息均为一个数组,对于该数组任一下标的取值,若该取值为第一预设值,则指示该下标对应的代码已在该组覆盖信息对应的版本代码中被执行,若该取值为第二预设值,则指示该下标对应的代码未在该组覆盖信息对应的版本代码中被执行;所述获取模块具体用于:
    按照所述第一覆盖信息的数组中每个下标,对所述N组第三覆盖信息的N个数组中该下标的取值按预设运算规则做运算,将该运算结果作为所述第一覆盖信息的数组中该下标的取值。
  9. 如权利要求6-8任一所述的装置,其特征在于,所述处理模块具体用于:
    若所述第一版本代码存在相对所述第二版本代码的新增代码,则将所述新增代码作为第一代码集合;
    若所述第一版本代码存在相对所述第二版本代码删除的代码块,则将在所述第二版本代码中,删除的代码块首行之前的一行代码和末尾行之后的一行代码,作为第二代码集合;
    若所述第一版本代码中存在相对所述第二版本代码注解发生变化的代码块,则将所述注解发生变化的代码块,作为第三代码集合;
    将所述第一代码集合、所述第三代码集合以及所述第三代码集合中所有代码,作为所述差异代码。
  10. 如权利要求6-8任一所述的装置,其特征在于,所述处理模块具体用于:
    针对所述差异代码中每一行代码,若在所述第一覆盖信息中指示了该行代码被执行,则确定该行代码在所述第一版本代码中被执行;否则,确定该行代码在所述第一版本代码中未被执行;
    根据所述差异代码中每一行代码在所述第一版本代码中是否被执行,确定所述第二覆盖信息。
  11. 一种计算机设备,其特征在于,包括:
    至少一个处理器;以及,
    与所述至少一个处理器通信连接的存储器;其中,
    所述存储器存储有可被所述至少一个处理器执行的程序,所述程序被所述至少一个处理器执行,以使所述至少一个处理器能够执行权利要求1-5任一所述的方法。
  12. 一种非暂态计算机可读存储介质,其特征在于,所述非暂态计算机 可读存储介质存储计算机程序,所述计算机程序用于使所述计算机执行权利要求1-5任一所述方法。
  13. 一种计算机程序产品,其特征在于,所述计算机程序产品包括存储在非暂态计算机可读存储介质上的计算机程序,当所述计算机程序被计算机执行时,使所述计算机执行权利要求1-5任一所述方法。
PCT/CN2020/093025 2019-06-03 2020-05-28 一种覆盖信息获取方法及装置 Ceased WO2020244445A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201910477036.1A CN110262966B (zh) 2019-06-03 2019-06-03 一种覆盖信息获取方法及装置
CN201910477036.1 2019-06-03

Publications (1)

Publication Number Publication Date
WO2020244445A1 true WO2020244445A1 (zh) 2020-12-10

Family

ID=67916534

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2020/093025 Ceased WO2020244445A1 (zh) 2019-06-03 2020-05-28 一种覆盖信息获取方法及装置

Country Status (2)

Country Link
CN (1) CN110262966B (zh)
WO (1) WO2020244445A1 (zh)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113590173A (zh) * 2021-06-25 2021-11-02 济南浪潮数据技术有限公司 一种代码统计方法、系统、设备以及介质
CN115794606A (zh) * 2022-10-25 2023-03-14 平安银行股份有限公司 一种代码覆盖率确定方法、装置、设备和可读存储介质
CN119807041A (zh) * 2024-12-17 2025-04-11 上海金融期货信息技术有限公司 一种面向发布的多维度集成测试质量实时观测方法和系统

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110262966B (zh) * 2019-06-03 2024-10-29 深圳前海微众银行股份有限公司 一种覆盖信息获取方法及装置
CN113377431B (zh) * 2020-02-25 2025-03-25 华为云计算技术有限公司 一种代码处理方法、装置、设备及介质
CN112181430B (zh) * 2020-09-29 2024-06-14 北京云族佳科技有限公司 代码变更统计方法、装置、电子设备及存储介质
CN114860296A (zh) * 2022-03-22 2022-08-05 北京快乐茄信息技术有限公司 软件持续集成方法、装置和存储介质

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105608011A (zh) * 2016-03-01 2016-05-25 网易(杭州)网络有限公司 代码测试覆盖率统计结果的确定方法及装置
US20170132109A1 (en) * 2015-11-11 2017-05-11 International Business Machines Corporation Automatic collection and presentation of runtime data semantics
CN107957956A (zh) * 2017-12-26 2018-04-24 广州品唯软件有限公司 软件差异覆盖率的测试方法、装置及可读存储介质
CN108519945A (zh) * 2018-03-21 2018-09-11 腾讯科技(深圳)有限公司 覆盖率测试方法、装置及存储设备
CN108829580A (zh) * 2018-05-07 2018-11-16 百度在线网络技术(北京)有限公司 多版本测试数据处理方法、装置、设备及存储介质
CN110262966A (zh) * 2019-06-03 2019-09-20 深圳前海微众银行股份有限公司 一种覆盖信息获取方法及装置

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104317706B (zh) * 2014-10-15 2017-08-25 中国科学院软件研究所 一种基于预运算的程序变异软件错误定位方法
US9639453B2 (en) * 2015-03-04 2017-05-02 Vmware, Inc. Method and system for determining functional tests to execute based on code coverage

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20170132109A1 (en) * 2015-11-11 2017-05-11 International Business Machines Corporation Automatic collection and presentation of runtime data semantics
CN105608011A (zh) * 2016-03-01 2016-05-25 网易(杭州)网络有限公司 代码测试覆盖率统计结果的确定方法及装置
CN107957956A (zh) * 2017-12-26 2018-04-24 广州品唯软件有限公司 软件差异覆盖率的测试方法、装置及可读存储介质
CN108519945A (zh) * 2018-03-21 2018-09-11 腾讯科技(深圳)有限公司 覆盖率测试方法、装置及存储设备
CN108829580A (zh) * 2018-05-07 2018-11-16 百度在线网络技术(北京)有限公司 多版本测试数据处理方法、装置、设备及存储介质
CN110262966A (zh) * 2019-06-03 2019-09-20 深圳前海微众银行股份有限公司 一种覆盖信息获取方法及装置

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113590173A (zh) * 2021-06-25 2021-11-02 济南浪潮数据技术有限公司 一种代码统计方法、系统、设备以及介质
CN113590173B (zh) * 2021-06-25 2025-05-27 济南浪潮数据技术有限公司 一种代码统计方法、系统、设备以及介质
CN115794606A (zh) * 2022-10-25 2023-03-14 平安银行股份有限公司 一种代码覆盖率确定方法、装置、设备和可读存储介质
CN119807041A (zh) * 2024-12-17 2025-04-11 上海金融期货信息技术有限公司 一种面向发布的多维度集成测试质量实时观测方法和系统

Also Published As

Publication number Publication date
CN110262966A (zh) 2019-09-20
CN110262966B (zh) 2024-10-29

Similar Documents

Publication Publication Date Title
WO2020244445A1 (zh) 一种覆盖信息获取方法及装置
CN108932282B (zh) 一种数据库迁移方法、装置和存储介质
CN102323945B (zh) 一种基于sql的数据库管理方法和装置
CN104484269A (zh) 一种自动生成测试脚本的方法
CN107665219B (zh) 一种日志管理方法及装置
CN112965939A (zh) 一种文件合并方法、装置和设备
CN108319711A (zh) 数据库的事务一致性测试方法、装置、存储介质及设备
CN109271199B (zh) 一种用于数据库持续集成与脚本文件管理的方法及系统
US20250199945A1 (en) Parallel software testing based on annotations
CN114896335B (zh) 一种数据库的数据转储方法及系统
CN109710698A (zh) 一种数据汇聚方法、装置、电子设备及介质
US10592400B2 (en) System and method for creating variants in a test database during various test stages
JP6293709B2 (ja) ストレージシステムおよびストレージシステム用プログラム
CN110543485B (zh) 一种基于快照的区块链预约归档方法
EP4109287B1 (en) A collaborative system and method for multi-user data management
US20250321949A1 (en) Extensive-dimensional solutions for data lineage
US9442698B2 (en) Migration between model elements of different types in a modeling environment
CN117076431B (zh) 一种用于系统升级数据迁移的方法
CN119988444A (zh) 数据查询方法、系统、设备及存储介质
US10706012B2 (en) File creation
CN118643096A (zh) 数据同步方法、装置、设备及存储介质
US8296336B2 (en) Techniques for efficient dataloads into partitioned tables using swap tables
CN113326268A (zh) 一种数据写入、读取方法及装置
CN119806409B (zh) 数据存储方法、装置、终端设备及计算机可读存储介质
CN114741666B (zh) 一种权限控制方法及相关装置

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 20818811

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 20818811

Country of ref document: EP

Kind code of ref document: A1

32PN Ep: public notification in the ep bulletin as address of the adressee cannot be established

Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205 DATED 18/03/2022)

122 Ep: pct application non-entry in european phase

Ref document number: 20818811

Country of ref document: EP

Kind code of ref document: A1