Code coverage test method and device, storage medium and electronic equipment
Patent Information
- Application Number
- CN202110379033.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-04-08
- Publication Date
- 2026-10-23
- Estimated Expiration
- 2041-04-08
AI Technical Summary
但是,此种方式生成覆盖率报告,强依赖于原生工具的环境和完整源码文件的获取
[0018]通过上述技术方案,可以不依赖原生工具对覆盖数据文件进行解析,因此可以响应于接收到覆盖数据文件则解析覆盖数据文件,实现上传文件即解析,相较于依赖原生工具的方式,可以省去文件聚合的步骤,从而减少代码覆盖率测试过程中的时延。并且,可以根据文件覆盖信息与从代码项目仓库获取到的修改文件信息,筛选出增量文件覆盖信息,从而根据该增量文件覆盖信息确定行覆盖率,省去了全量覆盖率的生成,无需加载完整源码文件,不仅可以进一步减少时延,而且可以减少内存消耗。
Smart Images

Figure CN115203004B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present disclosure relates to the technical field of testing, in particular, to a code coverage test method and device, a storage medium and an electronic device. BACKGROUND
[0002] Code coverage is an important embodiment of the degree of code coverage in testing, which can count the execution of the code after the mobile device is run. In related technologies, the test of code coverage mainly relies on open source tools, aggregates multiple coverage data files, parses the aggregated files, loads complete source code files, generates full coverage by combining the parsed aggregated files and complete source code files, and finally obtains incremental coverage by parsing and mapping. However, this way of generating coverage reports is strongly dependent on the environment of the original tool and the acquisition of complete source code files. Moreover, due to the limitation of the original tool, after uploading the coverage data file, the step of aggregating data must be performed first, and then the aggregated files are parsed, which is weak in real-time performance. When the concurrency is high, the calculation needs to load all source files and data files, which consumes a lot of memory. SUMMARY
[0003] This summary is provided to introduce a selection of concepts that are further described below in the detailed description. This summary is not intended to identify key or essential features of the claimed subject matter, nor is it intended to be used to limit the scope of the claimed subject matter.
[0004] In a first aspect, the present disclosure provides a code coverage test method, comprising:
[0005] In response to receiving a coverage data file, parsing the coverage data file to obtain function coverage information corresponding to the coverage data file, the function coverage information comprising a function name and a coverage number corresponding to the function;
[0006] According to the function coverage information and a first function-file mapping relationship, determining file coverage information corresponding to the function coverage information, the first function-file mapping relationship being used to represent the corresponding relationship between functions in the source code file and function files in the instrumentation product corresponding to the source code file;
[0007] Obtaining modification file information of the source code file compared with a historical source code file from a code project repository, and determining target file coverage information in the file coverage information according to the modification file information;
[0008] Determining function entity information corresponding to the target file coverage information, and determining line coverage of the coverage data file according to the coverage number and the function entity information.
[0009] Secondly, this disclosure provides a code coverage testing apparatus, the apparatus comprising:
[0010] The parsing module is used to parse the overlay data file in response to receiving the overlay data file, and obtain the function overlay information corresponding to the overlay data file. The function overlay information includes the function name and the number of times the function is overlaid.
[0011] The first determining module is used to determine the file coverage information corresponding to the function coverage information based on the function coverage information and the first function file mapping relationship. The first function file mapping relationship is used to characterize the correspondence between functions and function files in the instrumentation product corresponding to the source code file.
[0012] The second determining module is used to obtain the modified file information of the source code file compared with the historical source code file from the code project repository, and determine the target file overwrite information in the file overwrite information based on the modified file information;
[0013] The third determining module is used to determine the function entity information corresponding to the target file coverage information, and to determine the line coverage rate of the covered data file based on the coverage count and the function entity information.
[0014] Thirdly, this disclosure provides a computer-readable medium having a computer program stored thereon, which, when executed by a processing device, implements the steps of the method described in the first aspect.
[0015] Fourthly, this disclosure provides an electronic device, comprising:
[0016] A storage device on which computer programs are stored;
[0017] A processing device for executing the computer program in the storage device to implement the steps of the method in the first aspect.
[0018] The above technical solution allows for parsing of coverage data files without relying on native tools. Therefore, it can parse coverage data files upon receipt, enabling parsing upon file upload. Compared to methods relying on native tools, this eliminates the file aggregation step, thus reducing latency during code coverage testing. Furthermore, incremental file coverage information can be filtered based on file coverage information and modified file information obtained from the code project repository. Line coverage can then be determined based on this incremental file coverage information, eliminating the need to generate full coverage data and load the complete source code files. This further reduces latency and memory consumption.
[0019] Other features and advantages of this disclosure will be described in detail in the following detailed description section. Attached Figure Description
[0020] The above and other features, advantages, and aspects of the embodiments of this disclosure will become more apparent from the accompanying drawings and the following detailed description. Throughout the drawings, the same or similar reference numerals denote the same or similar elements. It should be understood that the drawings are schematic, and the originals and elements are not necessarily drawn to scale. In the drawings:
[0021] Figure 1 This is a schematic diagram illustrating the process of code coverage testing methods in related technologies;
[0022] Figure 2 This is a flowchart illustrating a code coverage testing method according to an exemplary embodiment of the present disclosure;
[0023] Figure 3 This is a schematic diagram illustrating the process of parsing instrumentation artifacts to obtain function file mapping relationships in a code coverage testing method according to an exemplary embodiment of this disclosure;
[0024] Figure 4 This is a schematic diagram illustrating the function file mapping relationship obtained in a code coverage testing method according to an exemplary embodiment of the present disclosure;
[0025] Figure 5 This is a schematic diagram illustrating the process of determining the line coverage of a coverage data file based on the function file mapping relationship in a code coverage testing method according to an exemplary embodiment of this disclosure;
[0026] Figure 6 This is a schematic diagram illustrating a code coverage testing method according to another exemplary embodiment of the present disclosure;
[0027] Figure 7 This is a block diagram illustrating a code coverage testing apparatus according to an exemplary embodiment of the present disclosure;
[0028] Figure 8 This is a block diagram illustrating an electronic device according to an exemplary embodiment of the present disclosure. Detailed Implementation
[0029] Embodiments of this disclosure will now be described in more detail with reference to the accompanying drawings. While some embodiments of this disclosure are shown in the drawings, it should be understood that this disclosure can be implemented in various forms and should not be construed as limited to the embodiments set forth herein. Rather, these embodiments are provided to provide a more thorough and complete understanding of this disclosure. It should be understood that the accompanying drawings and embodiments of this disclosure are for illustrative purposes only and are not intended to limit the scope of protection of this disclosure.
[0030] It should be understood that the steps described in the method embodiments of this disclosure may be performed in different orders and / or in parallel. Furthermore, the method embodiments may include additional steps and / or omit the steps shown. The scope of this disclosure is not limited in this respect.
[0031] The term "comprising" and its variations as used herein are open-ended inclusions, meaning "including but not limited to". The term "based on" means "at least partially based on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". Definitions of other terms will be given in the description below.
[0032] It should be noted that the concepts of "first" and "second" mentioned in this disclosure are used only to distinguish different devices, modules, or units, and are not used to limit the order of functions performed by these devices, modules, or units or their interdependencies. It should also be noted that the modifiers "a" and "a plurality of" mentioned in this disclosure are illustrative rather than restrictive, and those skilled in the art should understand that, unless explicitly stated otherwise in the context, they should be understood as "one or more".
[0033] The names of messages or information exchanged between multiple devices in the embodiments of this disclosure are for illustrative purposes only and are not intended to limit the scope of such messages or information.
[0034] Code coverage is an important indicator of how well tests cover the code; it allows you to analyze code execution after the test has finished running on a mobile device. (Refer to...) Figure 1 In related technologies, code coverage testing primarily relies on open-source tools. This involves aggregating multiple coverage data files uploaded from the client, parsing the aggregated files, loading the complete source code files, combining the parsed aggregated files and the complete source code files to generate full coverage, and finally performing parsing mapping to obtain incremental coverage. However, this method of generating coverage reports is heavily dependent on the environment of native tools and the availability of complete source code files. Furthermore, due to the limitations of native tools, after uploading the coverage data files, the data aggregation step must be performed first, followed by parsing the aggregated files, resulting in poor real-time performance. Under high concurrency, the calculation requires loading all source and data files, leading to significant memory consumption.
[0035] In view of this, the present disclosure provides a code coverage testing method, apparatus, storage medium, and electronic device to reduce latency and memory consumption during the code coverage testing process.
[0036] Figure 2 This is a flowchart of a code coverage testing method according to an embodiment of this disclosure. (Refer to...) Figure 2The code coverage testing method includes:
[0037] Step 201: In response to receiving the overlay data file, parse the overlay data file to obtain the function overlay information corresponding to the overlay data file. This function overlay information includes the function name and the number of times the function is overlaid.
[0038] For example, the coverage data file is generated by the client in response to user operations and can characterize the code coverage of the user operations. The client can upload the coverage data file generated for each user operation to the code coverage testing device. The client can be an electronic device with an iOS mobile operating system installed. The code coverage testing device can be a server device, which is not limited in this embodiment. The code coverage testing device can parse the coverage data file upon receiving it to obtain the function coverage information corresponding to the coverage data file. The function coverage information includes the function name and coverage count of the function in the coverage data file. The coverage count characterizes the number of times each line of code in the function is executed. It should be understood that the function coverage information obtained by parsing the coverage data file is a rough representation of code coverage; further steps are required to obtain more refined code coverage data.
[0039] Step 202: Based on the function coverage information and the first function file mapping relationship, determine the file coverage information corresponding to the function coverage information. This first function file mapping relationship is used to characterize the correspondence between functions and function files in the instrumentation artifacts corresponding to the source code files.
[0040] For example, multiple functions can form a function file. In practical applications, the number of functions is large, while the number of function files is relatively small. Therefore, in this embodiment of the disclosure, the file coverage information corresponding to the function coverage information is determined based on the mapping relationship between function coverage information and the first function file, thus transforming the processing dimension from the function dimension to the file dimension, thereby improving the processing efficiency of subsequent processes.
[0041] Step 203: Obtain the modified file information of the source code file compared with the historical source code file from the code project repository, and determine the target file overwrite information in the file overwrite information based on the modified file information.
[0042] For example, the code project repository could be GitLab, etc., but this embodiment of the disclosure is not limited to this. The code project repository can record the code version information of each commit made by the developer. Therefore, the modification information of the latest source code file compared with the historical source code file can be obtained from the code project repository, that is, the source code file information modified in this version can be obtained. Based on the modification file information, the target file coverage information related to the modified function information can be filtered out from the file coverage information, and then the function entity information corresponding to the incremental code can be loaded to achieve coverage detection.
[0043] Step 204: Determine the function entity information corresponding to the target file coverage information, and determine the line coverage rate of the covered data file based on the number of coverages and the function entity information.
[0044] For example, coverage counts can represent the number of times each line of code in a function is executed, and can be represented by a coverage count array. For instance, if the coverage count array for the first function is [2, 5, 3], it means that the first line of code in the first function is executed 2 times, the second line is executed 5 times, and the third line is executed 3 times. Function entity information is used to represent the function name, the starting position of the function code block, etc., for each function file in the target file coverage information. Using LLVM (Low-Level Virtual Machine) tools, the line coverage rate of the covered data file can be determined based on the coverage counts and the corresponding function entity information.
[0045] The above method allows for parsing of coverage data files without relying on native tools. Therefore, it can parse coverage data files upon receipt, achieving file upload and parsing simultaneously. Compared to methods relying on native tools, this eliminates the file aggregation step, thus reducing latency during code coverage testing. Furthermore, incremental file coverage information can be filtered based on file coverage information and modified file information obtained from the code project repository. Line coverage can then be determined based on this incremental file coverage information, eliminating the need to generate full coverage data and load the complete source code files. This further reduces latency and memory consumption.
[0046] To enable those skilled in the art to better understand the code coverage testing method provided in this disclosure, the steps described above are illustrated in detail below.
[0047] In one possible way, the function file mapping relationship can be obtained as follows: parse the instrumentation artifacts corresponding to the source code file to obtain the function names and function attribute information of all functions in the source code file. The function attribute information includes function code block information. Parse the function code block information to obtain the function file information to which each function belongs in the source code file and the position information of the code block corresponding to each function in the function file. Based on the function name of each function in the source code file, the function file information to which each function belongs, and the position information of the code block corresponding to each function in the function file, establish the function file mapping relationship.
[0048] It should be understood that program instrumentation involves inserting probes (also known as "detectors," which are essentially code segments that collect information, such as assignment statements or function calls for collecting coverage information) into the program while ensuring the original logical integrity of the program under test. The execution of these probes generates characteristic data about the program's operation. Analysis of this data allows for the acquisition of control flow and data flow information, thereby obtaining dynamic information such as logical coverage. In this embodiment, the instrumentation product can be the result of compiling the source code file after instrumentation. When the source code file is modified, the instrumentation product changes accordingly.
[0049] For example, after the packaging platform packages the binary instrumentation artifact, it can parse the artifact when the first coverage data file is uploaded to obtain the function file mapping relationship. Therefore, without modifying the source code file, a single parsing is sufficient to use the function file mapping relationship for code coverage testing at any time in subsequent processes, reducing the dependence of code coverage testing on the source code file.
[0050] For example, refer to Figure 3 By parsing the instrumentation artifacts corresponding to the source code file, we can obtain the function names and attribute information of all functions in the source code file. The function name can be used to calculate and store its hash value for later processing. The function attribute information can be used to parse function code block information, function associated file information, and the file index of the function's parent file. Then, the function code block information can be parsed to obtain the parent file information and the starting position of the function's code block within that file. Thus, we can obtain the function file information for each function, including the function name, the parent file information, and the position of the corresponding code block within that file. Finally, based on the function file information for each function, a function file mapping relationship can be established.
[0051] For example, refer to Figure 4Based on the function file information, a first function file mapping relationship and a second function file mapping relationship can be established. The first function file mapping relationship represents the correspondence between functions and function files, while the second function file mapping relationship represents the correspondence between function files and function entity information. In practical applications, the first function file mapping relationship can be stored in the cloud for subsequent parsing, while the second function file mapping relationship can be stored in a database to facilitate the rapid retrieval of function entity information corresponding to file overlay information during subsequent processes.
[0052] It should be understood that parsing the instrumentation artifacts corresponding to source code files can refer to parsing the instrumentation artifacts corresponding to the latest source code files in the current version. The resulting function file mapping relationships can be used to generate full coverage and incremental coverage, meeting the needs of different application scenarios. Alternatively, the file information modified in this version can be obtained from the code project repository first, and then the instrumentation artifacts corresponding to the file information related to this version modification can be parsed. This can reduce the storage size of the function file mapping relationships.
[0053] In one possible approach, parsing the overlay data file to obtain the function overlay information corresponding to the overlay data file could be: parsing the overlay data file to obtain the function information of all functions in the overlay data file, and filtering out function information not included in the first function file mapping relationship from the function information to obtain the function overlay information corresponding to the overlay data file.
[0054] In related technologies, parsing aggregated coverage data files requires first reading the header information of each coverage data file, then obtaining the file version based on the header information, and finally applying different parsing logic to different file versions. In this embodiment, the header information of the coverage data file can also be read first, and the version of the coverage data file can be obtained based on the header information before processing different versions of the coverage data file. Specifically, for different versions of the coverage data file, the function information of all functions in the coverage data file can be parsed first, and then function information not included in the first function file mapping relationship can be filtered out. Then, for the filtered function information, the corresponding function coverage count array can be read based on the function name corresponding to the function information, thereby obtaining function coverage information including the function name and the function coverage count array.
[0055] It should be understood that during testing, the code covered by user operations may include functions that are not present in the source code instrumentation artifacts. The methods described above can filter out these invalid functions, improving parsing efficiency and thus increasing the efficiency of coverage detection. Furthermore, the code covered by user operations may also include code unrelated to the current version's changes. Therefore, to achieve incremental code coverage testing, filtering can be performed at the file level based on the first function file mapping relationship, further improving processing efficiency and reducing latency and memory consumption during code coverage testing.
[0056] For example, we can first determine the file coverage information corresponding to the function coverage information based on the mapping relationship between the function coverage information and the first function file. Then, based on the modified file information of the latest source code file obtained from the code project repository compared to the historical source code files, we can determine the target file coverage information from the file coverage information. This allows us to filter out file coverage information irrelevant to the current modifications. Afterwards, we can determine the function entity information corresponding to the target file coverage information, and thus perform incremental code coverage testing based on this function entity information.
[0057] In one possible approach, determining the function entity information corresponding to the target file coverage information can be done by: reading the function entity information corresponding to the target file coverage information from the database based on the second function file mapping relationship, whereby the second function file mapping relationship is used to characterize the correspondence between function files and function entity information in the instrumentation artifacts corresponding to the source code file.
[0058] For example, the second function file mapping relationship is generated and stored in the database by parsing the instrumentation artifacts when overlay data is uploaded for the first time. Therefore, after the initial overlay data upload, the function entity information corresponding to the target file overlay information can be read from the database according to the second function file mapping relationship. Subsequently, the function entity information corresponding to the target file overlay information read from the database can be stored in a local cache to speed up the parsing of subsequent uploaded data files.
[0059] In another possible approach, determining the function entity information corresponding to the target file coverage information can also be done by: first reading the function entity information corresponding to the target file coverage information from the local cache; if reading the function entity information corresponding to the target file coverage information from the local cache fails, then reading the function entity information corresponding to the target file coverage information from the database according to the second function file mapping relationship. The second function file mapping relationship is used to characterize the correspondence between function files and function entity information in the instrumentation artifacts corresponding to the source code file, and the database stores the function entity information corresponding to each function file in the second function file mapping relationship.
[0060] Each time overwrite data is uploaded subsequently, the function entity information corresponding to the target file's overwrite information can be read from the local cache first. If reading the function entity information from the local cache fails, the function entity information corresponding to the target file's overwrite information is read from the database according to the second function file mapping relationship. Therefore, prioritizing reading function entity information from the local cache improves processing efficiency. Furthermore, searching for function entity information on a file-by-file basis using the second function file mapping relationship is more efficient than searching on a function-by-function basis, reducing database access pressure.
[0061] For example, refer to Figure 5 The system receives multiple coverage data files. Function coverage information includes function names and coverage count arrays (e.g., the coverage count array for functionName1 is [1, 1, 0]). File coverage information is obtained by mapping the function coverage information for each coverage data file to the first function file. Then, based on this file coverage information and modified file information obtained from the code project repository, the target file coverage information is determined. If reading the function entity information corresponding to the target file coverage information from the local cache fails, the function entity information is read from the database according to the second function file mapping relationship. Finally, the line coverage rate of each coverage data file can be obtained by combining the function entity information and the function coverage information.
[0062] In one possible approach, function coverage information includes multiple coverage count arrays, each containing function identifier information. Each element in each coverage count array represents the number of times each line of code in the corresponding function is executed. Therefore, for each function in the function coverage information, the following processing can be performed: determine the function entity information corresponding to the function, and based on the function identifier information, determine the corresponding coverage count array from the multiple coverage count arrays; determine the line coverage information based on the corresponding function entity information and the coverage count arrays. Then, aggregate the line coverage information for each function to obtain the line coverage rate of the covered data file.
[0063] For example, coverage counts can be represented by coverage count arrays. Since user operations may cover multiple functions, parsing the coverage data file may result in multiple coverage count arrays, each with a corresponding function identifier. This function identifier can be used to associate a function with its corresponding coverage count array, allowing the function's coverage count array to be determined later. Function entity information can be used to characterize the start and end positions of the function's code block, thus determining the location of the code block covered by the user operation. Combining the function entity information and the coverage count arrays, the line coverage rate of the code within the function can be determined.
[0064] Then, the line coverage of each function can be aggregated using LLVM tools to obtain the line coverage of the coverage data file. This allows for the simultaneous determination of line coverage information for each function, which improves processing efficiency and reduces latency during line coverage testing compared to determining the coverage of each line of code in the coverage data file sequentially.
[0065] In one possible approach, after obtaining the line coverage rate of the overlay data file, the historical line coverage rate of the source code file can be obtained from the database. Then, the historical line coverage rate is added to the line coverage rate of the overlay data file to obtain the target line coverage rate of the source code file.
[0066] It should be understood that the above method can determine the incremental line coverage of a single overlay data file. In this case, to obtain the full line coverage of the source code file, the historical line coverage of the source code file can be obtained from the database, and then the historical line coverage is added to the line coverage of the overlay data file. Afterwards, the accumulated line coverage of the source code file can be saved, for example, in a Redis database, for later determination of the full line coverage. Alternatively, in other possible methods, the saved line coverage of the source code file can be obtained, for example, by retrieving the line coverage of the source code file from a Redis database, and then incrementally mapped before being displayed on the front end for QA (Quality Assurance) analysis. The incremental mapping method can be similar to related technologies, and will not be elaborated here.
[0067] The code coverage testing method provided in this disclosure will now be described through another exemplary embodiment.
[0068] Reference Figure 6 First, the packaging platform packages a binary instrumentation artifact. Upon the first upload of an overlay data file, this artifact is parsed to obtain the first and second function file mapping relationships. Furthermore, these first and second function file mapping relationships can be stored in a database for subsequent parsing.
[0069] After the terminal device uploads the overlay data file, it can receive and parse the file to obtain the corresponding function coverage information. Then, based on the function coverage information and the first function file mapping relationship, the corresponding file coverage information can be determined. Next, modified file information of the source code file compared to historical source code files can be obtained from GitLab (code project repository), and the target file coverage information can be determined from the file coverage information based on this modified file information. Then, the function entity information corresponding to the target file coverage information can be read from the local cache. If reading the function entity information from the local cache fails, the function entity information corresponding to the target file coverage information is read from the database according to the second function file mapping relationship. Thus, the line coverage rate of the overlay data file can be determined based on the function entity information, i.e., the incremental line coverage rate of a single overlay data file can be obtained.
[0070] Continue to refer to Figure 6 After obtaining the incremental line coverage of a single coverage data file, the historical line coverage of the source code file can be retrieved from the database. This historical line coverage is then summed with the incremental line coverage to obtain the target line coverage of the source code file, i.e., the full line coverage of the source code file. Subsequently, the full line coverage can be incrementally mapped and displayed on the front end, if possible. This method reduces the dependence on source code files during code coverage testing. Even without modifying the source code files, the function file mapping relationship can be obtained through a single parsing of the instrumentation artifacts, allowing subsequent code coverage testing to directly utilize this mapping relationship. Furthermore, the coverage data file can be parsed in response to uploading, enabling parsing upon file upload. Compared to related technologies, this eliminates the file aggregation step, thus reducing latency during code coverage testing.
[0071] Furthermore, after parsing the coverage data file, incremental code coverage testing can be performed through function file mapping relationships, eliminating the need to load the instrumentation artifacts corresponding to the complete source code file into memory for each test. Testing has shown that, compared to loading the instrumentation artifacts corresponding to the complete source code file into memory, the method provided in this disclosure reduces memory consumption by two-thirds.
[0072] Based on the same inventive concept, this disclosure also provides a code coverage testing apparatus. Referring to FIG7, the code coverage testing apparatus 700 includes:
[0073] Parsing module 701 is used to parse the overlay data file in response to receiving the overlay data file, and obtain the function overlay information corresponding to the overlay data file, wherein the function overlay information includes the function name and the number of times the function is overlaid;
[0074] The first determining module 702 is used to determine the file coverage information corresponding to the function coverage information based on the function coverage information and the first function file mapping relationship. The first function file mapping relationship is used to characterize the correspondence between functions and function files in the instrumentation product corresponding to the source code file.
[0075] The second determining module 703 is used to obtain the modified file information of the latest source code file compared with the historical source code file from the code project repository, and determine the target file overwrite information in the file overwrite information based on the modified file information;
[0076] The third determining module 704 is used to determine the function entity information corresponding to the target file coverage information, and to determine the line coverage rate of the covered data file based on the coverage count and the function entity information.
[0077] Optionally, the parsing module 701 is used for:
[0078] The overlay data file is parsed to obtain function information for all functions in the overlay data file. Then, function information not included in the first function file mapping relationship is filtered out from the function information to obtain the function overlay information corresponding to the overlay data file.
[0079] Optionally, the second determining module 703 is used to:
[0080] Read the function entity information corresponding to the target file overwrite information from the local cache;
[0081] When it fails to read the function entity information corresponding to the target file coverage information from the local cache, the function entity information corresponding to the target file coverage information is read from the database according to the second function file mapping relationship. The second function file mapping relationship is used to characterize the correspondence between function files and function entity information in the instrumentation artifacts corresponding to the source code file. The database stores the function entity information corresponding to each function file in the second function file mapping relationship.
[0082] Optionally, the function coverage information includes multiple coverage count arrays, each of which has function identification information, and each element in each coverage count array is used to characterize the number of times each line of code in the corresponding function is executed. The third determining module 704 is used to:
[0083] For each function in the function coverage information, the following processing is performed:
[0084] Determine the function entity information corresponding to the function, and determine the corresponding coverage count array from the plurality of coverage count arrays based on the function identifier information of the function;
[0085] Based on the corresponding function entity information and the coverage count array, determine the row coverage information;
[0086] By aggregating the line coverage information of each function, the line coverage rate of the covered data file is obtained.
[0087] Optionally, the device 700 further includes the following module for obtaining the function file mapping relationship:
[0088] The first processing module is used to parse the instrumentation artifacts corresponding to the source code file to obtain the function names and function attribute information of all functions in the source code file, wherein the function attribute information includes function code block information;
[0089] The second processing module is used to parse the function code block information to obtain the function file information to which each function in the source code file belongs and the position information of the code block corresponding to each function in the function file to which it belongs;
[0090] A module is established to create a function file mapping relationship based on the function name of each function in the source code file, the function file information to which each function belongs, and the location information of the code block corresponding to each function in the function file.
[0091] Optionally, the device 700 further includes:
[0092] The acquisition module is used to retrieve the historical row coverage of the source code file from the database;
[0093] The accumulation module is used to accumulate the historical line coverage rate with the line coverage rate of the covered data file to obtain the target line coverage rate of the source code file.
[0094] Regarding the apparatus in the above embodiments, the specific manner in which each module performs its operation has been described in detail in the embodiments related to the method, and will not be elaborated upon here.
[0095] Based on the same inventive concept, embodiments of this disclosure also provide a computer-readable medium having a computer program stored thereon, which, when executed by a processing device, implements the steps of any of the above-described code coverage testing methods.
[0096] Based on the same inventive concept, this disclosure also provides an electronic device, including:
[0097] A storage device on which computer programs are stored;
[0098] A processing device for executing the computer program in the storage device to implement the steps of any of the code coverage testing methods described above.
[0099] The following is for reference. Figure 8 This illustration shows a structural schematic of an electronic device 800 suitable for implementing embodiments of the present disclosure. The terminal devices in the embodiments of the present disclosure may include, but are not limited to, mobile terminals such as mobile phones, laptops, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), in-vehicle terminals (e.g., in-vehicle navigation terminals), and fixed terminals such as digital TVs and desktop computers. Figure 8 The electronic device shown is merely an example and should not be construed as limiting the functionality and scope of the embodiments disclosed herein.
[0100] like Figure 8 As shown, the electronic device 800 may include a processing device (e.g., a central processing unit, a graphics processor, etc.) 801, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 802 or a program loaded from a storage device 808 into a random access memory (RAM) 803. The RAM 803 also stores various programs and data required for the operation of the electronic device 800. The processing device 801, ROM 802, and RAM 803 are interconnected via a bus 804. An input / output (I / O) interface 805 is also connected to the bus 804.
[0101] Typically, the following devices can be connected to I / O interface 805: input devices 806 including, for example, touchscreens, touchpads, keyboards, mice, cameras, microphones, accelerometers, gyroscopes, etc.; output devices 807 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; storage devices 808 including, for example, magnetic tapes, hard disks, etc.; and communication devices 809. Communication device 809 allows electronic device 800 to communicate wirelessly or wiredly with other devices to exchange data. Although Figure 8 An electronic device 800 with various devices is shown; however, it should be understood that it is not required to implement or possess all of the devices shown. More or fewer devices may be implemented or possessed alternatively.
[0102] In particular, according to embodiments of this disclosure, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of this disclosure include a computer program product comprising a computer program carried on a non-transitory computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication device 809, or installed from a storage device 808, or installed from a ROM 802. When the computer program is executed by a processing device 801, it performs the functions defined in the methods of embodiments of this disclosure.
[0103] It should be noted that the computer-readable medium described in this disclosure can be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. A computer-readable storage medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this disclosure, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in connection with an instruction execution system, apparatus, or device. In this disclosure, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium can be any computer-readable medium other than a computer-readable storage medium, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to: wires, optical fibers, RF (radio frequency), etc., or any suitable combination thereof.
[0104] In some implementations, communication can be conducted using any currently known or future-developed network protocol such as HTTP (Hypertext Transfer Protocol), and can be interconnected with digital data communication (e.g., communication networks) of any form or medium. Examples of communication networks include local area networks (“LANs”), wide area networks (“WANs”), the Internet (e.g., the Internet of Things), and end-to-end networks (e.g., ad hoc end-to-end networks), as well as any currently known or future-developed networks.
[0105] The aforementioned computer-readable medium may be included in the aforementioned electronic device; or it may exist independently and not assembled into the electronic device.
[0106] The aforementioned computer-readable medium carries one or more programs. When the aforementioned one or more programs are executed by the electronic device, the electronic device causes the following actions: In response to receiving an overlay data file, it parses the overlay data file to obtain function overlay information corresponding to the overlay data file, the function overlay information including the function name and overlay count of the corresponding function; based on the function overlay information and a first function file mapping relationship, it determines file overlay information corresponding to the function overlay information, the first function file mapping relationship being used to characterize the correspondence between functions and function files in the instrumentation artifacts corresponding to the source code file; it obtains modified file information of the source code file compared to historical source code files from the code project repository, and determines target file overlay information in the file overlay information based on the modified file information; it determines function entity information corresponding to the target file overlay information, and determines the line coverage rate of the overlay data file based on the overlay count and the function entity information.
[0107] Computer program code for performing the operations of this disclosure can be written in one or more programming languages or a combination thereof, including but not limited to object-oriented programming languages such as Java, Smalltalk, and C++, as well as conventional procedural programming languages such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0108] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this disclosure. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0109] The modules described in the embodiments of this disclosure can be implemented in software or hardware. The names of the modules are not, in some cases, intended to limit the functionality of the module itself.
[0110] The functions described above in this document can be performed, at least in part, by one or more hardware logic components. For example, exemplary types of hardware logic components that can be used, without limitation, include: Field Programmable Gate Arrays (FPGAs), Application-Specific Integrated Circuits (ASICs), Application Standard Products (ASSPs), System-on-Chip (SoCs), Complex Programmable Logic Devices (CPLDs), and so on.
[0111] In the context of this disclosure, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0112] According to one or more embodiments of this disclosure, Example 1 provides a code coverage testing method, including:
[0113] In response to receiving an overlay data file, the overlay data file is parsed to obtain the function overlay information corresponding to the overlay data file, the function overlay information including the function name and the number of times the function is overlaid;
[0114] Based on the function coverage information and the first function file mapping relationship, the file coverage information corresponding to the function coverage information is determined. The first function file mapping relationship is used to characterize the correspondence between functions and function files in the instrumentation artifacts corresponding to the source code files.
[0115] The modified file information of the source code file obtained from the code project repository compared with the historical source code file is used to determine the target file overwrite information based on the modified file information in the file overwrite information;
[0116] Determine the function entity information corresponding to the target file coverage information, and determine the line coverage rate of the covered data file based on the coverage count and the function entity information.
[0117] According to one or more embodiments of this disclosure, Example 2 provides the method of Example 1, wherein parsing the coverage data file to obtain function coverage information corresponding to the coverage data file includes:
[0118] The overlay data file is parsed to obtain function information for all functions in the overlay data file. Then, function information not included in the first function file mapping relationship is filtered out from the function information to obtain the function overlay information corresponding to the overlay data file.
[0119] According to one or more embodiments of this disclosure, Example 3 provides the method of Example 1, wherein determining the function entity information corresponding to the target file coverage information includes:
[0120] Read the function entity information corresponding to the target file overwrite information from the local cache;
[0121] If it fails to read the function entity information corresponding to the target file coverage information from the local cache, then according to the second function file mapping relationship, the function entity information corresponding to the target file coverage information is read from the database. The second function file mapping relationship is used to characterize the correspondence between function files and function entity information in the instrumentation artifacts corresponding to the source code file. The database stores the function entity information corresponding to each function file in the second function file mapping relationship.
[0122] According to one or more embodiments of this disclosure, Example 4 provides a method of any one of Examples 1-3, wherein the function coverage information includes multiple coverage count arrays, each of the coverage count arrays has function identification information, and each element in each coverage count array is used to characterize the number of times each line of code in the corresponding function is executed, and determining the line coverage rate of the coverage data file based on the coverage counts and the function entity information includes:
[0123] For each function in the function coverage information, the following processing is performed:
[0124] Determine the function entity information corresponding to the function, and determine the corresponding coverage count array from the plurality of coverage count arrays based on the function identifier information of the function;
[0125] Based on the corresponding function entity information and the coverage count array, determine the row coverage information;
[0126] By aggregating the line coverage information of each function, the line coverage rate of the covered data file is obtained.
[0127] According to one or more embodiments of this disclosure, Example 5 provides a method of any one of Examples 1-3, wherein the function file mapping relationship is obtained in the following manner:
[0128] Parse the instrumentation artifacts corresponding to the source code file to obtain the function names and function attribute information of all functions in the source code file, including function code block information;
[0129] The function code block information is parsed to obtain the function file information to which each function in the source code file belongs, as well as the position information of the code block corresponding to each function in the function file to which it belongs;
[0130] Based on the function name of each function in the source code file, the function file information to which each function belongs, and the location information of the code block corresponding to each function in the function file, a function file mapping relationship is established.
[0131] According to one or more embodiments of this disclosure, Example 6 provides a method of any one of Examples 1-3, the method further comprising:
[0132] Retrieve the historical line coverage rate of the source code file from the database;
[0133] The historical line coverage rate is added to the line coverage rate of the covered data file to obtain the target line coverage rate of the source code file.
[0134] According to one or more embodiments of this disclosure, Example 7 provides a code coverage testing apparatus, the apparatus comprising:
[0135] The parsing module is used to parse the overlay data file in response to receiving the overlay data file, and obtain the function overlay information corresponding to the overlay data file. The function overlay information includes the function name and the number of times the function is overlaid.
[0136] The first determining module is used to determine the file coverage information corresponding to the function coverage information based on the function coverage information and the first function file mapping relationship. The first function file mapping relationship is used to characterize the correspondence between functions and function files in the instrumentation product corresponding to the source code file.
[0137] The second determining module is used to obtain the modified file information of the latest source code file from the code project repository compared with the historical source code file, and to determine the target file overwrite information in the file overwrite information based on the modified file information;
[0138] The third determining module is used to determine the function entity information corresponding to the target file coverage information, and to determine the line coverage rate of the covered data file based on the coverage count and the function entity information.
[0139] According to one or more embodiments of this disclosure, Example 8 provides the apparatus of Example 7, wherein the parsing module is used for:
[0140] The overlay data file is parsed to obtain function information for all functions in the overlay data file. Then, function information not included in the first function file mapping relationship is filtered out from the function information to obtain the function overlay information corresponding to the overlay data file.
[0141] According to one or more embodiments of this disclosure, Example 9 provides the apparatus of Example 7, wherein the second determining module is configured to:
[0142] Read the function entity information corresponding to the target file overwrite information from the local cache;
[0143] When it fails to read the function entity information corresponding to the target file coverage information from the local cache, the function entity information corresponding to the target file coverage information is read from the database according to the second function file mapping relationship. The second function file mapping relationship is used to characterize the correspondence between function files and function entity information in the instrumentation artifacts corresponding to the source code file. The database stores the function entity information corresponding to each function file in the second function file mapping relationship.
[0144] According to one or more embodiments of this disclosure, Example 10 provides an apparatus according to any one of Examples 7-9, wherein the function coverage information includes a plurality of coverage count arrays, each of the coverage count arrays having function identification information, and each element in each coverage count array is used to characterize the number of times each line of code in the corresponding function is executed, and the third determining module is used to:
[0145] For each function in the function coverage information, the following processing is performed:
[0146] Determine the function entity information corresponding to the function, and determine the corresponding coverage count array from the plurality of coverage count arrays based on the function identifier information of the function;
[0147] Based on the corresponding function entity information and the coverage count array, determine the row coverage information;
[0148] By aggregating the line coverage information of each function, the line coverage rate of the covered data file is obtained.
[0149] According to one or more embodiments of this disclosure, Example 11 provides an apparatus according to any one of Examples 7-9, the apparatus further comprising the following module for obtaining function file mapping relationships:
[0150] The first processing module is used to parse the instrumentation artifacts corresponding to the source code file to obtain the function names and function attribute information of all functions in the source code file, wherein the function attribute information includes function code block information;
[0151] The second processing module is used to parse the function code block information to obtain the function file information to which each function in the source code file belongs and the position information of the code block corresponding to each function in the function file to which it belongs;
[0152] A module is established to create a function file mapping relationship based on the function name of each function in the source code file, the function file information to which each function belongs, and the location information of the code block corresponding to each function in the function file.
[0153] According to one or more embodiments of this disclosure, Example 12 provides an apparatus of any one of Examples 7-9, the apparatus further comprising:
[0154] The acquisition module is used to obtain the historical line coverage rate corresponding to the source code file from the database;
[0155] The accumulation module is used to accumulate the historical line coverage rate with the line coverage rate of the covered data file to obtain the target line coverage rate of the source code file.
[0156] According to one or more embodiments of the present disclosure, Example 13 provides a computer-readable medium having a computer program stored thereon that, when executed by a processing device, implements the steps of the method described in any one of Examples 1-6.
[0157] According to one or more embodiments of this disclosure, Example 14 provides an electronic device, including:
[0158] A storage device on which computer programs are stored;
[0159] A processing device for executing the computer program in the storage device to implement the steps of any one of the methods in Examples 1-6.
[0160] The above description is merely a preferred embodiment of this disclosure and an explanation of the technical principles employed. Those skilled in the art should understand that the scope of this disclosure is not limited to technical solutions formed by specific combinations of the above-described technical features, but should also cover other technical solutions formed by arbitrary combinations of the above-described technical features or their equivalents without departing from the above-described concept. For example, technical solutions formed by substituting the above features with (but not limited to) technical features disclosed in this disclosure that have similar functions.
[0161] Furthermore, while the operations are described in a specific order, this should not be construed as requiring these operations to be performed in the specific order shown or in a sequential order. In certain environments, multitasking and parallel processing may be advantageous. Similarly, while several specific implementation details are included in the above discussion, these should not be construed as limiting the scope of this disclosure. Certain features described in the context of individual embodiments may also be implemented in combination in a single embodiment. Conversely, various features described in the context of a single embodiment may also be implemented individually or in any suitable sub-combination in multiple embodiments.
[0162] Although the subject matter has been described using language specific to structural features and / or methodological logic, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. Rather, the specific features and actions described above are merely illustrative forms of implementing the claims. Regarding the apparatus in the above embodiments, the specific manner in which the various modules perform their operations has been described in detail in the embodiments relating to the method, and will not be elaborated upon here.
Claims
1. A code coverage testing method, characterized in that, The method includes: In response to receiving a coverage data file, the coverage data file is parsed to obtain function coverage information corresponding to the coverage data file. The function coverage information includes the function name and coverage count of the corresponding function. The function coverage information includes multiple coverage count arrays. Each coverage count array has function identification information, and each element in each coverage count array is used to characterize the number of times each line of code in the corresponding function is executed. Based on the function coverage information and the first function file mapping relationship, the file coverage information corresponding to the function coverage information is determined. The first function file mapping relationship is used to characterize the correspondence between functions and function files in the instrumentation artifacts corresponding to the source code file. The first function file mapping relationship is obtained by parsing the instrumentation artifacts when the coverage data file is first uploaded. Obtain the modified file information of the source code file compared to the historical source code file from the code project repository, and determine the target file overwrite information in the file overwrite information based on the modified file information; If reading the function entity information corresponding to the target file coverage information from the local cache fails, then according to the second function file mapping relationship, the function entity information corresponding to the target file coverage information is read from the database. The second function file mapping relationship is used to characterize the correspondence between function files and function entity information in the instrumentation artifacts corresponding to the source code file. The database stores the function entity information corresponding to each function file in the second function file mapping relationship. For each function in the function coverage information, the following processing is performed: Determine the function entity information corresponding to the function, and determine the corresponding coverage count array from the plurality of coverage count arrays based on the function identifier information of the function; Based on the corresponding function entity information and the coverage count array, determine the row coverage information; By aggregating the line coverage information of each function, the line coverage rate of the covered data file is obtained.
2. The method according to claim 1, characterized in that, The process of parsing the coverage data file to obtain the function coverage information corresponding to the coverage data file includes: The overlay data file is parsed to obtain function information for all functions in the overlay data file. Then, function information not included in the first function file mapping relationship is filtered out from the function information to obtain the function overlay information corresponding to the overlay data file.
3. The method according to claim 1 or 2, characterized in that, The function file mapping relationship is obtained in the following way: Parse the instrumentation artifacts corresponding to the source code file to obtain the function names and function attribute information of all functions in the source code file, including function code block information; The function code block information is parsed to obtain the function file information to which each function in the source code file belongs, as well as the position information of the code block corresponding to each function in the function file to which it belongs; Based on the function name of each function in the source code file, the function file information to which each function belongs, and the location information of the code block corresponding to each function in the function file, a function file mapping relationship is established.
4. The method according to claim 1 or 2, characterized in that, The method further includes: Retrieve the historical line coverage of the source code file from the database; The historical line coverage rate is added to the line coverage rate of the covered data file to obtain the target line coverage rate of the source code file.
5. A code coverage testing device, characterized in that, The device includes: The parsing module is used to parse the overlay data file in response to receiving the overlay data file, and obtain the function overlay information corresponding to the overlay data file. The function overlay information includes the function name and the number of times the function is covered. The function overlay information includes multiple overlay count arrays. Each overlay count array has function identification information, and each element in each overlay count array is used to represent the number of times each line of code in the corresponding function is executed. The first determining module is used to determine the file coverage information corresponding to the function coverage information based on the function coverage information and the first function file mapping relationship. The first function file mapping relationship is used to characterize the correspondence between functions and function files in the instrumentation product corresponding to the source code file. The first function file mapping relationship is obtained by parsing the instrumentation product when the coverage data file is first uploaded. The second determining module is used to obtain the modified file information of the source code file compared with the historical source code file from the code project repository, and determine the target file overwrite information in the file overwrite information based on the modified file information; The third determining module is used to read the function entity information corresponding to the target file coverage information from the local cache. If reading the function entity information corresponding to the target file coverage information from the local cache fails, the function entity information corresponding to the target file coverage information is read from the database according to the second function file mapping relationship. The second function file mapping relationship is used to characterize the correspondence between function files and function entity information in the instrumentation artifacts corresponding to the source code file. The database stores the function entity information corresponding to each function file in the second function file mapping relationship. For each function in the function coverage information, the following processing is performed: determine the function entity information corresponding to the function, and determine the corresponding coverage count array in the plurality of coverage count arrays according to the function identifier information of the function; determine the line coverage information according to the corresponding function entity information and the coverage count array; aggregate the line coverage information of each function to obtain the line coverage rate of the coverage data file.
6. The apparatus according to claim 5, characterized in that, The parsing module is used for: The overlay data file is parsed to obtain function information for all functions in the overlay data file. Then, function information not included in the first function file mapping relationship is filtered out from the function information to obtain the function overlay information corresponding to the overlay data file.
7. A computer-readable medium having a computer program stored thereon, characterized in that, When executed by the processing device, the program implements the steps of the method described in any one of claims 1-4.
8. An electronic device, characterized in that, include: A storage device on which computer programs are stored; A processing device for executing the computer program in the storage device to implement the steps of the method according to any one of claims 1-4.
Citation Information
Patent Citations
Statistical method and device for incremental coverage information
CN102722436A
Code information processing method and device
CN104714882A
Method of service operation breakpoint execution, service server and system
CN108241543A
Detection method, device and apparatus for realizing incremental code coverage rate based on lcov
CN110928776A