A program analysis method, device and electronic equipment

By analyzing the characteristic code and execution chain of program files through abstract syntax trees, the problem of existing tools being unable to determine the code execution results is solved, enabling the assessment of the reliability and robustness of program files and improving development efficiency and accuracy.

CN114138280BActive Publication Date: 2026-03-17BEIJING BAIDU NETCOM SCI & TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-08
Publication Date
2026-03-17

AI Technical Summary

Technical Problem

Existing program analysis tools cannot effectively determine whether the code's execution results meet expectations, which may lead to problems such as program projects failing to run normally during the development process.

Method used

By obtaining the abstract syntax tree of the program file to be analyzed, the number of preset characteristic codes and their sub-codes is found and counted. The statistical results are displayed to determine the reliability of the program file. The execution chain is then filtered and tested according to development needs, and the execution coverage is obtained to evaluate the reliability and robustness of the program file.

Benefits of technology

It improves the accuracy and efficiency of program analysis, enabling accurate assessment of the reliability and robustness of program files and helping developers quickly identify and correct abnormal code.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114138280B_ABST
    Figure CN114138280B_ABST
Patent Text Reader

Abstract

This disclosure provides a program analysis method, apparatus, and electronic device, relating to the field of computer technology, and particularly to the field of computer software technology. The specific implementation scheme is as follows: Obtaining the abstract syntax tree (AST) corresponding to the program file to be analyzed; searching the AST based on the preset feature codes to determine a first code file containing the preset feature codes, wherein the preset feature codes identify the execution process of the program file to be analyzed; counting the number of preset feature codes contained in the first code file and the number of sub-preset feature codes of the preset feature codes to obtain a first statistical result, wherein the sub-preset feature codes are sub-codes containing the preset feature codes; displaying the first statistical result. This demonstrates the reliability of the program file to be analyzed, enabling developers to more accurately determine whether the program file to be analyzed is reliable.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the field of computer technology, and more particularly to the field of computer software technology. Background Technology

[0002] During program development, human error can lead to problems in the resulting code. To prevent the program from malfunctioning due to these issues, the code is typically tested. Summary of the Invention

[0003] This disclosure provides a program analysis method, apparatus, device, and storage medium.

[0004] According to one aspect of this disclosure, a program analysis method is provided, comprising:

[0005] Obtain the abstract syntax tree corresponding to the program file to be analyzed;

[0006] The abstract syntax tree is searched based on the preset feature code to determine the first code file containing the preset feature code in the abstract syntax tree, wherein the preset feature code identifies the execution process of the program file to be analyzed;

[0007] The number of preset feature codes contained in the first code file and the number of sub-preset feature codes of the preset feature codes are counted to obtain a first statistical result, wherein the sub-preset feature code is a sub-code that contains the preset feature code;

[0008] Display the first statistical result.

[0009] According to another aspect of this disclosure, a program analysis apparatus is provided, comprising:

[0010] The program conversion module is used to obtain the abstract syntax tree corresponding to the program file to be analyzed;

[0011] The file determination module is used to search the abstract syntax tree based on the preset feature code, and determine the first code file containing the preset feature code in the abstract syntax tree, wherein the preset feature code identifies the execution process of the program file to be analyzed;

[0012] The statistics module is used to count the number of preset feature codes contained in the first code file and the number of sub-preset feature codes of the preset feature codes, and obtain a first statistical result, wherein the sub-preset feature code is a sub-code that contains the preset feature code;

[0013] The first display module is used to display the first statistical results.

[0014] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of this disclosure, nor is it intended to limit the scope of this disclosure. Other features of this disclosure will become readily apparent from the following description. Attached Figure Description

[0015] The accompanying drawings are provided to better understand this solution and do not constitute a limitation of this disclosure. Wherein:

[0016] Figure 1 This is a flowchart illustrating a procedural analysis method based on this disclosure;

[0017] Figure 2 This is another flowchart illustrating the procedural analysis method according to this disclosure;

[0018] Figure 3 This is another flowchart illustrating the procedural analysis method according to this disclosure;

[0019] Figure 4 This is another flowchart illustrating the procedural analysis method according to this disclosure;

[0020] Figure 5 This is another flowchart illustrating the procedural analysis method according to this disclosure;

[0021] Figure 6 This is a schematic diagram of a procedure analysis apparatus according to the present disclosure;

[0022] Figure 7 This is a block diagram of an electronic device used to implement the program analysis method of the embodiments of this disclosure. Detailed Implementation

[0023] The exemplary embodiments of this disclosure are described below with reference to the accompanying drawings, including various details of the embodiments to aid understanding, and should be considered merely exemplary. Therefore, those skilled in the art will recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of this disclosure. Similarly, for clarity and brevity, descriptions of well-known functions and structures are omitted in the following description.

[0024] During program development, it's common to encounter situations where the program's execution results don't meet expectations. Therefore, program analysis and testing are necessary. Currently, program analysis tools based on ECMAScript and TypeScript focus on checking code compilation and escaping, such as Babel, ESLint, Uglify, and Webpack. Their characteristic is to determine if the code can run normally, i.e., to check for syntax problems. However, they cannot determine whether the code's execution results meet expectations; in other words, they cannot analyze whether the program is reliable.

[0025] For example, in actual program project development, the program file to be analyzed may be the program corresponding to only one function in the program project. If it is impossible to determine whether the program file to be analyzed is accurate and reliable during the development process, and the program file to be analyzed is merged into other program files that have already been developed for running, the problem with the program file to be analyzed may cause the entire program project to malfunction and fail to run normally.

[0026] Based on this, this disclosure provides a program analysis method that can be applied to any electronic device with program analysis capabilities, including but not limited to personal computers and servers. The program analysis method provided in this disclosure is as follows: Figure 1 As shown, it includes:

[0027] S101, Obtain the abstract syntax tree corresponding to the program file to be analyzed.

[0028] S102, search the abstract syntax tree based on the preset feature code, and determine the first code file containing the preset feature code in the abstract syntax tree.

[0029] S103, count the number of preset feature codes contained in the first code file and the number of sub-preset feature codes contained in the preset feature codes to obtain the first statistical result.

[0030] S104, use all the first code statistical results as the first statistical results of the program file to be analyzed, and display the first statistical results.

[0031] In this embodiment, the program file to be analyzed is converted into an abstract syntax tree. Preset feature codes that can represent the execution process of the program file to be analyzed are identified within the abstract syntax tree. Then, a first code file containing these preset feature codes is identified. By counting the number of preset feature codes and sub-preset feature codes in the first code file, the total number of preset feature codes and sub-preset feature codes contained in the program file to be analyzed is determined. A first statistical result is obtained and displayed. Through this scheme, the frequency of calls to preset feature codes within the code of the program file to be analyzed can be effectively counted and presented, enabling developers to accurately determine whether the program file to be analyzed is reliable.

[0032] In S101, the abstract syntax tree (AST) is a tree-like structure representing the syntactic structure of source code. Each node of the AST represents a structure in the source code. The program file to be analyzed can be converted into its corresponding AST, allowing for analysis through the AST.

[0033] In S102, the preset feature code identifies the execution process of the program file to be analyzed.

[0034] Because the abstract syntax tree contains feature codes, such as the `callExpression` feature code, that can identify the execution process of the program file to be analyzed, and by analyzing these preset feature codes that identify the execution of the program file, the execution status of the entire program file can be revealed, thus enabling the analysis of the program file to be analyzed. Therefore, the first code file containing the preset feature code can be found in the abstract syntax tree, and the program file to be analyzed can be used for this purpose.

[0035] In S103, a sub-preset feature code is a sub-code that contains a preset feature code. It is understandable that a first code file containing preset feature codes, found through the preset feature code search, may contain multiple segments of preset feature codes. Furthermore, some of these preset feature codes may also contain sub-preset feature codes that are sub-functions relative to themselves. Therefore, given that the first code files have been identified, the number of all preset feature codes contained in each first code file can be counted in the abstract syntax tree and recorded. This statistical result is then used as the first statistical result.

[0036] In S104, the first statistical result is a statistical analysis of the preset feature codes in the abstract syntax tree. Since the abstract syntax tree is converted from the program file to be analyzed, all the first statistical results can be used as the statistical results of the preset feature codes in the program file to be analyzed. The first statistical result is then displayed so that the developers can fully understand the frequency of calls to specific program functions in the program file to be analyzed.

[0037] The presentation of initial statistical results can be complete or, depending on the specific needs, only the relevant portions. Furthermore, it's understood that the presentation of initial statistical results can be tailored to the developers' requirements. For example, to provide developers with a comprehensive understanding of the reliability of the analyzed program file simply by viewing the initial statistical results, the presentation can be an organized report, allowing developers to intuitively understand the actual relevant analysis data. For example, the presentation of initial statistical results can also provide a mechanism to interrupt execution, adapting to DevOps pipelines and facilitating subsequent compilation of the program by developers.

[0038] In actual program development, not all program functions are written by the developers themselves. Some functions in the program file to be analyzed will call functions from established function libraries. These functions are usually reliable and have been tested. If all functions in the program file to be analyzed were analyzed, the results might contain a large amount of analysis of the reliable functions called, leading to low efficiency and preventing the analysis from accurately identifying the specific functions that need to be analyzed. Therefore, this disclosure also provides a program analysis method, such as... Figure 2 As shown, it includes:

[0039] S201, Obtain the abstract syntax tree corresponding to the program file to be analyzed.

[0040] This step is the same as S101 above, and you can refer to the relevant description of S101 above, so it will not be repeated here.

[0041] S202, search the abstract syntax tree based on the preset feature code, and determine the first code file containing the preset feature code in the abstract syntax tree.

[0042] This step is the same as S102 above, and you can refer to the relevant description of S102 above, so it will not be repeated here.

[0043] S203, count the number of preset feature codes contained in the first code file and the number of sub-preset feature codes contained in the preset feature codes to obtain the first statistical result.

[0044] This step is the same as S103 above, and you can refer to the relevant description of S103 above, so it will not be repeated here.

[0045] S204, use all the first code statistical results as the first statistical results of the program file to be analyzed, and display the first statistical results.

[0046] This step is the same as S104 above, and you can refer to the relevant description of S104 above, so it will not be repeated here.

[0047] S205, Based on the preset filtering conditions, filter the first statistical result to obtain the second statistical result.

[0048] In S205, the preset filtering condition can be to filter out the function segments that are blocked in the program file to be analyzed. For example, the first statistical result can be traversed to determine the function position in the program file to be analyzed corresponding to each preset feature code in the first statistical result, and the statistical results of the corresponding position of the preset feature code in the first statistical result in the blocked function segment can be filtered out to obtain the second statistical result.

[0049] In one possible embodiment, the preset filtering condition may also be to pre-set the range of program functions to be analyzed in the program file to be analyzed, so as to retain the first statistical result in which the function position corresponding to the preset feature code in the first statistical result is within the preset program function range, and obtain the second statistical result.

[0050] It is understandable that preset filtering conditions can be set according to the needs of program development, and this disclosure does not limit this.

[0051] S206 presents the second statistical result.

[0052] This step is similar to the method of displaying the first statistical result in S104 above, except that the statistical result displayed is different. Please refer to the relevant explanation in S104 above, which will not be repeated here.

[0053] By using this embodiment, the program file to be analyzed can be analyzed according to the actual development needs of the program file to be analyzed. The first statistical results can be filtered by preset screening conditions to remove unnecessary statistical results, so that the obtained second statistical results can more accurately reflect whether the program file to be analyzed is reliable, thereby improving the accuracy of program analysis.

[0054] In program analysis, besides the frequency of calls to a specific function reflecting the program's reliability and robustness, the relationships between functions can also effectively reflect the program's reliability. Based on this, this disclosure also provides a program analysis method, such as... Figure 3 As shown, it includes:

[0055] S301, Obtain the abstract syntax tree corresponding to the program file to be analyzed.

[0056] This step is the same as S101 above, and you can refer to the relevant description of S101 above, so it will not be repeated here.

[0057] S302, search the abstract syntax tree based on the preset feature code, and determine the first code file containing the preset feature code in the abstract syntax tree.

[0058] This step is the same as S102 above, and you can refer to the relevant description of S102 above, so it will not be repeated here.

[0059] S303, count the number of preset feature codes contained in the first code file and the number of sub-preset feature codes contained in the preset feature codes to obtain the first statistical result.

[0060] This step is the same as S103 above, and you can refer to the relevant description of S103 above, so it will not be repeated here.

[0061] S304: Use all the first code statistics results as the first statistics results of the program file to be analyzed, and display the first statistics results.

[0062] This step is the same as S104 above, and you can refer to the relevant description of S104 above, so it will not be repeated here.

[0063] S305, if the function type of the function in the program file to be analyzed corresponding to the first code file is a named function, determine the execution link of the preset feature code in the first code file and obtain the first association result.

[0064] Because named functions have function names, they are easier to find and analyze. Therefore, when analyzing the relationships between functions in the program file to be analyzed, named functions can be the focus of the analysis. The first code file contains preset characteristic codes, which identify the execution process of the program file to be analyzed. Therefore, when the function in the first code file corresponding to a named function in the program file to be analyzed is a named function, its execution link in the first code file can be determined and registered based on the preset characteristic codes, thereby analyzing the relationships between functions in the program file to be analyzed.

[0065] For example, when determining the execution chain of a preset feature code in the first code file, its parent function in the first code file can be found based on the identifier of the preset feature code. Then, according to the execution order of functions with parent-child or sibling relationships, the search continues until the topmost parent function relative to the preset feature code is reached. This identifies all the child preset feature codes of the topmost parent function, and these child preset feature codes are registered. The topmost parent function, as a parent function, has its corresponding child functions, but no longer has its corresponding parent function. It can be understood that the above process of determining the execution chain involves finding all the child preset feature codes contained in the topmost parent function through a child preset feature code of that topmost parent function, registering them, and mapping the registration results to the program file to be analyzed as the first association result.

[0066] In one possible embodiment, if the preset feature code is the CallExpression feature code, when determining the execution link of the CallExpression feature code in the first code file, when determining and registering all the child preset feature codes contained in its top-level parent function, a valid callee function can also be found, the valid callee function can be registered, and the registration result can be mapped to the program file to be analyzed as the first association result.

[0067] In one possible embodiment, when registering preset feature codes, a unique index key value can be generated based on the file path of the function in the program file to be analyzed corresponding to the preset feature code and the function name of the function in the program file to be analyzed corresponding to the first code file. The index key value corresponding to each preset feature code is registered as a first association result. It can be understood that the first association result can correspond to each function in the program file to be analyzed.

[0068] S306 displays the first association result.

[0069] This step is similar to the method of displaying the first statistical result in S104 above, except that the content displayed is different. Please refer to the relevant description in S104 above, which will not be repeated here.

[0070] By selecting this embodiment, the execution links of preset feature codes are found and registered, and then the registered content is displayed. This can determine the relationship between functions in the function file to be analyzed, so that the program analysis results can further reflect the reliability and robustness of the program file to be analyzed.

[0071] The first association result reflects the relationships between functions during program writing. However, during actual program execution, even if no syntax errors are reported during the execution of the program file to be analyzed, there may be situations where some programs that should be executed fail to execute, while some programs that should not be executed execute due to writing issues. For example, if half of the programs in the program file to be analyzed are not executed, then the program file to be analyzed is definitely abnormal. Therefore, if only the first association result reflects the relationships between the program files to be analyzed, and thus reflects the reliability of the program file to be analyzed, without knowing the actual execution status of each piece of code registered in the first association result, it may not accurately reflect the relationships between the functions in the program file to be analyzed. Based on this, this disclosure also provides a program analysis method, such as... Figure 4 As shown, it includes:

[0072] S401, obtain the abstract syntax tree corresponding to the program file to be analyzed.

[0073] This step is the same as S101 above, and you can refer to the relevant description of S101 above, so it will not be repeated here.

[0074] S402, search the abstract syntax tree based on the preset feature code, and determine the first code file containing the preset feature code in the abstract syntax tree.

[0075] This step is the same as S102 above, and you can refer to the relevant description of S102 above, so it will not be repeated here.

[0076] S403, count the number of preset feature codes contained in the first code file and the number of sub-preset feature codes contained in the preset feature codes to obtain the first statistical result.

[0077] This step is the same as S103 above, and you can refer to the relevant description of S103 above, so it will not be repeated here.

[0078] S404: Use all the first code statistics as the first statistics of the program file to be analyzed, and display the first statistics.

[0079] This step is the same as S104 above, and you can refer to the relevant description of S104 above, so it will not be repeated here.

[0080] S405, if the function type of the function in the program file to be analyzed corresponding to the first code file is a named function, determine the execution link of the preset feature code in the first code file and obtain the first association result.

[0081] This step is the same as S305 above, and you can refer to the relevant description of S305 above, so it will not be repeated here.

[0082] S406, Test the first associated result and obtain the execution results of each code corresponding to the execution chain.

[0083] Since the first association result contains the registration results of each preset feature code corresponding to the execution link, testing the first association result can be done by executing each code corresponding to the execution link registered in the first association result, thereby obtaining the execution result of each code. For example, the execution result can indicate whether the code was executed successfully, or whether the code was executed at all.

[0084] S407, based on the execution results, determine the ratio of the executed code in the execution chain to all the code in the execution chain, as the execution coverage.

[0085] As mentioned earlier, not all functions in the program file being analyzed are typically executed. Therefore, some code in the abstract syntax tree (AST) converted from the program file will not be executed under normal circumstances. Furthermore, some pre-defined feature codes corresponding to the execution chains in the first association result may also not be executed. Thus, after obtaining the execution results of each code segment corresponding to the execution chain, the executed code can be determined based on these results, thereby determining the percentage of executed code out of all code, which serves as the execution coverage. It is understandable that execution coverage reflects the execution status of each code segment corresponding to the execution chain, thereby reflecting the execution status of each pre-defined feature code. The pre-defined feature codes, in turn, identify the entire execution process of the program file being analyzed. Therefore, execution coverage can reflect the functional relationships between functions in the program file being analyzed during actual execution.

[0086] For example, developers can pre-set an execution coverage threshold for the program file to be analyzed, such as 90%. Understandably, if the determined execution coverage is less than 90%, it means that some code that needs to be executed has not been executed, indicating an anomaly in the program file being analyzed. If the determined execution coverage is greater than 90%, it means that the execution of the program file being analyzed meets expectations, the logic is correct, and it is relatively reliable.

[0087] S408 uses the first association result and execution coverage as the second association result and displays the second association result.

[0088] The first association result reflects the relationships between functions in the program file being analyzed during its writing, while the execution coverage reflects these relationships during actual execution. Therefore, the first association result and execution coverage can be presented together as the second association result, allowing developers to accurately assess the reliability of the program file. Furthermore, since the first association result records data related to preset feature codes, such as index keys, and these preset feature codes can identify the execution process of the program file being analyzed, when the execution coverage indicates that the execution result of the program file is not as expected, the relevant data from the preset feature codes in the first association result, such as index keys, can be quickly used to map the abnormal code portion to the program file being analyzed, thus identifying the abnormal part of the program file and facilitating modification by developers.

[0089] By selecting this embodiment, the execution coverage is obtained by testing the first correlation result, thereby reflecting the correlation between the functions in the program file to be analyzed in actual execution. The execution coverage and the first correlation result are presented together, which further improves the accuracy of program analysis and facilitates the subsequent development work of developers.

[0090] In one possible embodiment, this disclosure also provides a program analysis method, such as... Figure 5 As shown, it includes:

[0091] S501, obtain the abstract syntax tree corresponding to the program file to be analyzed.

[0092] This step is the same as S101 above, and you can refer to the relevant description of S101 above, so it will not be repeated here.

[0093] S502, search the abstract syntax tree based on the preset feature code, and determine the first code file containing the preset feature code in the abstract syntax tree.

[0094] This step is the same as S102 above, and you can refer to the relevant description of S102 above, so it will not be repeated here.

[0095] S503, count the number of preset feature codes contained in the first code file and the number of sub-preset feature codes contained in the preset feature codes to obtain the first statistical result.

[0096] This step is the same as S103 above, and you can refer to the relevant description of S103 above, so it will not be repeated here.

[0097] S504: Use all the first code statistics as the first statistics of the program file to be analyzed, and display the first statistics.

[0098] This step is the same as S104 above, and you can refer to the relevant description of S104 above, so it will not be repeated here.

[0099] S505, if the function type of the function in the program file to be analyzed corresponding to the first code file is a named function, determine the execution link of the preset feature code in the first code file and obtain the first association result.

[0100] This step is the same as S305 above, and you can refer to the relevant description of S305 above, so it will not be repeated here.

[0101] S506, perform incremental screening on the first association result to obtain the screening result.

[0102] Incremental screening can refer to capturing code after a certain moment or checkpoint for testing. Therefore, incremental screening of the first associated result can selectively select the code corresponding to the execution chain of the first associated result for subsequent testing, thereby obtaining more accurate test results. For example, based on development needs, parts that are prone to runtime errors can be selected, or code with higher importance can be selected for subsequent testing, thereby avoiding testing unnecessary code parts.

[0103] S507, test the screening results and obtain the execution results of each piece of code corresponding to the execution chain.

[0104] This step is similar to S406 above, except that the object being tested is different. The testing method is the same, and you can refer to the relevant description of S406 above. It will not be repeated here.

[0105] S508 determines the ratio of executed code to all code in the execution chain based on the execution results, and uses this ratio as the execution coverage.

[0106] This step is the same as S407 above, and you can refer to the relevant description of S407 above, so it will not be repeated here.

[0107] S509 uses the first association result and execution coverage as the second association result and displays the second association result.

[0108] This step is the same as S408 above, and you can refer to the relevant description of S408 above, so it will not be repeated here.

[0109] By using this embodiment, the execution coverage of the program file to be analyzed can be obtained in a targeted manner, which improves both the accuracy and efficiency of the program analysis results.

[0110] To better illustrate the specific implementation process of the above-mentioned program analysis method, this disclosure also provides a specific detection method for incremental screening and coverage detection, as follows:

[0111] First, based on the abstract syntax tree and the first code file, determine the files to be tested (testableFiles). Execute the command (git diff-name-only) to obtain the modified files (modifiedFiles). Use the function intersection(modifiedFiles, testableFiles) to obtain the inspectFiles file, where the intersection function is used to find the intersection of modifiedFiles and testableFiles. For each file in the inspectFiles file, perform the following operations:

[0112] Step 1: Obtain the line numbers of code that were not covered during the test (failedCoverageLines).

[0113] Step 2: Obtain the covered lines of code during the test.

[0114] Step 3: Use the git diff command to get the line numbers (modifiedLines) of this modification.

[0115] Step 4: Execute the following command:

[0116] Intersection(failedCoverageLines,modifiedLines) / Intersection(coveraged Lines,modifiedLines)incrementalLineUnCoverage

[0117] The obtained incrementalLineUnCoverage represents the ratio of the uncovered code line numbers included in the modified line numbers to the covered code line numbers included in the modified line numbers.

[0118] Step 5: Check if any file has incrementalLineUnCoverage > 0.2. If so, exit abnormally.

[0119] The collection, storage, use, processing, transmission, provision, and disclosure of user personal information involved in the technical solution disclosed herein comply with the provisions of relevant laws and regulations and do not violate public order and good morals.

[0120] According to embodiments of this disclosure, this disclosure also provides a program analysis apparatus, such as... Figure 6 As shown, it includes:

[0121] The program conversion module 601 is used to obtain the abstract syntax tree corresponding to the program file to be analyzed;

[0122] The file determination module 602 is used to search the abstract syntax tree according to the preset feature code and determine the first code file containing the preset feature code in the abstract syntax tree, wherein the preset feature code identifies the execution process of the program file to be analyzed;

[0123] The statistics module 603 is used to count the number of preset feature codes contained in the first code file and the number of sub-preset feature codes of the preset feature codes to obtain a first statistical result, wherein the sub-preset feature code is a sub-code that contains the preset feature code;

[0124] The first display module 604 is used to display the first statistical result.

[0125] In one possible embodiment, the above-described program analysis apparatus further includes:

[0126] The result filtering module is used to filter the first statistical result according to preset filtering conditions to obtain the second statistical result;

[0127] The second display module is used to display the second statistical result.

[0128] In one possible embodiment, the above-described program analysis apparatus further includes:

[0129] The association result acquisition module is used to determine the execution link of the preset feature code in the first code file and obtain the first association result if the function type of the function in the program file to be analyzed corresponding to the first code file is a named function.

[0130] The third display module is used to display the first association result.

[0131] In one possible embodiment, the third display module includes:

[0132] The testing unit is used to test the first association result and obtain the execution results of each piece of code corresponding to the execution chain;

[0133] The coverage acquisition unit is used to determine the ratio of the executed code corresponding to the execution link to all the code corresponding to the execution link based on the execution result, and use it as the execution coverage.

[0134] The third display unit is used to display the second association result by taking the first association result and the execution coverage as the second association result.

[0135] In one possible embodiment, the test unit includes:

[0136] The screening subunit is used to perform incremental screening on the first association result to obtain the screening result;

[0137] The screening result testing subunit is used to test the screening results and obtain the execution results of each code corresponding to the execution link.

[0138] According to embodiments of this disclosure, this disclosure also provides an electronic device, a readable storage medium, and a computer program product.

[0139] Figure 7 A schematic block diagram of an example electronic device 700 that can be used to implement embodiments of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device may also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the present disclosure described and / or claimed herein.

[0140] like Figure 7As shown, device 700 includes a computing unit 701, which can perform various appropriate actions and processes based on a computer program stored in read-only memory (ROM) 702 or a computer program loaded from storage unit 708 into random access memory (RAM) 703. RAM 703 may also store various programs and data required for the operation of device 700. The computing unit 701, ROM 702, and RAM 703 are interconnected via bus 704. Input / output (I / O) interface 705 is also connected to bus 704.

[0141] Multiple components in device 700 are connected to I / O interface 705, including: input unit 706, such as keyboard, mouse, etc.; output unit 707, such as various types of monitors, speakers, etc.; storage unit 708, such as disk, optical disk, etc.; and communication unit 709, such as network card, modem, wireless transceiver, etc. Communication unit 709 allows device 700 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.

[0142] The computing unit 701 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of the computing unit 701 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. The computing unit 701 performs the various methods and processes described above, such as program analysis methods. For example, in some embodiments, the program analysis method may be implemented as a computer software program tangibly contained in a machine-readable medium, such as storage unit 708. In some embodiments, part or all of the computer program may be loaded and / or installed on device 700 via ROM 702 and / or communication unit 709. When the computer program is loaded into RAM 703 and executed by the computing unit 701, one or more steps of the program analysis method described above may be performed. Alternatively, in other embodiments, the computing unit 701 may be configured to perform program analysis methods by any other suitable means (e.g., by means of firmware).

[0143] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.

[0144] The program code used to implement the methods of this disclosure may be written in any combination of one or more programming languages. This program code may be provided to a processor or controller of a general-purpose computer, special-purpose computer, or other programmable data processing apparatus, such that when executed by the processor or controller, the program code causes the functions / operations specified in the flowcharts and / or block diagrams to be implemented. The program code may be executed entirely on a machine, partially on a machine, as a standalone software package partially on a machine and partially on a remote machine, or entirely on a remote machine or server.

[0145] In the context of this disclosure, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.

[0146] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device for displaying information to the user (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor); and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the computer. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).

[0147] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as a data server), or computing systems that include middleware components (e.g., an application server), or computing systems that include frontend components (e.g., a user computer with a graphical user interface or web browser through which a user can interact with embodiments of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., a communication network). Examples of communication networks include local area networks (LANs), wide area networks (WANs), and the Internet.

[0148] Computer systems can include clients and servers. Clients and servers are generally located far apart and typically interact via communication networks. Client-server relationships are created by computer programs running on the respective computers and having a client-server relationship with each other. Servers can be cloud servers, servers in distributed systems, or servers incorporating blockchain technology.

[0149] It should be understood that the various forms of processes shown above can be used to rearrange, add, or delete steps. For example, the steps described in this disclosure can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution disclosed in this disclosure can be achieved, and this is not limited herein.

[0150] The specific embodiments described above do not constitute a limitation on the scope of protection of this disclosure. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this disclosure should be included within the scope of protection of this disclosure.

Claims

1. A program analysis method, comprising: obtaining an abstract syntax tree corresponding to a program file to be analyzed, wherein the program file to be analyzed is a program file that needs to be verified for reliability and robustness through analysis; determining a first code file containing a preset feature code in the abstract syntax tree according to the preset feature code, wherein the preset feature code identifies an execution process of the program file to be analyzed, and the preset feature code is a callExpression feature code; counting a number of the preset feature codes and a number of sub preset feature codes of the preset feature code contained in the first code file to obtain a first statistical result, wherein the sub preset feature code is a sub code containing the preset feature code; displaying the first statistical result, wherein the first statistical result is used to represent a calling frequency of a specific program function of the program file to be analyzed; further comprising: if a function type of a function corresponding to the first code file in the program file to be analyzed is a named function, determining an execution link of the preset feature code in the first code file to obtain a first association result; displaying the first association result; wherein the first association result comprises: testing the first association result to obtain an execution result of each code corresponding to the execution link; determining a ratio of the executed code corresponding to the execution link to all codes corresponding to the execution link as an execution coverage according to the execution result; taking the first association result and the execution coverage as a second association result, and displaying the second association result. 2.The method of claim 1, further comprising: screening the first statistical result according to a preset screening condition to obtain a second statistical result; displaying the second statistical result.

3. The method of claim 1, wherein, The testing the first association result to obtain an execution result of each code corresponding to the execution link comprises: performing incremental screening on the first association result to obtain a screening result; testing the screening result to obtain an execution result of each code corresponding to the execution link. 4.A program analysis apparatus, comprising: a program conversion module configured to obtain an abstract syntax tree corresponding to a program file to be analyzed, wherein the program file to be analyzed is a program file that needs to be verified for reliability and robustness through analysis; a file determination module configured to determine a first code file containing a preset feature code in the abstract syntax tree according to the preset feature code, wherein the preset feature code identifies an execution process of the program file to be analyzed, and the preset feature code is a callExpression feature code; a counting module configured to count a number of the preset feature codes and a number of sub preset feature codes of the preset feature code contained in the first code file to obtain a first statistical result, wherein the sub preset feature code is a sub code containing the preset feature code; a first display module configured to display the first statistical result, wherein the first statistical result is used to represent a calling frequency of a specific program function of the program file to be analyzed; further comprising: The association result obtaining module is configured to determine an execution link of the preset characteristic code in the first code file to obtain a first association result if the function type of the function corresponding to the first code file in the program file to be analyzed is a named function. The third display module is configured to display the first association result. The third display module includes: The test unit is configured to test the first association result to obtain execution results of each code corresponding to the execution link. The coverage obtaining unit is configured to determine a ratio of the executed code corresponding to the execution link to all code corresponding to the execution link as an execution coverage according to the execution results. The third display unit is configured to display the first association result and the execution coverage as a second association result.

5. The apparatus of claim 4, further comprising: The result screening module is configured to screen the first statistical result according to a preset screening condition to obtain a second statistical result. The second display module is configured to display the second statistical result.

6. The apparatus of claim 4, wherein, The test unit includes: The screening subunit is configured to perform incremental screening on the first association result to obtain a screening result. The screening result test subunit is configured to test the screening result to obtain execution results of each code corresponding to the execution link.

7. An electronic device, comprising: at least one processor; and a memory communicatively connected with the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method of any one of claims 1-3.

8. A non-transitory computer readable storage medium having stored thereon computer instructions, wherein, The computer instructions are used to enable the computer to perform the method of any one of claims 1-3.

9. A computer program product comprising a computer program which, when executed by a processor, implements the method of any one of claims 1-3.

Citation Information

Patent Citations

  • LPC static code inspection method, apparatus and system

    CN105404584A

  • Test coverage rate statistical method and device, computer equipment and storage medium

    CN110597710A