CN114328254A - Method and device for testing system code, electronic equipment and storage medium - Google Patents
Method and device for testing system code, electronic equipment and storage medium Download PDFInfo
- Publication number
- CN114328254A CN114328254A CN202111669896.9A CN202111669896A CN114328254A CN 114328254 A CN114328254 A CN 114328254A CN 202111669896 A CN202111669896 A CN 202111669896A CN 114328254 A CN114328254 A CN 114328254A
- Authority
- CN
- China
- Prior art keywords
- class
- target
- function
- code
- index data
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
- 238000000034 method Methods 0.000 title claims abstract description 71
- 238000012360 testing method Methods 0.000 title claims abstract description 39
- 230000008859 change Effects 0.000 claims abstract description 91
- 230000006870 function Effects 0.000 claims description 212
- 230000008569 process Effects 0.000 claims description 16
- 238000004590 computer program Methods 0.000 claims description 13
- 238000012545 processing Methods 0.000 claims description 11
- 238000010998 test method Methods 0.000 claims description 9
- 230000004044 response Effects 0.000 claims description 3
- 238000004458 analytical method Methods 0.000 abstract description 28
- 238000010586 diagram Methods 0.000 description 18
- 238000004891 communication Methods 0.000 description 6
- 230000000694 effects Effects 0.000 description 4
- 238000005516 engineering process Methods 0.000 description 4
- 238000013522 software testing Methods 0.000 description 4
- 238000013459 approach Methods 0.000 description 3
- 230000008878 coupling Effects 0.000 description 3
- 238000010168 coupling process Methods 0.000 description 3
- 238000005859 coupling reaction Methods 0.000 description 3
- 238000013507 mapping Methods 0.000 description 3
- 230000003287 optical effect Effects 0.000 description 3
- 230000009471 action Effects 0.000 description 2
- 230000005540 biological transmission Effects 0.000 description 2
- 238000011161 development Methods 0.000 description 2
- 238000012986 modification Methods 0.000 description 2
- 230000004048 modification Effects 0.000 description 2
- 238000003491 array Methods 0.000 description 1
- 238000013473 artificial intelligence Methods 0.000 description 1
- 230000001413 cellular effect Effects 0.000 description 1
- 238000010276 construction Methods 0.000 description 1
- 230000008676 import Effects 0.000 description 1
- 230000010354 integration Effects 0.000 description 1
- 238000010801 machine learning Methods 0.000 description 1
- 238000012423 maintenance Methods 0.000 description 1
- 238000012544 monitoring process Methods 0.000 description 1
- 238000010606 normalization Methods 0.000 description 1
- 239000011800 void material Substances 0.000 description 1
Images
Landscapes
- Debugging And Monitoring (AREA)
Abstract
The present disclosure provides a method, an apparatus, an electronic device and a storage medium for testing a system code, which relate to the technical field of computers and at least solve the technical problems of high analysis cost and low accuracy of analysis results caused by lack of a precise automatic analysis method for a code change influence range in the prior art. The specific implementation scheme is as follows: acquiring first index data and second index data based on a target code, wherein the target code is a full system code, the first index data is a full class index, and the second index data is a full function index; generating 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; acquiring 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.
Description
Technical Field
The present disclosure relates to the field of computer technologies, and in particular, to a method and an apparatus for testing system codes, an electronic device, and a storage medium.
Background
During the development of software, the code is required to be changed frequently, however, the code change has a series of influences. For example, a line of code change directly affects the current function, and a function change directly affects the caller of the function, thereby affecting the class variables and the associated user entries. Since a large number of complex function call relations exist in the full-scale code of the system, and the influence of the change of the class variable on the user entry may be hidden, the influence range of the partial code change is difficult to determine. In this regard, those skilled in the art are constantly seeking various methods of automatically determining the scope of influence of code changes during software testing.
In the related scheme, the determination method of the code change influence range mainly includes the following three methods:
(1) by establishing the mapping between the functional keywords and the entry code classes, the affected area of the codes matched with the functional keywords can be located according to the mapping and the call link of the entry code classes. The drawbacks of this approach are: the method depends on the search of the functional keywords and the code normalization, and cannot determine the complete influence range.
(2) And comparing the difference codes before and after the change through the corresponding relation between the method and the function point which are pre-configured in the code base, and automatically analyzing the influence range. The drawbacks of this approach are: the accuracy and the validity of an analysis result are poor, the manpower maintenance cost is high, and the method is not easy to realize in an actual application scene.
(3) And analyzing the influence range by triggering a breakpoint between the entry and the change function based on a code development integration tool. The drawbacks of this approach are: part of the entries are easy to be omitted, the analysis result is not accurate,
therefore, how to more accurately and automatically analyze the complete influence range of the change codes becomes an important problem in the current software testing work. In view of the above problems, no effective solution has been proposed.
Disclosure of Invention
The disclosure provides a method and a device for testing system codes, electronic equipment and a storage medium, which are used for at least solving the technical problems of high analysis cost and low accuracy of analysis results caused by lack of a precise automatic analysis method for a code change influence range in the prior art.
According to an embodiment of the present disclosure, there is provided a method for testing system code, including: acquiring first index data and second index data based on a target code, wherein the target code is a full system code, the first index data is a full class index, and the second index data is a full function index; generating 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; acquiring 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.
According to an embodiment of the present disclosure, there is also provided an apparatus for testing system code, including: the first obtaining module is used for obtaining first index data and second index data based on a target code, wherein the target code is a full system code, the first index data is a full class index, and the second index data is a full function index; the generating module is used for generating a target calling chain by using the target code and the second index data, wherein the target calling chain is a full function calling chain; the second acquisition module is used for acquiring 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 the test module is used for carrying out code test according to the target class set.
According to an embodiment of the present disclosure, there is also provided an electronic device including: at least one processor; and a memory communicatively coupled to the at least one processor; wherein the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the method of testing system code set forth in the present disclosure.
There is also provided, in accordance with an embodiment of the present disclosure, a non-transitory computer-readable storage medium having stored thereon computer instructions for causing a computer to perform the method for testing system code set forth in the present disclosure.
There is also provided, in accordance with an embodiment of the present disclosure, a computer program product including a computer program which, when executed by a processor, performs the method for testing system code set forth in the present disclosure.
In the embodiment of the disclosure, a first index data and a second index data are obtained based on a target code, wherein the target code is a full system code, the first index data is a full class index, the second index data is a full function index, and a target call chain is generated by using the target code and the second index data, wherein the target call chain is a full function call chain, a method based on the first index data, change information of the target code and the target call chain is adopted to obtain a target class set corresponding to the change information, and then a code test is performed according to the target class set, so that the purpose of determining an influence range of the change code by using a full code index call joint analysis method is achieved, technical effects of reducing analysis cost and increasing accuracy of the influence range of the change code are achieved, and the problems that analysis cost is high, analysis cost is low, and analysis accuracy is high due to lack of an accurate automatic analysis method of the influence range of code change in the related technology are solved, The accuracy of the analysis result is low.
It should be understood that the statements in this section do not necessarily identify key or critical features of the embodiments of the present disclosure, nor do they limit the scope of the present disclosure. Other features of the present disclosure will become apparent from the following description.
Drawings
The drawings are included to provide a better understanding of the present solution and are not to be construed as limiting the present disclosure. Wherein:
FIG. 1 is a block diagram of a hardware architecture of a computer terminal (or mobile device) for implementing a method of testing system code according to an embodiment of the present disclosure;
FIG. 2 is a flow diagram of a method of testing system code in accordance with an embodiment of the present disclosure;
FIG. 3 is a schematic diagram of an alternative class index data structure in accordance with an embodiment of the present disclosure;
FIG. 4 is a schematic diagram of an alternative function index data structure in accordance with an embodiment of the present disclosure;
FIG. 5 is a schematic diagram of an alternative function call chain lookup process according to an embodiment of the present disclosure;
FIG. 6 is a diagram illustrating an alternative mesh function call chain structure according to an embodiment of the present disclosure;
FIG. 7 is a schematic diagram of an alternative target class cycle finding process according to an embodiment of the present disclosure;
FIG. 8 is a block diagram of an apparatus for testing system code according to an embodiment of the present disclosure;
fig. 9 is a block diagram of another apparatus for testing system code according to an embodiment of the present disclosure.
Detailed Description
Exemplary embodiments of the present disclosure are described below with reference to the accompanying drawings, in which various details of the embodiments of the disclosure are included to assist understanding, and which are to be considered as merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the present disclosure. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
It should be noted that the terms "first," "second," and the like in the description and claims of the present disclosure and in the above-described drawings are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used is interchangeable under appropriate circumstances such that the embodiments of the disclosure described herein are capable of operation in sequences other than those illustrated or otherwise described herein. Furthermore, the terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed, but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.
In accordance with an embodiment of the present disclosure, there is provided a method of testing system code, it being noted that the steps illustrated in the flowchart of the figure may be performed in a computer system such as a set of computer-executable instructions and that, although a logical order is illustrated in the flowchart, in some cases, the steps illustrated or described may be performed in an order different than here.
The method embodiments provided by the embodiments of the present disclosure may be executed in a mobile terminal, a computer terminal or similar electronic devices. Electronic devices are intended to represent various forms of digital computers, such as laptops, desktops, workstations, personal digital assistants, servers, blade servers, mainframes, and other appropriate computers. The electronic device may also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions, are meant to be examples only, and are not meant to limit implementations of the disclosure described and/or claimed herein. Fig. 1 is a block diagram of a hardware structure of a computer terminal (or mobile device) for implementing a method of testing system code according to an embodiment of the present disclosure.
As shown in fig. 1, the computer terminal 100 includes a computing unit 101 that 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. In the RAM 103, various programs and data necessary for the operation of the computer terminal 100 can also be stored. The computing unit 101, the ROM 102, and the RAM 103 are connected to each other via a bus 104. An input/output (I/O) interface 105 is also connected to bus 104.
A number of components in the computer terminal 100 are connected to the I/O interface 105, including: an input unit 106 such as a keyboard, a mouse, and the like; an output unit 107 such as various types of displays, speakers, and the like; a storage unit 108, such as a magnetic disk, optical disk, or the like; and a communication unit 109 such as a network card, modem, wireless communication transceiver, etc. The communication unit 109 allows the computer terminal 100 to exchange information/data with other devices through a computer network such as the internet and/or various telecommunication networks.
Various implementations of the systems and techniques described here can be implemented in digital electronic circuitry, integrated circuitry, Field Programmable Gate Arrays (FPGAs), Application Specific Integrated Circuits (ASICs), Application Specific Standard Products (ASSPs), system on a chip (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and/or combinations thereof. These various embodiments may include: implemented in one or more computer programs that are executable and/or interpretable on a programmable system including at least one programmable processor, which may be special or general purpose, receiving data and instructions from, and transmitting data and instructions to, a storage system, at least one input device, and at least one output device.
It should be noted here that in some alternative embodiments, the electronic device shown in fig. 1 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 fig. 1 is only one example of a particular specific example and is intended to illustrate the types of components that may be present in the electronic device described above.
In the above operating environment, the present disclosure provides a method of testing system code as shown in fig. 2, which may be performed by a computer terminal or similar electronic device as shown in fig. 1. FIG. 2 is a flow chart of a method of testing system code in accordance with an embodiment of the present disclosure. As shown in fig. 2, the method may include the steps of:
step S20, acquiring first index data and second index data based on the object code, wherein the object code is a full system code, the first index data is a full class index, and the second index data is a full function index;
the object code may be a full amount of system code, for example, Android language code, Java language code, or the like. Based on the object code, the first index data and the second index data may be obtained, wherein the first index data is a full class index and the second index data is a full function index.
The first index data may include a plurality of class index data, and each of the class index data may include: package name, class name, function name, parent class name, implementation interface name, file name, and a plurality of class variables. The second index data may include a plurality of function index data, and each of the function index data may include: class name, function name, return type, plurality of function parameters, plurality of function variables, package name, and file name.
Step S21, generating 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;
the object code is a full system code, and the second index data is a full function index. Since the target code may have a plurality of functions and a call relationship between the plurality of functions used in the target code may exist, the target call chain may be generated based on the target code and the second index data.
The target call chain may be used to represent a multi-call relationship between a plurality of functions used in the target code. Since the target call chain is a full number of function call chains, the target call chain includes a call chain for each function used in the full amount of system code.
Step S22, acquiring 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;
the object code is a full system code, and in an actual application scene, part of the full system code often needs to be changed, so that the change information of the object code can be obtained by comparing and analyzing the full system code before and after changing.
The first index data is a full class index, and the target call chain is a full function call chain. And acquiring a target class set corresponding to the change information based on the first index data, the change information of the target code and the target call chain. The target class set may be a set of classes that may be affected by changes to the target code.
And step S23, performing code test according to the target class set.
The code test may be performed according to the set of target classes. The code testing may include: and running the changed target code to obtain the influence range of the target code change, and performing problem positioning, problem regression and the like according to the influence range. The scope of influence may include classes, interface data, etc. that are affected by the change in the object code.
In the embodiment of the disclosure, a first index data and a second index data are obtained based on a target code, wherein the target code is a full system code, the first index data is a full class index, the second index data is a full function index, and a target call chain is generated by using the target code and the second index data, wherein the target call chain is a full function call chain, a method based on the first index data, change information of the target code and the target call chain is adopted to obtain a target class set corresponding to the change information, and then a code test is performed according to the target class set, so that the purpose of determining an influence range of the change code by using a full code index call joint analysis method is achieved, technical effects of reducing analysis cost and increasing accuracy of the influence range of the change code are achieved, and the problems that analysis cost is high, analysis cost is low, and analysis accuracy is high due to lack of an accurate automatic analysis method of the influence range of code change in the related technology are solved, The accuracy of the analysis result is low.
The above-described method of this embodiment is further described below.
As an alternative implementation, in step S20, the method further includes the following steps:
step S201, access and traverse the syntax tree of the target code, and obtain the first index data and the second index data.
The object code is a full system code, and a syntax tree of the object code can be used for representing an abstract syntax structure of the full system code. The first index data and the second index data may be obtained by accessing and traversing the syntax tree of the object code. The first index data is a full class index, and the second index data is a full function index.
For example, the method provided by the present embodiment may be used when testing the entire amount of code of a certain software. The total initial code is referred to as code _ all0, and the total code after the change is referred to as code _ all 1. Traversing the abstract syntax tree of the full code _ all1 can obtain a class index class _ index and a function index function _ index.
Fig. 3 is a schematic diagram of an alternative class index data structure according to an embodiment of the present disclosure, and as shown in fig. 3, the class index class _ index may include a plurality of class index data, where each class index data may include a package name, a class name, a package name, a parent class list, an implementation interface list, a code attribution file, and a class variable.
Specifically, for example, in the class index data com.xxx.yy.player.player.player.abstract media Player:
(1) package name, com.xxx.yyy.player.player;
(2) parent name parent _ class _ name, com.
(3) Implementing an interface name instances _ name, com.xxx.yyy.player.inter.imedia Player;
(4) file name, abstract media player, java;
(5) the class variable may include a plurality of variables, where each variable includes a variable name and a variable type, for example, variable 1 is named mvideodiplaywidth, and type is int; the name of the variable 2 is mVideoDisplayHeight, and the type is int; the variable 3 is named mVideoSerNum and is int type.
Fig. 4 is a schematic diagram of an alternative function index data structure according to an embodiment of the disclosure, and as shown in fig. 4, the function index function _ index may include a plurality of function index data, where each function index data may include a class name, a function name, and the like.
Specifically, for example, in the function index data alarmreceiver.
(1) Returning a type return _ type as void;
(2) the function parameter func _ params may include a plurality of parameters, wherein each parameter includes a parameter name and a parameter type, for example, parameter 1 is named Context, and type is Context; the parameter 2 is named Intent and the type is Intent;
(3) the function variable may include a plurality of variables, where each variable includes a variable name and a variable type, e.g., variable 1 is named time and type is int; the name of the variable 2 is name, and the type is string;
(4) a package name, which is cn.jpush.android.service;
(5) file name, file _ name, is alarmreceiver.
Based on the full-size code _ all1 and the function index function _ index, a function call chain function _ call _ N (equivalent to the target call chain described above) can be generated. Fig. 5 is a schematic diagram of an alternative function call chain lookup process according to an embodiment of the disclosure, where as shown in fig. 5, a function a is in class _ a under a package _ a, and the function a calls a function B and a function C. And inquiring the function attribution relation of the function B and the function C to obtain an internal variable, a function parameter, a class variable, a class function and an external function. Further, a corresponding variable type, parameter type, class variable type, current class, and entry (import) class may be obtained. The class name (class) and the type name (int.char) of the function B and the function C can be obtained through analysis, and finally, the function call chain can be obtained. And determining that the function B is in class _ B under the packet _ B, and the function C is in class _ C under the packet _ C.
After a plurality of times of function call chain searching, a mesh function call chain can be obtained. Fig. 6 is a diagram illustrating an alternative mesh function call chain structure according to an embodiment of the disclosure, where a function B calls a function a, and a function D, a function E, and a function F all call a function B, as shown in fig. 6. Function C calls function a and function G further calls function C.
As an alternative embodiment, the method for testing system code further comprises the following method steps:
step S24, in the process of performing a commit operation on the target code, comparing the difference between the code content stored in the first storage area and the code content stored in the second storage area by using the difference instruction corresponding to the preset version library to obtain change information, where the first storage area is a temporary storage area corresponding to the preset version library, and the second storage area is a working area corresponding to the preset version library.
The preset version library may be a code version tool library in the distributed version control system Git, and the preset version library may include difference instructions diff for finding different parts between different versions of the same code.
The first storage area may be a temporary storage area corresponding to the preset version library, and the temporary storage area may store an original version code of the object code. The second storage area may be a working area corresponding to the preset version library, and the working area may store a change version code of the target code. The object code may be global system code.
In the process of software testing, the target code is often changed, and in the process of submitting the changed target code, the original target code before being changed can be stored in the first storage area, and the changed target code can be stored in the second storage area. Through the difference instruction diff corresponding to the preset version library, the original target code before the change and the target code after the change can be compared to obtain the difference between the original target code before the change and the target code after the change, and further obtain the change information of the target code.
As an alternative implementation manner, in step S22, the method further includes the following steps:
step S221, a first function set is obtained through the change information;
step S222, determining an initial class set by adopting a target calling chain and a first function set;
step S223, acquiring a target class set according to the first index data and the initial class set.
The change information is information obtained by comparing the object codes before and after the change. The first function set can be obtained by the change information. The first set of functions may be a set of functions that are directly affected by the change in the target code.
The target call chain is a full function call chain, and may be used to represent multiple call relationships between a plurality of functions used in the target code. The initial class set may be determined by the chain of target function calls and the first set of functions. The initial class set may be a set of classes that are directly affected by the target code change.
The first index data may be a full class index, and may be used to indicate an affiliation between multiple classes in the target code. And obtaining the target class set through the first index data and the initial class set. The target class set may be a set of classes that are directly affected and indirectly affected by the target code change, i.e., the target class set may include the initial class set.
As an alternative implementation, in step S221, acquiring the first function set by changing the information includes: and acquiring function information to which the change information belongs to obtain a first function set.
The change information is information obtained by comparing the target codes before and after the change, and may include a code in which a part of the total system code is changed. The code to which the part is changed may be attributed to a plurality of functions, that is, the function information to which the change information is attributed may be acquired. The first function set can be obtained by function information to which the change information belongs. The first set of functions may be a set of functions that are directly affected by the change in the target code.
As an alternative implementation, in step S222, the method of determining the initial class set by using the target call chain and the first function set further includes the following steps:
step S2221, 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 for describing the call relation of all functions which directly or indirectly call each function in the first function set;
step S2222, based on the call chain result, a second function set is obtained, wherein the second function set is a function set having a direct call relation with each function in the first function set;
step S2223, determine an initial class set according to the class to which each function in the second function set belongs.
The target call chain is a full function call chain, and may be used to represent multiple call relationships between a plurality of functions used in the target code. The first set of functions may be a set of functions that are directly affected by the change in the target code. From the target call chain, a call chain result of each function in the first function set can be obtained, and the call chain result can be used for describing the call relation of all functions which directly or indirectly call each function in the first function set.
Based on the call chain result, the second function set may be obtained, and the second function set may be a function set having a direct call relationship with each function in the first function set. The initial set of classes may be determined based on the class to which each function in the second set of functions belongs. The initial class set may be a set of classes that are directly affected by the target code change.
For example, the method provided by the present embodiment may be used when testing the entire amount of code of a certain software. And storing the total initial code _ all0 to a temporary storage area corresponding to the distributed version control system Git, and submitting the changed total code _ all1 to a working area corresponding to the distributed version control system Git. The initial code _ all0 of the entire amount and the code _ all1 of the entire amount after the change are compared and analyzed by using the difference command diff, and the partial code which has been changed most recently can be obtained as code _ fix (corresponding to the change information).
A plurality of functions related to the partial code _ fix, that is, a plurality of functions functionC (corresponding to the first function set) directly affected by the code change can be obtained by the analysis. Based on the function call chain function _ call _ N described above, the call chain function _ call _ c of each of the plurality of function functions c can be obtained. The call chain function _ call _ c may represent a call relationship of all functions in which the corresponding function makes a direct or indirect call.
By calling the chain function _ call _ c, a plurality of function functions d (corresponding to the second function set) having a direct calling relationship between the code and each function directly affected by the change can be obtained. A class set class _ D (corresponding to the initial class set) to which each function belongs is obtained from the plurality of function functions. Each class in the class set class _ D is directly affected by the change code _ fix in the target code.
As an optional implementation manner, in step S223, obtaining the target class set according to the first index data and the initial class set, further comprising the following method steps:
step S2231, selecting target class elements from the initial class set;
step S2232, a determining step, performed to determine whether a first preset condition is satisfied between the current class found by the target class element through the target class index element and the target class index element, where the target class index element is any one of the class index elements included in the first index data;
step S2233, an obtaining step, in response to that the first preset condition is met between the current class and the target class index element, adding the current class to the initial class set, and returning to the selecting step until the second preset condition is met, so as to obtain the target class set.
The initial class set may be a set of classes that are directly affected by the target code change. From the initial class set, the target class element may be selected. The steps are selection steps.
The first index data may be a full class index, and may be used to indicate an affiliation between multiple classes in the target code. And regarding each type of index element contained in the first index data, taking the type of index element as the target type of index element. And determining the current class searched by the target class element through the target class index element, and judging whether the first preset condition is met between the current class and the target class index element to obtain a judgment result.
According to the judgment result, if the first preset condition is met between the index elements of the current class and the index elements of the target class, adding the current class to the initial class set, and returning to the selection step; and if the first preset condition is not met between the index elements of the current class and the index elements of the target class, directly returning to the selection step.
And monitoring the process of adding classes into the initial class set, and taking the initial class set at the moment as the target class set when the second preset condition is met. The target class set may be a set of classes that are directly affected and indirectly affected by the target code change, i.e., the target class set may include the initial class set.
As an alternative embodiment, 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 current class belongs to the variable type corresponding to any variable in the class variables of the target class index element.
The first preset condition is a condition for determining whether to add the current class to the initial class set. The target class index element is any class index element contained in the full class index. The first predetermined condition is considered to be satisfied when one of the following three conditions is satisfied:
(1) the current class belongs to a parent class of the target class index element;
(2) the current class belongs to the implementation interface of the target class index element;
(3) the current class belongs to a variable type corresponding to any variable in the class variables of the target class index element.
As an alternative embodiment, the second preset condition includes: the number of the class elements contained in the initial class set stops changing, and all the class elements contained in the initial class set are processed.
The second predetermined condition is a condition for determining whether the initial class set can be used as the target class set. The initial class set may be a set of classes that are directly affected by the target code change. The target class set may be a set of classes that are directly affected and indirectly affected by the target code change, i.e., the target class set may include the initial class set. The second preset condition is considered to be satisfied when the following two conditions are satisfied simultaneously:
(1) stopping changing the number of class elements contained in the initial class set;
(2) and finishing processing all the class elements contained in the initial class set.
For example, the method provided by the present embodiment may be used when testing the entire amount of code of a certain software. Fig. 7 is a schematic diagram of an alternative target class loop search process according to an embodiment of the present disclosure, where, as shown in fig. 7, an initial element in a variable class set (corresponding to the initial class set) includes multiple classes directly affected by a part of code _ fix that has been changed last time. And circularly searching each class element in the variable class set, and marking the searched element as a target class element each time.
Based on the target class element, the current class can be found through the class index class _ index. Based on the current class and the target class element, the following judgment is made:
(1) whether the current class belongs to a parent class;
(2) whether the current class is input into the interface;
(3) whether the current class belongs to the variable type of the class declaration variable.
If one of the three judgments is yes, the current class is deduplicated and added to the variable class set; and if the three conditions are judged to be negative, searching the target class elements in the next variable class set. The judgment condition for completing the search of the target class elements in the variable class set is as follows: and finishing the processing of all the class elements in the variable class set, and stopping changing the number of the class elements in the variable class set, namely adding no current class to the variable class set, and finishing the search.
According to the method provided by the embodiment, the class index and the function index are established, and the function set directly and indirectly influenced by code change can be obtained. Through the class set formed by the classes to which each function belongs in the function set, subclasses, interfaces, variables and the like which are directly and indirectly influenced by code change can be searched and obtained. Finally, user-related entry activity (activity) classes can be screened from the search results, and then entry data influenced by accurate code change can be obtained.
It is easy to notice that the method can ensure the complete coverage of the analysis of the code change influence range and improve the accuracy of the analysis result; in addition, code annotation, relationship mapping and other work do not need to be done in advance in the analysis process, so that the labor cost is saved; by establishing the full index, the automation of the analysis process is realized, the efficiency is further improved, and the cost is saved. Therefore, the method has practical significance for software testing application scenes.
Through the above description of the embodiments, those skilled in the art can clearly understand that the method according to the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but the former is a better implementation mode in many cases. Based on such understanding, the technical solutions of the present disclosure may be embodied in the form of a software product, which is stored in a storage medium and includes several instructions to enable a terminal device (which may be a mobile phone, a computer, a server, or a network device) to execute the methods according to the embodiments of the present disclosure.
The present disclosure further provides a device for testing system codes, where the device is used to implement the foregoing embodiments and preferred embodiments, and the description of the device that has been already made is omitted. As used below, the term "module" may be a combination of software and/or hardware that implements a predetermined function. Although the means described in the embodiments below are preferably implemented in software, an implementation in hardware, or a combination of software and hardware is also possible and contemplated.
Fig. 8 is a block diagram of an apparatus for testing system code according to an embodiment of the present disclosure, and as shown in fig. 8, the apparatus 800 for testing system code includes: a first obtaining module 801, a generating module 802, a second obtaining module 803, and a testing module 804.
A first obtaining module 801, configured to obtain first index data and second index data based on a target code, where the target code is a full system code, the first index data is a full class index, and the second index data is a full function index; a generating module 802, configured to generate a target call chain by using the target code and the second index data, where the target call chain is a full function call chain; a second obtaining module 803, configured to obtain, through the first index data, change information of the target code, and the target call chain, a target class set corresponding to the change information; and the testing module 804 is used for performing code testing according to the target class set.
Optionally, the first obtaining module 801 is further configured to: and accessing and traversing the syntax tree of the target code to acquire first index data and second index data.
Optionally, fig. 9 is a block diagram of another apparatus for testing system codes according to an embodiment of the present disclosure, and as shown in fig. 9, the apparatus includes, in addition to all modules shown in fig. 8: the comparing module 805 is configured to compare, by using a difference instruction corresponding to the preset version library, a difference between the code content stored in the first storage area and the code content stored in the second storage area to obtain change information, in a process of performing a commit operation on the target code, where the first storage area is a temporary storage area corresponding to the preset version library, and the second storage area is a working area corresponding to the preset version library.
Optionally, the second obtaining module 803 is further configured to: acquiring a first function set through the change information; determining an initial class set by adopting a target calling chain and a first function set; and acquiring a target class set according to the first index data and the initial class set.
Optionally, the second obtaining module 803 is further configured to: and acquiring function information to which the change information belongs to obtain a first function set.
Optionally, the second obtaining module 803 is further configured to: acquiring a calling chain result of each function in the first function set from the target calling chain, wherein the calling chain result is used for describing the calling relation of all functions which directly or indirectly call each function in the first function set; acquiring a second function set based on the calling chain result, wherein the second function set is a function set having a direct calling relationship with each function in the first function set; and determining an initial class set through the class to which each function in the second function set belongs.
Optionally, the second obtaining module 803 includes: a selecting unit 8031 (not shown in the figure) for selecting a target class element from the initial class set; a determining unit 8032 (not shown in the figure), configured to determine whether a first preset condition is satisfied between a current class found by the target class element through the target class index element and the target class index element, where the target class index element is any class of index elements included in the first index data; the obtaining unit 8033 (not shown in the figure) is configured to, in response to that a first preset condition is met between the current class and the target class index element, add the current class to the initial class set, and return to the selecting step until a second preset condition is met, so as to obtain the target class set.
Optionally, the first preset condition includes one of: 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 current class belongs to the variable type corresponding to any variable in the class variables of the target class index element.
Optionally, the second preset condition includes: the number of the class elements contained in the initial class set stops changing, and all the class elements contained in the initial class set are processed.
It should be noted that, the above modules may be implemented by software or hardware, and for the latter, the following may be implemented, but not limited to: the modules are all positioned in the same processor; alternatively, the modules are respectively located in different processors in any combination.
According to an embodiment of the present disclosure, there is also provided an electronic device including a memory having stored therein computer instructions and at least one processor configured to execute the computer instructions to perform the steps in any of the above method embodiments.
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.
Optionally, in this embodiment, the processor may be configured to execute the following steps by a computer program:
step S1, acquiring first index data and second index data based on the object code, wherein the object code is a full system code, the first index data is a full class index, and the second index data is a full function index;
step S2, generating 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;
step S3, acquiring 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 step S4, performing code test according to the target class set.
Optionally, the specific examples in this embodiment may refer to the examples described in the above embodiments and optional implementation manners, and this embodiment is not described herein again.
According to an embodiment of the present disclosure, there is also provided a non-transitory computer readable storage medium having stored therein computer instructions, wherein the computer instructions are arranged to perform the steps in any of the above method embodiments when executed.
Alternatively, in the present embodiment, the above-mentioned nonvolatile storage medium may be configured to store a computer program for executing the steps of:
step S1, acquiring first index data and second index data based on the object code, wherein the object code is a full system code, the first index data is a full class index, and the second index data is a full function index;
step S2, generating 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;
step S3, acquiring 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 step S4, performing code test according to the target class set.
Optionally, in this embodiment, the non-transitory computer readable storage medium may include, but is not limited to: various media capable of storing computer programs, such as a U disk, a Read Only Memory (ROM), a Random Access Memory (RAM), a removable hard disk, a magnetic or optical disk, and the like.
The present disclosure also provides a computer program product according to an embodiment of the present disclosure. Program code for implementing the methods of testing system code of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general purpose computer, special purpose computer, or other programmable data processing apparatus, such that the program codes, when executed by the processor or controller, cause the functions/operations specified in the flowchart and/or block diagram to be performed. The program code may execute entirely on the machine, partly on the machine, as a stand-alone software package partly on the machine and partly on a remote machine or entirely on the remote machine or server.
The above-mentioned serial numbers of the embodiments of the present disclosure are merely for description and do not represent the merits of the embodiments.
In the above embodiments of the present disclosure, the descriptions of the respective embodiments have respective emphasis, and for parts that are not described in detail in a certain embodiment, reference may be made to related descriptions of other embodiments.
In the embodiments provided in the present disclosure, it should be understood that the disclosed technology can be implemented in other ways. The above-described embodiments of the apparatus are merely illustrative, and for example, the division of the units may be a logical division, and in actual implementation, there may be another division, for example, multiple units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, units or modules, and may be in an electrical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present disclosure may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit.
The integrated unit, if implemented in the form of a software functional unit and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present disclosure may be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present disclosure. And the aforementioned storage medium includes: various media capable of storing program codes, such as a U disk, a Read Only Memory (ROM), a Random Access Memory (RAM), a removable hard disk, a magnetic disk, or an optical disk.
The foregoing is merely a preferred embodiment of the present disclosure, and it should be noted that modifications and embellishments could be made by those skilled in the art without departing from the principle of the present disclosure, and these should also be considered as the protection scope of the present disclosure.
Claims (21)
1. A method of testing system code, comprising:
acquiring first index data and second index data based on a target code, wherein the target code is a full system code, the first index data is a full class index, and the second index data is a full function index;
generating 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;
acquiring 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.
2. The method of claim 1, wherein obtaining the first index data and the second index data based on the object code comprises:
and accessing and traversing the syntax tree of the target code to acquire the first index data and the second index data.
3. The method of claim 1, wherein the method further comprises:
and in the process of executing the submitting operation on the target code, comparing the difference between the code content stored in a first storage area and the code content stored in a second storage area by using a difference instruction corresponding to a preset version library to obtain the change information, wherein the first storage area is a temporary storage 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 obtaining the target class set via the first index data, the change information, and the target call chain comprises:
acquiring a first function set through the change information;
determining an initial class set by adopting the target calling chain and the first function set;
and acquiring the target class set according to the first index data and the initial class set.
5. The method of claim 4, wherein obtaining the first set of functions via the change information comprises:
and acquiring function information to which the change information belongs to obtain the first function set.
6. The method of claim 4, wherein determining the initial set of classes using the target call chain and the first set of functions comprises:
obtaining a calling chain result of each function in the first function set from the target calling chain, wherein the calling chain result is used for describing the calling relation of all functions which directly or indirectly call each function in the first function set;
obtaining a second function set based on the calling chain result, wherein the second function set is a function set having a direct calling relationship with each function in the first function set;
and determining the initial class set according to the class to which each function in the second function set belongs.
7. The method of claim 4, wherein obtaining the target class set according to the first index data and the initial class set comprises:
selecting target class elements from the initial class set;
judging whether a first preset condition is met between a current class searched by a target class element through the target class index element and the target class index element, wherein the target class index element is any one class index element contained in the first index data;
and an obtaining step, in response to the first preset condition being met between the current class and 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 met, so as to obtain the target class set.
8. The method of claim 7, wherein the first preset condition comprises one of:
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 the class variables of the target class index element.
9. The method of claim 7, wherein the second preset condition comprises:
and stopping changing the number of the class elements contained in the initial class set, and finishing processing all the class elements contained in the initial class set.
10. An apparatus for testing system code, comprising:
the system comprises a first obtaining module, a second obtaining module and a third obtaining module, wherein the first obtaining module is used for obtaining first index data and second index data based on target codes, the target codes are full system codes, the first index data are full class indexes, and the second index data are full function indexes;
a generating module, configured to generate a target call chain using the target code and the second index data, where the target call chain is a full function call chain;
a second obtaining module, configured to obtain, through the first index data, change information of the target code, and the target call chain, a target class set corresponding to the change information;
and the test module is used for carrying out code test according to the target class set.
11. The apparatus of claim 10, wherein the first obtaining means is further configured to:
and accessing and traversing the syntax tree of the target code to acquire the first index data and the second index data.
12. The apparatus of claim 10, wherein the apparatus further comprises:
and the comparison module is used for comparing the difference between the code content stored in the first storage area and the code content stored in the second storage area by using a difference instruction corresponding to a preset version library in the process of executing the submitting operation on the target code to obtain the change information, wherein the first storage area is a temporary storage area corresponding to the preset version library, and the second storage area is a working area corresponding to the preset version library.
13. The apparatus of claim 10, wherein the second obtaining means is further configured to:
acquiring a first function set through the change information; determining an initial class set by adopting the target calling chain and the first function set; and acquiring the target class set according to the first index data and the initial class set.
14. The apparatus of claim 13, wherein the second obtaining means is further configured to:
and acquiring function information to which the change information belongs to obtain the first function set.
15. The apparatus of claim 13, wherein the second obtaining means is further configured to:
obtaining a calling chain result of each function in the first function set from the target calling chain, wherein the calling chain result is used for describing the calling relation of all functions which directly or indirectly call each function in the first function set; obtaining a second function set based on the calling chain result, wherein the second function set is a function set having a direct calling relationship with each function in the first function set; and determining the initial class set according to the class to which each function in the second function set belongs.
16. The apparatus of claim 13, wherein the second obtaining means comprises:
a selecting unit, configured to select a target class element from the initial class set;
a determining unit, configured to determine whether a first preset condition is satisfied between a current class found by a target class element through the target class index element and the target class index element, where the target class index element is any class of index elements included in the first index data;
and the obtaining unit is used for responding to the situation that the first preset condition is met between the current class and 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 met, so as to obtain the target class set.
17. The apparatus of claim 16, wherein the first preset condition comprises one of:
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 the class variables of the target class index element.
18. The apparatus of claim 16, wherein the second preset condition comprises:
and stopping changing the number of the class elements contained in the initial class set, and finishing processing all the class elements contained in the initial class set.
19. An electronic device, comprising:
at least one processor; and
a memory communicatively coupled to the at least one processor; wherein,
the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the method of any one of claims 1-9.
20. A non-transitory computer readable storage medium having stored thereon computer instructions for causing the computer to perform the method of any one of claims 1-9.
21. A computer program product comprising a computer program which, when executed by a processor, implements the method according to any one of claims 1-9.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202111669896.9A CN114328254A (en) | 2021-12-30 | 2021-12-30 | Method and device for testing system code, electronic equipment and storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202111669896.9A CN114328254A (en) | 2021-12-30 | 2021-12-30 | Method and device for testing system code, electronic equipment and storage medium |
Publications (1)
Publication Number | Publication Date |
---|---|
CN114328254A true CN114328254A (en) | 2022-04-12 |
Family
ID=81020105
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202111669896.9A Pending CN114328254A (en) | 2021-12-30 | 2021-12-30 | Method and device for testing system code, electronic equipment and storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN114328254A (en) |
-
2021
- 2021-12-30 CN CN202111669896.9A patent/CN114328254A/en active Pending
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN108090567B (en) | Fault diagnosis method and device for power communication system | |
CN110825619A (en) | Automatic generation method and device of interface test case and storage medium | |
CN108197306A (en) | SQL statement processing method, device, computer equipment and storage medium | |
CN110688305B (en) | Test environment synchronization method, device, medium and electronic equipment | |
CN111124872A (en) | Branch detection method and device based on difference code analysis and storage medium | |
CN103186463B (en) | Determine the method and system of the test specification of software | |
US9760470B2 (en) | Device, method, and program analysis of new source code to be added to execution program to check for bug | |
CN112181430B (en) | Code change statistical method, device, electronic equipment and storage medium | |
CN111427784B (en) | Data acquisition method, device, equipment and storage medium | |
CN103064780A (en) | Software testing method and device thereof | |
CN105912467A (en) | Performance test method and device | |
CN110908869B (en) | Application program data monitoring method, device, equipment and storage medium | |
CN102789417B (en) | Program detecting system and method based on directional symbol execution on mobile intelligent terminal | |
US11520682B2 (en) | Code coverage method for embedded system on chip | |
CN116401113B (en) | Environment verification method, device and medium for heterogeneous many-core architecture acceleration card | |
CN110377476B (en) | Terminal testing method, terminal and readable storage medium | |
CN114328254A (en) | Method and device for testing system code, electronic equipment and storage medium | |
CN113742156B (en) | Joint debugging method, joint debugging device, electronic equipment and storage medium | |
CN116737535A (en) | Interface test method, device, computer equipment and storage medium | |
CN115576831A (en) | Test case recommendation method, device, equipment and storage medium | |
CN115687129A (en) | Coverage rate report generation method and device, storage medium and computer equipment | |
CN113568662B (en) | Code change influence range analysis method and system based on calling relation | |
CN113608996B (en) | Mirror image compiling test method, system, device and readable storage medium | |
CN111881128B (en) | Big data regression verification method and big data regression verification device | |
CN118502732B (en) | Analysis method, device, equipment and medium of byte code program |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |