Method, apparatus, electronic device and storage medium for testing system code

By obtaining the class and function indices of the entire system code and generating function call chains, the problem of accurate and automatic analysis of the impact scope of code changes is solved, achieving low-cost and high-accuracy analysis results.

CN114328254BActive Publication Date: 2026-01-06BEIJING BAIDU NETCOM SCI & TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202111669896.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-30
Publication Date
2026-01-06
Estimated Expiration
2041-12-30

AI Technical Summary

Technical Problem

The lack of accurate and automated analysis methods for the scope of code changes in existing technologies leads to high analysis costs and low accuracy of analysis results.

Method used

Based on the full system code, class and function indices are obtained, a full function call chain is generated, and the class set corresponding to the change information is obtained through index data and change information for code testing.

Benefits of technology

It enables precise analysis of the impact scope of code changes, reducing analysis costs and improving accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114328254B_ABST
    Figure CN114328254B_ABST
Patent Text Reader

Abstract

The present disclosure provides a method and device for testing system code, electronic equipment and storage medium, relating to the technical field of computer, to at least solve the technical problem of high analysis cost and low analysis result accuracy caused by the lack of precise automatic analysis method of code change influence range in the prior art. The specific implementation scheme is: obtaining first index data and second index data based on target code, wherein the target code is the full system code, the first index data is the full class index, and the second index data is the full function index; generating a target call chain using the target code and the second index data, wherein the target call chain is the full function call chain; obtaining a target class set corresponding to the change information through the first index data, the change information of the target code and the target call chain; and performing code testing according to the target class set.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the field of computer technology, and in particular to methods, apparatus, electronic devices, and storage media for testing system code. Background Technology

[0002] In software development, code changes are frequently necessary; however, these changes have a range of impacts. For example, a single line of code change directly affects the current function, which in turn affects the callers of that function, consequently impacting class variables and related user entry points. Because the entire system's codebase contains numerous complex function call relationships, and the impact of class variable changes on user entry points may be hidden, the scope of impact of some code changes is difficult to determine. Therefore, those skilled in the art are constantly exploring various methods to automatically determine the scope of impact of code changes during software testing.

[0003] In the relevant solutions, there are three main methods for determining the scope of impact of code changes:

[0004] (1) By establishing a mapping between functional keywords and entry code classes, the scope of code affected by the functional keywords can be located based on this mapping and the call chain of the entry code classes. The drawback of this method is that it relies on the search of functional keywords and code standardization, and cannot determine the complete scope of impact.

[0005] (2) By comparing the differences in code before and after the change through the pre-configured correspondence between methods and functional points in the code library, the scope of impact can be automatically analyzed. The drawbacks of this method are: poor accuracy and effectiveness of the analysis results, high human maintenance costs, and difficulty in implementation in practical application scenarios.

[0006] (3) Based on code development integration tools, the impact range is analyzed by triggering breakpoints between entry points and changed functions. The drawback of this method is that some entry points are easily missed, leading to inaccurate analysis results.

[0007] Therefore, how to more accurately and automatically analyze the full impact scope of code changes has become a crucial issue in current software testing. Currently, no effective solution has been proposed to address this problem. Summary of the Invention

[0008] This disclosure provides methods, apparatus, electronic devices, and storage media for testing system code, in order to at least solve the technical problems of high analysis costs and low accuracy of analysis results caused by the lack of accurate automatic analysis methods for the scope of code changes in the prior art.

[0009] According to one embodiment of this disclosure, a method for testing system code is provided, comprising: obtaining first index data and second index data based on target code, wherein the target code is the full system code, the first index data is the full class index, and the second index data is the full function index; generating a target call chain using the target code and the second index data, wherein the target call chain is the full function call chain; obtaining a target class set corresponding to the change information through the first index data, change information of the target code, and the target call chain; and performing code testing based on the target class set.

[0010] According to one embodiment of this disclosure, an apparatus for testing system code is also provided, comprising: a first acquisition module, configured to acquire first index data and second index data based on target code, wherein the target code is the full system code, the first index data is the full class index, and the second index data is the full function index; a generation module, configured to generate a target call chain using the target code and the second index data, wherein the target call chain is the full function call chain; a second acquisition module, configured to acquire a set of target classes corresponding to the change information through the first index data, change information of the target code, and the target call chain; and a testing module, configured to perform code testing based on the set of target classes.

[0011] According to one embodiment of the present disclosure, an electronic device is also provided, including: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor to enable the at least one processor to execute the test system code proposed in the present disclosure.

[0012] According to one embodiment of the present disclosure, a non-transitory computer-readable storage medium storing computer instructions is also provided, wherein the computer instructions are used to cause a computer to execute the test system code proposed in the present disclosure.

[0013] According to one embodiment of this disclosure, a computer program product is also provided, including a computer program, wherein the computer program is executed by a processor using the method of test system code proposed in this disclosure.

[0014] In the embodiments of this disclosure, first index data and second index data are obtained based on the target code. The target code is the full system code, the first index data is the full class index, and the second index data is the full function index. A target call chain is generated using the target code and the second index data. The target call chain is the full function call chain. A method based on the first index data, the change information of the target code, and the target call chain is used to obtain the target class set corresponding to the change information. Then, code testing is performed based on the target class set. This achieves the goal of determining the scope of influence of the changed code through the joint analysis method of the index call of the full code. It realizes the technical effect of reducing the analysis cost and increasing the accuracy of the analysis of the scope of influence of the changed code, and solves the technical problem in related technologies that the lack of accurate automatic analysis methods for the scope of influence of code changes leads to high analysis costs and low accuracy of analysis results.

[0015] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of this disclosure, nor is it intended to limit the scope of this disclosure. Other features of this disclosure will become readily apparent from the following description. Attached Figure Description

[0016] The accompanying drawings are provided to better understand this solution and do not constitute a limitation of this disclosure. Wherein:

[0017] Figure 1 This is a hardware structure block diagram of a computer terminal (or mobile device) for implementing test system code according to an embodiment of the present disclosure;

[0018] Figure 2 This is a flowchart of a method for testing system code according to an embodiment of the present disclosure;

[0019] Figure 3 This is a schematic diagram of an optional class index data structure according to an embodiment of the present disclosure;

[0020] Figure 4 This is a schematic diagram of an optional function index data structure according to an embodiment of the present disclosure;

[0021] Figure 5 This is a schematic diagram of an optional function call chain lookup process according to an embodiment of the present disclosure;

[0022] Figure 6 This is a schematic diagram of an optional mesh function call chain structure according to an embodiment of the present disclosure;

[0023] Figure 7 This is a schematic diagram of an optional target class cyclic search process according to an embodiment of the present disclosure;

[0024] Figure 8This is a structural block diagram of an apparatus for testing system code according to an embodiment of the present disclosure;

[0025] Figure 9 This is a structural block diagram of an apparatus for another test system code according to an embodiment of the present disclosure. Detailed Implementation

[0026] The exemplary embodiments of this disclosure are described below with reference to the accompanying drawings, including various details of the embodiments to aid understanding, and should be considered merely exemplary. Therefore, those skilled in the art will recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of this disclosure. Similarly, for clarity and brevity, descriptions of well-known functions and structures are omitted in the following description.

[0027] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this disclosure 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 so that the embodiments of this disclosure described herein can be implemented in orders other than those illustrated or 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.

[0028] According to embodiments of this disclosure, a method for testing system code is provided. It should be noted that the steps shown in the flowcharts in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowcharts, in some cases, the steps shown or described may be executed in a different order than that shown here.

[0029] The method embodiments provided in this disclosure can be performed in a mobile terminal, computer terminal, or similar electronic device. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the disclosure described and / or claimed herein. Figure 1This is a hardware structure block diagram of a computer terminal (or mobile device) for implementing test system code according to an embodiment of the present disclosure.

[0030] like Figure 1 As shown, the computer terminal 100 includes a computing unit 101, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 102 or a computer program loaded from a storage unit 108 into a random access memory (RAM) 103. The RAM 103 may also store various programs and data required for the operation of the computer terminal 100. The computing unit 101, ROM 102, and RAM 103 are interconnected via a bus 104. An input / output (I / O) interface 105 is also connected to the bus 104.

[0031] Multiple components in the computer terminal 100 are connected to the I / O interface 105, including: an input unit 106, such as a keyboard and mouse; an output unit 107, such as various types of displays and speakers; a storage unit 108, such as a hard disk and optical disk; and a communication unit 109, such as a network interface card (NIC), a modem, or a wireless transceiver. The communication unit 109 allows the computer terminal 100 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.

[0032] The computing unit 101 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of the computing unit 101 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. The computing unit 101 executes the method of testing system code described herein. For example, in some embodiments, the method of testing system code may be implemented as a computer software program tangibly contained in a machine-readable medium, such as storage unit 108. In some embodiments, part or all of the computer program may be loaded and / or installed on the computer terminal 100 via ROM 102 and / or communication unit 109. When the computer program is loaded into RAM 103 and executed by the computing unit 101, one or more steps of the method of locating a faulty hard disk described herein may be performed. Alternatively, in other embodiments, the computing unit 101 may be configured to execute the method of locating a faulty hard disk by any other suitable means (e.g., by means of firmware).

[0033] Various implementations of the systems and techniques described herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), payload-programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations may include: implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transferring data and instructions to the storage system, the at least one input device, and the at least one output device.

[0034] It should be noted here that, in some optional embodiments, the above... Figure 1 The electronic device shown may include hardware elements (including circuitry), software elements (including computer code stored on a computer-readable medium), or a combination of both hardware and software elements. It should be noted that... Figure 1 This is only one instance of a specific particular example, and is intended to illustrate the types of components that may exist in the aforementioned electronic devices.

[0035] Under the aforementioned operating environment, this disclosure provides, for example... Figure 2 The method shown in the test system code can be used by Figure 1 The computer terminal or similar electronic device shown is used for execution. Figure 2 This is a flowchart of a method for testing system code according to an embodiment of this disclosure. Figure 2 As shown, the method may include the following steps:

[0036] Step S20: Obtain first index data and second index data based on the target code, wherein the target code is the full system code, the first index data is the full class index, and the second index data is the full function index;

[0037] The target code mentioned above can be the entire system code, such as Android language code, Java language code, etc. Based on this target code, the first index data and the second index data mentioned above can be obtained, wherein the first index data is the full class index, and the second index data is the full function index.

[0038] The first index data mentioned above may include multiple class index data, each of which may include: package name, class name, function name, parent class name, implemented interface name, file name, and multiple class variables. The second index data mentioned above may include multiple function index data, each of which may include: class name, function name, return type, multiple function parameters, multiple function variables, package name, and file name.

[0039] Step S21: Generate a target call chain using the target code and the second index data, wherein the target call chain is a complete function call chain;

[0040] The target code described above is the complete system code, and the second index data described above is the complete function index. Since functions can be used multiple times in this target code, and there can be call relationships between the multiple functions used in the target code, the target call chain described above can be generated based on this target code and the second index data.

[0041] The target call chain described above can be used to represent multiple call relationships between various functions used in the target code. Since this target call chain is a complete function call chain, it includes the call chain of every function used in the entire system code.

[0042] Step S22: Obtain the target class set corresponding to the change information through the first index data, the change information of the target code, and the target call chain;

[0043] The target code mentioned above is the full system code. In practical application scenarios, it is often necessary to modify some of the system code in the full system code. Therefore, by comparing and analyzing the full system code before and after the change, the change information of the target code can be obtained.

[0044] The aforementioned first index data is a complete class index, and the aforementioned target call chain is a complete function call chain. Based on this first index data, the change information of the target code, and the target call chain, the target class set corresponding to the aforementioned change information can be obtained. This target class set can be a collection of multiple classes that may be affected by the aforementioned changes to the target code.

[0045] Step S23: Perform code testing based on the target class set.

[0046] Based on the aforementioned set of target classes, the code tests described above can be performed. These tests may include: running the modified target code to determine the scope of its impact, and then using this scope to locate and regress issues. The scope of impact may include classes and interface data affected by the target code changes.

[0047] In the embodiments of this disclosure, first index data and second index data are obtained based on the target code. The target code is the full system code, the first index data is the full class index, and the second index data is the full function index. A target call chain is generated using the target code and the second index data. The target call chain is the full function call chain. A method based on the first index data, the change information of the target code, and the target call chain is used to obtain the target class set corresponding to the change information. Then, code testing is performed based on the target class set. This achieves the goal of determining the scope of influence of the changed code through the joint analysis method of the index call of the full code. It realizes the technical effect of reducing the analysis cost and increasing the accuracy of the analysis of the scope of influence of the changed code, and solves the technical problem in related technologies that the lack of accurate automatic analysis methods for the scope of influence of code changes leads to high analysis costs and low accuracy of analysis results.

[0048] The method described in this embodiment will be further described below.

[0049] As an optional implementation, step S20, which involves obtaining the first index data and the second index data based on the target code, further includes the following method steps:

[0050] Step S201: Access and traverse the syntax tree of the target code to obtain the first index data and the second index data.

[0051] The target code described above is the complete system code. The syntax tree of this target code can be used to represent the abstract syntactic structure of the complete system code. Accessing and traversing the syntax tree of this target code allows the acquisition of the first index data and the second index data. The first index data is the complete class index, and the second index data is the complete function index.

[0052] For example, when testing the full codebase of a software, the method provided in this embodiment can be used. The initial full codebase is denoted as `code_all0`, and the modified full codebase is denoted as `code_all1`. Traversing the abstract syntax tree of the full codebase `code_all1` yields the class index `class_index` and the function index `function_index`.

[0053] Figure 3 This is a schematic diagram of an optional class index data structure according to an embodiment of this disclosure, such as... Figure 3 As shown, the class index class_index above can include multiple class index data, where each class index data can include package name.class name, package name, parent class list, implementation interface list, code file, and class variables.

[0054] Specifically, for example, in the class index data com.xxx.yyy.player.player.AbstractMedia Player:

[0055] (1) Package name is com.xxx.yyy.player.player;

[0056] (2) The parent class name is com.xxx.zzz.player.BDVideoPlayer;

[0057] (3) Implement the interface name, which is com.xxx.yyy.player.inter.IMediaPlayer;

[0058] (4) The file name is file_name, which is AbstractMediaPlayer.java;

[0059] (5) A class variable can include multiple variables, each of which includes a variable name and a variable type. For example, variable 1 is named mVideoDisplayWidth and is of type int; variable 2 is named mVideoDisplayHeight and is of type int; and variable 3 is named mVideoSarNum and is of type int.

[0060] Figure 4 This is a schematic diagram of an optional function index data structure according to an embodiment of this disclosure, such as... Figure 4 As shown, the function index function_index can include multiple function index data, where each function index data can include class name, function name, etc.

[0061] Specifically, for example, in the function index data AlarmReceiver.onReceive:

[0062] (1) The return type is void;

[0063] (2) The function parameter func_params can include multiple parameters, each of which includes a parameter name and a parameter type. For example, parameter 1 is named context and is of type Context; parameter 2 is named intent and is of type Intent.

[0064] (3) Function variables can include multiple variables, each of which includes a variable name and a variable type. For example, variable 1 is named time and is of type int; variable 2 is named name and is of type string.

[0065] (4) Package name, which is cn.jpush.android.service;

[0066] (5) The file name is file_name, which is AlarmReceiver.java.

[0067] Based on the full code (code_all1) and function index (function_index), a function call chain (function_call_N) can be generated (equivalent to the target call chain mentioned above). Figure 5 This is a schematic diagram of an optional function call chain lookup process according to an embodiment of the present disclosure, such as... Figure 5 As shown, function A resides in class `class_A` under package `package_A`. Function A calls functions B and C. A function hierarchy lookup for functions B and C yields information about internal variables, function parameters, class variables, class functions, and external functions. Further analysis reveals the corresponding variable types, parameter types, class variable types, current class, and import class. Analyzing these information allows us to obtain the class names and type names (int.char) of functions B and C, ultimately leading to the function call chain. This confirms that function B resides in class `class_B` under package `package_B`, and function C resides in class `class_C` under package `package_C`.

[0068] After multiple function call chain searches, a mesh function call chain can be obtained. Figure 6 This is a schematic diagram of an optional mesh function call chain structure according to an embodiment of the present disclosure, such as... Figure 6 As shown, function B calls function A, and functions D, E, and F all call function B. Function C calls function A, and function G further calls function C.

[0069] As an optional implementation, the method for testing system code also includes the following steps:

[0070] Step S24: During the commit operation on the target code, the code content stored in the first storage area is compared with the code content stored in the second storage area using the difference instruction corresponding to the preset version repository to obtain change information. The first storage area is the staging area corresponding to the preset version repository, and the second storage area is the working area corresponding to the preset version repository.

[0071] The aforementioned preset repository can be a code version utility library in the distributed version control system Git. This preset repository may include the diff command, which is used to find the differences between different versions of the same code.

[0072] The first storage area mentioned above can be the staging area corresponding to the preset version repository, where the original version of the target code can be stored. The second storage area mentioned above can be the working area corresponding to the preset version repository, where the modified version of the target code can be stored. The target code can be global system code.

[0073] Software testing often involves changes to the target code. When committing the modified target code, the original target code (before the change) can be stored in the first storage area, and the modified target code in the second storage area. Using the `diff` command corresponding to the preset repository, the original and modified target code can be compared to obtain their differences and thus the change information.

[0074] As an optional implementation, in step S22, obtaining the target class set through the first index data, change information, and target call chain further includes the following method steps:

[0075] Step S221: Obtain the first function set by changing the information;

[0076] Step S222: Determine the initial class set using the target call chain and the first function set;

[0077] Step S223: Obtain the target class set based on the first index data and the initial class set.

[0078] The aforementioned change information is obtained by comparing the target code before and after the change. This change information allows us to obtain the first set of functions. This first set of functions can be a collection of multiple functions directly affected by the change in the target code.

[0079] The target call chain described above is a complete function call chain, which can be used to represent multiple call relationships between various functions used in the target code. Using this target function call chain and the first set of functions described above, the initial class set can be determined. This initial class set can be a collection of multiple classes directly affected by changes to the target code.

[0080] The aforementioned first index data can be a full class index, used to represent the hierarchical relationships between multiple classes in the target code. Using this first index data and the aforementioned initial class set, the aforementioned target class set can be obtained. This target class set can be a collection of multiple classes directly or indirectly affected by the changes to the target code; that is, the target class set can include the initial class set.

[0081] As an optional implementation, in step S221, obtaining the first function set through change information includes: obtaining the function information to which the change information belongs, and thus obtaining the first function set.

[0082] The aforementioned change information is obtained by comparing the target code before and after the change. This change information may include some modified code from the entire system code. This modified code may belong to multiple functions, thus revealing the function information to which the change information pertains. Based on this function information, the aforementioned first function set can be obtained. This first function set may be a collection of multiple functions directly affected by the change in the target code.

[0083] As an optional implementation, step S222, which uses the target call chain and the first function set to determine the initial class set, further includes the following method steps:

[0084] Step S2221: Obtain the call chain result of each function in the first function set from the target call chain, wherein the call chain result is used to describe the call relationship of all functions that directly or indirectly call each function in the first function set;

[0085] Step S2222: Based on the call chain result, obtain the second function set, wherein the second function set is a set of functions that have a direct call relationship with each function in the first function set;

[0086] Step S2223: Determine the initial class set by the class to which each function in the second function set belongs.

[0087] The target call chain described above is a complete function call chain, which can be used to represent the multiple call relationships between multiple functions used in the target code. The first function set can be a collection of multiple functions directly affected by the changes to the target code. From this target call chain, the call chain result for each function in the first function set can be obtained, and this call chain result can be used to describe the call relationships of all functions that directly or indirectly call each function in the first function set.

[0088] Based on the above call chain results, the second function set can be obtained. This second function set can be a set of functions that have a direct call relationship with each function in the first function set. Based on the class to which each function in the second function set belongs, the initial class set can be determined. This initial class set can be a set of multiple classes directly affected by the target code change.

[0089] For example, when testing the full codebase of a software, the method provided in this embodiment can be used. The initial full codebase `code_all0` is stored in the staging area of ​​the Git distributed version control system, and the modified full codebase `code_all1` is committed to the working directory of the Git distributed version control system. Using the `diff` command to compare and analyze the initial full codebase `code_all0` and the modified full codebase `code_all1`, the most recently changed portion of the code can be obtained and denoted as `code_fix` (equivalent to the aforementioned change information).

[0090] Analysis reveals multiple functions related to the `code_fix` section of code, specifically the `functionC` function (equivalent to the first set of functions mentioned above) directly affected by the code change. Based on the function call chain `function_call_N`, the call chain `function_call_c` for each function within `functionC` can be obtained. The call chain `function_call_c` represents the call relationship of all functions directly or indirectly called by the corresponding function.

[0091] By calling the function call chain `function_call_c`, we can obtain multiple functions `functionD` (equivalent to the second set of functions mentioned above) that have direct call relationships with each function directly affected by the code and the change. Then, we obtain the class set `class_D` (equivalent to the initial class set mentioned above) to which each function in `functionD` belongs. Each class in this class set `class_D` is directly affected by the changed code `code_fix` in the target code.

[0092] As an optional implementation, in step S223, obtaining the target class set based on the first index data and the initial class set further includes the following method steps:

[0093] Step S2231: Select a step, select a target class element from the initial class set;

[0094] Step S2232, judgment step, judging whether the current class found by the target class element through the target class index element and the target class index element meet the first preset condition, wherein the target class index element is any class index element contained in the first index data;

[0095] Step S2233, the acquisition step, in response to the first preset condition being met between the index elements of the current class and the target class, adds the current class to the initial class set and returns to the selection step until the second preset condition is met, and obtains the target class set.

[0096] The initial class set mentioned above can be a collection of multiple classes directly affected by the change in the target code. The target class elements can be selected from this initial class set. The above steps are selection steps.

[0097] The aforementioned first index data can be a full class index, used to represent the hierarchical relationships between multiple classes in the target code. For each class index element contained in the first index data, that class index element is used as the target class index element. The current class found by the target class element through the target class index element is determined, and it is judged whether the current class and the target class index element satisfy the aforementioned first preset condition, thus obtaining the judgment result.

[0098] Based on the above judgment results, if the current class and the target class index element meet the first preset condition, then the current class is added to the initial class set and the selection step is returned; if the current class and the target class index element do not meet the first preset condition, then the selection step is returned directly.

[0099] The process of adding classes to the initial class set is monitored. When the second preset condition is met, the initial class set at this time is used as the target class set. The target class set can be a collection of multiple classes that are directly or indirectly affected by the target code change; that is, the target class set can include the initial class set.

[0100] As an optional implementation, the first preset condition includes one of the following: the current class belongs to the parent class of the target class index element; the current class belongs to the implementation interface of the target class index element; the variable type of any variable in the class variables of the target class index element.

[0101] The first preset condition is used to determine whether to add the current class to the initial class set. The target class index element is any class index element included in the full class index. The first preset condition is considered satisfied when one of the following three conditions is met:

[0102] (1) The current class belongs to the parent class of the index element of the target class;

[0103] (2) The current class belongs to the implementation interface of the index element of the target class;

[0104] (3) The variable type of any variable in the class variables of the target class index element of the current class.

[0105] As an optional implementation, the second preset condition includes: the number of class elements contained in the initial class set stops changing, and all class elements contained in the initial class set have been processed.

[0106] The second presupposition condition is used to determine whether the initial class set can be used as the target class set. The initial class set can be a collection of multiple classes directly affected by the target code change. The target class set can be a collection of multiple classes directly or indirectly affected by the target code change; that is, the target class set can include the initial class set. The second presupposition condition is considered satisfied when both of the following conditions are met:

[0107] (1) The number of class elements contained in the initial class set stops changing;

[0108] (2) All class elements contained in the initial class set have been processed.

[0109] For example, when testing the full code of a software, the method provided in this embodiment can be used. Figure 7 This is a schematic diagram of an optional target class cyclic search process according to an embodiment of the present disclosure, such as... Figure 7 As shown, the initial elements in the mutable class set (equivalent to the initial class set mentioned above) include multiple classes directly affected by the most recently changed code_fix. Each class element in this mutable class set is searched repeatedly, and the element found each time is denoted as the target class element.

[0110] Based on the target class element mentioned above, the current class can be found using the class index `class_index`. Based on this current class and the target class element, the following judgment is made:

[0111] (1) Whether the current class belongs to the parent class;

[0112] (2) Whether the current class has an input interface;

[0113] (3) Whether the current class belongs to the variable type of the class declaration variable.

[0114] If any one of the above three conditions is true, the current class is added to the variable class collection after deduplication. If all three conditions are false, the next search for the target class element in the variable class collection is performed. The search for the target class element in the variable class collection is complete when all class elements in the variable class collection have been processed and the number of class elements in the variable class collection stops changing, meaning no more of the current class is added to the variable class collection.

[0115] According to the method provided in this embodiment, by establishing class indexes and function indexes, a set of functions directly and indirectly affected by code changes can be obtained. Through the class set composed of the classes to which each function belongs, subclasses, interfaces, variables, etc., directly and indirectly affected by code changes can be found. Finally, user-related entry activity classes can be filtered from the search results to obtain accurate entry data affected by code changes.

[0116] It is noteworthy that the above method can ensure full and complete coverage of the impact analysis of code changes, improving the accuracy of the analysis results; moreover, it eliminates the need for pre-processing code comments and relation mapping, saving manpower costs; and by establishing a full index, the analysis process is automated, further improving efficiency and saving costs. Therefore, this method has practical significance for software testing applications.

[0117] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods according to the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this disclosure, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a terminal device (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods described in the various embodiments of this disclosure.

[0118] This disclosure also provides an apparatus for testing system code, which is used to implement the above embodiments and preferred embodiments, and will not be repeated hereafter. As used below, the term "module" can be a combination of software and / or hardware that implements a predetermined function. Although the apparatus described in the following embodiments is preferably implemented in software, hardware implementation, or a combination of software and hardware, is also possible and contemplated.

[0119] Figure 8 This is a structural block diagram of an apparatus for testing system code according to an embodiment of the present disclosure, such as... Figure 8 As shown, the device 800 for testing system code includes: a first acquisition module 801, a generation module 802, a second acquisition module 803, and a testing module 804.

[0120] The first acquisition module 801 is used to acquire first index data and second index data based on the target code, wherein the target code is the full system code, the first index data is the full class index, and the second index data is the full function index; the generation module 802 is used to generate a target call chain using the target code and the second index data, wherein the target call chain is the full function call chain; the second acquisition module 803 is used to acquire the target class set corresponding to the change information through the first index data, the change information of the target code, and the target call chain; the testing module 804 is used to perform code testing based on the target class set.

[0121] Optionally, the first acquisition module 801 is further configured to: access and traverse the syntax tree of the target code to acquire first index data and second index data.

[0122] Optionally, Figure 9 This is a structural block diagram of an apparatus for another test system code according to an embodiment of the present disclosure, such as... Figure 9 As shown, the device includes Figure 8 In addition to all the modules shown, it also includes: a comparison module 805, which is used to compare the differences between the code content stored in the first storage area and the code content stored in the second storage area by using the difference instructions corresponding to the preset version repository during the commit operation of the target code, and obtain change information. The first storage area is the staging area corresponding to the preset version repository, and the second storage area is the working area corresponding to the preset version repository.

[0123] Optionally, the second acquisition module 803 is further configured to: acquire the first function set through change information; determine the initial class set using the target call chain and the first function set; and acquire the target class set based on the first index data and the initial class set.

[0124] Optionally, the second acquisition module 803 is further configured to: acquire the function information to which the change information belongs, and obtain the first function set.

[0125] Optionally, the second acquisition module 803 is further configured to: acquire the call chain result of each function in the first function set from the target call chain, wherein the call chain result is used to describe the call relationship of all functions that directly or indirectly call each function in the first function set; acquire the second function set based on the call chain result, wherein the second function set is a set of functions that have a direct call relationship with each function in the first function set; and determine the initial class set by the class to which each function in the second function set belongs.

[0126] Optionally, the second acquisition module 803 includes: a selection unit 8031 ​​(not shown in the figure), used to select a target class element from the initial class set; a judgment unit 8032 (not shown in the figure), used to judge whether the current class found by the target class element through the target class index element and the target class index element satisfy a first preset condition, wherein the target class index element is any class index element contained in the first index data; and an acquisition unit 8033 (not shown in the figure), used to add the current class to the initial class set in response to the first preset condition being met between the current class and the target class index element, and return to the selection step until the second preset condition is met, thereby obtaining the target class set.

[0127] Optionally, the first preset condition mentioned above includes one of the following: the current class belongs to the parent class of the target class index element; the current class belongs to the implementation interface of the target class index element; the variable type of any variable in the class variables of the target class index element.

[0128] Optionally, the second preset condition includes: the number of class elements contained in the initial class set stops changing, and all class elements contained in the initial class set have been processed.

[0129] It should be noted that the above modules can be implemented by software or hardware. For the latter, they can be implemented in the following ways, but are not limited to: all the above modules are located in the same processor; or, the above modules are located in different processors in any combination.

[0130] According to embodiments of this disclosure, this disclosure also provides an electronic device including a memory and at least one processor, the memory storing computer instructions, the processor being configured to execute the computer instructions to perform the steps in any of the above method embodiments.

[0131] Optionally, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor and the input / output device is connected to the processor.

[0132] Optionally, in this embodiment, the processor can be configured to perform the following steps via a computer program:

[0133] Step S1: Obtain first index data and second index data based on the target code, wherein the target code is the full system code, the first index data is the full class index, and the second index data is the full function index;

[0134] Step S2: Generate the target call chain using the target code and the second index data, wherein the target call chain is the complete function call chain;

[0135] Step S3: Obtain the target class set corresponding to the change information through the first index data, the change information of the target code, and the target call chain;

[0136] Step S4: Perform code testing based on the target class set.

[0137] Optionally, specific examples in this embodiment can refer to the examples described in the above embodiments and optional implementations, and will not be repeated here.

[0138] According to embodiments of the present disclosure, the present disclosure also provides a non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are configured to perform the steps in any of the above method embodiments at runtime.

[0139] Optionally, in this embodiment, the non-volatile storage medium described above can be configured to store a computer program for performing the following steps:

[0140] Step S1: Obtain first index data and second index data based on the target code, wherein the target code is the full system code, the first index data is the full class index, and the second index data is the full function index;

[0141] Step S2: Generate the target call chain using the target code and the second index data, wherein the target call chain is the complete function call chain;

[0142] Step S3: Obtain the target class set corresponding to the change information through the first index data, the change information of the target code, and the target call chain;

[0143] Step S4: Perform code testing based on the target class set.

[0144] Optionally, in this embodiment, the aforementioned non-transitory computer-readable storage medium may include, but is not limited to, various media capable of storing computer programs, such as USB flash drives, read-only memory (ROM), random access memory (RAM), portable hard drives, magnetic disks, or optical disks.

[0145] According to embodiments of this disclosure, a computer program product is also provided. Program code for implementing the test system code of this disclosure can be written in any combination of one or more programming languages. This program code can be provided to a processor or controller of a general-purpose computer, special-purpose computer, or other programmable data processing device, such that when executed by the processor or controller, the program code causes the functions / operations specified in the flowcharts and / or block diagrams to be implemented. The program code can be executed entirely on a machine, partially on a machine, partially on a remote machine as a standalone software package, or entirely on a remote machine or server.

[0146] The sequence numbers of the embodiments disclosed above are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.

[0147] In the above embodiments of this disclosure, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments.

[0148] In the several embodiments provided in this disclosure, it should be understood that the disclosed technical content can be implemented in other ways. The device embodiments described above are merely illustrative; for example, the division of units can be a logical functional division, and in actual implementation, there may be other division methods. For instance, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the displayed or discussed mutual couplings, direct couplings, or communication connections may be through some interfaces; indirect couplings or communication connections between units or modules may be electrical or other forms.

[0149] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0150] Furthermore, the functional units in the various embodiments of this disclosure can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0151] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this disclosure, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this disclosure. The aforementioned storage medium includes various media capable of storing program code, such as a USB flash drive, read-only memory (ROM), random access memory (RAM), portable hard disk, magnetic disk, or optical disk.

[0152] The above description is only a preferred embodiment of this disclosure. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principles of this disclosure, and these improvements and modifications should also be considered within the scope of protection of this disclosure.

Claims

1. A method for testing system code, comprising: obtaining first index data and second index data based on target code, wherein the target code is full system code, the first index data is full class index, and the second index data is full function index; generating a target call chain using the target code and the second index data, wherein the target call chain is a full function call chain; obtaining a first function set through change information of the target code, wherein the first function set is a set of functions directly affected by the change of the target code; obtaining a call chain result of each function in the first function set from the target call chain, wherein the call chain result is used to describe the calling relationship of all functions directly or indirectly calling each function in the first function set; obtaining a second function set based on the call chain result, wherein the second function set is a set of functions having a direct calling relationship with each function in the first function set; determining an initial class set through classes to which each function in the second function set belongs, wherein the initial class set is a set of classes directly affected by the change of the target code; obtaining a target class set according to the first index data and the initial class set; performing code testing according to the target class set; wherein obtaining the target class set according to the first index data and the initial class set comprises: a selecting step of selecting a target class element from the initial class set; a judging step of judging whether a current class found by the target class element through a target class index element satisfies a first preset condition with the target class index element, wherein the target class index element is any class index element contained in the first index data; and an obtaining step of, in response to the current class satisfying the first preset condition with the target class index element, adding the current class to the initial class set and returning to the selecting step until a second preset condition is satisfied to obtain the target class set; the first preset condition comprises one of the following: the current class belongs to a parent class of the target class index element, the current class belongs to an implementation interface of the target class index element, and the current class belongs to a variable type corresponding to any variable in a class variable of the target class index element; and the second preset condition comprises that the number of class elements contained in the initial class set stops changing and all class elements contained in the initial class set are processed.

2. The method of claim 1, wherein, obtaining the first index data and the second index data based on the target code comprises: accessing and traversing a syntax tree of the target code to obtain the first index data and the second index data.

3. The method of claim 1, wherein, The method further comprises: In a process of performing a commit operation on the target code, differences between code content stored in a first storage area and code content stored in a second storage area are compared by using difference instructions corresponding to the preset version library, and the change information is obtained, wherein the first storage area is a staging area corresponding to the preset version library, and the second storage area is a working area corresponding to the preset version library.

4. The method of claim 1, wherein, The first function set is obtained through the change information.

5. An apparatus for testing system code, comprising: a first obtaining module configured to obtain first index data and second index data based on target code, wherein the target code is full system code, the first index data is full class index, and the second index data is full function index; a generating module configured to generate a target call chain by using the target code and the second index data, wherein the target call chain is a full function call chain; a second obtaining module configured to obtain a target class set corresponding to change information of the target code through the first index data, the change information of the target code, and the target call chain; a testing module configured to perform code testing according to the target class set; wherein the second obtaining module is further configured to obtain a first function set through the change information, wherein the first function set is a set of functions directly affected by the change of the target code; determine an initial class set by using the target call chain and the first function set; and obtain the target class set according to the first index data and the initial class set; the second obtaining module is further configured to obtain a call chain result of each function in the first function set from the target call chain, wherein the call chain result is used to describe the calling relationship of all functions directly or indirectly calling each function in the first function set; obtain a second function set based on the call chain result, wherein the second function set is a set of functions having a direct calling relationship with each function in the first function set; and determine the initial class set through classes to which each function in the second function set belongs, wherein the initial class set is a set of classes directly affected by the change of the target code; wherein the second obtaining module comprises: a selecting unit configured to select a target class element from the initial class set; a judging unit configured to judge whether a current class found by the target class element through a target class index element and the target class index element satisfy a first preset condition, wherein the target class index element is any class index element contained in the first index data; and an obtaining unit configured to add the current class to the initial class set and return to the selecting unit in response to the current class and the target class index element satisfying the first preset condition, until a second preset condition is satisfied, and the target class set is obtained. ​ The first preset condition comprises one of the following: the current class belongs to a parent class of the target class index element; the current class belongs to an implementation interface of the target class index element; the current class belongs to a variable type corresponding to any variable in a class variable of the target class index element. The second preset condition comprises: the number of class elements contained in the initial class set stops changing, and all class elements contained in the initial class set are processed.

6. The apparatus of claim 5, wherein, The first obtaining module is further configured to: access and traverse the syntax tree of the target code, and obtain the first index data and the second index data.

7. The apparatus of claim 5, wherein, The device further comprises: a comparison module configured to, in a process of performing a commit operation on the target code, compare differences between code content stored in a first storage area and code content stored in a second storage area by using difference instructions corresponding to a preset version library, to obtain the change information, wherein the first storage area is a staging area corresponding to the preset version library, and the second storage area is a working area corresponding to the preset version library.

8. The apparatus of claim 5, wherein, The second obtaining module is further configured to: obtain function information to which the change information belongs, to obtain the first function set.

9. An electronic device, comprising: at least one processor; and a memory connected to the at least one processor in communication; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method of any one of claims 1-4.

10. A non-transitory computer readable storage medium having stored thereon computer instructions, wherein, The computer instructions are used to enable the computer to perform the method of any one of claims 1-4.

11. A computer program product comprising a computer program which, when executed by a processor, implements the method of any one of claims 1-4.

Citation Information

Patent Citations

  • Code testing method and apparatus, terminal and storage medium

    CN107085555A