Software code testing system and device and storage medium

By combining static analysis and dynamic testing modules, a code defect knowledge graph is constructed, and the test case generation strategy is dynamically adjusted. This solves the problems of high false positive rate, incomplete coverage and low efficiency of existing tools, and achieves more efficient code testing.

CN121501643APending Publication Date: 2026-02-10SHANGHAI YUYU INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510944823.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-07-09
Publication Date
2026-02-10

AI Technical Summary

Technical Problem

Existing code testing tools suffer from high false positive rates, incomplete coverage, low efficiency, lack of cross-version defect pattern learning capabilities, and inability to effectively predict high-risk code areas.

Method used

By combining static analysis, dynamic testing, knowledge graph construction, and test optimization engines, the system dynamically adjusts test case generation strategies and optimizes test resource allocation by generating abstract syntax trees and control flow graphs, monitoring source code behavior, and constructing a code defect knowledge graph.

Benefits of technology

It improved testing efficiency, reduced redundant testing, increased code coverage and defect detection rate, and optimized test resource allocation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121501643A_ABST
    Figure CN121501643A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of code testing, in particular to a software code testing system and device and a storage medium, and the testing system comprises a static analysis module which is used for carrying out grammar and semantic analysis on source codes and generating an abstract syntax tree and a control flow diagram; the dynamic test module is used for executing source codes, monitoring behaviors during operation and capturing behavior abnormal data and code performance data; the knowledge graph construction module is used for constructing a code defect knowledge graph based on a historical defect database, and the code defect knowledge graph comprises an incidence relation between a code mode and a defect type; the test optimization engine is used for dynamically adjusting a test case generation strategy according to the static analysis result and the code defect knowledge graph; and the multi-dimensional evaluation module outputs a code coverage rate, a defect detection rate and a performance bottleneck analysis report. According to the software code test system, the test efficiency of the test optimization engine is improved through combination of the static analysis module and the dynamic test module; 48% of redundancy tests are reduced through priority distribution, and the test efficiency is further improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of code testing technology, specifically to a software code testing system, apparatus, and storage medium. Background Technology

[0002] In current software applications, to ensure the quality and stability of the application, it is usually necessary to test the application package in order to discover potential problems and defects as much as possible. When conducting software testing, it is usually necessary to determine the completeness of the source code execution of the test cases. The completeness of the test case execution is used to evaluate the testing work, which facilitates the adjustment of the test cases and the improvement of the software code.

[0003] Common code testing tools include static analysis tools (such as SonarQube), dynamic testing tools (such as JUnit), and fuzzing tools (such as AFL). However, all of these tools have their own shortcomings. For example, static analysis tools have a high false positive rate and lack context awareness; dynamic testing tools rely on manually written test cases and have incomplete coverage; fuzzing tools have blind mutation strategies and are inefficient; and they lack the ability to learn cross-version defect patterns and cannot predict high-risk code areas. In view of this, we propose a software code testing system, device, and storage medium. Summary of the Invention

[0004] The purpose of this invention is to provide a software code testing system, apparatus, and storage medium to solve the problems mentioned in the background art.

[0005] To achieve the above objectives, the present invention provides the following technical solution: A software code testing system, the testing system comprising: The static analysis module is used to perform syntactic and semantic analysis on the source code, generating an abstract syntax tree and a control flow graph; The dynamic testing module is used to execute source code and monitor runtime behavior, capturing abnormal behavior data and code performance data; The knowledge graph construction module constructs a code defect knowledge graph based on a historical defect database. The code defect knowledge graph contains the association between code patterns and defect types. The test optimization engine dynamically adjusts the test case generation strategy based on static analysis results and code defect knowledge graph. The multi-dimensional evaluation module outputs code coverage, defect detection rate, and performance bottleneck analysis reports.

[0006] Preferably, the static analysis module further includes: A cross-language parser to support syntax and semantic analysis for Java, Python, and C++; The data flow analysis unit is used to track the lifecycle of source code variables and potential null pointer exceptions.

[0007] Preferably, the data flow analysis unit uses the following constraint-solving model to detect null pointers:

[0008] in, This refers to variables in the source code program; This represents the set of all variables in the program; This indicates that the value of variable v is null; This indicates that the variable v is dereferenced.

[0009] Preferably, the dynamic testing module includes: An adaptive fuzz testing engine generates test inputs with a high mutation rate using a genetic algorithm; The memory monitoring unit monitors memory leaks and buffer overflows in the source code.

[0010] Preferably, the mutation strategy of the adaptive fuzz testing engine is:

[0011] in, Let x be the probability of mutation of the test input x; This represents the code coverage at the current moment. The coverage rate at the previous moment; Based on the basic probability coefficient of variation, This is the sensitivity coefficient.

[0012] Preferably, the memory monitoring unit uses shadow memory technology, and the mapping relationship is as follows:

[0013] This is a shadow memory mapping function; The address is the memory address of the monitored program; 0 indicates that the address is unallocated and inaccessible; 1 indicates that the address has been allocated and not released, and access is legal; 2 indicates that the address has been released, and access is considered illegal.

[0014] Preferably, the formula for calculating the defect detection confidence score using the multi-dimensional evaluation module is:

[0015] This indicates the confidence level of the entire testing process in defect detection; This indicates the number of potential defect types covered in this test; The i-th type of defect; The system's detection probability for the i-th defect type.

[0016] Preferably, the test optimization engine performs the following steps: Identifying high-risk paths based on CFG; Recommend targeted test cases based on knowledge graphs; Test resources are dynamically allocated, and the priority of dynamic allocation satisfies the following:

[0017] in, This indicates the priority of the test path; a larger value indicates a higher priority. Indicates the risk value of the path; This indicates the extent of the impact of potential defects along the path; This indicates the estimated time required to execute the path.

[0018] The present invention also provides an apparatus comprising: The memory stores the executable instructions of the test system. Processor; used to execute executable instructions stored in memory.

[0019] The present invention also provides a read storage medium storing a computer program, which, when executed, implements the functions of the test system.

[0020] Compared with the prior art, the beneficial effects of the present invention are: the software code testing system improves the testing efficiency of the test optimization engine by combining the static analysis module and the dynamic testing module; and reduces redundant testing by 48% through priority allocation, further improving testing efficiency. Attached Figure Description

[0021] Figure 1 This is a schematic diagram of the software code testing system framework of the present invention. Detailed Implementation

[0022] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0023] Please see Figure 1 As shown, the present invention provides a technical solution: A software code testing system, the testing system comprising: The static analysis module is used to perform syntactic and semantic analysis on the source code, generating an abstract syntax tree and a control flow graph; The dynamic testing module is used to execute source code and monitor runtime behavior, capturing abnormal behavior data and code performance data; The knowledge graph construction module constructs a code defect knowledge graph based on a historical defect database. The code defect knowledge graph contains the association between code patterns and defect types. The test optimization engine dynamically adjusts the test case generation strategy based on static analysis results and code defect knowledge graph. The multi-dimensional evaluation module outputs code coverage, defect detection rate, and performance bottleneck analysis reports.

[0024] Specifically, the static analysis module includes: A cross-language parser to support syntax and semantic analysis for Java, Python, and C++; The data flow analysis unit is used to track the lifecycle of source code variables and potential null pointer exceptions.

[0025] The data flow analysis unit uses the following constraint-solving model to detect null pointers: ,in, This refers to variables in the source code program; This represents the set of all variables in the program; This indicates that the value of variable v is null; This indicates that variable v is dereferenced. This formula is a constraint stating that for any variable v in the program, it is not allowed for v to be null and simultaneously dereferenced. If static analysis finds a path that may violate this constraint, a potential null pointer exception is reported.

[0026] Specifically, the dynamic testing module includes: An adaptive fuzz testing engine generates test inputs with a high mutation rate using a genetic algorithm; The memory monitoring unit monitors memory leaks and buffer overflows in the source code.

[0027] The mutation strategy of the adaptive fuzz testing engine is as follows:

[0028] in, Let x be the probability of mutation of the test input x; This represents the code coverage at the current moment. The coverage rate at the previous moment; The basic probability coefficient of variation (preset constant, 0.2~0.8). This is the sensitivity coefficient. The formula is a variation of the Sigmoid function used to dynamically adjust the mutation probability based on coverage growth. When coverage grows rapidly (i.e.,...), the mutation probability is adjusted accordingly. When the coverage is relatively high, the mutation probability will decrease (because the current mutation strategy is effective and should be maintained); when the coverage increases slowly or decreases, the mutation probability will increase (in order to try new mutation strategies).

[0029] Specifically, in this embodiment, the code defect knowledge graph is constructed using graph neural networks (GNNs). The nodes include: code entities (functions, variables, classes); defect types (null pointers, resource leaks, concurrency conflicts); and the weights of the associated edges are calculated from the historical defect frequencies.

[0030] The knowledge graph update mechanism includes: When new defect data is added, the node embedding is updated via GNN message passing; Edge weights are adjusted according to the decay factor:

[0031] in, This represents the updated edge weights; This indicates the edge weights before the update; The decay factor (0≤λ≤1) is used to control the proportion of old weights retained. This indicates the frequency of occurrence of the defect pattern corresponding to this edge recently (e.g., the number of times it has occurred in the last month). This formula is used to dynamically update the weights of edges in the knowledge graph, allowing new defect data to influence the graph while preserving historical information.

[0032] Specifically, the memory monitoring unit uses shadow memory technology, and the mapping relationship is as follows:

[0033] This is a shadow memory mapping function; This represents the memory address of the monitored program; 0 indicates that the address is unallocated and inaccessible; 1 indicates that the address has been allocated and not freed, and access is legal; 2 indicates that the address has been freed, and access is considered illegal. This formula defines the status marking rules for each memory address in shadow memory technology.

[0034] Specifically, the formula for calculating the confidence score of defect detection in the multi-dimensional evaluation module is as follows:

[0035] This indicates the confidence level of the entire testing process in defect detection; This indicates the number of potential defect types covered in this test; The i-th type of defect; The system's detection probability for the i-th defect type. This formula is based on an independent event probability model, calculating the probability of detecting at least one defect as the overall confidence level. The higher the coverage of defect types and the higher the detection probability of each defect, the higher the confidence level.

[0036] Specifically, the test optimization engine performs the following steps: Step 1: Identify high-risk paths based on CFG; the criteria for determining high-risk paths are: path complexity (cyclomatic complexity > 10 is high-risk); historical defect density (number of defects / thousand lines of code > 0.5 is high-risk). Step 2: Recommend targeted test cases based on the knowledge graph; Step 3: Dynamically allocate test resources, and the priority of dynamic allocation should meet the following requirements:

[0037] in, This indicates the priority of the test path; a larger value indicates a higher priority. Indicates the risk value of the path; This indicates the extent of the impact of potential defects along the path; This represents the estimated time required to execute the path. This formula is used to prioritize testing high-risk, high-impact paths with short execution times, in situations where resources are limited, to optimize test resource allocation.

[0038] The present invention also provides an apparatus comprising: a memory for storing executable instructions of the test system; and a processor for executing the executable instructions stored in the memory.

[0039] The present invention also provides a read storage medium storing a computer program, which, when executed, implements the functions of the test system.

[0040] The foregoing has shown and described the basic principles, main features, and advantages of the present invention. Those skilled in the art should understand that the present invention is not limited to the above embodiments. The embodiments and descriptions in the specification are merely preferred examples and are not intended to limit the invention. Various changes and modifications can be made to the invention without departing from its spirit and scope, and all such changes and modifications fall within the scope of the present invention as claimed. The scope of protection of the present invention is defined by the appended claims and their equivalents.

Claims

1. A software code testing system, characterized in that, The testing system includes: The static analysis module is used to perform syntactic and semantic analysis on the source code, generating an abstract syntax tree and a control flow graph; The dynamic testing module is used to execute source code and monitor runtime behavior, capturing abnormal behavior data and code performance data; The knowledge graph construction module constructs a code defect knowledge graph based on a historical defect database. The code defect knowledge graph contains the association between code patterns and defect types. The test optimization engine dynamically adjusts the test case generation strategy based on static analysis results and code defect knowledge graph. The multi-dimensional evaluation module outputs code coverage, defect detection rate, and performance bottleneck analysis reports.

2. The software code testing system according to claim 1, characterized in that, The static analysis module further includes: A cross-language parser to support syntax and semantic analysis for Java, Python, and C++; The data flow analysis unit is used to track the lifecycle of source code variables and potential null pointer exceptions.

3. The software code testing system according to claim 2, characterized in that, The data flow analysis unit uses the following constraint-solving model to detect null pointers: Where v represents a variable in the source code program; Variables represents the collection of all variables in the program; v = null means that the value of variable v is null; v.isDereferenced() means that variable v is dereferenced.

4. The software code testing system according to claim 1, characterized in that: The dynamic testing module includes: An adaptive fuzz testing engine generates test inputs with a high mutation rate using a genetic algorithm; The memory monitoring unit monitors memory leaks and buffer overflows in the source code.

5. The software code testing system according to claim 4, characterized in that, The mutation strategy of the adaptive fuzz testing engine is as follows: Among them, P mut (x) represents the probability of mutation of the test input x; cov t This represents the code coverage at the current moment; cov t-1 α represents the coverage rate at the previous time step; α is the basic variation probability coefficient, and β is the sensitivity coefficient.

6. The software code testing system according to claim 4, characterized in that: The memory monitoring unit uses shadow memory technology, and the mapping relationship is as follows: M shadow This is the shadow memory mapping function; addr is the memory address of the monitored program; 0 indicates that the address is unallocated and inaccessible; 1 indicates that the address has been allocated and not released, and access is legal; 2 indicates that the address has been released, and access is considered illegal.

7. The software code testing system according to claim 4, characterized in that, The formula for calculating the confidence level of defect detection by the multi-dimensional evaluation module is as follows: Confidence represents the confidence level of the entire testing process in defect detection; n represents the number of potential defect types covered in this test; defect i The i-th defect type; P detect (defect i The system's detection probability for the i-th defect type.

8. The software code testing system according to claim 1, characterized in that, The test optimization engine performs the following steps: Identifying high-risk paths based on CFG; Recommend targeted test cases based on knowledge graphs; Test resources are dynamically allocated, and the priority of dynamic allocation satisfies the following: Here, Priority indicates the priority of the test path, with a higher value indicating higher priority; Risk path Indicates the risk value of the path; Impact defect Indicates the extent of the impact of potential defects along this path; Execution time This indicates the estimated time required to execute the path.

9. An apparatus, characterized in that, include: The memory stores executable instructions of the test system as described in any one of claims 1-8; processor; Used to execute executable instructions stored in memory.

10. A read storage medium, characterized in that, It stores a computer program that, when executed, performs the functions of the test system as described in any one of claims 1-8.