Coverage acquisition method, device, computer storage medium and electronic device

CN116049018BActive Publication Date: 2026-09-25INDUSTRIAL AND COMMERCIAL BANK OF CHINA
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310275135.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-03-20
Publication Date
2026-09-25
Estimated Expiration
2043-03-20

AI Technical Summary

Technical Problem

[0005]本申请提供一种覆盖率的获取方法、装置、计算机存储介质及电子装置,以解决相关技术中难以采集加壳应用在操作系统中的覆盖率的问题

Benefits of technology

[0016]通过本申请,采用以下步骤:获取操作系统的源码以及第一目标应用的源码,并利用操作系统中的目标类触发类加载进程;在类加载进程运行至链接阶段的情况下,将探针数组注入到操作系统的源码中,得到修改后的操作系统,其中,修改后的操作系统包含修改后的目标类;利用探针数组获取第一目标应用在修改后的操作系统中的覆盖率,并将覆盖率传递至远程服务器,其中,覆盖率是指已经运行代码与待运行代码的比值数据,远程服务器与第一目标应用所在的服务器相连,由远程服务器对覆盖率进行数据格式的解析,得到第一目标应用的代码覆盖情况,解决了相关技术中难以采集加壳应用在操作系统中的覆盖率的问题,通过对加壳应用运行的操作系统进行修改,在操作系统源码中加入探针数组,以此完成应用在操作系统中的覆盖率的采集,进而达到了无需运行应用源码即可获得应用覆盖率的效果。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116049018B_ABST
    Figure CN116049018B_ABST
Patent Text Reader

Abstract

The application discloses a coverage acquisition method and device, a computer storage medium and an electronic device, relates to the application test field, and the method comprises the following steps: acquiring source code of an operating system and source code of a first target application, and triggering a class loading process by using a target class in the operating system; in the case that the class loading process runs to a linking stage, injecting a probe array into the source code of the operating system to obtain a modified operating system, wherein the modified operating system contains a modified target class; acquiring the coverage of the first target application in the modified operating system by using the probe array, and delivering the coverage to a remote server. Through the application, the problem that it is difficult to collect the coverage of a shell application in an operating system in the related art is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of application testing, and more specifically, to a method, apparatus, computer storage medium, and electronic device for obtaining coverage. Background Technology

[0002] During application development, continuous testing is required before the application can be used by users. Completeness testing necessitates examining the application's source code. However, due to the large volume of code, testers need to focus on identifying which parts of the code have been tested and which have not. This is where the concept of coverage comes in. Coverage is a metric for measuring the sufficiency and completeness of software testing; it represents the proportion of executed code to the total code under test. Therefore, collecting coverage data is an essential step in the testing process.

[0003] On the other hand, the application's source code is its core, and its leakage is a very serious crisis. To protect the source code, most applications employ obfuscation strategies. During testing, testers also use obfuscated application packages to minimize the scope of code leakage. However, this obfuscation can prevent the collection of application coverage data, thus hindering the analysis of whether multiple application files contain anomalies.

[0004] There is currently no effective solution to the problem of difficulty in collecting the coverage of packed applications in the operating system in related technologies. Summary of the Invention

[0005] This application provides a method, apparatus, computer storage medium, and electronic device for obtaining coverage, in order to solve the problem in the related art of difficulty in collecting the coverage of packed applications in the operating system.

[0006] According to one aspect of this application, a method for obtaining coverage is provided. The method includes: obtaining the source code of an operating system and the source code of a first target application, and triggering a class loading process using a target class in the operating system; when the class loading process reaches the linking stage, injecting a probe array into the source code of the operating system to obtain a modified operating system, wherein the modified operating system contains the modified target class; using the probe array to obtain the coverage of the first target application in the modified operating system, and transmitting the coverage to a remote server, wherein coverage refers to the ratio of executed code to code to be executed, the remote server is connected to the server where the first target application resides, and the remote server parses the coverage data format to obtain the code coverage status of the first target application.

[0007] Optionally, when the class loading process reaches the linking stage, injecting the probe array into the source code of the operating system to obtain the modified operating system includes: obtaining a preset probe array, initializing the value of the preset probe array to obtain the probe array; writing the probe array into the code of the method to be executed in the source code of the operating system to obtain the modified operating system, wherein the value of the probe array is modified after the first target application runs.

[0008] Optionally, the value of the preset probe array after initialization is 0. Obtaining the coverage of the first target application in the modified operating system using the probe array includes: when running the first target application in the modified operating system, obtaining the assignment results of the values ​​corresponding to each branch code in the probe array; when the values ​​corresponding to each branch code in the probe array are all 1, collecting the coverage to obtain the coverage of the first target application in the modified operating system.

[0009] Optionally, transmitting the coverage to the remote server includes: acquiring a target thread when the first target application starts, wherein the target thread is used to transmit the coverage; establishing a long connection between the target thread and the remote server; and sending the acquired coverage to the remote server through the target thread.

[0010] Optionally, obtaining the source code of the operating system includes: running the first target application and the unpacking program in the operating system; using the unpacking program to obtain and decode the encrypted bytecode in the operating system to obtain the decoded encrypted bytecode; and identifying the decoded encrypted bytecode as the source code of the operating system.

[0011] Optionally, after passing the coverage to the remote server, the method further includes running the modified operating system until the class loading process ends.

[0012] Optionally, after sending the obtained coverage rate to the remote server via the target thread, the method further includes: recompiling the modified operating system source code to obtain an operating system image, and burning the operating system image to the test machine; if the second target application needs to collect coverage rate, or if the first target application needs to collect coverage rate after a preset time period, the application that needs to collect coverage rate is run in the operating system image to obtain the coverage rate.

[0013] According to another aspect of this application, a coverage acquisition apparatus is provided. The apparatus includes: a first acquisition unit, configured to acquire the source code of an operating system and the source code of a first target application, and trigger a class loading process using a target class in the operating system; an injection unit, configured to inject a probe array into the source code of the operating system when the class loading process reaches the linking stage, to obtain a modified operating system, wherein the modified operating system contains the modified target class; and a second acquisition unit, configured to acquire the coverage of the first target application in the modified operating system using the probe array, and transmit the coverage to a remote server, wherein the coverage refers to the ratio of already executed code to code to be executed, the remote server is connected to the server where the first target application resides, and the remote server parses the coverage data format to obtain the code coverage status of the first target application.

[0014] According to another aspect of the present invention, a computer storage medium is also provided for storing a program, wherein the program, when running, controls the device where the non-volatile storage medium is located to execute a coverage acquisition method.

[0015] According to another aspect of the present invention, an electronic device is also provided, comprising a processor and a memory; the memory stores computer-readable instructions, and the processor is configured to execute the computer-readable instructions, wherein the computer-readable instructions, when executed, perform a coverage acquisition method.

[0016] This application employs the following steps: obtaining the source code of the operating system and the source code of the first target application, and triggering a class loading process using the target class in the operating system; when the class loading process reaches the linking stage, injecting a probe array into the source code of the operating system to obtain a modified operating system, wherein the modified operating system contains the modified target class; using the probe array to obtain the coverage of the first target application in the modified operating system, and transmitting the coverage to a remote server, wherein the coverage refers to the ratio of the already executed code to the code to be executed, the remote server is connected to the server where the first target application is located, and the remote server parses the data format of the coverage to obtain the code coverage of the first target application. This solves the problem in related technologies of the difficulty in collecting the coverage of packed applications in the operating system. By modifying the operating system on which the packed application runs and adding a probe array to the operating system source code, the coverage of the application in the operating system is collected, thereby achieving the effect of obtaining application coverage without running the application source code. Attached Figure Description

[0017] The accompanying drawings, which form part of this application, are used to provide a further understanding of this application. The illustrative embodiments and descriptions of this application are used to explain this application and do not constitute an undue limitation of this application. In the drawings:

[0018] Figure 1 This is a flowchart of a method for obtaining coverage according to an embodiment of this application;

[0019] Figure 2 This is a flowchart of an optional coverage acquisition method provided according to an embodiment of this application;

[0020] Figure 3 This is a schematic diagram of a coverage acquisition device provided according to an embodiment of this application;

[0021] Figure 4 This is a schematic diagram of an electronic device provided according to an embodiment of this application. Detailed Implementation

[0022] It should be noted that, unless otherwise specified, the embodiments and features described in this application can be combined with each other. This application will now be described in detail with reference to the accompanying drawings and embodiments.

[0023] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort should fall within the scope of protection of the present application.

[0024] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate for the embodiments of this application described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0025] It should be noted that all information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for display, data used for analysis, etc.) involved in this disclosure are information and data authorized by the user or fully authorized by all parties.

[0026] According to an embodiment of this application, a method for obtaining coverage is provided.

[0027] Figure 1 This is a flowchart of a method for obtaining coverage according to an embodiment of this application, such as... Figure 1 As shown, the method includes the following steps:

[0028] Step S102: Obtain the source code of the operating system and the source code of the first target application, and trigger the class loading process using the target class in the operating system.

[0029] Specifically, before collecting coverage data for the application under test, it is necessary to obtain the source code of the operating system on which the application runs and the source code of the application itself. In order to inject the collection probe into the program, it is necessary to use the classes in the operating system to trigger the class loading process. The classes in the operating system are user-defined reference data types that contain data descriptions and functions for manipulating data or passing messages. They are the foundation for information encapsulation in object-oriented programming.

[0030] The first target application can be the application whose code coverage is to be tested. To prevent data leakage, the source code of the first target application and the source code of the operating system have been packed.

[0031] Step S104: When the class loading process reaches the linking stage, the probe array is injected into the source code of the operating system to obtain the modified operating system, wherein the modified operating system contains the modified target class.

[0032] Specifically, the class loading process is divided into three phases: loading, linking, and initialization. To inject the probes, they need to be injected into the operating system's source code at a critical point in time. Therefore, when class loading reaches the linking phase, the probe code is written into the operating system's source code. The probes used for coverage collection are an array. After writing the probe array into the operating system's source code, a modified operating system capable of collecting application coverage is obtained. This operating system can then be used to obtain the coverage data of the application under test.

[0033] Step S106: Use the probe array to obtain the coverage of the first target application in the modified operating system, and transmit the coverage to the remote server. The coverage refers to the ratio of the code that has been run to the code that is to be run. The remote server is connected to the server where the first target application is located. The remote server parses the data format of the coverage to obtain the code coverage of the first target application.

[0034] Specifically, the first target application is run in the operating system, and the probe array is added during the linking phase of the class loading process. At this time, the source code of the first target application is input into the modified operating system, and the probe array in the operating system can collect the code coverage of the application, that is, the code coverage rate.

[0035] Furthermore, after obtaining the application coverage, a new thread needs to be created to transmit the coverage data to a remote server. The remote server will then convert and parse the data to obtain the specific application's code coverage.

[0036] The coverage acquisition method provided in this application embodiment obtains the source code of the operating system and the source code of the first target application, and triggers the class loading process using the target class in the operating system. When the class loading process reaches the linking stage, a probe array is injected into the source code of the operating system to obtain a modified operating system, wherein the modified operating system contains the modified target class. The probe array is used to obtain the coverage of the first target application in the modified operating system, and the coverage is transmitted to a remote server. The coverage refers to the ratio of the code that has been run to the code that is to be run. The remote server is connected to the server where the first target application is located, and the remote server parses the data format of the coverage to obtain the code coverage of the first target application. This solves the problem in related technologies that it is difficult to collect the coverage of packed applications in the operating system. By modifying the operating system on which the packed application runs and adding a probe array to the source code of the operating system, the coverage of the application in the operating system can be collected, thereby achieving the effect of obtaining the application coverage without running the application source code.

[0037] Optionally, in the coverage acquisition method provided in this application embodiment, when the class loading process runs to the linking stage, injecting the probe array into the source code of the operating system to obtain the modified operating system includes: obtaining a preset probe array, initializing the value of the preset probe array to obtain the probe array; writing the probe array into the code of the method to be executed in the source code of the operating system to obtain the modified operating system, wherein the value of the probe array is modified after the first target application runs.

[0038] Specifically, when the method to be executed contains two branches, the probe array can be an array of length 3 (i.e., 3 elements), of type boolean, and named probe, represented in code as: static boolean probe[] = new boolean[3]. After obtaining the preset probe array and writing it to the operating system, the probe array must first be initialized before the application can run. The probe array needs to be written into the branch code of the method to be executed in the system source code, and the coverage of the application is collected by different branch codes. When the application running on the operating system executes a piece of code, the value of the array can be changed, thereby determining the coverage of the application.

[0039] Optionally, in the coverage acquisition method provided in this application embodiment, the value of the preset probe array after initialization is 0. Obtaining the coverage of the first target application in the modified operating system using the probe array includes: when running the first target application in the modified operating system, obtaining the assignment result of the corresponding values ​​of each branch code in the probe array; when the corresponding values ​​of each branch code in the probe array are all 1, performing coverage acquisition to obtain the coverage of the first target application in the modified operating system.

[0040] Specifically, the probe array is initialized by setting all its values ​​to 0. Each time the application executes a section of code, the array's value changes from 0 to 1. An integer `a` is defined, and the application's source code is segmented using `a` to obtain branch code. The assignment result of the probe array within each branch code indicates whether the application's code has been executed, i.e., the code coverage. A probe array value of 1 indicates a result of true; conversely, a probe array value of 0 indicates a result of false.

[0041] When the first element of the array is true, that is, probe[0] = true, it means that the array value is 1, the application x starts running, that is, the code coverage collection begins. When probe[1] = true, that is, the array value is 1, it means that part of the application's source code has been executed, that is, the code of one branch; when probe[2] = true, it means that another part of the application's source code has been executed, that is, the code of another branch. When the source code of all branches of the application has been executed, the code coverage collected at this time is the code coverage of the application.

[0042] Optionally, in the coverage acquisition method provided in this application embodiment, transmitting the coverage to the remote server includes: acquiring a target thread when the first target application starts, wherein the target thread is used to transmit the coverage; establishing a long connection between the target thread and the remote server; and sending the acquired coverage to the remote server through the target thread.

[0043] Specifically, the target thread runs in parallel on the same server as the first target application, establishing a long-lived connection between this thread and a remote server storing and resolving coverage data. Once the coverage data for the application is obtained from that server, the thread can send the coverage data to the remote server in a specific data format.

[0044] Optionally, in the coverage acquisition method provided in this application embodiment, acquiring the source code of the operating system includes: running a first target application and an unpacking program in the operating system; using the unpacking program to acquire and decode the encrypted bytecode in the operating system to obtain the decoded encrypted bytecode; and determining the decoded encrypted bytecode as the source code of the operating system.

[0045] When using a probe array to collect application coverage, the probe array needs to be written into the operating system's source code, which means obtaining the operating system's source code. The source code consists of multiple encrypted bytecode data. To obtain the operating system's source code, specifically, a depackaging program provided by a third-party vendor is run in the operating system. The depackaging program parses and stores the operating system's encrypted bytecode, and the parsed bytecode is the operating system's source code.

[0046] Optionally, in the coverage acquisition method provided in the embodiments of this application, after the coverage is transmitted to the remote server, the method further includes: running the modified operating system until the class loading process ends.

[0047] Specifically, after the coverage data of the target application is obtained by the probe array and transmitted to the remote server, the operating system running the target application continues to run until the class loading process ends, in order to complete the application testing process. The operating system is the modified operating system after being written by the probe array.

[0048] Optionally, in the coverage acquisition method provided in this application embodiment, after sending the acquired coverage to a remote server through a target thread, the method further includes: recompiling the modified operating system source code to obtain an operating system image, and burning the operating system image to a test machine; when a second target application needs to collect coverage, or when a first target application needs to collect coverage after a preset time period, running the application that needs to collect coverage in the operating system image to obtain the coverage.

[0049] Specifically, once the remote server obtains the modified operating system, it compiles the operating system's source code into an image, resulting in an operating system image identical to the original operating system. This image is then used for application testing. The operating system image is then burned to a test machine for storage. When it's necessary to test the coverage of a specific application, the application is run directly on the operating system image on the test machine, directly obtaining the application's code coverage, i.e., its coverage rate.

[0050] For example, when testing the coverage of an application other than the first target application (i.e., the second target application), there is no need to modify the source code of the operating system. The coverage of the second target application can be obtained by directly running the second target application in the operating system image on the test machine.

[0051] For example, when retesting the coverage of the first target application in the next testing cycle, there is no need to modify the source code of the operating system. The coverage of the first target application can be obtained by directly running the first target application in the operating system image on the test machine.

[0052] It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and although a logical order is shown in the flowchart, in some cases the steps shown or described may be executed in a different order than that shown here.

[0053] This application also provides a method for obtaining coverage. Figure 2 This is a flowchart of an optional coverage acquisition method provided according to an embodiment of this application. Figure 2 As shown, the method includes:

[0054] The application to be tested and the unpacking program are run on the operating system. After obtaining the encrypted bytecode of the operating system, the unpacking program is used to parse the encrypted bytecode of the operating system to obtain the source code of the operating system.

[0055] The class in the operating system triggers the class loading process, and after running to the linking stage, the source code of the operating system is modified. That is, the probe array for collecting coverage is written into the source code of the operating system, resulting in the modified operating system.

[0056] At this point, the application to be tested is running in the modified operating system, and the coverage of the application is collected through a probe array.

[0057] Simultaneously, a new thread is created to transmit the collected coverage data to a remote server connected to the thread. The remote server then parses and stores the coverage data, thereby obtaining the application's coverage.

[0058] Finally, after the coverage data is transmitted, the modified operating system continues to run until the class loading process ends. The source code of the modified operating system is then image-compiled and burned into the test machine for subsequent coverage data collection.

[0059] This application also provides a coverage acquisition device. It should be noted that the coverage acquisition device of this application can be used to execute the coverage acquisition method provided in this application. The coverage acquisition device provided in this application will be described below.

[0060] Figure 3 This is a schematic diagram of a coverage acquisition device provided according to an embodiment of this application, such as... Figure 3 As shown, the device includes: a first acquisition unit 30, an injection unit 31, and a second acquisition unit 32.

[0061] The first acquisition unit 30 is used to acquire the source code of the operating system and the source code of the first target application, and to trigger the class loading process using the target class in the operating system.

[0062] Injection unit 31 is used to inject a probe array into the source code of the operating system when the class loading process reaches the linking stage, so as to obtain a modified operating system, wherein the modified operating system contains the modified target class.

[0063] The second acquisition unit 32 is used to acquire the coverage of the first target application in the modified operating system using a probe array, and transmit the coverage to a remote server. The coverage refers to the ratio of the code that has been run to the code that is to be run. The remote server is connected to the server where the first target application is located. The remote server parses the data format of the coverage to obtain the code coverage of the first target application.

[0064] Optionally, in the coverage acquisition device provided in this application embodiment, the injection unit 31 includes: an acquisition module, used to acquire a preset probe array, initialize the value of the preset probe array, and obtain a probe array; and a writing module, used to write the probe array into the code of the method to be executed in the source code of the operating system, to obtain a modified operating system, wherein the value of the probe array is modified after the first target application runs.

[0065] Optionally, in the coverage acquisition device provided in the embodiments of this application, the second acquisition unit 32 includes: a first running module, used to acquire the assignment results of the values ​​corresponding to each branch code in the probe array when running the first target application in the modified operating system; and a collection module, used to collect the coverage when the values ​​corresponding to each branch code in the probe array are all 1, so as to obtain the coverage of the first target application in the modified operating system.

[0066] Optionally, in the coverage acquisition device provided in this application embodiment, the second acquisition unit 32 includes: a first acquisition module, used to acquire a target thread when the first target application starts, wherein the target thread is used to transmit the coverage; an establishment module, used to establish a long connection between the target thread and a remote server; and a sending module, used to send the acquired coverage to the remote server through the target thread.

[0067] Optionally, in the coverage acquisition device provided in this application embodiment, the second acquisition unit 32 includes: a second running module, used to run a first target application and a depackaging program in the operating system; a second acquisition module, used to use the depackaging program to acquire and decode the encrypted bytecode in the operating system to obtain the decoded encrypted bytecode; and a determination module, used to determine the decoded encrypted bytecode as the source code of the operating system.

[0068] Optionally, in the coverage acquisition device provided in the embodiments of this application, the device further includes: a first running unit, used to transmit the coverage to a remote server and then run a modified operating system until the class loading process ends.

[0069] Optionally, in the coverage acquisition device provided in this application embodiment, the device further includes: a compilation unit, configured to send the acquired coverage to a remote server via a target thread, recompile the modified operating system source code to obtain an operating system image, and burn the operating system image to a test machine; and a second running unit, configured to run the application requiring coverage acquisition in the operating system image to obtain coverage when the second target application needs to collect coverage, or when the first target application needs to collect coverage after a preset time period.

[0070] The coverage acquisition device provided in this application embodiment, through a first acquisition unit 30, is used to acquire the source code of the operating system and the source code of the first target application, and to trigger a class loading process using the target class in the operating system. An injection unit 31 is used to inject a probe array into the source code of the operating system when the class loading process reaches the linking stage, resulting in a modified operating system, wherein the modified operating system contains the modified target class. A second acquisition unit 32 is used to acquire the coverage of the first target application in the modified operating system using the probe array, and to transmit the coverage to a remote server. The coverage refers to the ratio of already executed code to code to be executed. The remote server is connected to the server where the first target application resides, and the remote server parses the data format of the coverage to obtain the code coverage of the first target application. This solves the problem in related technologies of the difficulty in collecting the coverage of packed applications in the operating system. By modifying the operating system on which the packed application runs and adding a probe array to the operating system source code, the coverage of the application in the operating system is collected, thereby achieving the effect of obtaining application coverage without running the application source code.

[0071] The aforementioned coverage acquisition device includes a processor and a memory. The first acquisition unit 30, injection unit 31, second acquisition unit 32, etc., are all stored in the memory as program units, and the processor executes the aforementioned program units stored in the memory to realize the corresponding functions.

[0072] The processor contains a kernel, which retrieves the corresponding program units from memory. One or more kernels can be configured, and adjusting kernel parameters can address the challenge of obtaining coverage data for packed applications within the operating system, a problem often encountered in related technologies.

[0073] The memory may include non-permanent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.

[0074] This application also provides a computer storage medium for storing a program, wherein the program, when running, controls the device where the non-volatile storage medium is located to execute a coverage acquisition method.

[0075] This application also provides an electronic device. Figure 4 This is a schematic diagram of an electronic device provided according to an embodiment of this application. Figure 4As shown, electronic device 40 includes a processor and a memory; the memory stores computer-readable instructions, and the processor executes the computer-readable instructions, wherein the computer-readable instructions, when executed, perform a coverage acquisition method. The electronic device in this document can be a server, PC, PAD, mobile phone, etc.

[0076] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0077] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0078] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0079] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0080] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.

[0081] Memory may include non-persistent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.

[0082] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.

[0083] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.

[0084] The above are merely embodiments of this application and are not intended to limit the scope of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of the claims of this application.

Claims

1. A method for obtaining coverage, characterized in that, include: Obtain the source code of the operating system and the source code of the first target application, and trigger the class loading process using the target class in the operating system; When the class loading process reaches the linking stage, the probe array is injected into the source code of the operating system to obtain a modified operating system, wherein the modified operating system contains the modified target class; The probe array is used to obtain the coverage of the first target application in the modified operating system, and the coverage is transmitted to a remote server. The coverage refers to the ratio of the code that has been run to the code that is to be run. The remote server is connected to the server where the first target application is located. The remote server parses the data format of the coverage to obtain the code coverage of the first target application. Transmitting the coverage rate to the remote server includes: when the first target application starts, obtaining a target thread, wherein the target thread is used to transmit the coverage rate; establishing a long connection between the target thread and the remote server; and sending the obtained coverage rate to the remote server through the target thread. After sending the obtained coverage rate to the remote server through the target thread, the method further includes: recompiling the source code of the modified operating system to obtain an operating system image, and burning the operating system image to the test machine; when the second target application needs to collect coverage rate, or when the first target application needs to collect coverage rate after a preset time period, running the application that needs to collect coverage rate in the operating system image to obtain the coverage rate; The method further includes: without modifying the source code of the first target application, modifying the operating system on which the packed application runs, and adding a probe array to the operating system source code.

2. The method according to claim 1, characterized in that, When the class loading process reaches the linking stage, a probe array is injected into the source code of the operating system, resulting in a modified operating system including: Obtain a preset probe array, initialize the values ​​of the preset probe array, and obtain the probe array; The probe array is written into the code of the method to be executed in the source code of the operating system to obtain the modified operating system, wherein the value of the probe array is modified after the first target application runs.

3. The method according to claim 2, characterized in that, The initialized value of the preset probe array is 0. Obtaining the coverage of the first target application in the modified operating system using the probe array includes: When the first target application is run in the modified operating system, the assignment results of the corresponding values ​​of each branch code in the probe array are obtained; When the corresponding values ​​of each branch code in the probe array are all 1, the coverage is collected to obtain the coverage of the first target application in the modified operating system.

4. The method according to claim 1, characterized in that, Obtaining the operating system's source code includes: The first target application and the unpacking program are run in the operating system; The unpacking program is used to acquire and decode the encrypted bytecode in the operating system to obtain the decoded encrypted bytecode. The decoded encrypted bytecode is identified as the source code of the operating system.

5. The method according to claim 1, characterized in that, After transmitting the coverage to the remote server, the method further includes: Run the modified operating system until the class loading process ends.

6. A coverage acquisition device, characterized in that, include: The first acquisition unit is used to acquire the source code of the operating system and the source code of the first target application, and to trigger a class loading process using the target class in the operating system. An injection unit is used to inject a probe array into the source code of the operating system when the class loading process reaches the linking stage, so as to obtain a modified operating system, wherein the modified operating system contains a modified target class; The second acquisition unit is used to acquire the coverage of the first target application in the modified operating system using the probe array, and transmit the coverage to a remote server. The coverage refers to the ratio of the code that has been run to the code that is to be run. The remote server is connected to the server where the first target application is located. The remote server parses the data format of the coverage to obtain the code coverage of the first target application. The second acquisition unit includes: a first acquisition module, used to acquire a target thread when the first target application starts, wherein the target thread is used to transmit the coverage rate; and an establishment module, used to establish a long connection between the target thread and the remote server; and to send the acquired coverage rate to the remote server through the target thread. The device further includes: a compilation unit, configured to, after sending the obtained coverage rate to the remote server via the target thread, recompile the source code of the modified operating system to obtain an operating system image, and burn the operating system image to the test machine; and a second running unit, configured to, when the second target application needs to collect coverage rate, or when the first target application needs to collect coverage rate after a preset time period, run the application that needs to collect coverage rate in the operating system image to obtain the coverage rate. The device further includes: without modifying the source code of the first target application, modifying the operating system on which the packed application runs, and adding a probe array to the operating system source code.

7. A computer storage medium, characterized in that, The computer storage medium is used to store a program, wherein the program, when running, controls the device where the computer storage medium is located to execute the coverage acquisition method according to any one of claims 1 to 5.

8. An electronic device, characterized in that, The device includes a processor and a memory, the memory storing computer-readable instructions, and the processor executing the computer-readable instructions, wherein the computer-readable instructions, when executed, perform the coverage acquisition method according to any one of claims 1 to 5.

Citation Information

Patent Citations

  • Operating system level program target code coverage rate test method and system for and medium

    CN110580226A

  • Coverage rate report generation method and device, equipment and storage medium

    CN115061901A