Bytecode acquisition method, computer device, storage medium and program product

By parsing image files and container runtime information, the program bytecode files in container development mode can be obtained, solving the problem of difficulty in obtaining them in traditional methods and improving testing efficiency and quality.

CN114817049BActive Publication Date: 2025-10-21INDUSTRIAL AND COMMERCIAL BANK OF CHINA
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202210490760.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-05-07
Publication Date
2025-10-21
Estimated Expiration
2042-05-07

AI Technical Summary

Technical Problem

In container development, traditional methods cannot effectively obtain the bytecode files of the software under test, making code coverage collection and analysis difficult and affecting the efficiency and quality of software testing.

Method used

By parsing the image file through the code extraction server, the storage paths of the library and bytecode in the image file are obtained. Combined with the container runtime information, the program bytecode file is located, enabling flexible acquisition in container development mode.

Benefits of technology

It improves the efficiency of obtaining program bytecode files, supports testers in analyzing and improving code coverage, and enhances the efficiency and quality of software testing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114817049B_ABST
    Figure CN114817049B_ABST
Patent Text Reader

Abstract

The application relates to a bytecode acquisition method, a computer device, a storage medium and a program product, which can be used in the financial field or other fields. The method comprises the following steps: a code extraction server acquires and runs an image file to generate a container in the code extraction server; the code extraction server analyzes the image file to obtain a first storage path of a library and bytecode in the image file; the code extraction server analyzes running information of the container to obtain a second storage path of corresponding program code of the container runtime in the code extraction server; and the code extraction server searches for a program bytecode file corresponding to the image file in the second storage path according to the first storage path. The source code of tested software can be acquired in a container development mode by using the method.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of software development technology, and in particular to a bytecode acquisition method, computer equipment, storage medium, and program product. Background Art

[0002] In software development, the primary goal of software testing is to ensure software quality. Code coverage is a key metric for measuring test completeness. Coverage is measured by the coverage of test requirements and test cases, or the coverage of executed code. Code coverage measures the effectiveness of testing and improves testing efficiency. It also helps improve code quality, thereby enhancing product reliability and stability.

[0003] Container development is a common software development model today. It offers advantages such as rapid deployment and dynamic scalability through container orchestration, significantly improving software delivery efficiency. Typically, code coverage collection requires obtaining both code coverage and source code for the software under test. However, traditional methods are not suitable for both code coverage collection and source code acquisition in today's container development model. Therefore, obtaining source code for the software under test in this model urgently needs to be addressed. Summary of the Invention

[0004] Based on this, it is necessary to provide a bytecode acquisition method, computer equipment, storage medium and program product that can obtain the source code of the tested software in a container development mode to address the above technical problems.

[0005] In a first aspect, the present application provides a bytecode acquisition method. The method comprises:

[0006] The code extraction server obtains and runs the image file to generate a container in the code extraction server; the code extraction server parses the image file to obtain a first storage path of the library and bytecode in the image file; the code extraction server parses the running information of the container to obtain a second storage path in the code extraction server of the program code corresponding to the container running; the code extraction server searches the second storage path for the program bytecode file corresponding to the image file according to the first storage path.

[0007] In one embodiment, the code extraction server parses the image file to obtain a first storage path of the library and bytecode in the image file, including: the code extraction server performs an initial parsing on the image file to obtain a data storage path in the image file; and the code extraction server searches the data storage path to obtain the first storage path.

[0008] In one embodiment, before the code extraction server obtains and runs the image file to generate a container in the code extraction server, the method further includes: the code extraction server pulling a target artifact from an artifact repository, the target artifact including the image file.

[0009] In one embodiment, the method further includes: the container orchestration server pulls the target artifact from the artifact warehouse and runs the image file contained in the target artifact to generate the container; the program in the container reads the configuration information pre-set in the container orchestration server, obtains a coverage collection tool based on the configuration information, and deploys the coverage collection tool to the container for execution; wherein the coverage collection tool is used to collect coverage for the program in the container.

[0010] In one embodiment, the configuration information includes a download address, and obtaining the coverage collection tool according to the configuration information includes: downloading the coverage collection tool according to the download address.

[0011] In one embodiment, the method further includes: the code packaging server sending a deployment request to the container orchestration server, where the deployment request is used to instruct the container orchestration platform to pull the target artifact from the artifact repository.

[0012] In one embodiment, the method further includes: the code packaging server obtains the program source code corresponding to the program bytecode; the code packaging server packages the program source code to form the image file; the code packaging server makes the target product according to the image file, and pushes the target product to the product warehouse for storage.

[0013] In one embodiment, the code packaging server obtains the program source code corresponding to the program bytecode, including: the code packaging server obtains code indication information; the code packaging server obtains the program source code from a code repository according to the code indication information.

[0014] In one embodiment, the method further includes: the coverage analysis server obtains coverage data corresponding to the program in the container collected by the coverage collection tool; the coverage analysis server obtains the program bytecode file; and the coverage analysis server generates an analysis report based on the coverage data and the program bytecode file.

[0015] In a second aspect, the present application further provides a computer device comprising a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of any one of the methods described in the first aspect when executing the computer program.

[0016] In a third aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of any one of the methods described in the first aspect above.

[0017] In a fourth aspect, the present application further provides a computer program product, which includes a computer program, and when the computer program is executed by a processor, it implements the steps of any one of the methods in the first aspect.

[0018] The above-mentioned bytecode acquisition method, computer device, storage medium and program product obtain and run the image file through the code extraction server to generate a container in the code extraction server; to obtain the bytecode file, the code extraction server parses the image file to obtain the first storage path of the library and bytecode in the image file. Furthermore, the code extraction server parses the running information of the container to obtain the second storage path of the program code corresponding to the container runtime in the code extraction server, so that the code extraction server can search the program bytecode file corresponding to the image file in the second storage path according to the first storage path, and realize the flexible acquisition of the corresponding program bytecode file in the running image file in the container development mode, so that the tester can view the code coverage in combination with the program bytecode file after obtaining it. At the same time, by centrally extracting the program bytecode file, the efficiency of obtaining the program bytecode file is greatly improved. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] Figure 1 Schematic diagram of a flow chart of a bytecode acquisition method in one embodiment;

[0020] Figure 2 A schematic diagram of a process for obtaining a first storage path in one embodiment;

[0021] Figure 3 A schematic diagram of a process for obtaining program source code in one embodiment;

[0022] Figure 4 A schematic diagram of a process for producing a target product in one embodiment;

[0023] Figure 5 A schematic diagram of a process for generating an analysis report in one embodiment;

[0024] Figure 6 Schematic diagram of the process of collecting coverage data and extracting bytecodes in a container in one embodiment;

[0025] Figure 7 FIG. 1 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION

[0026] In order to make the purpose, technical solutions and advantages of this application more clear, the following further describes this application in detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain this application and are not intended to limit this application.

[0027] In software development, the primary goal of software testing is to ensure software quality. Code coverage is a key metric for measuring test completeness. Coverage is measured by the coverage of test requirements and test cases, or the coverage of executed code. Code coverage measures the effectiveness of testing and improves testing efficiency. It also improves code quality and reduces defects, thereby enhancing product reliability and stability.

[0028] Traditional software development and deployment typically deploys business programs on relatively fixed servers. In these scenarios, the server's network and storage configuration information changes little or remains virtually unchanged. Coverage collection and analysis tools deployed directly on the host where the business program is deployed can collect coverage of the business code and upload the corresponding coverage data and source code. However, this simple and relatively fixed configuration collection method is not suitable for collection work in today's container model. An image is a special file system that provides libraries of programs and dependent programs required for container runtime. It is a read-only file system that serves as a template for the container. A container is the entity on which the image runs. The relationship between an image and a container is like that between a class and an instance in object-oriented programming: an image becomes a container after it runs.

[0029] The container development model is a common software development model today. It offers advantages such as rapid deployment and dynamic scalability through container orchestration, significantly improving software delivery efficiency. Microservices' low coupling, rapid startup, and scalability are driving increasing adoption of this architecture for software development. Java source code, when run in the container development model, generates bytecode files with the extension .class. This bytecode file is required during software testing.

[0030] However, while software development in today's containerized model has improved efficiency, it also means that code coverage collection is no longer as straightforward as with traditional configurations. Key challenges include: 1. On traditional servers, coverage collection requires only configuring the coverage collection tool and output data to a specified directory. However, for containers, the code required for coverage collection is not part of the software itself, and packaging it into an image file would result in an excessively large image file. 2. In traditional server deployment models, both the coverage data and program source code collected are stored on the deployed server, and the storage path is relatively fixed. Therefore, obtaining coverage data and program bytecode in traditional deployment models is relatively easy. However, in container deployment models, the tested code in the software is non-persistent and is cleared upon container restart. Therefore, the program bytecode in the container cannot be retrieved, preventing operations and maintenance personnel from making changes to the code based on coverage data. Therefore, obtaining the program bytecode files in containers deployed in containerized models is a pressing issue during software testing.

[0031] In view of this, the present application provides a bytecode acquisition method to solve the above-mentioned problem of being unable to obtain program bytecode files in the container development mode.

[0032] In one embodiment, Figure 1 As shown, a bytecode acquisition method is provided. The embodiment of the present application uses the method applied to a server as an example for illustration. It is understandable that the method can also be applied to a terminal, and can also be applied to a system including a terminal and a server, and implemented through the interaction between the terminal and the server. The server can be implemented as an independent server or a server cluster consisting of multiple servers. The method includes the following steps:

[0033] Step 101: The code extraction server obtains and runs the image file to generate a container in the code extraction server.

[0034] Among them, for the software program under test, the image file contains information such as the source code of the software program, the libraries of the dependent programs, and the operating environment of the source code. The image file is a template for the container, and the container is the entity after the image file is run. After the image file is run in the code extraction server, the corresponding container is generated, so the source code can be obtained from the container, among which the Docker image is a commonly used image. The code extraction server is used to run the image file to generate the container. Optionally, a container program extraction tool can be pre-installed in the code extraction server, and the tool runs in the code extraction server to enable the code extraction server to obtain and run the image file to generate the container, and subsequently obtain the source code.

[0035] Step 102: The code extraction server parses the image file to obtain a first storage path of the library and bytecode in the image file.

[0036] Java source code is compiled into a bytecode file, so obtaining the bytecode file allows you to retrieve the source code. Source code also relies on related libraries, so you need to obtain the libraries the source code depends on and the bytecode corresponding to the source code to retrieve the source code.

[0037] Optionally, the code extraction server is pre-installed with an image packaging command tool, and the code extraction server can parse the image file through the image packaging command tool to obtain the storage path of the library and bytecode in the image file to obtain the first storage path.

[0038] Step 103: The code extraction server parses the running information of the container to obtain a second storage path of the program code corresponding to the container when it is running in the code extraction server.

[0039] The code extraction server runs the image file in a specific path, which is the container's runtime information. By parsing this runtime information, the path mapped to the container runtime on the code server is obtained, which is the second storage path of the program code for the container runtime on the extraction server. This program code includes libraries and bytecode.

[0040] Step 104: The code extraction server searches the second storage path for the program bytecode file corresponding to the image file according to the first storage path.

[0041] The image file code is extracted and run under the second storage path in the server to generate a container. Specifically, the libraries and bytecodes in the image file are stored in the first storage path. Therefore, after the image file is run to generate a container, the path for the container to run in the code server is first determined based on the first storage path. Furthermore, under the first storage path, the libraries and bytecodes are continuously searched according to the second storage path, thereby obtaining the libraries and bytecodes in the container. Based on the libraries and bytecodes, a program bytecode file is generated, that is, a program bytecode file corresponding to the image file is obtained. The program bytecode file contains the bytecode of the program of the software under test. When analyzing the coverage of the software under test, the program bytecode file can be combined for specific viewing and analysis.

[0042] The above-mentioned bytecode acquisition method obtains and runs the image file through the code extraction server to generate a container in the code extraction server. To obtain the bytecode file, the code extraction server parses the image file to obtain the first storage path of the library and bytecode in the image file. Furthermore, the code extraction server parses the running information of the container to obtain the second storage path of the program code corresponding to the container runtime in the code extraction server. The code extraction server can then search the second storage path for the program bytecode file corresponding to the image file according to the first storage path, thereby achieving flexible acquisition of the corresponding program bytecode file in the running image file in the container development mode, so that the tester can view the code coverage in combination with the program bytecode file after obtaining it. At the same time, by centrally extracting the program bytecode file, the efficiency of obtaining the program bytecode file is greatly improved.

[0043] In one embodiment, Figure 2 As shown, it shows a schematic diagram of a process for obtaining a first storage path provided by an embodiment of the present application. The code extraction server parses the image file to obtain the first storage path of the library and bytecode in the image file, including:

[0044] Step 201: The code extraction server performs an initial analysis on the image file to obtain a data storage path in the image file.

[0045] Specifically, during the image file creation process, source code-related data is usually stored in directories related to COPY or ADD. Therefore, based on this storage rule, the data storage path of source code-related data in the image file can be obtained. The source code-related data includes libraries and source code.

[0046] Step 202: The code extraction server searches the data storage path to obtain the first storage path.

[0047] Among them, under this data storage path, libraries and bytecodes are stored, so it is necessary to further obtain the paths of the libraries and bytecodes to obtain the first storage path. Usually, the storage path of the library is named LIB_PATH, and the storage path of the bytecode is CLASSES_PATH. Therefore, the code extraction server searches for LIB_PATH in the data storage path to obtain the first storage path of the library, and searches for CLASSES_PATH in the data storage path to obtain the first storage path of the bytecode. Optionally, the first storage path of the library and bytecode can be saved in an info file, where the info file refers to an ordinary text file. In the process of searching the first storage path based on the second storage path to obtain the library and bytecode, the first storage path can be directly obtained from the info file.

[0048] In an embodiment of the present application, by obtaining the data storage path in the image file and searching for the first storage path of the library and bytecode based on the data storage path, the first storage path is accurately obtained, the efficiency and accuracy of obtaining the first storage path are improved, and the server running time is effectively reduced.

[0049] In one embodiment, before the code extraction server obtains and runs the image file to generate a container in the code extraction server, the method further includes: the code extraction server pulling a target artifact from an artifact repository, the target artifact including the image file.

[0050] Artifacts are stored in an artifact repository and contain image files, with one artifact corresponding to one software program. For a software program under test, its corresponding source code can be packaged to generate multiple image files based on actual circumstances. Correspondingly, the artifact corresponding to the program code contains multiple image files, the order in which each image file is run, and information such as the name and version number of each image file. A code extraction server can retrieve the target artifact corresponding to the software under test from the artifact repository, run each image file in the order in which the image files in the artifact are run, generate a container, and further retrieve the bytecode within the container.

[0051] The image file in the product is obtained by packaging the source code. Therefore, the following is the process of obtaining the source code of the software program under test.

[0052] Please refer to Figure 3 , which shows a schematic diagram of a process for obtaining program source code provided by an embodiment of the present application. The code packaging server obtains the program source code corresponding to the program bytecode, including:

[0053] Step 301: The code packaging server obtains code indication information.

[0054] Among them, the code packaging server is used to package the target source code according to the code indication information to generate an image file. Among them, the code indication information is used to instruct the code packaging server which source code to package to generate the image file, and further obtain the target product. Optionally, the CI / CD platform can be integrated into the code packaging server to achieve tasks such as obtaining code indication information and packaging source code. Among them, the CI / CD platform is a continuous integration and continuous delivery platform, which can provide functions such as source code packaging and deployment delivery of software programs. Testers can establish a pipeline task in the CI / CD platform, and the pipeline task contains code indication information, which is used for the CI / CD platform to obtain the corresponding target source code according to the code indication information and package it. Usually, a pipeline task corresponds to a software program. For example, for a target software program, the tester establishes a pipeline task corresponding to the target software program. The pipeline task table tests the source code related to the target software program, and obtains the coverage rate during the test process and the bytecode corresponding to the source code.

[0055] Step 302: The code packaging server obtains the program source code from the code repository according to the code indication information.

[0056] A code repository is a server used to store and manage source code during software development. It contains the source code for multiple software programs. Therefore, the code packaging server can retrieve the source code for the software program under test from the code repository based on the code indication information, use it to generate an image file, and further obtain the corresponding target product.

[0057] Please refer to Figure 4 , which shows a schematic diagram of a process for producing a target product provided by an embodiment of the present application. The product warehouse is used to store products, including:

[0058] Step 401: The code packaging server obtains the program source code corresponding to the program bytecode.

[0059] Among them, the code packaging server can obtain the program source code from the code warehouse according to the code indication information. The program source code is JAVA source code, which becomes program bytecode after being run. Therefore, the program source code corresponding to the program bytecode is obtained, and the image file is further generated according to the code indication information.

[0060] Step 402: The code packaging server packages the program source code to form the image file.

[0061] Among them, the code packaging server packages the program source code to form a mirror file. Optionally, if the code indication information indicates that the program source code to be obtained will be packaged into multiple mirror files, the code packaging server packages the program source code into multiple mirror files according to the code indication information and synchronously generates information such as the name and version number of each mirror file, and further obtains the target product.

[0062] In step 403, the code packaging server creates the target product according to the image file and pushes the target product to the product warehouse for storage.

[0063] Among them, the code packaging server produces the target product based on the generated image file and simultaneously generates the version number of the target product. In the case of generating multiple image files, the target product contains multiple image files, the running order of each image file, and the name and version number of each image file. The generated target product corresponds to the software being tested. In addition, the code packaging server pushes the target product and the version number of the target product to the product warehouse for storage. The product warehouse can store the target product and the version number in correspondence. Among them, the product warehouse is a server that stores and manages the products corresponding to each software program.

[0064] Correspondingly, the CI / CD platform can be integrated into the code packaging server. Therefore, the CI / CD platform can be used to implement the above steps of obtaining the program source code corresponding to the program bytecode, packaging the program source code to form the image file, and making the target product based on the image file, and pushing the target product to the product warehouse for storage.

[0065] In one embodiment, the method further includes: the code packaging server sending a deployment request to the container orchestration server, where the deployment request is used to instruct the container orchestration platform to pull the target artifact from the artifact repository.

[0066] Among them, the container orchestration server may be pre-installed with a container orchestration tool, which is a tool that provides automated container deployment, management, and expansion. Common container orchestration tools include Kubernetes. After generating the target product, it is necessary to run the image file in the target product to generate the container and test the source code. Specifically, the operation of the container can be implemented in the container orchestration server. Therefore, after generating the target product, the code packaging server sends a deployment request to the container orchestration server to instruct the container orchestration platform to pull the target product from the product warehouse and run it. Among them, the deployment request contains the version number of the target product, so that the container orchestration server can pull the corresponding target product from the product warehouse according to the version number.

[0067] During software program testing, while containers are running on a container orchestration server, coverage data can be obtained from the source code testing process, allowing testers to clearly assess the quality of the source code. The following describes the process of obtaining coverage data during source code testing.

[0068] In one embodiment, the method further includes: the container orchestration server pulls the target artifact from the artifact warehouse and runs the image file contained in the target artifact to generate the container; the program in the container reads the configuration information pre-set in the container orchestration server, obtains a coverage collection tool based on the configuration information, and deploys the coverage collection tool to the container for execution; wherein the coverage collection tool is used to collect coverage for the program in the container.

[0069] The configuration information includes a download address, and obtaining the coverage collection tool according to the configuration information includes: downloading the coverage collection tool according to the download address.

[0070] Among them, the container orchestration server pulls the target product according to the deployment request and runs the image file therein to generate a container. During the operation of the container, the coverage of the source code can be obtained. Therefore, the container orchestration server is preset with configuration information so that the program in the container pulls the coverage collection tool according to the configuration information and deploys it in the container for operation, thereby obtaining the coverage data of the source code through the coverage collection tool. Specifically, the configuration information contains the download address of the coverage collection tool, and the program in the container downloads the coverage collection tool according to the download address and deploys it in the container. Optionally, the download address can be a file path, and the coverage collection tool can be obtained through this path.

[0071] Optionally, the coverage collection tool may be Jacoco. Jacoco is a code coverage detection tool that can insert probes into source code and detect whether the probes are executed, thereby obtaining source code coverage data, and is often used for analyzing source code test results.

[0072] In the embodiment of the present application, the coverage tool and the product deployment are independently operated through split modularization, which reduces the impact of the coverage collection tool on the container itself and improves the efficiency of coverage data collection. Specifically, the deployment of the coverage collection tool is controlled by variables, so that the container can download and deploy the coverage collection tool on demand, flexibly control the collection switch of the coverage collection tool, and the image file does not contain the coverage collection tool, so the problem of the image file being too large will not occur. The separate deployment of the coverage collection tool and the container minimizes the impact of the coverage collection work on the container itself, does not occupy container resources, and reduces the coupling degree of the collected data.

[0073] Based on the program bytecode files found by the code extraction server and the coverage data collected by the above-mentioned coverage collection tool, an analysis report for the tested software can be generated.

[0074] Please refer to Figure 5 , which shows a schematic diagram of a process for generating an analysis report provided by an embodiment of the present application. The bytecode acquisition method also includes:

[0075] Step 501: The coverage analysis server obtains coverage data corresponding to the program in the container collected by the coverage collection tool.

[0076] Step 502: The coverage analysis server obtains the program bytecode file.

[0077] The coverage analysis server is primarily used to obtain coverage data collected by the coverage acquisition tool and program bytecode files obtained by the code extraction server. Optionally, the coverage acquisition tool can establish a socket connection with the coverage analysis server to send the collected coverage data corresponding to the program in the container to the coverage analysis server. The code extraction server can also send the program bytecode files to the coverage analysis server after finding them.

[0078] Step 503: The coverage analysis server generates an analysis report based on the coverage data and the program bytecode file.

[0079] The coverage analysis server generates an analysis report based on the acquired coverage data and the program bytecode files. Optionally, a coverage analysis platform can be integrated into the coverage analysis server. The coverage analysis platform can provide various functions, such as aggregation, analysis, display, and query of coverage data. After the analysis report is generated, it is displayed on the coverage analysis platform for testers to review, compare coverage data, and improve the program bytecode files.

[0080] In the embodiment of the present application, by generating an analysis report, the tester can check the code defects involved in the coverage data and modify the source code in a timely manner.

[0081] In one embodiment, a program bytecode extraction system is provided, comprising a CI / CD platform, a container orchestration platform, a coverage analysis platform, a code repository, an artifact repository, and a container program bytecode extraction tool. The CI / CD platform, the container orchestration platform, and the coverage analysis platform can be implemented using a single server or a server cluster consisting of multiple servers, and the container program bytecode extraction tool can run on any of these servers. The code repository and artifact repository can also be implemented using a single server or a server cluster consisting of multiple servers.

[0082] Please refer to Figure 6 , which shows a schematic flow chart of coverage data collection and bytecode extraction in a container provided in an embodiment of the present application.

[0083] During the code development phase, developers develop code programs and store them in a code repository, which contains code programs corresponding to multiple software programs.

[0084] During the container deployment phase, testers configure pipeline tasks on the CI / CD platform. Based on the target software information included in the pipeline task, the CI / CD platform retrieves the code corresponding to the target software from the code repository and compiles it according to the compilation strategy configured in the pipeline task, packaging the code into a compressed package in jar or war format. After compilation, multiple Docker images are built based on the configuration files provided in the code repository. The target artifact is generated from these multiple images and its corresponding version number is also generated. The target artifact contains multiple image files, the name and version number of each image, and the order in which each image file is executed.

[0085] The CI / CD platform pushes the target artifacts to an artifact repository for storage. The artifact repository provides storage and management for artifacts during the software development process. The CI / CD platform then sends a deployment request to the container orchestration platform, instructing it to pull the target artifacts from the artifact repository and deploy them.

[0086] Based on the version number included in the deployment request, the container orchestration platform pulls the target artifact from the artifact repository to the local machine and runs it on the specified server. The image file in the target artifact generates a container after running. During the container startup process, the program in the container reads the download address of the coverage collection tool pre-configured in the container orchestration platform, and downloads the coverage collection tool jacoco based on the download address, deploying the coverage collection tool in the container and running it synchronously. The program in the container will also synchronously start the coverage collection tool during the startup process, so that the coverage collection tool can be used to collect coverage data of the code in the container. The coverage collection tool establishes a socket connection with the coverage analysis platform, thereby sending the collected coverage data to the coverage analysis platform.

[0087] During the coverage analysis phase, the coverage analysis platform sends a bytecode extraction request to the container program bytecode extraction tool. This bytecode extraction request contains the target artifact version number. Based on the version number in the bytecode extraction request, the container bytecode extraction tool pulls the target artifact from the artifact repository to its local machine, runs the image file in the target artifact, and generates a container.

[0088] The container bytecode extraction tool also uses the image packaging command tool to parse the image file in the target artifact. Based on the directories related to COPY or ADD during the image file creation process, it obtains the initial path of the code program to be extracted. Then, within this initial path, it searches the LIB_PATH path to obtain the root path of the libraries that the code program depends on. Within this initial path, it searches the CLASSES_PATH path to obtain the root path of the bytecode corresponding to the code program, and stores each root path in the info file.

[0089] The container bytecode extraction tool also parses the data path mapped to the server during container runtime based on the container running information. Under this data path, combined with the root path, it obtains the library and bytecode corresponding to the code program, and generates a program bytecode file based on the obtained library and bytecode, and sends the program bytecode file to the coverage analysis platform.

[0090] Coverage analysts can view coverage data and program bytecode files corresponding to the pipeline tasks configured by the tester on the coverage analysis platform.

[0091] The program bytecode extraction system provided in this application solves the problem that traditional coverage collection methods are unavailable in container mode. Through a split modular design, collection and analysis tasks are deployed and run independently, reducing the impact of coverage collection on the container and improving the efficiency of coverage collection and analysis.

[0092] The deployment of the coverage collection tool is controlled by variables, enabling on-demand download and deployment of the coverage collection tool during container startup. This allows for flexible control over the coverage collection switch, and the image does not contain the coverage collection tool program, thus not affecting the image size. The separate deployment design of coverage collection and analysis tools minimizes the impact of coverage collection on business containers, preventing the preemption of business container resources and reducing the coupling between collection and analysis. The container bytecode extraction tool is deployed and run separately, rather than directly within the business container. This reduces intrusion into the business container and enables centralized extraction of program bytecode, greatly improving extraction efficiency.

[0093] It should be understood that, although the various steps in the flowcharts involved in the various embodiments described above are displayed in sequence according to the instructions of the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and these steps can be executed in other orders. Moreover, at least a portion of the steps in the flowcharts involved in the various embodiments described above can include multiple steps or multiple stages, and these steps or stages are not necessarily executed and completed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a portion of steps or stages in other steps.

[0094] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Figure 7 As shown. The computer device includes a processor, a memory, and a network interface connected via a system bus. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program, and a database. The internal memory provides an environment for the operation of the operating system and computer program in the non-volatile storage medium. The database of the computer device is used to store bytecode acquisition data. The network interface of the computer device is used to communicate with an external terminal via a network connection. When the computer program is executed by the processor, a bytecode acquisition method is implemented.

[0095] Those skilled in the art will understand that Figure 7 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than shown in the figure, or combine certain components, or have a different component arrangement.

[0096] In one embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and when the processor executes the computer program, the following steps are implemented:

[0097] Obtain and run an image file to generate a container; parse the image file to obtain a first storage path for libraries and bytecodes in the image file; parse running information of the container to obtain a second storage path for program code corresponding to the container runtime; and search the second storage path for a program bytecode file corresponding to the image file according to the first storage path.

[0098] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:

[0099] The image file is initially parsed to obtain a data storage path in the image file; and the first storage path is obtained by searching the data storage path.

[0100] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:

[0101] Pull the target artifact from the artifact repository, which contains the image file.

[0102] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:

[0103] Obtain code instruction information; obtain the program source code from the code repository according to the code instruction information.

[0104] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:

[0105] Obtain the program source code corresponding to the program bytecode; package the program source code to form the image file; produce the target product based on the image file, and push the target product to the product warehouse for storage.

[0106] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:

[0107] Send a deployment request, which is used to instruct the target artifact to be pulled from the artifact warehouse.

[0108] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:

[0109] Pulling a target artifact from an artifact repository and running the image file contained in the target artifact to generate the container; a program in the container reads configuration information, obtains a coverage collection tool based on the configuration information, and deploys the coverage collection tool into the container for execution; wherein the coverage collection tool is used to collect coverage for the program in the container. The configuration information includes a download address, and obtaining the coverage collection tool based on the configuration information includes: downloading the coverage collection tool based on the download address.

[0110] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:

[0111] Obtain coverage data corresponding to the program in the container collected by the coverage collection tool; obtain the program bytecode file; and generate an analysis report based on the coverage data and the program bytecode file.

[0112] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the following steps are implemented:

[0113] Obtain and run an image file to generate a container; parse the image file to obtain a first storage path for libraries and bytecodes in the image file; parse running information of the container to obtain a second storage path for program code corresponding to the container runtime; and search the second storage path for a program bytecode file corresponding to the image file according to the first storage path.

[0114] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:

[0115] The image file is initially parsed to obtain a data storage path in the image file; and the first storage path is obtained by searching the data storage path.

[0116] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:

[0117] Pull the target artifact from the artifact repository, which contains the image file.

[0118] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:

[0119] Obtain code instruction information; obtain the program source code from the code repository according to the code instruction information.

[0120] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:

[0121] Obtain the program source code corresponding to the program bytecode; package the program source code to form the image file; produce the target product based on the image file, and push the target product to the product warehouse for storage.

[0122] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:

[0123] Send a deployment request, which is used to instruct the target artifact to be pulled from the artifact warehouse.

[0124] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:

[0125] Pulling a target artifact from an artifact repository and running the image file contained in the target artifact to generate the container; a program in the container reads configuration information, obtains a coverage collection tool based on the configuration information, and deploys the coverage collection tool into the container for execution; wherein the coverage collection tool is used to collect coverage for the program in the container. The configuration information includes a download address, and obtaining the coverage collection tool based on the configuration information includes: downloading the coverage collection tool based on the download address.

[0126] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:

[0127] Obtain coverage data corresponding to the program in the container collected by the coverage collection tool; obtain the program bytecode file; and generate an analysis report based on the coverage data and the program bytecode file.

[0128] In one embodiment, a computer program product is provided, comprising a computer program, which, when executed by a processor, implements the following steps:

[0129] Obtain and run an image file to generate a container; parse the image file to obtain a first storage path for libraries and bytecodes in the image file; parse running information of the container to obtain a second storage path for program code corresponding to the container runtime; and search the second storage path for a program bytecode file corresponding to the image file according to the first storage path.

[0130] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:

[0131] The image file is initially parsed to obtain a data storage path in the image file; and the first storage path is obtained by searching the data storage path.

[0132] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:

[0133] Pull the target artifact from the artifact repository, which contains the image file.

[0134] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:

[0135] Obtain code instruction information; obtain the program source code from the code repository according to the code instruction information.

[0136] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:

[0137] Obtain the program source code corresponding to the program bytecode; package the program source code to form the image file; produce the target product based on the image file, and push the target product to the product warehouse for storage.

[0138] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:

[0139] Send a deployment request, which is used to instruct the target artifact to be pulled from the artifact warehouse.

[0140] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:

[0141] Pulling a target artifact from an artifact repository and running the image file contained in the target artifact to generate the container; a program in the container reads configuration information, obtains a coverage collection tool based on the configuration information, and deploys the coverage collection tool into the container for execution; wherein the coverage collection tool is used to collect coverage for the program in the container. The configuration information includes a download address, and obtaining the coverage collection tool based on the configuration information includes: downloading the coverage collection tool based on the download address.

[0142] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:

[0143] Obtain coverage data corresponding to the program in the container collected by the coverage collection tool; obtain the program bytecode file; and generate an analysis report based on the coverage data and the program bytecode file.

[0144] It should be noted that the bytecode acquisition method, computer equipment, storage medium and program product provided in this application can be used in the software testing and development process in the financial field, and can also be used in the software testing and development process in any field other than the financial field. The application field of the bytecode acquisition method, computer equipment, storage medium and program product provided in this application is not limited.

[0145] Those skilled in the art will appreciate that all or part of the processes in the above-mentioned embodiment methods can be implemented by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, database or other media used in the embodiments provided in this application may include at least one of non-volatile and volatile memory. Non-volatile memory may include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory may include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in the various embodiments provided herein may include at least one of a relational database and a non-relational database. Non-relational databases may include, but are not limited to, distributed databases based on blockchains. The processor involved in the various embodiments provided herein may be, but are not limited to, a general-purpose processor, a central processing unit, a graphics processing unit, a digital signal processor, a programmable logic unit, a data processing logic unit based on quantum computing, and the like.

[0146] The technical features of the above embodiments can be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0147] The above-described embodiments merely represent several implementation methods of the present application. While the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the present application. It should be noted that a person of ordinary skill in the art may make various modifications and improvements without departing from the spirit of the present application, and these modifications and improvements fall within the scope of protection of the present application. Therefore, the scope of protection of the present application shall be determined by the appended claims.

Claims

1. A bytecode acquisition method, characterized in that: The method comprises: The code extraction server pulls the target artifact from the artifact warehouse, and the target artifact includes an image file and a version number; The code extraction server runs the image file contained in the target product to generate a container in the code extraction server; The code extraction server parses the image file to obtain a first storage path of the library and bytecode in the image file; The code extraction server parses the running information of the container to obtain a second storage path of the program code corresponding to the container running in the code extraction server; The code extraction server searches the second storage path for the program bytecode file corresponding to the image file according to the first storage path; The method further comprises: The container orchestration server pulls the target artifact from the artifact warehouse and runs the image file contained in the target artifact to generate the container; The program in the container reads configuration information pre-set in the container orchestration server, obtains a coverage collection tool based on the configuration information, and deploys the coverage collection tool in the container for execution; wherein the coverage collection tool is used to collect coverage for the program in the container.

2. The method according to claim 1, characterized in that The code extraction server parses the image file to obtain a first storage path of the library and bytecode in the image file, including: The code extraction server performs a preliminary analysis on the image file to obtain a data storage path in the image file; The code extraction server searches the data storage path to obtain the first storage path.

3. The method according to claim 1, characterized in that The configuration information includes a download address, and obtaining the coverage collection tool according to the configuration information includes: Download the coverage collection tool according to the download address.

4. The method according to claim 1, wherein The method further comprises: The code packaging server sends a deployment request to the container orchestration server, where the deployment request is used to instruct the container orchestration platform to pull the target artifact from the artifact warehouse.

5. The method according to claim 4, characterized in that The method further comprises: The code packaging server obtains the program source code corresponding to the program bytecode; The code packaging server packages the program source code to form the image file; The code packaging server creates the target product according to the image file, and pushes the target product to the product warehouse for storage.

6. The method according to claim 5, characterized in that The code packaging server obtains the program source code corresponding to the program bytecode, including: The code packaging server obtains code indication information; The code packaging server obtains the program source code from a code repository according to the code indication information.

7. The method according to claim 1, characterized in that The method further comprises: The coverage analysis server obtains coverage data corresponding to the program in the container collected by the coverage collection tool; The coverage analysis server obtains the program bytecode file; The coverage analysis server generates an analysis report according to the coverage data and the program bytecode file.

8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.

10. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.

Citation Information

Patent Citations

  • Terminal code coverage rate monitoring method and system, medium and electronic device

    CN110245073A

  • Method and system for realizing container mirror image by adopting web language

    CN111352692A

  • Containerization processing method and device for code assembly line, medium and equipment

    CN113778486A