Code scanning-based memory automatic test method and system
Through the memory automation testing method based on code scanning, test cases are automatically generated and memory growth trends are analyzed, which solves the memory leakage problem, improves test efficiency and coverage, and reduces enterprise costs.
Patent Information
- Application Number
- CN202211662780.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-23
- Publication Date
- 2025-10-17
- Estimated Expiration
- 2042-12-23
AI Technical Summary
In the prior art, memory leaks are common in design applications, leading to a gradual increase in memory usage. Manual testing is inefficient, with insufficient coverage, and problems cannot be discovered in a timely manner.
Through the memory automation testing method based on code scanning, we formulate naming rules for entity classes and handler class names, use the automated testing platform to scan and extract comments to generate use cases, combine creation and deletion operations to generate test cases, and automatically record memory values, analyze memory growth trends, and locate memory leaks.
It achieves fast and fully automated memory testing, improves test coverage, saves manpower, shortens test cycles, and reduces enterprise costs.
Smart Images

Figure CN115952087B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of test development technology, and more specifically designs a memory automation test method and system based on code scanning Background Art
[0002] Memory leaks are very common in design applications. They manifest as: when creating entities, the number of objects in the object pool increases, resulting in memory growth; when deleting objects, the objects are not destroyed and the memory is not released. As the number of operations and the operation time increase, the number of objects in the memory stack increases, and the memory occupied gradually increases. When it reaches a certain threshold, it will crash, especially in browser applications.
[0003] Currently, memory testing requires testers to write test cases for different functional modules, manually execute them, and record the data, or convert each test case into a test script for automatic execution. This process is time-consuming and often results in missed tests or omissions due to tight deadlines.
[0004] Design applications are designed in layers, divided into entity layer, display layer and handler layer. The handler layer defines the operation instructions for the entity. By utilizing the characteristics of dynamic language, the test-end program can dynamically load instructions to realize software control. Based on the above technology, the present invention proposes a memory automation testing method and system based on code scanning. Based on the code-level test, problems can be quickly located to ensure test coverage. The whole process is automatically executed without human intervention, which can save manpower, improve test efficiency, shorten the test cycle and save enterprise costs. Summary of the Invention
[0005] The present invention has been made in view of the above-mentioned problems.
[0006] According to one aspect of the present invention, a memory automation testing method based on code scanning is proposed, the method comprising:
[0007] Step S1: Establish naming rules for entity classes and handler classes and write them into code review tools to set restrictions;
[0008] Step S2: According to the rules, the automated testing platform scans the entity class registration entry, obtains the registered entity class name, finds the definition file corresponding to the class and calls the handler of the class based on the class name, extracts the comments using regular expressions, and converts them into the use case description part;
[0009] Step S3: storing the extracted entity class name, handler class name, annotation, etc. into a database, combining the creation, deletion, etc. handler method to generate a unit operation of the use case, and setting the number of unit operations to generate a complete memory test case;
[0010] Step S4: executing the test, executing one unit operation each time, recording the process virtual memory and physical memory values of the tested application each time, and writing the results back to the database;
[0011] Step S5: obtaining the memory values during the execution of each use case to obtain the memory growth trend corresponding to a single use case; if the memory continues to rise linearly during the execution of the use case, it is a possible memory leakage problem, the test result is abnormal, and the problem is located; if it does not rise or rises first and then stabilizes, it is normal;
[0012] Step S6: when the last test task is executed, the test platform automatically integrates the test data to generate a test report, sends it to the mailbox of the relevant personnel, and feeds back the abnormal problem to the maintenance personnel of the related code.
[0013] The application also proposes a memory automatic test system based on code scanning, which comprises a code scanner, a use case generator, a use case executor and a report generator, and performs the following operations: formulating the naming rules of entity classes and handler class names and writing them into a code audit tool for restriction; according to the rules, the automatic test platform scans the entity class registration entrance, obtains the registered entity class name, finds the definition file corresponding to the class according to the class name, and calls the handler of the class, extracts the annotation by using a regular expression, and converts it into a use case description part; storing the extracted entity class name, handler class name, annotation, etc. into a database, combining the creation, deletion, etc. handler method to generate a unit operation of the use case, and setting the number of unit operations to generate a complete memory test case; executing the test, executing one unit operation each time, recording the process virtual memory and physical memory values of the tested application each time, and writing the results back to the database; obtaining the memory values during the execution of each use case to obtain the memory growth trend corresponding to a single use case; if the memory continues to rise linearly during the execution of the use case, it is a possible memory leakage problem, the test result is abnormal, and the problem is located; if it does not rise or rises first and then stabilizes, it is normal; when the last test task is executed, the test platform automatically integrates the test data to generate a test report, sends it to the mailbox of the relevant personnel, and feeds back the abnormal problem to the maintenance personnel of the related code.
[0014] Compared with the prior art, the application has the following beneficial effects:
[0015] The memory test applied from the code level helps to locate the memory leakage problem more quickly; the application can automatically generate test cases, and does not need test personnel to participate in the maintenance and execution of the test cases, and can generate a test report without human intervention BRIEF DESCRIPTION OF DRAWINGS
[0016] The above and other objects, features and advantages of the present application will become more apparent from the following detailed description of embodiments of the present application taken in conjunction with the accompanying drawings. The drawings provided in the Drawings serve to provide a further understanding of the embodiments of the present application, constitute a part of the specification and are included to explain the present application, and do not constitute a limitation of the present application. In the drawings, the same reference numerals refer to the same components or steps throughout.
[0017] Figure 1 A use case generation flow schematic block diagram according to an embodiment of the present application is shown;
[0018] Figure 2 A system implementation flow schematic block diagram according to an embodiment of the present application is shown;
[0019] Figure 3 A system module composition diagram according to an embodiment of the present application is shown. DETAILED DESCRIPTION
[0020] In order to make the objects, technical solutions and advantages of the present application more obvious, the example embodiments according to the present application will be described in detail below with reference to the drawings. Obviously, the described embodiments are only part of the embodiments of the present application, not all embodiments of the present application, and it should be understood that the present application is not limited to the example embodiments described herein. Based on the embodiments of the present application described in the present application, all other embodiments obtained by those skilled in the art without creative labor should fall within the protection scope of the present application.
[0021] Embodiment one:
[0022] In order to solve the problems described above, a code scanning based memory automatic test method and system are proposed. Specifically, Figure 1 As shown, the embodiment of the present application proposes a code scanning based memory automatic test method, which is based on code level testing, can quickly locate problems, guarantees test coverage, is automatically executed throughout, does not need human intervention, can save manpower, improve test efficiency, shorten test cycle, and save enterprise cost. The specific implementation method is as follows:
[0023] Step S1: Formulate the naming rules of entity classes and handler class names and write them into the code audit tool for restriction;
[0024] Step S2: According to the rules, the automated test platform scans the entity class registration portal, obtains the registered entity class name, and finds the definition file corresponding to the class and the handler calling the class according to the class name, extracts the annotations by using a regular expression, and converts them into a use case description part;
[0025] Step S3: The extracted entity class name, handler class name, annotations, etc. are stored in a database, combined with the handler methods of creation, deletion, etc. to generate unit operations of the use case, and the number of unit operations is set to generate a complete memory test use case;
[0026] Step S4: Execute the test, execute one unit operation at a time, record the process virtual memory and physical memory values of the tested application once, and write the results back to the database;
[0027] Step S5: Obtain the memory values during the execution of each use case to obtain the memory growth trend corresponding to a single use case. During the execution of the use case, if the memory continues to rise linearly, it is a possible memory leak problem, the test result is abnormal, and the problem is located. If it does not rise or rises first and then stabilizes, it is normal;
[0028] Step S6: When the last test task is executed, the test platform automatically integrates the test data to generate a test report, sends it to the mailbox of the relevant personnel, and feeds back the abnormal problems to the maintenance personnel of the related code.
[0029] Optionally, the method can be added to a CICD pipeline, as shown in Figure 2 The pipeline includes the following processes: R&D test, test platform scans test branch code, test platform automatically generates memory test cases, test platform automatically initiates corresponding test tasks, test cluster receives test tasks to start consuming test task queues, test platform collects test results and produces test reports, and reminds relevant R&D personnel of scenes with memory leak risks and follows up. The scanning of the test branch code includes: obtaining an entity class registration portal, obtaining registered entity classes, and obtaining definition files corresponding to the entity classes and handlers calling the entity. The handlers of the creation and deletion operations are filtered, the annotations of the entity classes and handler classes are extracted by using a regular expression, the entity, handler class name and annotation description are stored in a database to generate test cases; the test platform automatically initiates corresponding test tasks according to the scanning results; the test cluster receives test tasks to start consuming test task queues, and the results are written back to the database; the test platform collects test results and produces test reports, which includes: the test platform automatically integrates test data to generate a test report, sends it to the mailbox of the relevant personnel, and feeds back the abnormal problems to the maintenance personnel of the related code.
[0030] Example two:
[0031] The application also provides a code scanning-based memory automatic testing system, which comprises:
[0032] The code scanner, the use case generator, the use case executor and the report generator perform the following operations: a naming rule of entity classes and handler class names is formulated and written into a code auditing tool for restriction; according to the rule, the automatic testing platform scans an entity class registration entrance, obtains the registered entity class name, and finds the definition file corresponding to the class and the handler calling the class according to the class name, extracts the comment by using a regular expression, and converts the comment into a use case description part; the extracted entity class name, handler class name and comment are stored into a database, a unit operation of a use case is generated in combination with the handler methods such as creation and deletion, and the number of unit operations is set, so that a complete memory test use case is generated; the test is executed, one unit operation is executed each time, the process virtual memory and physical memory values of the tested application are recorded each time, and the results are written back to the database; the memory values during the execution of each use case are obtained, and the memory growth trend corresponding to a single use case is obtained; if the memory continuously rises linearly during the execution of the use case, it is a possible memory leakage problem, and the test result is abnormal, if it does not rise or rises first and then tends to be stable, it is normal; when the last test task is executed, the testing platform automatically integrates the test data to generate a test report, sends the test report to the mailbox of the relevant personnel, and feeds back the abnormal problems to the maintenance personnel of the relevant code.
[0033] Meanwhile, the system also performs a CICD pipeline, which comprises the following processes: development and testing, the testing platform scans the test branch code, the testing platform automatically generates a memory test use case, the testing platform automatically initiates a corresponding test task, the test cluster receives the test task and starts to consume the test task queue, the testing platform collects the test results and produces a test report, and the scene with a memory leakage risk is reminded to the relevant development and strategy personnel and followed up. The scanning of the test branch code comprises the following steps: obtaining an entity class registration entrance, obtaining the registered entity class, obtaining the definition file corresponding to the entity class and the handler calling the entity, screening the handler of the creation and deletion operation, extracting the comment of the entity class and the handler class by using a regular expression, storing the entity, the handler class name and the comment description into a database to generate a test use case; the testing platform automatically initiates a corresponding test task comprises that the testing platform automatically initiates a corresponding test task according to the scanning result; the test cluster receiving the test task and starting to consume the test task queue further comprises writing the results back to the database; the testing platform collecting the test results and producing a test report further comprises that the testing platform automatically integrates the test data to generate a test report, sends the test report to the mailbox of the relevant personnel, and feeds back the abnormal problems to the maintenance personnel of the relevant code.
[0034] The application obtains an entity class and a handler class of the entity through code scanning, and generates a rule of an automatic test case; a memory test case is generated by designing a unit operation and specifying the operation times of the unit operation; the memory is recorded once for each unit operation, and the growth trend chart of the memory is obtained through multiple operations; if the memory continues to rise linearly, it is a possible memory leakage problem, and the test result is abnormal, and the problem needs to be located; if it does not rise or rises first and then stabilizes, it is normal; the whole process is automatically completed, the test case writing and execution steps of the test personnel are removed, and the distributed cluster is used to quickly consume the test task queue, so that the test report is quickly obtained, and the test cycle is shortened.
[0035] Although example embodiments have been described herein with reference to the accompanying drawings, it is to be understood that the example embodiments are only exemplary and are not intended to limit the scope of the application. Those of ordinary skill in the art can make various changes and modifications without departing from the scope and spirit of the application. All such changes and modifications are intended to be included within the scope of the application as claimed in the appended claims.
[0036] In the specification provided herein, a large number of specific details are described. However, it can be understood that the embodiments of the application can be practiced without these specific details. In some instances, well-known methods, structures and techniques are not shown in detail in order not to obscure the understanding of the specification.
[0037] Similarly, it should be appreciated that the individual features of the application described in the description of the example embodiments of the application are sometimes grouped together in a single embodiment, figure or description of a related aspect of the application. However, this method of the application should not be construed to reflect an intention that the application requires more features than are explicitly recited in each claim. Rather, it is intended that the application lie in at least as broad a scope as is reflected in the corresponding claims. Accordingly, the claims are to be interpreted not only in view of the disclosure, but also in view of the specification as a whole. It is thus expressly intended that all combinations of those elements that perform substantially the same function in substantially the same way to achieve the same results are within the scope of the application. Moreover, it should be appreciated that the application has multiple aspects, and that each aspect can provide an independent basis for defining some, but possibly not all claims. Accordingly, aspects can be broadly construed based on this disclosure. It will be understood by those within the art that, in general, terms used herein, and especially to the immediately preceding feature, are intended to be generic and not limited to the specific embodiments, which can be set forth in the specification. In addition, it should be understood that aspects can include specific aspects and / or particular features, where applicable. It will be appreciated that the application can be practiced otherwise than is specifically explained and illustrated herein without departing from the spirit or scope of the application. For example, the scope of the application is not limited to the exact details shown and described herein but covers any and all adaptations of the application within the scope of the appended claims including what is presently described and understood, what is currently claimed and wanted, and what will later occur to be especially adaptive. Accordingly, it is intended that the application be construed broadly, and exactly as is set out in the appended claims.
[0038] Furthermore, those skilled in the art will recognize that, while certain embodiments described herein comprise other embodiments, certain features described herein can be used in combination with other features to form yet further embodiments, and that the application should be judged in light of the claims and the full scope of equivalents, not based on any drawings, which are deemed illustrative only.
[0039] It should be noted that the above-mentioned embodiments illustrate rather than limit the application, and that those skilled in the art will be able to design many alternative embodiments without departing from the scope of the appended claims. In the claims, any reference signs placed between parentheses shall not be construed as limiting the claim. The word "comprising" does not exclude the presence of elements or steps other than those listed in a claim. The word "a" or "an" preceding an element does not exclude the presence of a plurality of such elements. The application can be implemented by means of both hardware and software, and any combination thereof. In a unitary claim, several devices or means can be listed, comprising at least one of each device, but not only one of each device. The use of the terms first, second and third, and the like, does not imply any ordering but rather are used for naming purposes only. Features, steps or components that are described in the application can also appear under a different heading.
[0040] The above description is only specific embodiments or specific implementations of the present application, and the protection scope of the present application is not limited thereto. Any person skilled in the art can easily think of changes or replacements within the technical range disclosed by the present application, and all such changes or replacements should be covered within the protection scope of the present application. The protection scope of the present application should be subject to the protection scope of the claims.
Claims
1. A memory automation testing method based on code scanning, the method comprising: Step S1: Establish naming rules for entity classes and handler classes and write them into code review tools to set restrictions; Step S2: According to the rules, the automated testing platform scans the entity class registration entry, obtains the registered entity class name, finds the definition file corresponding to the class and calls the handler of the class based on the class name, extracts the comments using regular expressions, and converts them into the use case description part; Step S3: Store the extracted entity class name, handler class name, and comments into the database, combine the creation and deletion of handler methods to generate unit operations of the use case, and set the number of unit operations to generate a complete memory test case; Step S4: Execute the test, each time executing a unit operation, record the process virtual memory and physical memory values of the tested application, and write the results back to the database; Step S5: Obtain the memory value during the execution of each use case and obtain the memory growth trend corresponding to the single use case; During the execution of the test case, if the memory usage continues to increase linearly, it is a possible memory leak problem. If the test result is abnormal, locate the problem. If it does not increase or increases first and then stabilizes, it is normal. Step S6: When the last test task is completed, the test platform automatically integrates the test data to generate a test report, sends it to the relevant personnel's email, and feeds back the abnormal problems to the maintainer of the relevant code.
2. The memory automation testing method based on code scanning according to claim 1, characterized in that: The method is also added to the CICD pipeline, which includes the following process: R&D submits a test request, the test platform scans the test branch code, the test platform automatically generates memory test cases, the test platform automatically initiates the corresponding test tasks, the test cluster receives the test tasks and starts consuming the test task queue, the test platform collects the test results and generates a test report, and alerts relevant R&D personnel to follow up on scenarios with memory leak risks; The scanning and testing branch code includes: obtaining the entity class registration entry, obtaining the registered entity class, and obtaining the definition file corresponding to the entity class and the handler that calls the entity class, filtering out the handlers for creation and deletion operations, and using regular expressions to extract the comments of the entity class and handler class, and storing the entity, handler class name and comments together in the library to generate test cases.
3. The memory automated testing method based on code scanning according to claim 2, characterized in that: The test platform automatically initiating the corresponding test task includes: the test platform automatically initiating the corresponding test task according to the current scanning result.
4. The memory automated testing method based on code scanning according to claim 2, wherein: The test cluster receives the test task and starts consuming the test task queue, further comprising writing the result back to the database.
5. The memory automated testing method based on code scanning according to claim 2, wherein: The test platform collects test results and produces test reports, and further includes: the test platform automatically integrates test data to generate a test report, sends it to the mailbox of relevant personnel, and feeds back abnormal problems to the maintainer of the relevant code.
6. A memory automation testing system based on code scanning, the system comprising: A code scanner, a use case generator, a use case executor and a report generator, and executes the method according to any one of claims 1 to 5.
Citation Information
Patent Citations
Method and device for realizing rapid judgment of memory leak trend for software system, processor and storage medium thereof
CN112395162A
CDN (Content Delivery Network) gateway back-to-source method and device
CN114466000A