Code coverage testing method, system, device and storage medium
By configuring the service architecture compatible configuration information and code coverage parameters in the compiler kernel source code, C++ code coverage is automatically obtained, which solves the problem of cumbersome process of obtaining code coverage in the existing technology, and achieves fast and accurate code coverage. Information acquisition.
Patent Information
- Application Number
- CN202010744868.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-07-29
- Publication Date
- 2024-11-29
- Estimated Expiration
- 2040-07-29
AI Technical Summary
When obtaining C++ code coverage, the process of the existing technology is complicated and requires manual modification of the configuration of the compilation and construction tool, which is difficult to maintain and cannot quickly obtain code coverage information.
By pre-configuring the compiler's kernel source code includes service architecture compatibility configuration information and code coverage parameters, the code coverage information can be automatically obtained without understanding the underlying compilation details and dependency environment, and obtaining code coverage in real time.
It realizes the rapid and efficient acquisition of code coverage information, simplifies the compilation process, avoids the cumbersomeness of manually modifying the compilation instructions, and improves the accuracy and detail of code coverage.
Smart Images

Figure CN113297064B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of this specification relate to the field of software testing technology, and in particular, to code coverage testing methods, systems, devices, and storage media. Background Art
[0002] In the process of testing computer programs, code coverage is an indicator to evaluate the coverage of product code by test activities, and is used to measure the degree of coverage of program code by tests. Through code coverage statistics, we can obtain how much code in the program has been executed and which code has insufficient test coverage.
[0003] Currently, the industry's C++ code coverage is generally based on the capabilities provided by the GCC (GNU Compiler Collection) compiler. This method requires adding parameters to the compilation command, and the process is cumbersome and complicated. For complex modules such as engines, there are hundreds of thousands or millions of lines of code and thousands of cpp (the suffix of source code files written in C++) files. Manually modifying the configuration of compilation and build tools (such as makefile and Blade) is extremely complicated and difficult to maintain, and there is no mature corresponding solution.
[0004] Therefore, how to quickly obtain code coverage has become an urgent problem to be solved. Summary of the invention
[0005] In view of this, the embodiments of this specification provide a code coverage testing method, system, device and storage medium, which can quickly obtain code coverage.
[0006] The present invention provides a method for testing code coverage, including:
[0007] Copying source code to a pre-configured compiler, wherein the kernel source code of the pre-configured compiler includes service architecture compatibility configuration information, and the configuration parameters of the compiler include code coverage parameters;
[0008] Compiling the source code using the compiler to generate a binary executable file;
[0009] Using the executable file, starting and executing the online service;
[0010] During the compilation process, first coverage information of the executed code during the running of the online service is generated based on the service architecture compatibility configuration information included in the kernel source code of the compiler and the pre-configured code coverage parameters of the compiler.
[0011] Optionally, the compiling operation using the compiler to generate first coverage information of the executed code during the running of the online service based on the service architecture compatibility configuration information contained in the kernel source code of the compiler and the pre-configured code coverage parameters of the compiler includes:
[0012] During the compilation process, in response to a coverage acquisition instruction, the thread monitoring code set in the source code acquires first coverage data of the executed code during the running of the online service;
[0013] Based on the first coverage data of the executed code acquired by the thread monitoring code, first coverage information of the executed code during the running of the online service is generated.
[0014] Optionally, the adopting the executable file to start and execute the online service includes:
[0015] Copy the executable file to the target path and start the online service;
[0016] Run the test case to execute the online service.
[0017] Optionally, generating first coverage information of the executed code during the running of the online service based on the service architecture compatibility configuration information included in the kernel source code of the compiler and the pre-configured code coverage parameters of the compiler includes:
[0018] During the compilation process, based on the service architecture compatibility configuration information contained in the kernel source code of the compiler and the pre-configured code coverage parameters of the compiler, a code coverage map is generated to a preset first compilation result directory, wherein the code coverage map is suitable for reorganizing the executable file;
[0019] During the compilation process, in response to a coverage acquisition instruction, a thread listening code set in the source code is triggered to acquire second coverage data corresponding to the coverage acquisition instruction during the running of the online service, and output the second coverage data to a preset second compilation result directory;
[0020] A code coverage report file is generated based on the code coverage graph obtained from the first compilation result directory and the second coverage data obtained from the second compilation result directory, wherein the code coverage report file includes the first coverage information.
[0021] Optionally, the generating the code coverage report file of the online service based on the code coverage graph obtained from the first compilation result directory and the second coverage data obtained from the second compilation result directory includes:
[0022] According to a preset coverage type, based on the code coverage graph obtained from the first compilation result directory and the second coverage data obtained from the second compilation result directory, a code coverage report file for the external service is generated.
[0023] Optionally, the method further includes: outputting the first coverage information of the online service using a visualization page.
[0024] Optionally, the method further comprises:
[0025] Parsing the first coverage information of the source code output by the visualization page and converting it into second coverage data in a preset storage format;
[0026] Based on the second coverage data in the preset storage format, second coverage information of a type corresponding to the preset coverage is calculated;
[0027] The second coverage information of the corresponding type is output according to a preset display format.
[0028] Optionally, the calculating, based on the second coverage data in the preset storage format, to obtain second coverage information of a type corresponding to the preset coverage includes:
[0029] Based on the second coverage data in the preset storage format, according to the preset coverage type, at least one of the line coverage, function coverage, branch coverage, and path coverage of each file corresponding to the source code, as well as the corresponding line-level hit and miss information are calculated.
[0030] The embodiment of this specification also provides a code coverage testing system, including:
[0031] A copying unit, adapted to copy source code to a pre-configured compiler, wherein the kernel source code of the pre-configured compiler includes service architecture compatibility configuration information, and the configuration parameters of the compiler include code coverage parameters;
[0032] A compiling unit, adapted to compile the source code using the pre-configured compiler to generate a binary executable file;
[0033] An online service startup and execution unit, adapted to start and execute the online service using the executable file;
[0034] The first coverage information generating unit is adapted to use the compiler to perform a compiling operation, and to generate first coverage information of the executed code during the running of the online service based on the service architecture compatibility configuration information contained in the kernel source code of the compiler and the pre-configured code coverage parameters of the compiler.
[0035] An embodiment of the present specification also provides a code coverage testing device, including: a memory and a processor, wherein the memory stores computer instructions that can be executed on the processor, and when the processor executes the computer instructions, the steps of the method described in any of the above embodiments are executed.
[0036] The embodiments of the present specification also provide a computer-readable storage medium on which computer instructions are stored, wherein the computer instructions, when executed, execute the steps of the method described in any of the aforementioned embodiments.
[0037] The code coverage test scheme of the embodiment of the present specification is adopted, by pre-configuring the kernel source code of the compiler to include service architecture compatibility configuration information, and configuring the configuration parameters of the compiler to include code coverage parameters, the source code is copied to the compiler for compilation, and a binary executable file is generated, and the executable file is used to start and execute the online service. Since the kernel source code of the compiler includes service architecture compatibility configuration information and the configuration parameters of the compiler include code coverage parameters, there is no need to understand the complex underlying compilation details and dependent environment, and there is no need to modify the compilation instructions one by one, and the first coverage information of the executed code can be automatically obtained, so that the code coverage information can be obtained quickly and efficiently.
[0038] Furthermore, by setting a thread monitoring code in the source code, and during the compilation process, the thread monitoring code of the source code responds to the coverage acquisition instruction to obtain the first coverage data of the code executed by the online service during the operation, thereby eliminating the need to stop the service and obtaining code coverage information in real time during the service operation.
[0039] Furthermore, by parsing the first coverage information of the source code output by the visualization page and converting it into second coverage data in a preset storage format, and based on the second coverage data in the preset storage format, second coverage information of a type corresponding to the predicted coverage can be calculated, and the second coverage information of the corresponding type can be output according to a preset display format. Through this data format conversion process and based on the converted storage format, the second coverage data can be analyzed and processed more deeply, so as to obtain more comprehensive, detailed and accurate coverage information of the source code during the service execution process, that is, the second coverage information. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] Figure 1 A flowchart of a code coverage testing method in an embodiment of this specification is shown.
[0041] Figure 2 A code example of a coverage parameter added to a GCC kernel compiler in a display interface in an embodiment of this specification is shown.
[0042] Figure 3 An example of an instrumentation code displayed on a display interface in an embodiment of this specification is shown.
[0043] Figure 4 A schematic diagram of a coverage information visualization page output during the operation of an online service is shown;
[0044] Figure 5 An example of a test report display interface in an embodiment of this specification is shown;
[0045] Figure 6 A schematic diagram of the structure of a code coverage testing system in an embodiment of this specification is shown;
[0046] Figure 7 A schematic diagram of the structure of a code coverage testing device in an embodiment of this specification is shown. DETAILED DESCRIPTION
[0047] For software systems with huge amounts of code, such as large C++ project engineering, there may be hundreds of thousands or millions of lines of code and thousands of cpp files. In order to obtain code coverage information, based on the capabilities provided by the compiler, it is necessary to manually add parameters to the compilation command. The process is cumbersome and difficult to maintain, and it is impossible to quickly obtain code coverage.
[0048] In view of this, this specification provides corresponding code coverage testing methods, systems, devices and storage media.
[0049] In order to enable those skilled in the art to better understand and implement the embodiments of this specification, the following is a detailed description with reference to the accompanying drawings and through specific application scenarios.
[0050] like Figure 1 The flowchart of the code coverage testing method shown may specifically include the following steps:
[0051] S11, copying source code to a pre-configured compiler, wherein the kernel source code of the pre-configured compiler includes service architecture compatibility configuration information, and the configuration parameters of the compiler include code coverage parameters.
[0052] In a specific implementation, the source code may be stored locally or in a remote repository such as the cloud. Accordingly, it can be copied directly from the local repository or pulled from the remote repository of the source code.
[0053] At present, compilers usually do not support automatic acquisition of code coverage. To obtain code coverage, compiler commands need to be manually modified one by one. In this way, for many large software projects, it takes a lot of time to modify them one by one, and errors or omissions are prone to occur. As the code changes, the compilation command configuration needs to be modified one by one again, which is very cumbersome and complicated, and difficult to maintain. To avoid this problem, in the embodiments of this specification, service architecture compatibility configuration information can be configured in the kernel source code of the compiler, and the configuration parameters of the compiler can be configured including code coverage parameters.
[0054] In order to obtain code coverage information quickly and efficiently, service architecture compatibility configuration information can be configured in the kernel code of the compiler, which can be implemented through corresponding codes. Figure 2 As shown, in the display interface 20, a code example of adding coverage parameters in the GCC kernel compiler is shown. The kernel code in the GCC compiler can be compiled in assembly language. In a specific implementation, by configuring *asm, *asm_debug, etc. in the kernel code of the GCC kernel compiler, Figure 2 The configuration parameter examples shown can achieve code coverage information acquisition in the corresponding working modes, including normal compilation (asm) mode and debug (debug) mode, and by setting the *asm_final parameter, the created separate object file containing DWARF debug information can be output to the preset compilation result directory, such as gcda. In addition, for the GCC compiler, code coverage configuration parameters can be added. In some optional examples of this manual, code coverage configuration parameters are added: –fprofile-arcs and –ftest-coverage.
[0055] In order to achieve the coverage of the executed code during the service operation, as an optional example, compilation and instrumentation can be performed in advance, and thread monitoring code can be set in the source code. The code coverage tester can select some locations in the source code and set the thread monitoring code, such as Figure 3 In the example of the plug-in code shown in the display interface 30, if the plug-in code shown in the display interface 30 is inserted into the source code, when the source code receives a signal with a signal code of 36, the acquisition of code coverage can be triggered.
[0056] In a specific implementation, any compilation tool such as GCC compiler, Blade, makefile, SCons, etc. can be used for compilation.
[0057] S12, using the compiler to compile the source code to generate a binary executable file.
[0058] In a specific implementation, the source code is compiled using the compiler configured as above to generate a binary executable file with the file suffix ".bin".
[0059] S13, using the executable file to start and execute the online service.
[0060] In a specific implementation, the executable file may be copied to a target path, the online service may be started, and the test case may be run to execute the online service.
[0061] For example, when running a test case, one or more tests such as smoke test, online environment stress test, performance test, etc. can be performed. Other types of tests can also be performed through corresponding test cases as needed.
[0062] S14, using the compiler to perform a compiling operation, and generating first coverage information of the online service based on the service architecture compatibility configuration information included in the kernel source code of the compiler and the pre-configured code coverage parameters of the compiler.
[0063] During the compilation process, on the one hand, based on the service architecture compatibility configuration information contained in the kernel source code of the compiler and the pre-configured code coverage parameters of the compiler, a code coverage map can be generated to a preset first compilation result directory, and the code coverage map is suitable for reorganizing the executable file; on the other hand, in response to a coverage acquisition instruction, the thread listening code set in the source code is triggered to obtain the second coverage data corresponding to the coverage acquisition instruction during the operation of the online service, and output it to a preset second compilation result directory; thereafter, based on the code coverage map obtained from the first compilation result directory and the second coverage data obtained from the second compilation result directory, a code coverage report file can be generated, and the code coverage report file includes the first coverage information of the online service.
[0064] As a specific example implemented in the GCC compiler, due to the service architecture compatible configuration information contained in the kernel source code of the compiler and the pre-configured code coverage parameters of the compiler, a binary executable file generated after adding the two configuration parameters "-fprofile-arcs" and "-ftest-coverage" can be obtained during compilation and linking. The -fprofile-arcs-ftest-coverage option is added when compiling with GCC, and is also added when linking.
[0065] The fprofile-arcs option causes GCC to create a profile of the program's code and then find a spanning tree that fits the profile. Only arcs that are not in the spanning tree are instrumented: GCC adds code to count the number of times these arcs are executed. When this arc is the only exit or entry to a block, instrumentation code is added to the block, otherwise a basic block is created to contain the instrumentation code.
[0066] In a specific implementation, gcov (a coverage statistics tool for code running, released with GCC) can be used to obtain two files with suffixes ".gcno" and ".gcna". Among them, the file with the suffix ".gcno" is generated by -ftest-coverage, where the code coverage map is suitable for reorganizing the executable file, and can contain information on the line numbers of the source code of the reconstructed basic block map and the corresponding blocks; the file with the suffix ".gcda" is generated by the running of the compiled file with the GCC compiler adding the compilation configuration parameter "-fprofile-arcs", which can include the number of arc jumps and other summary information.
[0067] For example, if the sudo kill-36pid command is received during the service execution, it means that the signal number 36 is received to terminate the process. Figure 3 The instrumentation code shown here, therefore, triggers Figure 3 The instrumented code shown obtains the coverage data of the executed code during the service operation process. For the convenience of description and to distinguish it from the coverage data described in the subsequent embodiments, it is referred to as "first coverage data" here. Among them, the instrumented code will create a .gcda file corresponding to the source file when it is executed. The .gcda file will record the operation data of the source code.
[0068] Based on the first coverage data of the executed code obtained by the thread monitoring code, the first coverage information of the executed code during the operation of the online service can be generated. In a specific implementation, Icov can be used to generate info data. As a specific example, the command "lcov xxx.info-d" can be executed to obtain the first coverage data under the ".gcno" and ".gcda" folders. For example, if the pre-set coverage type includes line coverage and function coverage, the line coverage and function coverage information of the online service can be given in the code coverage report file. It can also include the specific coverage of the online service, the number of hit code lines, and the number of covered code lines. Among them, functional coverage is also called function coverage.
[0069] By adopting the above embodiment, by setting the service architecture compatibility configuration information in the kernel source code of the compiler, and setting the configuration parameters of the compiler including the code coverage parameters, it is possible to automatically obtain the code coverage data without having to understand the complex underlying compilation details and dependent environment, and without having to modify the compilation instructions one by one, so that the code coverage information can be output quickly and efficiently.
[0070] In a specific implementation, a visualization page may be used to output the first coverage information of the online service. In some embodiments of the present specification, the GCOV graphical front-end tool LCOV may be used to output based on HyperText Markup Language (HTML) and generate a complete HTML tree. The specific output may include an overview, coverage percentage, icons, etc., so that the coverage information can be quickly browsed. Figure 4 The following is a schematic diagram of a visualization page of coverage information output during the operation of an online service. The genhtml tool provided by Icov is used to generate an HTML document based on the information file (.info), that is, to generate a web page result report. The coverage information can be browsed in a web page format, such as Figure 4 As shown, it includes line coverage and function coverage information. Figure 4 In addition to the file view shown, the first coverage information can also be output in other view modes such as directory view, source code view, etc. In addition, in a specific implementation, in order to distinguish each specific data, it can be highlighted by different colors, textures, etc.
[0071] In specific implementation, the inventor has found through research that the first coverage information displayed in the form of an HTML webpage is convenient for users to view, but it is not convenient for data comparison. To this end, in some embodiments of this specification, the first coverage information of the source code output by the visualization page is first parsed and converted into second coverage data stored in a preset format; based on the second coverage data in the preset storage format, the second coverage information of the type corresponding to the preset coverage is calculated; then, the corresponding second coverage information can be output according to the preset display format.
[0072] For example, the first coverage information output in the form of an HTML webpage can be parsed and converted into a JSON format, and then, based on the second coverage data in the JSON format, the second coverage information of a type corresponding to the preset coverage can be calculated. Specifically, based on the second coverage data in the preset storage format, according to the preset coverage type, at least one of the line coverage, function coverage, branch coverage, and path coverage of each file corresponding to the source code is calculated, as well as information such as the number of hits and misses at the corresponding line level.
[0073] Code coverage refers to the percentage of items that have been executed at least once to the total number of items. For different types of code coverage, if the "number of items" is a statement, the corresponding one is code line coverage; if the "number of items" is a function, the corresponding one is function coverage; if the "number of items" is a path, the corresponding one is path coverage.
[0074] In some embodiments of this specification, the second coverage information may include more detailed coverage information, including some comparison information, such as Figure 5 As shown in the example of the incremental code test report display, in the test report display interface 50, for the code branch master, a global test data display area 51 corresponding to the incremental code detailed information, a functional test information display area 52 corresponding to the functional test details, and a functional A / B test information display area 53 corresponding to the recommended traffic comparison details are respectively provided, wherein the functional test information display area 52 shows that the number of online service precise use cases is 46, the total number of functional module test cases is 82, and by clicking on the details corresponding to the "Functional Test Report" column, more refined test information can be obtained. The functional A / B test information display area 53 shows the number of covered code lines, the incremental functional code coverage, the recommended traffic quantity, and the functional A / B test report, wherein the precise recommended traffic quantity obtained by statistics is shown to be 273, and by clicking on the details corresponding to the functional A / B test report information, more refined functional A / B test report information can be further obtained.
[0075] It can be seen from the above example that by parsing the first coverage information of the source code output by the visualization page and converting it into second coverage data in a preset storage format, and based on the second coverage data in the preset storage format, the second coverage information of the corresponding type to the predicted coverage can be calculated, and the second coverage information of the corresponding type can be output according to the preset display format. Through this data format conversion process, and based on the converted storage format, the second coverage data can be analyzed and processed more deeply, so as to obtain more comprehensive, detailed and accurate coverage information of the source code during the service execution process, that is, the second coverage information.
[0076] Reference Figure 6 In some embodiments of the present specification, the code coverage testing system 60 may include: a copying unit 61, a compiling unit 62, an online service startup and construction unit 63, and a first coverage information generating unit 64, such as Figure 6 As shown, where:
[0077] The copying unit 61 is adapted to copy source code to a pre-configured compiler, wherein the kernel source code of the pre-configured compiler includes service architecture compatibility configuration information, and the configuration parameters of the compiler include code coverage parameters;
[0078] The compiling unit 62 is adapted to compile the source code using the pre-configured compiler to generate a binary executable file;
[0079] The online service starting and executing unit 63 is adapted to start and execute the online service using the executable file;
[0080] The first coverage information generating unit 64 is suitable for using the compiler to perform compilation operations, and based on the service architecture compatibility configuration information contained in the kernel source code of the compiler and the pre-configured code coverage parameters of the compiler, generates the first coverage information of the executed code during the operation of the online service.
[0081] In a specific implementation, the code coverage test system used in the embodiments of this specification can be obtained by using existing general code coverage test software to configure the kernel code and configuration information in the manner of the embodiments of this specification, or it can be a completely new code coverage test system that is newly developed and designed. The code coverage test system can be run and implemented on a dedicated or general-purpose computer.
[0082] In the specific implementation, Figure 6 As shown, the code coverage testing system 60 may also include an insertion unit 65, which is suitable for setting a thread listening code in the source code; accordingly, the first coverage information generating unit 64 is suitable for generating the first coverage information of the executed code during the operation of the online service based on the first coverage data of the executed code during the operation of the online service obtained by the thread listening code in response to the coverage acquisition instruction.
[0083] In a specific implementation, the online service starting and executing unit 63 is adapted to copy the executable file to a target path, start the online service, run the test case, and execute the online service.
[0084] In some embodiments of this specification, continue to refer to Figure 6 , the first coverage information generating unit 64 may include: a code coverage graph generating subunit 641, a second coverage data acquiring subunit 642 and a code coverage report file generating subunit 643, wherein:
[0085] The code coverage graph generating subunit 641 is adapted to generate a code coverage graph to a preset first compilation result directory based on the service architecture compatibility configuration information contained in the kernel source code of the compiler and the pre-configured code coverage parameters of the compiler during the compilation process, wherein the code coverage graph is adapted to reorganize the executable file;
[0086] The first coverage data acquisition subunit 642 is adapted to, in the compilation process, in response to a coverage acquisition instruction, trigger a thread listening code set in the source code to acquire second coverage data corresponding to the coverage acquisition instruction during the running of the online service, and output the second coverage data to a preset second compilation result directory;
[0087] The code coverage report file generation subunit 643 is suitable for generating a code coverage report file based on the code coverage graph obtained from the first compilation result directory and the second coverage data obtained from the second compilation result directory, and the code coverage report file includes the first coverage information.
[0088] In a specific implementation, the code coverage report file generation subunit 643 is suitable for generating the code coverage report file for the external service according to a preset coverage type, based on the code coverage graph obtained from the first compilation result directory and the first coverage data obtained from the second compilation result directory.
[0089] Continue to refer to Figure 6 In a specific implementation, the code coverage testing system 60 may further include: a first output unit 66, adapted to output the first coverage information of the online service using a visualization page.
[0090] In order to obtain more comprehensive, detailed and accurate coverage information of the source code during the service execution process, that is, the second coverage information, such as Figure 6 As shown, the code coverage testing system 60 may further include: a parsing unit 67, a second coverage information acquiring unit 68 and a second output unit 69, wherein:
[0091] The parsing unit 67 parses the first coverage information of the source code output by the visualization page and converts it into second coverage data in a preset storage format;
[0092] The second coverage information acquiring unit 68 calculates and obtains the second coverage information of a type corresponding to the preset coverage based on the second coverage data in the preset storage format;
[0093] The second output unit 69 outputs the second coverage information of the corresponding type according to a preset display format.
[0094] As an optional example, the embodiments of this specification can be applied to the coverage acquisition of C++ code, and can also be applied to the code coverage of other types of programming languages, such as C language code and Java language code.
[0095] The embodiment of this specification also provides a code coverage testing device, such as Figure 7 As shown, the code coverage testing device 70 may include: a memory 71 and a processor 72, wherein the memory 71 stores computer instructions that can be executed on the processor 72, and the processor 72 executes the steps of the method described in any of the aforementioned embodiments when executing the computer instructions. For details, please refer to the aforementioned embodiments and will not be repeated here.
[0096] In the specific implementation, continue to refer to Figure 7 The code coverage testing device 70 may further include a communication component 73, which is suitable for obtaining source code, for example, obtaining the source code for code coverage testing from a remote server via a network or from other storage devices via a USB interface, a Bluetooth interface or other transmission interfaces.
[0097] In the specific implementation, Figure 7 As shown, the code coverage test device 70 may further include a display component, which is suitable for displaying code coverage test information, including test information of different forms and granularities such as the first coverage test information and the second coverage test information in the aforementioned embodiment.
[0098] In some embodiments of the present specification, the memory, processor, communication component, and display component may communicate with each other via a bus network.
[0099] In the specific implementation, Figure 7 As shown, the communication component 73 and the display component 74 etc. may be components disposed inside the electronic device 70, or may be external devices connected via expansion components such as an expansion interface, an expansion dock, and an expansion cable.
[0100] In a specific implementation, the code coverage test equipment can be implemented through various types of computer devices such as desktop computers and cloud servers.
[0101] The embodiments of the present specification also provide a computer-readable storage medium on which computer instructions are stored. When the computer instructions are executed, the steps of the method described in any of the above embodiments are executed. For details, please refer to the above embodiments and will not be repeated here.
[0102] In a specific implementation, the computer-readable storage medium may be any appropriate readable storage medium such as an optical disk, a mechanical hard disk, a solid-state hard disk, etc.
[0103] Although the embodiments of this specification are disclosed as above, the present invention is not limited thereto. Any person skilled in the art can make various changes and modifications without departing from the spirit and scope of the embodiments of this specification, so the protection scope of the present invention shall be subject to the scope defined by the claims.
Claims
1. A code coverage testing method, wherein: include: Copying source code to a pre-configured compiler, wherein the kernel source code of the pre-configured compiler includes service architecture compatibility configuration information, and the configuration parameters of the compiler include code coverage parameters; Compiling the source code using the compiler to generate a binary executable file; Using the executable file, starting and executing the online service; During the compilation process, first coverage information of the executed code during the running of the online service is generated based on the service architecture compatibility configuration information included in the kernel source code of the compiler and the pre-configured code coverage parameters of the compiler.
2. The method according to claim 1, wherein: The compiling operation using the compiler to generate first coverage information of the executed code during the running of the online service based on the service architecture compatibility configuration information contained in the kernel source code of the compiler and the pre-configured code coverage parameters of the compiler includes: During the compilation process, in response to a coverage acquisition instruction, the thread monitoring code set in the source code acquires first coverage data of the executed code during the running of the online service; Based on the first coverage data of the executed code acquired by the thread monitoring code, first coverage information of the executed code during the running of the online service is generated.
3. The method according to claim 2, wherein: The adopting the executable file to start and execute the online service includes: Copy the executable file to the target path and start the online service; Run the test case to execute the online service.
4. The method according to claim 3, wherein during the compiling process, based on the service architecture compatibility configuration information included in the kernel source code of the compiler and the pre-configured code coverage parameters of the compiler, generating first coverage information of the executed code during the running of the online service comprises: During the compilation process, based on the service architecture compatibility configuration information contained in the kernel source code of the compiler and the pre-configured code coverage parameters of the compiler, a code coverage map is generated to a preset first compilation result directory, wherein the code coverage map is suitable for reorganizing the executable file; During the compilation process, in response to a coverage acquisition instruction, a thread listening code set in the source code is triggered to acquire second coverage data corresponding to the coverage acquisition instruction during the running of the online service, and output the second coverage data to a preset second compilation result directory; A code coverage report file is generated based on the code coverage graph obtained from the first compilation result directory and the second coverage data obtained from the second compilation result directory, wherein the code coverage report file includes the first coverage information.
5. The method according to claim 4, wherein: The generating a code coverage report file for the online service based on the code coverage graph obtained from the first compilation result directory and the second coverage data obtained from the second compilation result directory includes: According to a preset coverage type, a code coverage report file of the online service is generated based on the code coverage graph obtained from the first compilation result directory and the second coverage data obtained from the second compilation result directory.
6. The method according to any one of claims 1 to 5, wherein: Also includes: The first coverage information of the online service is outputted using a visualization page.
7. The method according to claim 6, further comprising: Parsing the first coverage information of the source code output by the visualization page and converting it into second coverage data in a preset storage format; Based on the second coverage data in the preset storage format, second coverage information of a type corresponding to the preset coverage is calculated; The second coverage information of the corresponding type is output according to a preset display format.
8. The method according to claim 7, wherein: The calculating of the second coverage rate data based on the preset storage format to obtain the second coverage rate information of a type corresponding to the preset coverage rate includes: Based on the second coverage data in the preset storage format, according to the preset coverage type, at least one of the line coverage, function coverage, branch coverage, and path coverage of each file corresponding to the source code, as well as the corresponding line-level hit and miss information are calculated.
9. A code coverage testing system, wherein: include: A copying unit, adapted to copy source code to a pre-configured compiler, wherein the kernel source code of the pre-configured compiler includes service architecture compatibility configuration information, and the configuration parameters of the compiler include code coverage parameters; A compiling unit, adapted to compile the source code using the pre-configured compiler to generate a binary executable file; An online service startup and execution unit, adapted to start and execute the online service using the executable file; The first coverage information generating unit is adapted to use the compiler to perform a compiling operation, and to generate first coverage information of the executed code during the running of the online service based on the service architecture compatibility configuration information contained in the kernel source code of the compiler and the pre-configured code coverage parameters of the compiler.
10. A code coverage testing device, comprising: A memory and a processor, wherein the memory stores computer instructions that can be executed on the processor, wherein the processor executes the steps of the method according to any one of claims 1 to 8 when executing the computer instructions.
11. A computer-readable storage medium having computer instructions stored thereon, wherein: When the computer instructions are executed, the steps of the method according to any one of claims 1 to 8 are executed.
Citation Information
Patent Citations
Test analysis system and method based on embedded software
CN102222041A
Coverage rate testing method and system
CN103699476A
Software defect positioning technology on-line evaluating and experimenting platform and method based on coverage
CN104239219A
Performance test evaluation method and device, computer equipment and readable storage medium
CN111045927A
System and method for automatically testing software unit
CN1983209A
