Code testing method and device and electronic equipment
By static and dynamic processing of the software code and using preset correction models to correct the detection results, the problems of insufficient static analysis and low correction efficiency in code testing in the existing technology are solved, and the code accuracy and correction efficiency are achieved Improvement.
Patent Information
- Application Number
- CN202411252072.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-06
- Publication Date
- 2024-12-24
AI Technical Summary
In the software code test in the prior art, the SVN code server can only perform static analysis and cannot monitor the problems of the code during operation in real time. When an error is found, it needs to be manually inspected and corrected, resulting in low correction efficiency.
By obtaining the code to be detected, performing static and dynamic processing, and correcting the detection results in combination with the preset correction model to ensure the accuracy and correction efficiency of the target code.
It has achieved improvements in the accuracy and correction efficiency of software code, reduced the dependence of manual inspection, and improved the degree of automation of code correction.
Smart Images

Figure CN119179642A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a code testing method, device and electronic equipment. Background Art
[0002] With the development of computer technology, the scale of software projects continues to expand, and the amount of code in software projects has increased dramatically. In order to determine high-quality software codes and provide better experience to users, software codes need to be tested.
[0003] In order to realize the quality monitoring of software code, the code to be tested is usually connected to the source code control system (English full name: Subversion, abbreviated as: SVN), so that SVN can monitor the code to be tested in real time and capture the changed code of the code to be tested. The changed code is the code that is modified or updated in the code to be tested. After the changed code is determined, the Checkstyle, FindBugs, and Sonar code detection tools are used to detect the changed code to obtain the detection result of the code to be tested.
[0004] During the above code testing process, the SVN code server only involves static analysis tools in the real-time monitoring process, namely: Checkstyle, FindBugs, and Sonar code detection tools. It is impossible to know the problems of the code to be detected during operation. Moreover, when it is determined that there are errors in the code to be detected, it can only be corrected by manual inspection. Manual inspection requires staff to check each line of code in turn, determine the location of the error code, and then implement the correction, resulting in low efficiency of code correction. Summary of the invention
[0005] The present application provides a code testing method, device and electronic device, which correct the code to be tested through a preset correction model to ensure the accuracy of the obtained target code.
[0006] In a first aspect, the present application provides a code testing method, the method comprising:
[0007] Get the code to be tested;
[0008] Performing static processing on the code to be detected to obtain a static detection result;
[0009] Dynamically processing the code to be detected to obtain a dynamic detection result;
[0010] The static detection result and the dynamic detection result are corrected based on a preset correction model to obtain a target code corresponding to the code to be detected.
[0011] Through the above method, the code to be detected is statically detected and dynamically detected, and the code to be detected is corrected based on a preset correction model, thereby ensuring the accuracy of the target code.
[0012] In a possible design, obtaining the code to be detected includes:
[0013] Determining a change code from a database storing codes, wherein the change code is a code added, deleted or modified in the database;
[0014] Determine the source file of the change code, and perform format processing on all codes in the source file to obtain the target change code;
[0015] The target change code is used as the code to be detected.
[0016] Through the above method, the newly added change codes in the database are screened out, the source files of the change codes are determined, and all the codes in the source files are formatted to obtain the code to be tested, thereby ensuring the accuracy of the code to be tested.
[0017] In a possible design, the static processing of the code to be detected to obtain a static detection result includes:
[0018] Determine the code description information and code rules corresponding to the code to be detected, wherein the code description information at least includes: code description keywords, task names, and module names corresponding to the code to be detected;
[0019] Detecting whether the code description information is consistent with preset code description information, detecting whether the code to be detected complies with the code rules, and scanning whether there are no code security vulnerabilities in the code to be detected;
[0020] If yes, the static detection is passed as the static detection result;
[0021] If not, the static detection failure is taken as the static detection result.
[0022] Through the above method, the code to be detected is statically detected based on the code description information, thereby ensuring the accuracy of the static detection of the code to be detected.
[0023] In a possible design, the dynamically processing the code to be detected to obtain a dynamic detection result includes:
[0024] When the static detection of the code to be detected passes, determining the database to which the code to be detected belongs;
[0025] Compile all codes in the database to obtain an executable file;
[0026] Running the executable file to obtain the actual code function of the changed code;
[0027] The actual code function is compared with the preset code function to obtain the dynamic detection result.
[0028] Through the above method, the code to be detected is dynamically detected, and the functionality and logical correctness of the code to be detected are verified by running the executable file, thereby ensuring the accuracy of the dynamic detection.
[0029] In a possible design, the correcting the static detection result based on a preset correction model includes:
[0030] Determining that the static detection result of the code to be detected is failed, and determining the detection failure factor corresponding to the code to be detected;
[0031] If the detection failure factor is that the code description information is inconsistent with the preset description, the code description information is corrected based on the preset correction model;
[0032] If the detection failure factor is that the code to be detected does not comply with the code rules, the code to be detected is corrected based on the code rules;
[0033] If the detection failure factor is that the code to be detected has a code vulnerability, the code to be detected is corrected based on the preset correction model.
[0034] Through the above method, the code to be detected that fails the static detection is corrected based on the preset correction model, which is conducive to ensuring the accuracy of the target code.
[0035] In a possible design, the correcting the dynamic detection result based on a preset correction model includes:
[0036] Extracting the execution result of the code to be detected in the dynamic detection result;
[0037] If the execution result is inconsistent with the preset execution result, determining the code log and stack information in the execution result;
[0038] The code to be detected is modified based on the preset execution result, the code log and the stack information.
[0039] Through the above method, the code to be detected that fails the dynamic detection is corrected based on the preset correction model, and the functionality and logic of the code to be detected are corrected, which is conducive to ensuring the accuracy of the target code.
[0040] In a possible design, after obtaining the target code corresponding to the code to be detected, the method further includes:
[0041] Determine the detection coverage of the code to be detected, and detect whether the detection coverage is greater than the coverage threshold;
[0042] If yes, the code to be detected is stored in a designated database;
[0043] If not, the uncovered code in the code to be detected is extracted, and the uncovered code is prompted based on the preset correction model.
[0044] Through the above method, the codes executed in the code to be detected are counted based on the detection coverage, so as to prevent the code from being missed during the code detection process, thereby causing the problem of inaccurate code detection of the code to be detected, thereby ensuring the detection accuracy of the code to be detected.
[0045] In a second aspect, the present application provides a code testing device, the device comprising:
[0046] An acquisition module is used to obtain the code to be detected;
[0047] A static module is used to perform static processing on the code to be detected to obtain a static detection result;
[0048] A dynamic module is used to dynamically process the code to be detected to obtain a dynamic detection result;
[0049] The correction module is used to correct the static detection result and the dynamic detection result based on a preset correction model to obtain a target code corresponding to the code to be detected.
[0050] In a possible design, the acquisition module is specifically used to determine the change code from a database storing the code, determine the source file of the change code, and format all the codes in the source file to obtain the target change code, and use the target change code as the code to be detected.
[0051] In one possible design, the static module is specifically used to determine the code description information and code rules corresponding to the code to be detected, wherein the code description information at least includes: code description keywords, task name, and module name corresponding to the code to be detected, detect whether the code description information is consistent with preset code description information, detect whether the code to be detected complies with the code rules, and scan whether the code to be detected does not have code security vulnerabilities. If so, the static detection pass is used as the static detection result, if not, the static detection fail is used as the static detection result.
[0052] In one possible design, the dynamic module is specifically used to determine the database to which the code to be detected belongs when the static detection of the code to be detected passes, compile all the codes in the database to obtain an executable file, run the executable file, obtain the actual code function of the changed code, compare the actual code function with the preset code function, and obtain the dynamic detection result.
[0053] In one possible design, the correction module is specifically used to determine that the static detection result of the code to be detected is failed, and determine the detection failure factor corresponding to the code to be detected. If the detection failure factor is that the code description information is inconsistent with the preset description, the code description information is corrected based on the preset correction model. If the detection failure factor is that the code to be detected does not comply with the code rules, the code to be detected is corrected based on the code rules. If the detection failure factor is that the code to be detected has a code vulnerability, the code to be detected is corrected based on the preset correction model.
[0054] In one possible design, the correction module is also used to extract the execution result of the code to be detected in the dynamic detection result. If the execution result is inconsistent with the preset execution result, the code log and stack information in the execution result are determined, and the code to be detected is corrected based on the preset execution result, the code log and the stack information.
[0055] In a possible design, the correction module is also used to determine the detection coverage of the code to be detected, and detect whether the detection coverage is greater than the coverage threshold. If so, the code to be detected is stored in a designated database; if not, the uncovered code in the code to be detected is extracted, and the uncovered code is prompted based on the preset correction model.
[0056] In a third aspect, the present application provides an electronic device, including:
[0057] Memory, used to store computer programs;
[0058] The processor is used to implement the above-mentioned steps of a code detection method when executing the computer program stored in the memory.
[0059] In a fourth aspect, a computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the above-mentioned code detection method are implemented.
[0060] For each aspect from the first to the fourth aspect and the technical effects that may be achieved by each aspect, please refer to the above description of the technical effects that can be achieved by the first aspect or various possible schemes in the first aspect, and no further details will be given here. BRIEF DESCRIPTION OF THE DRAWINGS
[0061] Figure 1 A flowchart of the steps of a code testing method provided for this application;
[0062] Figure 2 A schematic diagram of the code detection system provided for this application;
[0063] Figure 3 A schematic diagram of the process of detecting the code to be detected based on the preset correction model provided by this application;
[0064] Figure 4 A schematic diagram of the structure of a code testing device provided in this application;
[0065] Figure 5 A schematic diagram of the structure of an electronic device provided in this application. DETAILED DESCRIPTION
[0066] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application will be further described in detail below in conjunction with the accompanying drawings. The specific operating methods in the method embodiments can also be applied to device embodiments or system embodiments. It should be noted that in the description of the present application, "multiple" is understood as "at least two". "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. A is connected to B, which can represent: A is directly connected to B and A is connected to B through C. In addition, in the description of the present application, words such as "first" and "second" are only used to distinguish the purpose of description, and cannot be understood as indicating or implying relative importance, nor can they be understood as indicating or implying order.
[0067] In the past code testing process, the SVN code server only involved static analysis tools in the real-time monitoring process, and was unable to know the problems in the code to be tested during operation. Moreover, when it was determined that there were errors in the code to be tested, it could only be corrected by manual inspection. Manual inspection requires staff to check each line of code in turn, determine the location of the error code, and then implement corrections, resulting in low efficiency in code correction.
[0068] In order to solve the problems described above, the present application provides a code testing method for improving the efficiency of code correction, wherein the method and device described in the embodiments of the present application are based on the same technical concept. Since the principles of the problems solved by the method and the device are similar, the embodiments of the device and the method can refer to each other, and the repeated parts will not be repeated.
[0069] The embodiments of the present application are described in detail below in conjunction with the accompanying drawings.
[0070] Reference Figure 1 , this application provides a code testing method, which can improve the efficiency of code correction. The implementation process of the method is as follows:
[0071] Step S1: Obtain the code to be detected.
[0072] In order to obtain codes with higher stability and security, the embodiments of the present application need to test the codes. First, the changed codes need to be determined from the database storing the codes. The changed codes are the codes that have changed in the database, such as the codes that have been added, deleted, or modified. Then, the source files corresponding to the changed codes need to be determined. In order to make the codes have higher security and stability, all the codes in the source files need to be formatted to obtain target changed codes. The formats of all target changed codes are the same, and the target changed codes are used as the codes to be tested.
[0073] Through the above method, the changed codes are screened and the format of the codes to be detected is unified, which is conducive to improving the detection of the codes to be detected.
[0074] Step S2: statically process the code to be detected to obtain a static detection result.
[0075] After determining the code to be detected, in order to ensure the accuracy of the code to be detected, it is necessary to determine the code description information and code rules corresponding to the code to be detected, the code description information at least includes: code description keywords, task name, module name, and then check whether the code description information is consistent with the preset code description information, check whether the code to be detected complies with the code rules, and scan whether the code to be detected does not have code security vulnerabilities. The preset code information stores the preset code description keywords, preset task name, and preset module name of the code to be detected. Specifically, check whether the code description keywords are consistent with the preset code description keywords, check whether the task name is consistent with the preset task name, and check whether the module name is consistent with the preset module name. If all the test results are yes, it is determined that the static test of the code to be detected has passed. Otherwise, it is determined that the static test of the code to be detected has failed.
[0076] Through the above method, static detection is performed on the code to be detected based on the code description information, ensuring that the code to be detected can be accurately detected.
[0077] Step S3: Dynamically process the code to be detected to obtain a dynamic detection result.
[0078] When the static test of the code to be tested passes, it is necessary to test the functionality and logic of the code to be tested. In the embodiment of the present application, it is necessary to obtain all the codes in the database to which the code to be tested belongs, compile all the codes in the database to obtain an executable file, and run the executable file to obtain the actual code function of the changed code. The actual code function contains the corresponding execution result of the code to be tested. In order to ensure the accuracy of the dynamic test result of the code to be tested, it is necessary to compare the actual code function with the preset code function to obtain the dynamic test result.
[0079] Specifically, the actual code function corresponding to the code to be tested includes the execution result of the executable file, and the preset code function stores the preset execution result corresponding to the code to be tested. Therefore, the actual code function is compared with the preset code function, that is, the execution result is compared with the preset execution result in the preset code function. If the execution result is consistent with the preset execution result, it means that both the functional test and the logical test of the code to be tested have passed; if the execution result is inconsistent with the preset execution result, it means that there is at least one error in the functionality and the logic.
[0080] For example, when the code to be tested runs an executable file, it calculates a cumulative value, and the cumulative value is the result of the cumulative calculation. If the preset cumulative value is 16, and the actual cumulative calculation is accumulated to 16, it means that the functionality and logic of the code to be tested corresponding to the cumulative value calculation are accurate.
[0081] Through the above method, the executable file corresponding to the code to be detected is run, and the functionality and logic of the code to be detected are determined based on the actual running results, thereby ensuring the accuracy of dynamic detection of the code to be detected.
[0082] Step S4: Correct the static detection result and the dynamic detection result based on a preset correction model to obtain a target code corresponding to the code to be detected.
[0083] During the static and dynamic detection of the code to be detected, if the static detection fails and the execution result in the dynamic detection result is inconsistent with the preset execution result, the code to be detected needs to be corrected based on the preset correction model. The specific process of correcting the static detection result by the preset correction model is as follows:
[0084] When the static detection fails, the detection failure factor of the code to be detected is determined. If the detection failure factor is that the code description information of the code to be detected is inconsistent with the preset code description information, the difference description between the code description information and the preset code description information will be determined, and the difference description will be marked in the code description information. The marked code description information will be used as the static detection result. Therefore, the marked code to be detected can be input into the preset correction model. In the preset correction model, the code to be detected will be matched with the set standard code. When the code to be detected is inconsistent with the standard code, the code to be detected will be replaced based on the standard code replacement.
[0085] If the detection failure factor is that the code to be detected does not comply with the code rules, the code position that does not comply with the code rules in the code to be detected is marked, and the code at the code position is modified. The code rule can be that the first letter of each line of code is uppercase, and there cannot be blank lines between each line of code. The code rules can be set according to the actual situation and will not be explained in detail here.
[0086] If the detection failure factor is the existence of a code vulnerability in the code to be detected, the code vulnerability in the code to be detected needs to be corrected based on a preset correction model.
[0087] The embodiment of the present application also discloses a method for training a preset correction model, and the specific process of obtaining the preset correction model is as follows:
[0088] OpenBMC code samples are collected from various platforms or network databases. In order to ensure the correctness of the code samples, the code samples need to be marked, the error type, error location and correct correction method in the code samples are marked, and the marked code samples are divided into training set, verification set and test set in a ratio of 6:2:2.
[0089] Select and design a suitable neural network architecture, initialize the weights and biases, and input the data in the training set into the neural network for training, calculate through the network layer, and obtain the output. Use the loss function to calculate the difference between the predicted value and the true value, and update the network parameters through gradient descent or other optimization algorithms. During the training process, if the loss function value is greater than the expected value, adjust the model parameters and then recalculate the loss function. After each training iteration, use the validation set to evaluate the model performance, adjust the model parameters according to the performance on the validation set, and select the model with the best performance on the validation set during the training process. Finally, use the test set to evaluate the final model. If the performance of the test set does not meet the requirements, it is necessary to continue to use the training set for training, adjust the model architecture or parameters, and finally use the neural network model tested by the validation set as the preset correction model. After determining the preset correction model, the specific process of correcting the dynamic detection results based on the preset correction model is as follows:
[0090] The execution result corresponding to the code to be detected in the dynamic detection result is extracted. The execution result is inconsistent with the preset execution result. The code log and stack information in the execution result are determined. The code log records the information of the code during the execution process, which is used for code operation failure analysis and problem location. The stack information is composed of a series of stack frames. The stack frame shows the order of code execution, the code source file and line number, and the specific function executed when the code is executed abnormally. Therefore, the preset correction model will determine the error log and stack trace based on all the codes, code logs and stack frame information in the database to which the code to be detected belongs, and extract the function name, code line number, error type and other information to determine the code with abnormal execution in the code to be detected. After determining the abnormal code, the preset correction model will determine the context of the abnormal code and correct the abnormal code based on the error type. The correction may include replacement, etc. to obtain the target code.
[0091] After determining the target code, determine the detection coverage corresponding to the code to be detected, and judge whether the detection coverage is greater than the coverage threshold. When the detection coverage is greater than the coverage threshold, the code to be detected is stored in a custom database. When the detection coverage is not greater than the coverage threshold, it is necessary to extract the uncovered code in the code to be detected, and prompt the uncovered code based on the preset correction model.
[0092] It should be noted that the system diagram of code detection provided in the embodiment of the present application is as follows Figure 2 As shown, in Figure 2 The system includes: a monitoring server, a preset correction model server, engineering code, an embedded server (full name in English: Baseboard Management Controller, abbreviated as: BMC), a web server, and a device end for the R&D team. The monitoring server includes a code formatting tool. The monitoring server can perform static detection, compile and build, upload images, send use case execution tasks, quality processing, and reporting. The BMC server is used to execute automated use cases, and the web server is used to display code quality and perform quality management configuration.
[0093] The embodiment of the present application implements the detection of the code to be detected based on the above system. In the process of code testing of the code to be detected, the flow chart of detecting the code to be detected based on the preset correction model is as follows: Figure 3 As shown, in Figure 3In the process, the code to be detected is determined, and the code description information of the code to be detected is detected to see if it is accurate. If so, the code to be detected is compiled to obtain an executable file. If not, the analysis results and corrections of the code to be detected are uploaded to the web server. When the compilation of the code to be detected fails, the web server will display the reason for the failure, and the preset correction model will provide modification suggestions. When the compilation of the code to be detected is successful, the executable file will be uploaded to the BMC server to execute automated use cases and dynamic detection.
[0094] Since the BMC is equipped with eMMC devices, it can store more executable file images, which meets the storage space required for executing automated use cases. During the execution of automated use cases, the monitoring server only needs to call the automation framework in the script, and the enabled automation use cases in the automation framework will be automatically executed.
[0095] When the dynamic detection passes, the detection coverage of the code to be detected is determined. When the dynamic detection fails, the web displays the reason for failure and the reason for failure and modification strategy based on the preset correction model analysis. When the detection coverage is greater than the coverage threshold, it is determined that the detection has passed. When the detection coverage is not greater than the coverage threshold, the web displays the uncovered code lines and supplements the automation use case based on the preset correction model. The code to be detected is modified and the code detection process is resubmitted. The embodiment of the present application can also be inspected. When the inspection passes, the code to be detected is stored in the specified database. When the inspection fails, the code to be detected is modified and the code detection process is resubmitted.
[0096] Based on the above method, the code to be detected is corrected and prompted in time during the static detection and dynamic detection of the code to be detected by presetting the correction model, which improves the correction efficiency of the code to be detected and ensures the accuracy of the obtained target code.
[0097] Based on the same inventive concept, a code detection device is also provided in the embodiment of the present application. The code detection device is used to implement the function of a code detection method. Figure 4 , the device comprises:
[0098] An acquisition module 401 is used to obtain a code to be detected;
[0099] The static module 402 is used to perform static processing on the code to be detected to obtain a static detection result;
[0100] The dynamic module 403 is used to dynamically process the code to be detected to obtain a dynamic detection result;
[0101] The correction module 404 is used to correct the static detection result and the dynamic detection result based on a preset correction model to obtain a target code corresponding to the code to be detected.
[0102] In a possible design, the acquisition module 401 is specifically used to determine the change code from a database storing the code, determine the source file of the change code, and format all the codes in the source file to obtain the target change code, and use the target change code as the code to be detected.
[0103] In one possible design, the static module 402 is specifically used to determine the code description information and code rules corresponding to the code to be detected, wherein the code description information at least includes: code description keywords, task name, and module name corresponding to the code to be detected, detect whether the code description information is consistent with preset code description information, detect whether the code to be detected complies with the code rules, and scan whether the code to be detected does not have code security vulnerabilities. If so, the static detection pass is used as the static detection result, if not, the static detection fail is used as the static detection result.
[0104] In one possible design, the dynamic module 403 is specifically used to determine the database to which the code to be detected belongs when the static detection of the code to be detected passes, compile all the codes in the database to obtain an executable file, run the executable file, obtain the actual code function of the changed code, compare the actual code function with the preset code function, and obtain the dynamic detection result.
[0105] In one possible design, the correction module 404 is specifically used to determine that the static detection result of the code to be detected is failed, and determine the detection failure factor corresponding to the code to be detected. If the detection failure factor is that the code description information is inconsistent with the preset description, the code description information is corrected based on the preset correction model. If the detection failure factor is that the code to be detected does not comply with the code rules, the code to be detected is corrected based on the code rules. If the detection failure factor is that the code to be detected has a code vulnerability, the code to be detected is corrected based on the preset correction model.
[0106] In one possible design, the correction module 404 is also used to extract the execution result of the code to be detected in the dynamic detection result. If the execution result is inconsistent with the preset execution result, the code log and stack information in the execution result are determined, and the code to be detected is corrected based on the preset execution result, the code log and the stack information.
[0107] In a possible design, the correction module 404 is also used to determine the detection coverage of the code to be detected, and detect whether the detection coverage is greater than the coverage threshold. If so, the code to be detected is stored in a designated database; if not, the uncovered code in the code to be detected is extracted, and the uncovered code is prompted based on the preset correction model.
[0108] Based on the same inventive concept, an electronic device is also provided in the embodiment of the present application, and the electronic device can realize the function of the aforementioned code detection device, referring to Figure 5 , the electronic device comprises:
[0109] At least one processor 501, and a memory 502 connected to the at least one processor 501. The specific connection medium between the processor 501 and the memory 502 is not limited in the embodiment of the present application. Figure 5 In the example, the processor 501 and the memory 502 are connected via a bus 500. The bus 500 is Figure 5 The connections between other components are shown in bold lines, and are not intended to be limiting. The bus 500 can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 5 Only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus. Alternatively, the processor 501 can also be called a controller, and there is no limitation on the name.
[0110] In the embodiment of the present application, the memory 502 stores instructions that can be executed by at least one processor 501. The at least one processor 501 can execute a code detection method discussed above by executing the instructions stored in the memory 502. The processor 501 can implement Figure 4 The functions of each module in the device shown.
[0111] Among them, the processor 501 is the control center of the device, and can use various interfaces and lines to connect the various parts of the entire control device. By running or executing instructions stored in the memory 502 and calling data stored in the memory 502, the various functions of the device and processing data, the device can be monitored as a whole.
[0112] In one possible design, the processor 501 may include one or more processing units, and the processor 501 may integrate an application processor and a modem processor, wherein the application processor mainly processes an operating system, a user interface, and application programs, and the modem processor mainly processes wireless communications. It is understandable that the modem processor may not be integrated into the processor 501. In some embodiments, the processor 501 and the memory 502 may be implemented on the same chip, and in some embodiments, they may also be implemented separately on separate chips.
[0113] Processor 501 can be a general-purpose processor, such as a central processing unit (CPU), a digital signal processor, an application-specific integrated circuit, a field programmable gate array or other programmable logic device, a discrete gate or transistor logic device, a discrete hardware component, and can implement or execute the various methods, steps and logic block diagrams disclosed in the embodiments of the present application. A general-purpose processor can be a microprocessor or any conventional processor, etc. The steps of a code detection method disclosed in conjunction with the embodiments of the present application can be directly embodied as a hardware processor execution, or a combination of hardware and software modules in the processor.
[0114] The memory 502 is a non-volatile computer-readable storage medium that can be used to store non-volatile software programs, non-volatile computer executable programs and modules. The memory 502 may include at least one type of storage medium, such as a flash memory, a hard disk, a multimedia card, a card-type memory, a random access memory (Random Access Memory, RAM), a static random access memory (Static Random Access Memory, SRAM), a programmable read-only memory (Programmable Read Only Memory, PROM), a read-only memory (Read Only Memory, ROM), an electrically erasable programmable read-only memory (Electrically Erasable Programmable Read-Only Memory, EEPROM), a magnetic memory, a disk, an optical disk, etc. The memory 502 is any other medium that can be used to carry or store a desired program code in the form of an instruction or data structure and can be accessed by a computer, but is not limited thereto. The memory 502 in the embodiment of the present application can also be a circuit or any other device that can realize a storage function, for storing program instructions and / or data.
[0115] By programming the processor 501, the code corresponding to the code detection method described in the above embodiment can be fixed into the chip, so that the chip can execute the code detection method when running. Figure 1A code detection step of the embodiment shown. How to design and program the processor 501 is a technique known to those skilled in the art and will not be described in detail here.
[0116] Based on the same inventive concept, an embodiment of the present application further provides a storage medium, which stores computer instructions. When the computer instructions are executed on a computer, the computer executes a code detection method discussed above.
[0117] In some possible implementations, various aspects of a code detection method provided by the present application may also be implemented in the form of a program product, which includes program code. When the program product is run on an apparatus, the program code is used to enable the control device to execute the steps of a code detection method according to various exemplary implementations of the present application described above in this specification.
[0118] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0119] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0120] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0121] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0122] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.
Claims
1. A code testing method, characterized in that: include: Get the code to be tested; Performing static processing on the code to be detected to obtain a static detection result; Dynamically processing the code to be detected to obtain a dynamic detection result; The static detection result and the dynamic detection result are corrected based on a preset correction model to obtain a target code corresponding to the code to be detected.
2. The method according to claim 1, characterized in that The obtaining of the code to be detected comprises: Determining a change code from a database storing codes, wherein the change code is a code added, deleted or modified in the database; Determine the source file of the change code, and perform format processing on all codes in the source file to obtain the target change code; The target change code is used as the code to be detected.
3. The method according to claim 1, characterized in that The static processing of the code to be detected to obtain a static detection result includes: Determine the code description information and code rules corresponding to the code to be detected, wherein the code description information at least includes: code description keywords, task names, and module names corresponding to the code to be detected; Detecting whether the code description information is consistent with preset code description information, detecting whether the code to be detected complies with the code rules, and scanning whether there are no code security vulnerabilities in the code to be detected; If yes, the static detection is passed as the static detection result; If not, the static detection failure is taken as the static detection result.
4. The method according to claim 1, characterized in that The dynamically processing the code to be detected to obtain a dynamic detection result includes: When the static detection of the code to be detected passes, determining the database to which the code to be detected belongs; Compile all codes in the database to obtain an executable file; Running the executable file to obtain the actual code function of the changed code; The actual code function is compared with the preset code function to obtain the dynamic detection result.
5. The method according to claim 1, characterized in that The correcting the static detection result based on a preset correction model includes: Determining that the static detection result of the code to be detected is failed, and determining the detection failure factor corresponding to the code to be detected; If the detection failure factor is that the code description information is inconsistent with the preset description, the code description information is corrected based on the preset correction model; If the detection failure factor is that the code to be detected does not comply with the code rules, the code to be detected is corrected based on the code rules; If the detection failure factor is that the code to be detected has a code vulnerability, the code to be detected is corrected based on the preset correction model.
6. The method according to claim 1, characterized in that The correcting the dynamic detection result based on a preset correction model includes: Extracting the execution result of the code to be detected in the dynamic detection result; If the execution result is inconsistent with the preset execution result, determining the code log and stack information in the execution result; The code to be detected is modified based on the preset execution result, the code log and the stack information.
7. The method according to claim 1, characterized in that After obtaining the target code corresponding to the code to be detected, the method further includes: Determine the detection coverage of the code to be detected, and detect whether the detection coverage is greater than the coverage threshold; If yes, the code to be detected is stored in a designated database; If not, the uncovered code in the code to be detected is extracted, and the uncovered code is prompted based on the preset correction model.
8. A code testing device, characterized in that: include: An acquisition module is used to obtain the code to be detected; A static module is used to perform static processing on the code to be detected to obtain a static detection result; A dynamic module is used to dynamically process the code to be detected to obtain a dynamic detection result; The correction module is used to correct the static detection result and the dynamic detection result based on a preset correction model to obtain a target code corresponding to the code to be detected.
9. An electronic device, characterized in that: include: Memory, used to store computer programs; A processor, for implementing the method steps described in any one of claims 1 to 7 when executing the computer program stored in the memory.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method steps described in any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Coverage test method and device, computer device and storage medium
CN109766261A
Software test and test coverage rate counting method and device, equipment and medium
CN113568839A
Software integration evaluation method based on machine learning and static analysis
CN114490344A
Test report generation method and device, equipment and storage medium
CN116185874A
Test method and electronic equipment
CN116701164A
Cited By
Code task processing method and code repairing method
CN119807017A
Code error detection method and device and storage medium
CN120353713A
Code task processing method and code repair method
WO2026188951A1
