Code testing method and device, equipment and storage medium
By establishing a logical relationship tree of the code, the problem of being unable to quickly locate the cause of test failure in the existing technology is solved, and rapid and accurate analysis and optimization support of code testing are achieved.
Patent Information
- Application Number
- CN202410235788.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-03-01
- Publication Date
- 2024-09-17
AI Technical Summary
Existing code testing methods cannot quickly and accurately locate the factors that lead to test failure, making it difficult to analyze later test results.
By obtaining the target code and test cases, the code is parsed to establish a logical relationship tree, which represents the running nodes and logical relationships. Based on this, the failure factors are determined when the test fails.
It can quickly and accurately locate the cause of code test failure, providing reliable data support for later test result analysis and code optimization.
Smart Images

Figure CN118656292A
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a code testing method, device, equipment and storage medium. Background Art
[0002] After the application is developed, it is usually necessary to test the application code to ensure that the application can run normally after it is launched. The current code testing solution only has the function of testing the code, and cannot locate the part where the test error is reported, making it difficult to analyze the test results later. Summary of the invention
[0003] The purpose of the embodiments of the present application is to provide a code testing method, apparatus, device and storage medium for realizing automated code testing and quickly and accurately locating the factors in the code that caused the test failure after the test failed.
[0004] In order to achieve the above objectives, the present application embodiment adopts the following technical solutions:
[0005] In a first aspect, an embodiment of the present application provides a code testing method, comprising:
[0006] Obtaining a target code to be tested and a test case for testing the target code;
[0007] Parsing the target code to obtain operation logic information of the target code;
[0008] Based on the operation logic information, a logic relationship tree of the target code is established, wherein the logic relationship tree represents the operation nodes in the target code and the logical relationships between different operation nodes;
[0009] The target code is tested based on the test case, and in case of test failure, a failure factor causing the test failure of the target code is determined based on the logic relationship tree.
[0010] In a second aspect, an embodiment of the present application provides a code testing device, including:
[0011] An acquisition unit, used for acquiring a target code to be tested and a test case for testing the target code;
[0012] An establishing unit, configured to parse the target code to obtain operation logic information of the target code, and to establish a logic relationship tree of the target code based on the operation logic information, wherein the logic relationship tree represents operation nodes in the target code and logic relationships between different operation nodes;
[0013] The testing unit is used to test the target code based on the test case, and in case of test failure, determine the failure factor causing the test failure of the target code based on the logic relationship tree.
[0014] In a third aspect, an embodiment of the present application provides an electronic device, comprising: a processor; and a memory for storing commands executable by the processor; wherein the processor is configured to execute the commands to implement the code testing method as described in the first aspect.
[0015] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, which, when commands in the storage medium are executed by a processor of an electronic device, enables the electronic device to execute the code testing method described in the first aspect.
[0016] In a fifth aspect, an embodiment of the present application provides a computer program product, which includes a non-transitory computer-readable storage medium storing a computer program, and the computer program is operable to cause a computer to execute some or all of the steps in the method described in the first aspect.
[0017] At least one of the above technical solutions adopted in the embodiments of the present application can achieve the following beneficial effects:
[0018] By parsing the target code and establishing a logic relationship tree based on the running logic information of the target code, the logical relationship between the running nodes in the target code can be clearly and intuitively reflected. This logical relationship contains the execution logic between the code statements related to the running nodes in the target code; after testing the target code based on the test case, if the test fails, by analyzing the logical relationship between the running nodes represented by the logic relationship tree, capturing the execution logic between the code statements related to the running nodes, and reversely deducing the test failure results, the failure factors that caused the failure of the target code test can be quickly and accurately determined, providing reliable data support for subsequent test result analysis, exception handling and code optimization. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0020] Figure 1 A flowchart of a code testing method provided for one embodiment of the present application;
[0021] Figure 2 A schematic diagram of a logical relationship tree provided for an embodiment of the present application;
[0022] Figure 3 A flowchart of a code testing method provided for another embodiment of the present application;
[0023] Figure 4 A schematic diagram of the structure of a code testing device provided for one embodiment of the present application;
[0024] Figure 5 A schematic diagram of the structure of an electronic device provided for one embodiment of the present application. DETAILED DESCRIPTION
[0025] In order to make the purpose, technical solution and advantages of the present application clearer, the technical solution of the present application will be clearly and completely described below in combination with the specific embodiments of the present application and the corresponding drawings. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present application.
[0026] The terms "first", "second", etc. in the specification and claims of the present application are used to distinguish similar objects, and are not used to describe a specific order or precedence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present application can be implemented in an order other than those illustrated or described here. In addition, "and / or" in the specification and claims represents at least one of the connected objects, and the character " / " generally represents that the objects associated with each other are in an "or" relationship.
[0027] It should be understood that the code testing method provided in the embodiment of the present application can be executed by an electronic device, specifically by a processor of the electronic device. The electronic device can be a terminal device, such as a smart phone, a tablet computer, a laptop computer, a desktop computer, an intelligent voice interaction device, a smart home appliance, a smart watch, a vehicle terminal, an aircraft, etc.; or, the electronic device can also be a server, such as an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server providing cloud computing services.
[0028] The technical solutions provided by various embodiments of the present application are described in detail below in conjunction with the accompanying drawings.
[0029] See also Figure 1 , is a flowchart of a code testing method provided by an embodiment of the present application, the method comprising the following steps:
[0030] S102, obtaining a target code to be tested and a test case for testing the target code.
[0031] A test case is a description of the test task performed on the target code, including a set of test inputs, execution conditions, and expected results compiled for the test target, which is used to test whether the target code meets a specific requirement.
[0032] The test case can be obtained in various ways, and can be set according to actual needs, which is not limited in the present embodiment. In one embodiment, the test case can be written by a tester according to actual test requirements.
[0033] In another embodiment, in order to increase the degree of automation of code testing, reduce manual participation, and improve testing efficiency and accuracy, test cases can be obtained in the following manner: based on the parsing function corresponding to the test command in the test command set, the test command is parsed to obtain the parameter range of the test command; based on the reference parameter range and parameter range of the test command, the test command is verified; based on the test command that has passed the verification in the test command set, a test case is generated.
[0034] The test command set includes a plurality of test commands for testing the code, and each test command has a corresponding reference parameter range to indicate the available value range of the parameters involved in the test command. The test commands contained in the test command set vary according to the type of the target code. As an example, if the type of the target code is a Hypertext Transfer Protocol (HTTP) code, then the test command set is an AT (Attention) command set, which includes a plurality of AT commands. The AT command set is sent from a terminal equipment (TE) or a data interruption equipment (DTE) to a terminal adapter (TA) or a data circuit terminal equipment (DCE). Through the TA command, TE sends AT commands to control the relevant functions of the application code.
[0035] The parsing function of the test command is used to parse the parameters involved in the test command to determine the actual parameter range of the parameters (i.e. the parameter range of the test command). By comparing the actual value range of the parameters with the available value range, if the actual value range of all parameters involved in the test command is consistent with the corresponding available value range, it is determined that the test command has passed the verification; otherwise, it is determined that the test command has not passed the verification.
[0036] For example, one AT command in the AT command set is:
[0037] AT+MHTTPDBG= <mode>,<DBG_TYPE>
[0038] Among them, MODE and DBG_TYPE are parameters involved in the AT command, the reference value range of MODE is 0 to 1, and the reference value range of DBG_TYPE is 1 to 5. If the actual value range of MODE obtained by parsing the AT command is 0 to 1, and the actual value range of DBG_TYPE is 1 to 5, it is determined that the AT command passes the verification.
[0039] After determining the test commands that have passed the verification in the test command set, based on the value range of such test commands, a target test command is randomly generated, and based on the target test command and the test task for the target code, a test case for executing the test task is generated. For example, taking the above AT command as an example, if the AT command passes the verification, the target commands AT+MHTTPDGB=1,1 and AT+MHTTPDBG=1,3 are generated, and then the test case is generated based on the target command.
[0040] It is worth noting that if the target code is an HTTP code, when using the relevant AT commands for obtaining data, the test system used to test the target code will also be connected to the module that has been input with the AT command, and the test system will send the constructed data packet to the module, which will parse the data after receiving it to judge the performance of the module; when the test system is connected to the module that has been input with the AT command, the test system will put the constructed data into the corresponding parsing function for parsing to judge whether the parsing function can correctly parse the corresponding data and whether the parsed data is complete, etc.
[0041] The test task for the target code can be a single-threaded task or a multi-threaded task. In the case where the test task is a multi-threaded task, in order to quickly generate a complete test case, the process of generating a test case based on the verified test command in the test command set can include the following steps: splitting the test task into N sub-test tasks, and determining the logical information between the N sub-test tasks; generating N sub-test cases based on the N sub-test tasks and the verified test commands in the test command set, and the N sub-test cases correspond to the N sub-test tasks one by one; based on the logical information between the N sub-test tasks, combining the N sub-test cases to obtain a test case. Among them, the logical information between the N sub-test tasks is used to represent the execution logic between the N sub-test tasks, such as sub-test task 1 is executed after sub-test task 2, sub-test task 1 is executed synchronously with sub-test task 2, and so on.
[0042] For example, if the test task is to test the function of jumping from page A to page B and then to page C, the test task is split into the following two sub-test tasks, and the execution logic between the two sub-test tasks is determined to be sequential execution.
[0043] Subtest Task 1: Test the function of jumping from page A to page B;
[0044] Subtest Task 2: Test the function of jumping from page B to page C.
[0045] Further, a test command related to sub-test task 1 is determined from the verified test commands, and sub-test case 1 is generated based on the test command and sub-test task 1; and a test command related to sub-test task 2 is determined from the verified test commands, and sub-test case 2 is generated based on the test command and sub-test task 2; sub-test case 1 and sub-test case 2 are combined in series to obtain a test case for executing the above-mentioned test tasks.
[0046] S104, parsing the target code to obtain the operation logic information of the target code.
[0047] The operation logic information is used to represent the operation logic of the target code, and may specifically include the operation nodes contained in the target code and the logical relationship between the operation nodes. The operation nodes may include objects involved in the operation of the target code, such as web pages, controls, functional modules, etc. The logical relationship may include, for example, but is not limited to, at least one of the following relationships: jump logic, interpretation logic, association logic, parallel logic, etc.
[0048] For example, if the target code is used to implement the function from page A to page B, then page A and page B are two running nodes, and the logical relationship between them is jump logic. For another example, if the target code contains function module A and function module B, and function module B is used to interpret function module A, then function module A and function module B are two running nodes, and the logical relationship between them is interpretation logic. For another example, if the target code is used to implement the function of running function module C after control B is triggered, then control B and function module C are two running nodes, and the logical relationship between them is association logic. For another example, if function module A and function module B in the target code run in parallel, then function module A and function module B are two running nodes, and the logical relationship between them is parallel logic.
[0049] S106: Establish a logic relationship tree of the target code based on the operation logic information.
[0050] The logical relationship tree represents the running nodes in the target code and the logical relationships between different running nodes. The logical relationship tree includes parent nodes and child nodes, and the running order of the parent node is before the running order of the child node. A parent node can have a logical relationship with multiple child nodes, that is, a parent node can have multiple child nodes. A child node leaf can have a logical relationship with multiple parent nodes, that is, a child node can have multiple parent nodes. There can be logical relationships between different parent nodes, and there can also be logical relationships between different child nodes. Therefore, the logical relationship tree can clearly and accurately represent the logical relationship between different running nodes in the target code.
[0051] The logical relationship tree can be established in various ways, and can be set according to actual needs. The embodiment of the present application does not limit this. In one embodiment, the above S106 may include the following steps: based on the logical relationship between the running nodes, the running nodes with logical relationships in the target code are obtained; the running nodes with the earlier running order in the obtained running nodes are used as parent nodes, and the running nodes with the later running order are used as child nodes, and a connection edge is created between the parent node and the child node, and the logical relationship between the parent node and the child node is determined as the edge attribute of the connection edge.
[0052] For example, the target code includes running nodes 1 to 5, the logical relationship between running node 1 and running node 2 is jump logic, the logic between running node 2 and running node 3 is parallel logic, the logic between running node 3 and running node 4 is association logic, and the logic between running node 4 and running node 5 is interpretation logic, then the following is established: Figure 2 The logical relationship tree shown.
[0053] Each running node in the logical relationship tree has a corresponding node attribute to describe the relevant information of the running node. In order to locate the cause of the test failure more quickly and accurately, the node-related information may include the pointer function call logic corresponding to the running node. The pointer function call logic represents the calling logic of the pointer function by the corresponding running node, such as how the code statements, functions, etc. involved in the running node call the pointer function. In this way, combined with the logical relationship represented by the logical relationship tree and the pointer function call logic of each running node, the cause of the test failure can be quickly located when the test fails.
[0054] S108, testing the target code based on the test case.
[0055] The test case contains the test input, execution conditions and expected results. The target code is run based on the test input and execution conditions to obtain the running results. If the running results are inconsistent with the expected results, the test is determined to have failed; if the running results are consistent with the expected results, the test is determined to have succeeded.
[0056] In another embodiment of the present application, in order to avoid abnormalities such as code freezing during the test process, before the above S108, the code testing method provided in the embodiment of the present application may further include the following steps:
[0057] Performing an anomaly detection operation on the target code, and modifying the target code based on the detection result of the anomaly detection operation. The anomaly detection operation includes at least one of the following operations:
[0058] Exception detection operation 1: obtain the array to be assigned and the assignment length of the array to be assigned in the target code, and determine whether the array to be assigned is out of bounds based on the assignment length.
[0059] For example, the array to be assigned in the target code includes array A. If the assignment length of array A is greater than the length of array A, it is determined that array A is out of bounds, which may cause the target code to get stuck during execution. For example, after array A is out of bounds, if there is no length limit when printing array A, it will cause array A to be accessed out of bounds; after array A is accessed out of bounds, the data stored in array A may be erased and overwritten, so that a crash may occur after accessing the data stored in array A.
[0060] In this case, if there is an array out of bounds in the array to be assigned, the assignment length of the array to be assigned in the target code is modified to ensure that the assignment length is smaller than the length of the array to be assigned.
[0061] Exception detection operation 2: obtaining actual write information and target write information of the assignment function in the target code, and determining whether there is an out-of-bounds exception in the assignment function based on the actual write information and the target write information.
[0062] The actual writing information of the assignment function includes the spatial size relationship between the actual writing length of the assignment function and the writing position. The target writing information includes the spatial size relationship between the length of the data to be written by the assignment function and the writing position.
[0063] For example, the assignment function in the target code includes a sprintf function. If the actual write information of the sprintf function does not match the target write information, it is determined that an out-of-bounds exception exists in the assignment function, and this out-of-bounds exception may cause a pointer to access out-of-bounds.
[0064] In this case, if an out-of-bounds exception occurs in the assignment function, the target write information of the assignment function is modified in the target code to ensure that the actual write information of the assignment function is consistent with the target write information.
[0065] Anomaly detection operation 3: obtaining the space information of the target code application, and determining whether the target code has an application space anomaly based on the application space information.
[0066] For example, if the space applied by the target code does not match the actual space, it is determined that the target code has an applied space anomaly. In this case, the space information applied by the target code is corrected to ensure that the space applied by the target code matches the actual space.
[0067] Anomaly detection operation 4: obtain the space information released by the target code and the historical application records based on the released space information to determine whether there is any space release anomaly in the target code.
[0068] For example, if the space released by the target code has been applied for, the space cannot be released, otherwise it will cause a crash. Therefore, based on the historical application records of the released space information, it can be determined whether the space released by the target code has been applied for. If so, it is determined whether the target code has a space anomaly. In this case, a judgment method can be added to the target code to determine whether the released space has been applied for before the space is released. If so, the release operation is not performed on the space.
[0069] S110, in case of test failure, determining the failure factor causing the target code test failure based on the logic relationship tree.
[0070] Since the logic relationship tree clearly and intuitively describes the logical relationship between the running nodes in the target code, in the case of test failure, the currently running running node can be determined. By analyzing the code statements related to the currently running running node and the code statements related to the running node that has a logical relationship with the currently running node, the failure factors that caused the failure of the target code test can be determined, such as the function that caused the test failure, the code statements in the function that caused the test failure, etc.
[0071] Since the logical relationship between the running nodes is implemented by calling the corresponding function based on the pointer function, the calling logic of the pointer function by the running node can reflect how the logical relationship between the running nodes is implemented. Based on this, in one embodiment, the failure factor can be quickly and accurately located on the basis of the logical relationship tree representing the logical relationship between the running nodes combined with the pointer function calling logic of the running nodes. Specifically, the above S110 may include the following steps:
[0072] S1102, obtaining the current address where the pointer function is stored.
[0073] The current address points to the next line of code to be executed in the target code.
[0074] S1104, determining a candidate execution node from the execution nodes included in the target code based on the current address, the logic relationship tree, and the pointer function calling logic of the execution node included in the target code.
[0075] S1106, analyzing the code statements related to the candidate running node in the target code to obtain failure factors.
[0076] As an example, if the current address stored in the pointer function is abnormal, the first running node that calls the pointer function is determined based on the pointer function calling logic of the running node contained in the target code, the second running node located upstream of the first running node is determined based on the logic relationship tree, and the first running node and the second running node are determined as candidate running nodes.
[0077] Since the current address stored in the pointer function is the address of the code statement to be executed in the next line, if the current address is abnormal, it can be preliminarily determined that the cause of the test failure is the call to the wrong pointer function. Then, the first running node that calls the pointer function and the second running node located upstream of the first running node in the logical relationship tree can be identified as candidate running nodes that may cause the test failure. By analyzing the code statements related to these running nodes, the failure factors that actually cause the failure of the target code test can be accurately determined.
[0078] For example, Figure 2 Taking the logical relationship tree shown as an example, if the current address stored in the pointer function is abnormal, such as 0, and the running node that calls the pointer function is running node 2, then running node 2 and the upstream running node 1 are determined as candidate running nodes, and the code statements used to execute the jump logic are found from the code statements related to the candidate running nodes. By analyzing these code statements, the failure factors that caused the test failure can be quickly determined.
[0079] If the current address stored in the pointer function is normal, determine the previous line of code statement of the code statement pointed to by the current address, and the third running node related to the previous line of code statement, and determine the fourth running node located upstream of the third running node based on the logical relationship tree, and determine the third running node and the third running node as candidate running nodes.
[0080] Since the current address stored in the pointer function is the address of the code statement to be executed in the next line, if the current address is normal, it can be preliminarily determined that the cause of the test failure is the code statement being executed when the target code runs incorrectly, and then the code statement to be executed in the next line can be located through the current address stored in the pointer function, and the third running node related to the previous code statement of the code statement and the fourth running node located upstream of the third running node are determined as candidate running nodes that may cause the test failure. By analyzing the code statements related to these running nodes, the failure factors that actually cause the test failure can be accurately determined.
[0081] For example, Figure 2 Taking the logical relationship tree shown as an example, if the current address stored in the pointer function is normal, the next code statement to be executed is located at the 50th line of code statement through the current address. If the running node related to the 49th code statement is running node 4, running node 4 and the upstream running nodes 1 to 3 are all determined as candidate running nodes. Then, the code statements for executing the jump logic are found from the code statements related to running node 1 and the code statements related to running node 2, the code statements for executing the parallel logic are found from the code statements related to running node 2 and the code statements related to running node 3, and the jump statements for executing the associated logic are found from the code statements related to running node 3 and the code statements related to running node 4. By analyzing these code statements, the failure factors that cause the test failure can be quickly located.
[0082] In another embodiment of the present application, after locating the failure factor, in order to optimize the target code in a targeted manner, such as Figure 3 As shown, after the above S110, the code testing method provided in the embodiment of the present application may further include the following steps:
[0083] S112, clustering the factor set to obtain K clusters.
[0084] Each cluster includes at least one historical failure factor, and each cluster corresponds to a category. K clusters are obtained by clustering the factor set. The factor set includes multiple historical failure factors.
[0085] The factor set may include historical failure factors obtained during historical testing of the target code, or may include historical failure factors obtained through the Internet, or may include historical failure factors obtained through other means.
[0086] The categories of failure factors may include, for example, but are not limited to, at least one of the following categories: localization error, execution of null pointer function, code statement spelling error, etc.
[0087] The clustering process of the factor set may be implemented by using various clustering algorithms, which may be specifically configured according to actual needs, and the embodiments of the present application do not limit this.
[0088] As an example, a mean clustering algorithm commonly used in the art, such as a k-means algorithm, may be used to cluster the historical failure factors in the factor set.
[0089] As another example, the spectral clustering algorithm and the mean clustering algorithm may be combined to cluster the historical failure factors in the factor set, so that the clustering result obtained is more accurate. Specifically, the above S112 may include the following steps:
[0090] Step A1, construct the distance matrix corresponding to the factor set.
[0091] The distance matrix represents the distance between historical failure factors in the factor set (such as Euclidean distance). For example, the factor set includes n historical failure factors, that is, X = (x1, x2, ..., xn). After calculating the distance between each pair of historical failure factors in the factor set, the distance matrix dist is constructed. n×n , the element dist in the i-th row and j-th column of the distance matrix ij Represents the distance between the i-th historical failure factor and the j-th historical failure factor in the factor set.
[0092] Step A2: construct similarity graph matrix and degree matrix based on the distance matrix.
[0093] The similarity graph matrix represents the similarity between the historical failure factors in the factor set. For example, taking the above distance matrix as an example, the constructed similarity graph matrix S n×n The element in the i-th row and j-th column in the factor set represents the similarity between the i-th historical failure factor and the j-th historical failure factor.
[0094] The degree matrix represents the sum of the similarities between a historical failure factor in the factor set and each historical failure factor in the factor set. The degree matrix is a diagonal matrix, that is, only the elements on the main diagonal are not zero. For example, taking the above distance matrix as an example, the element in the i-th row and i-th column of the constructed similarity graph matrix D represents the sum of the similarities between the i-th historical failure factor and each historical failure factor in the factor set.
[0095] As an example, the above step A2 includes: arranging each row element in the distance matrix, and determining the scale parameter of each element in the distance matrix based on the sorting result, wherein the i-th row and j-th column element in the distance matrix represents the distance between the i-th historical failure factor in the factor set and the j-th historical failure factor set, and the scale parameter of the i-th row and j-th column element represents the arrangement order of the i-th row and j-th column element after arranging the i-th row element in the distance matrix; constructing a similar graph matrix based on each element in the distance matrix and the scale parameter of each element; constructing a degree matrix based on the sum of each row element in the similar graph matrix, and the i-th row and i-th column element in the degree matrix is the sum of the i-th row elements in the similar graph matrix. Wherein, i and j are positive integers, and i and j are less than the number of historical failure factors contained in the factor set.
[0096] In practical applications, the arrangement of each row of elements in the distance matrix can be implemented based on various sorting rules, such as ascending order, etc. The specific selection can be made according to actual needs, and the embodiments of the present application are not limited to this.
[0097] For example, taking the above distance matrix dist ij Take the i-th row element in the matrix as an example, the i-th row element includes the distance between the i-th historical failure factor xi and all the historical failure factors x1~xn in the factor set. By arranging the elements in the i-th row in ascending order, the arrangement order corresponding to each element in the i-th row is obtained, which is equivalent to sorting all the historical failure factors x1~xn in order of the distance from the historical failure factor xi from small to large, and obtaining the arrangement order (i.e., serial number) of each historical failure factor with respect to the historical failure factor xi. The arrangement order of the elements in the i-th row and j-th column in the distance matrix is equivalent to the arrangement order of the historical failure factor j with respect to the historical failure factor xi.
[0098] Then, based on the order of each historical failure factor with respect to the historical failure factor xi, the scale parameter of the element in the i-th row and j-th column is determined, where the elements in the i-th row of the distance matrix have a greater distance represented by the elements with a later order, and thus the corresponding similarity between the two historical failure factors is smaller, and the scale parameter σ of such elements is smaller. Taking the element in the i-th row and j-th column of the distance matrix as an example, the difference between n and the sequence number of the element can be determined as the scale parameter σij of the element.
[0099] Further, the similarity matrix is determined by the following formula (1), and the degree matrix is determined by the following formula (2).
[0100]
[0101]
[0102] Among them, s ij Represents the element in the i-th row and j-th column of the similarity graph matrix, dist ij represents the element in the i-th row and j-th column of the distance matrix, σ ij represents the scale parameter of the element in the i-th row and j-th column of the distance matrix, d ii represents the element in the i-th row and i-th column of the degree matrix, S i ” represents the element of the ith row in the noisy similarity graph matrix, which is obtained by adding random noise under a given privacy budget to the symmetric elements in the similarity matrix.
[0103] Step A3: Based on the similarity graph matrix and the degree matrix, the factor set is clustered to obtain K clusters.
[0104] As an example, the above step A3 includes: constructing a Laplace matrix based on the similarity graph matrix and the degree matrix; analyzing the Laplace matrix based on the characteristic maximum margin algorithm to determine the value of K, and calculating the eigenvectors corresponding to the first K smallest eigenvalues in the Laplace matrix; constructing a feature matrix based on the eigenvectors corresponding to the first K smallest eigenvalues, wherein each row vector of the feature matrix corresponds to a historical failure factor; clustering the row vectors of the feature matrix based on the mean clustering algorithm, and determining K cluster clusters based on the clustering results of the row vectors.
[0105] More specifically, the Laplace matrix can be determined by the following formula (3):
[0106] L=I-(D) -1 / 2 S'(D) -1 / 2 (3)
[0107] Among them, L represents the Laplace matrix, I represents the identity matrix, D represents the degree matrix, and S' represents the similarity matrix after adding noise.
[0108] Then, all eigenvalues λ1,...,λ k Very small, but k+1 With the goal of being relatively large, the appropriate number of clusters K is adaptively selected from the Laplace matrix based on the characteristic maximum margin algorithm, and then the first K minimum eigenvalues are selected from the Laplace matrix, and the eigenvectors corresponding to these minimum eigenvalues are determined.
[0109] Based on perturbation theory, in the ideal case of K completely unconnected clusters, eigenvalue 0 has K multiplicity and there is an interval with the K+1th eigenvalue. The feature maximum interval algorithm can be used as a standard to measure the value of K. The value of K when the feature interval is the largest is the most appropriate value. The feature interval refers to the absolute value of the difference between two adjacent eigenvalues.
[0110] After determining the eigenvectors corresponding to the first K smallest eigenvalues, the matrix U composed of these eigenvectors can be normalized row by row to generate an n×K-dimensional eigenmatrix T, where t ij represents the element in the i-th row and j-th column of the feature matrix T, u ij represents the original value of the i-th row and j-th column in the normalized matrix U, u ik Represents the element in the i-th row and k-th column of the normalized matrix.
[0111] Finally, the k-means++ algorithm is used to transform the i-th row vector t of the feature matrix i Clustered into the corresponding cluster, if the i-th row vector is marked as the j-th category and belongs to the j-th cluster, then the i-th historical failure factor xi is attributed to the j-th cluster, that is, the category is the j-th category.
[0112] S114, determining the category of the failure factor based on the historical failure factors included in the K clusters and the categories corresponding to the K clusters.
[0113] As an example, based on the historical failure factors contained in each cluster, the similarity between each cluster and the failure factor is calculated; the cluster with the highest similarity to the failure factor is selected from the K clusters; and the category corresponding to the selected cluster is determined as the category of the failure factor.
[0114] More specifically, for each cluster, the average of the similarities between all historical failure factors included in the cluster and the failure factor may be determined as the similarity between the failure factor and the cluster.
[0115] In this embodiment, after clustering the historical failure factors in the factor set, the similarity between the K clusters obtained by the clustering process and the failure factors can be used to quickly and accurately determine the category of the failure factor based on the category of the historical failure factor, thereby providing reliable data support for optimizing the target code.
[0116] The code testing method provided by one or more embodiments of the present application can clearly and intuitively reflect the logical relationship between the running nodes in the target code by parsing the target code and establishing a logical relationship tree based on the running logic information of the target code. This logical relationship contains the execution logic between the code statements related to the running nodes in the target code; after testing the target code based on the test case, if the test fails, by analyzing the logical relationship between the running nodes represented by the logical relationship tree, capturing the execution logic between the code statements related to the running nodes, and reversely deducing the test failure results, the failure factors that caused the failure of the target code test can be quickly and accurately determined, providing reliable data support for subsequent test result analysis, exception handling, and code optimization.
[0117] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0118] Based on the same inventive concept, the present application embodiment also provides a code testing device. Figure 4 , is a schematic diagram of the structure of a code testing device 400 provided in one embodiment of the present application, the device 400 includes: an acquisition unit 410, a creation unit 420 and a test unit 430. The acquisition unit 410 is used to acquire the target code to be tested and the test case for testing the target code.
[0119] Establishing unit 420 is used to parse the target code to obtain the operation logic information of the target code, and establish a logic relationship tree of the target code based on the operation logic information, wherein the logic relationship tree represents the operation nodes in the target code and the logical relationships between different operation nodes.
[0120] The testing unit 430 is used to test the target code based on the test case, and in case of test failure, determine the failure factor causing the test failure of the target code based on the logic relationship tree.
[0121] In one embodiment, the operation logic information includes the operation nodes included in the target code and the logical relationship between the operation nodes;
[0122] When the establishing unit 420 establishes the logic relationship tree of the target code based on the operation logic information, the establishing unit 420 performs the following steps:
[0123] Based on the logical relationship between the running nodes, obtaining nodes having a logical relationship in the target code;
[0124] The acquired running nodes with an earlier running order are taken as parent nodes, and the running nodes with a later running order are taken as child nodes, and a connection edge is created between the parent node and the child node;
[0125] The logical relationship between the parent node and the child node is determined as an edge attribute of the connecting edge.
[0126] In one embodiment, the running node has corresponding pointer function call logic;
[0127] When determining the failure factor causing the target code test failure based on the logic relationship tree, the testing unit 430 performs the following steps:
[0128] Obtaining the current address indicated by the pointer function, wherein the current address points to the next line of code statement to be executed in the target code;
[0129] Determine a candidate execution node from the execution nodes included in the target code based on the current address, the logic relationship tree, and the pointer function call logic of the execution node included in the target code;
[0130] The code statements related to the candidate running node in the target code are analyzed to obtain the failure factor.
[0131] In one embodiment, the test unit 430 performs the following steps when determining a candidate execution node from the execution nodes included in the target code based on the current address, the logic relationship tree, and the pointer function call logic of the execution node included in the target code:
[0132] If the current address is abnormal, determining a first running node that calls the pointer function based on the pointer function calling logic of the running node contained in the target code, determining a second running node located upstream of the first running node based on the logic relationship tree, and determining the first running node and the second running node as candidate running nodes;
[0133] If the current address is normal, determine the previous line of code statement of the code statement pointed to by the current address, and the third running node to which the previous line of code statement belongs, and determine the fourth running node located upstream of the third running node based on the logical relationship tree, and determine the third running node and the third running node as candidate running nodes.
[0134] In one embodiment, the acquisition unit 410 is further used to perform clustering processing on the factor set to obtain K clusters, wherein the factor set includes multiple historical failure factors, each cluster includes at least one historical failure factor, and each cluster corresponds to a category;
[0135] The code testing device 400 further includes:
[0136] A determining unit is used to determine the category of the failure factor based on the historical failure factors included in the K clusters and the categories corresponding to the K clusters.
[0137] In one implementation, the acquisition unit 410 performs the following steps when performing clustering processing on the factor set to obtain K clusters:
[0138] Constructing a distance matrix corresponding to the factor set, wherein the distance matrix represents the distances between the historical failure factors in the factor set;
[0139] Based on the distance matrix, construct a similarity graph matrix and a degree matrix, wherein the similarity graph matrix represents the similarities between the historical failure factors in the factor set, and the degree matrix represents the sum of the similarities between a historical failure factor in the factor set and each of the historical failure factors in the factor set;
[0140] Based on the similarity graph matrix and the degree matrix, clustering is performed on the factor set to obtain the K clusters.
[0141] In one embodiment, constructing a similarity graph matrix and a degree matrix based on the distance matrix includes:
[0142] Arrange each row of elements in the distance matrix, and determine the scale parameter of each element in the distance matrix based on the sorting result, wherein the element in the i-th row and j-th column of the distance matrix represents the distance between the i-th historical failure factor in the factor set and the j-th historical failure factor set, and the scale parameter of the element in the i-th row and j-th column represents the arrangement order of the elements in the i-th row and j-th column after the elements in the i-th row of the distance matrix are arranged, and i and j are positive integers, and i and j are less than the number of historical failure factors included in the factor set;
[0143] Constructing the similarity graph matrix based on each element in the distance matrix and a scale parameter of each element;
[0144] The degree matrix is constructed based on the sum of the elements in each row of the similarity graph matrix, and the element in the i-th row and i-th column of the degree matrix is the sum of the elements in the i-th row of the similarity graph matrix.
[0145] In one embodiment, clustering the factor set based on the similarity graph matrix and the degree matrix to obtain the K clusters includes:
[0146] Constructing a Laplace matrix based on the similarity graph matrix and the degree matrix;
[0147] Analyze the Laplace matrix based on the characteristic maximum margin algorithm to determine the value of K, and determine the eigenvectors corresponding to the first K minimum eigenvalues in the Laplace matrix;
[0148] Based on the eigenvectors corresponding to the first K smallest eigenvalues, construct a characteristic matrix, wherein each row vector of the characteristic matrix corresponds to a historical failure factor;
[0149] The row vectors of the feature matrix are clustered based on a mean value clustering algorithm, and the K cluster clusters are determined based on the clustering results of the row vectors.
[0150] In one embodiment, the test case is obtained by:
[0151] Parsing the test command based on the parsing function corresponding to the test command in the test command set to obtain a parameter range of the test command;
[0152] Verifying the test command based on a reference parameter range of the test command and the parameter range;
[0153] The test case is generated based on the verified test commands in the test command set.
[0154] In one implementation, the generating the test case based on the test command that has passed verification in the test command set includes:
[0155] Acquire a test task for the target code;
[0156] If the test task is a multi-threaded test task, split the test task into N sub-test tasks, and determine the logic information between the N sub-test tasks;
[0157] Based on the N sub-test tasks and the verified test commands in the test command set, N sub-test cases are generated, and the N sub-test cases correspond to the N sub-test tasks one by one;
[0158] The N sub-test cases are combined based on the logic information between the N sub-test tasks to obtain the test case.
[0159] In one implementation, the code testing device 400 further includes:
[0160] an anomaly detection unit, configured to perform an anomaly detection operation on the target code, and to modify the target code based on a detection result of the anomaly detection operation;
[0161] The abnormality detection operation includes at least one of the following operations:
[0162] Obtaining an array to be assigned in the target code and an assignment length of the array to be assigned, and determining whether the array to be assigned is out of bounds based on the assignment length;
[0163] Acquire actual write information and target write information of the assignment function in the target code, and determine whether the assignment function has an out-of-bounds exception based on the actual write information and the target write information;
[0164] Acquiring the spatial information of the target code application, and determining whether the target code has an application spatial anomaly based on the application spatial information;
[0165] The space information released by the target code is obtained, and based on the historical application record of the released space information, it is determined whether there is any space release anomaly in the target code.
[0166] Obviously, the code testing device provided in the embodiment of the present application can be used as Figure 1 The code shown tests the execution body of the method, for example Figure 1 In the code testing method shown, step S102 can be performed by Figure 4 The acquisition module 410 in the code testing device shown in FIG. 1 is executed, and steps S104 and S106 can be performed by Figure 4 The establishment module 420 in the code testing device shown in FIG. 1 is executed, and steps S108 and S110 can be performed by Figure 4 The code testing apparatus shown is executed by the testing module 430 .
[0167] According to another embodiment of the present application, Figure 4 The various modules in the code testing device shown can be separately or completely combined into one or several other modules to constitute, or one (some) of the modules can also be split into multiple smaller modules in function to constitute, which can achieve the same operation without affecting the realization of the technical effects of the embodiments of the present application. The above modules are divided based on logical functions. In practical applications, the functions of one module can also be implemented by multiple modules, or the functions of multiple modules can be implemented by one module. In an embodiment of the present application, the code testing device may also include other modules. In practical applications, these functions can also be implemented with the assistance of other modules, and can be implemented by the collaboration of multiple modules.
[0168] According to another embodiment of the present application, the program can be executed on a general computing device such as a computer including a central processing unit (CPU), a random access memory (RAM), a read-only memory (ROM), and other processing elements and storage elements. Figure 1 A computer program (including program code) for each step involved in the corresponding method shown in FIG. Figure 4 The code testing device shown in the figure implements the code testing method of the embodiment of the present application. The computer program can be recorded on a computer-readable storage medium, for example, and transferred to an electronic device through the computer-readable storage medium and run therein.
[0169] Figure 5 This is a schematic diagram of the structure of an electronic device according to an embodiment of the present application. Figure 5 At the hardware level, the electronic device includes a processor, and optionally also includes an internal bus, a network interface, and a memory. The memory may include a memory, such as a high-speed random access memory (RAM), and may also include a non-volatile memory (non-volatile memory), such as at least one disk storage. Of course, the electronic device may also include hardware required for other services.
[0170] The processor, network interface and memory can be interconnected through an internal bus, which can be an ISA (Industry Standard Architecture) bus, a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus. The bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 5 Only one bidirectional arrow is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0171] The memory is used to store the program. Specifically, the program may include a program code, and the program code includes a computer operation command. The memory may include a memory and a non-volatile memory, and provides commands and data to the processor.
[0172] The processor reads the corresponding computer program from the non-volatile memory into the memory and then runs it, forming a code test device at the logical level. The processor executes the program stored in the memory and is specifically used to perform the following operations:
[0173] Obtaining a target code to be tested and a test case for testing the target code;
[0174] Parsing the target code to obtain operation logic information of the target code;
[0175] Based on the operation logic information, a logic relationship tree of the target code is established, wherein the logic relationship tree represents the operation nodes in the target code and the logical relationships between different operation nodes;
[0176] The target code is tested based on the test case, and in case of test failure, a failure factor causing the test failure of the target code is determined based on the logic relationship tree.
[0177] The above application Figure 1 The method performed by the code testing device disclosed in the illustrated embodiment can be applied to a processor or implemented by a processor. The processor may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by a hardware integrated logic circuit in the processor or a command in the form of software. The above processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The methods, steps and logic block diagrams disclosed in the embodiments of the present application can be implemented or executed. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in the embodiments of the present application can be directly embodied as a hardware decoding processor for execution, or a combination of hardware and software modules in the decoding processor for execution. The software module can be located in a mature storage medium in the field such as random access memory, flash memory, read-only memory, programmable read-only memory or electrically erasable programmable memory, register, etc. The storage medium is located in the memory, and the processor reads the information in the memory and completes the steps of the above method in combination with its hardware.
[0178] The electronic device may also perform Figure 1 The method and implement the code test device in Figure 1 , Figure 3 The functions of the illustrated embodiment will not be described in detail in the embodiments of the present application.
[0179] Of course, in addition to software implementation methods, the electronic device of the present application does not exclude other implementation methods, such as logic devices or a combination of software and hardware, etc. That is to say, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.
[0180] The embodiment of the present application also provides a computer-readable storage medium, which stores one or more programs, wherein the one or more programs include commands, which, when executed by a portable electronic device including a plurality of application programs, enable the portable electronic device to execute Figure 1 The method of the embodiment shown is specifically used to perform the following operations:
[0181] Obtaining a target code to be tested and a test case for testing the target code;
[0182] Parsing the target code to obtain operation logic information of the target code;
[0183] Based on the operation logic information, a logic relationship tree of the target code is established, wherein the logic relationship tree represents the operation nodes in the target code and the logical relationships between different operation nodes;
[0184] The target code is tested based on the test case, and in case of test failure, a failure factor causing the test failure of the target code is determined based on the logic relationship tree.
[0185] An embodiment of the present application also provides a computer program product, which includes a non-transitory computer-readable storage medium storing a computer program, and the computer program is operable to cause a computer to execute some or all of the steps in the code testing method provided in the embodiment of the present application.
[0186] In short, the above description is only a preferred embodiment of the present application and is not intended to limit the protection scope of the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.
[0187] The systems, devices, modules or units described in the above embodiments may be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer. Specifically, the computer may be, for example, a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.
[0188] Computer readable media include permanent and non-permanent, removable and non-removable media that can be used to store information by any method or technology. Information can be computer readable commands, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.
[0189] It should also be noted that the term "includes", "comprising" or any other variation thereof is intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of further restrictions, an element defined by the sentence "comprising a ..." does not exclude the existence of other identical elements in the process, method, commodity or device including the element.
[0190] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.< / mode>
Claims
1. A code testing method, characterized in that: include: Obtaining a target code to be tested and a test case for testing the target code; Parsing the target code to obtain operation logic information of the target code; Based on the operation logic information, a logic relationship tree of the target code is established, wherein the logic relationship tree represents the operation nodes in the target code and the logical relationships between different operation nodes; The target code is tested based on the test case, and in case of test failure, a failure factor causing the test failure of the target code is determined based on the logic relationship tree.
2. The method according to claim 1, characterized in that The operation logic information includes the operation nodes contained in the target code and the logical relationship between the operation nodes; The step of establishing a logic relationship tree of the target code based on the operation logic information comprises: Based on the logical relationship between the running nodes, acquiring the running nodes having the logical relationship in the target code; The acquired running nodes with an earlier running order are taken as parent nodes, and the running nodes with a later running order are taken as child nodes, and a connection edge is created between the parent node and the child node; The logical relationship between the parent node and the child node is determined as an edge attribute of the connecting edge.
3. The method according to claim 1, characterized in that The running node has corresponding pointer function calling logic; The determining, based on the logic relationship tree, a failure factor causing the target code test failure includes: Obtaining a current address stored in the pointer function, wherein the current address points to a next line of code statement to be executed in the target code; Determine a candidate execution node from the execution nodes included in the target code based on the current address, the logic relationship tree, and the pointer function call logic of the execution node included in the target code; The code statements related to the candidate running nodes in the target code are analyzed to obtain the failure factors.
4. The method according to claim 3, characterized in that The step of determining a candidate running node from the running nodes included in the target code based on the current address, the logic relationship tree, and the pointer function calling logic of the running nodes included in the target code comprises: If the current address is abnormal, determining a first running node that calls the pointer function based on the pointer function calling logic of the running node contained in the target code, determining a second running node located upstream of the first running node based on the logic relationship tree, and determining the first running node and the second running node as candidate running nodes; If the current address is normal, determine the previous line of code statement of the code statement pointed to by the current address, and the third running node related to the previous line of code statement, and determine the fourth running node located upstream of the third running node based on the logical relationship tree, and determine the third running node and the third running node as candidate running nodes.
5. The method according to claim 1, characterized in that After determining the failure factor causing the target code test failure based on the logic relationship tree, the method further includes: Performing clustering processing on the factor set to obtain K clusters, the factor set includes multiple historical failure factors, each cluster includes at least one historical failure factor, and each cluster corresponds to a category; Based on the historical failure factors included in the K clusters and the categories corresponding to the K clusters, the category of the failure factor is determined.
6. The method according to claim 5, characterized in that The step of clustering the factor set to obtain K clusters includes: Constructing a distance matrix corresponding to the factor set, wherein the distance matrix represents the distances between the historical failure factors in the factor set; Based on the distance matrix, construct a similarity graph matrix and a degree matrix, wherein the similarity graph matrix represents the similarities between the historical failure factors in the factor set, and the degree matrix represents the sum of the similarities between a historical failure factor in the factor set and each of the historical failure factors in the factor set; Based on the similarity graph matrix and the degree matrix, clustering is performed on the factor set to obtain the K clusters.
7. The method according to claim 6, characterized in that The constructing of a similarity graph matrix and a degree matrix based on the distance matrix includes: Arrange each row of elements in the distance matrix, and determine the scale parameter of each element in the distance matrix based on the sorting result, wherein the element in the i-th row and j-th column of the distance matrix represents the distance between the i-th historical failure factor in the factor set and the j-th historical failure factor set, and the scale parameter of the element in the i-th row and j-th column represents the arrangement order of the elements in the i-th row and j-th column after the elements in the i-th row of the distance matrix are arranged, and i and j are positive integers, and i and j are less than the number of historical failure factors included in the factor set; Constructing the similarity graph matrix based on each element in the distance matrix and a scale parameter of each element; The degree matrix is constructed based on the sum of the elements in each row of the similarity graph matrix, and the element in the i-th row and i-th column of the degree matrix is the sum of the elements in the i-th row of the similarity graph matrix.
8. The method according to claim 6, characterized in that The step of clustering the factor set based on the similarity graph matrix and the degree matrix to obtain the K clusters includes: Constructing a Laplace matrix based on the similarity graph matrix and the degree matrix; Analyze the Laplace matrix based on the characteristic maximum margin algorithm to determine the value of K, and determine the eigenvectors corresponding to the first K minimum eigenvalues in the Laplace matrix; Based on the eigenvectors corresponding to the first K smallest eigenvalues, construct a characteristic matrix, wherein each row vector of the characteristic matrix corresponds to a historical failure factor; The row vectors of the feature matrix are clustered based on a mean value clustering algorithm, and the K cluster clusters are determined based on the clustering results of the row vectors.
9. The method according to claim 1, characterized in that: The test case is obtained in the following way: Parsing the test command based on the parsing function corresponding to the test command in the test command set to obtain a parameter range of the test command; Verifying the test command based on a reference parameter range of the test command and the parameter range; The test case is generated based on the verified test commands in the test command set.
10. The method according to claim 9, characterized in that The generating the test case based on the verified test command in the test command set includes: Acquire a test task for the target code; If the test task is a multi-threaded test task, split the test task into N sub-test tasks, and determine the logic information between the N sub-test tasks; Based on the N sub-test tasks and the verified test commands in the test command set, N sub-test cases are generated, and the N sub-test cases correspond to the N sub-test tasks one by one; The N sub-test cases are combined based on the logic information between the N sub-test tasks to obtain the test case.
11. The method according to any one of claims 1 to 10, characterized in that Before testing the target code based on the test case, the method further includes: performing an anomaly detection operation on the target code, and modifying the target code based on a detection result of the anomaly detection operation; The abnormality detection operation includes at least one of the following operations: Obtaining an array to be assigned in the target code and an assignment length of the array to be assigned, and determining whether the array to be assigned is out of bounds based on the assignment length; Acquire actual write information and target write information of the assignment function in the target code, and determine whether the assignment function has an out-of-bounds exception based on the actual write information and the target write information; Acquiring the spatial information of the target code application, and determining whether the target code has an application spatial anomaly based on the application spatial information; The space information released by the target code is obtained, and based on the historical application record of the released space information, it is determined whether there is any space release anomaly in the target code.
12. A code testing device, characterized in that: include: An acquisition unit, used for acquiring a target code to be tested and a test case for testing the target code; An establishing unit, configured to parse the target code to obtain operation logic information of the target code, and to establish a logic relationship tree of the target code based on the operation logic information, wherein the logic relationship tree represents operation nodes in the target code and logic relationships between different operation nodes; The testing unit is used to test the target code based on the test case, and in case of test failure, determine the failure factor causing the test failure of the target code based on the logic relationship tree.
13. An electronic device, characterized in that: include: processor; a memory for storing instructions executable by the processor; The processor is configured to execute the command to implement the code testing method according to any one of claims 1 to 11.
14. A computer-readable storage medium, characterized in that: When the commands in the storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute the code testing method as claimed in any one of claims 1 to 11.
15. A computer program product, characterized in that The computer program product comprises a non-transitory computer-readable storage medium storing a computer program, wherein the computer program is operable to cause a computer to execute part or all of the steps in the method according to any one of claims 1 to 11.
Citation Information
Cited By
Index cross-border test method, computer equipment and computer program product
CN119902979A
Development data detection method and device based on low-code platform and medium
CN119917419A
A development data detection method, device and medium based on a low-code platform
CN119917419B
