Polyspace-based code analysis method and device and medium

Through the automated Polyspace code analysis process, including precompilation, file division and batch analysis, the problem of low utilization of Polyspace in actual projects is solved, the analysis efficiency and accuracy are improved, and the code quality is ensured.

CN119576741APending Publication Date: 2025-03-07KOSTAL SHANGHAI ELECTROMECHANICAL CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411659584.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-19
Publication Date
2025-03-07

AI Technical Summary

Technical Problem

Polyspace has low utilization rate in actual projects, mainly because there should not be too many single analysis files. Too many files lead to exponential growth of over-analysis time, and the server cannot calculate too much data, resulting in blockage and stuck operation, and cannot analyze large software.

Method used

By receiving code analysis trigger commands and parameter settings, obtaining source code files, calling Polyspace for pre-compilation, dividing them into multiple blacklist files, uploading them to the code repository, scanning the blacklist files in batches, calling Polyspace for static code analysis and detection, and outputting analysis reports of all source code files.

Benefits of technology

The automated code analysis process reduces manual operations, improves the efficiency of analysis, improves the accuracy of analysis through precompilation and batch scanning strategies, ensures code quality, and concentrates resources and attention in the potentially risky part of the code through the division of blacklist files.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119576741A_ABST
    Figure CN119576741A_ABST
Patent Text Reader

Abstract

The invention discloses a Polyspace-based code analysis method and device and a medium. Relates to the field of computers, solves the problem of low utilization rate of Polyspace in actual engineering, reduces manual operation through an automatic code analysis process, and improves analysis efficiency. In addition, the analysis accuracy is improved through pre-compiling and batch scanning strategies, and the code quality is ensured. By dividing blacklist files, resources and attention are focused on the code part with the highest potential risk. Polyspace analysis integrated in Jenkins allows for continuous improvements in continuous integration and continuous deployment processes.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computers, and in particular to a Polyspace-based code analysis method, device and medium. Background Art

[0002] As a professional code quality management tool, Polyspace (software runtime error detection tool) has significant advantages in analyzing runtime code vulnerabilities. It can prove that there are no overflows, divisions by zero, array access out of bounds, and other specific runtime errors in the source code of different programming languages. It can detect errors that are difficult to detect with ordinary scanning tools. It does not require program execution, code instrumentation, or test cases to produce results. Polyspace uses static analysis and abstract interpretation based on formal methods. It can be used to verify handwritten code, generated code, or a combination of the two.

[0003] Although Polyspace has significant advantages in analyzing runtime code vulnerabilities, it is usually not advisable to analyze too many files at a time. Too many files will lead to exponentially increasing analysis time, and the server cannot calculate too much data, resulting in operation blockage and inability to analyze large software. In the process of automated integration, since it is impossible to analyze too many files, it is necessary to manually divide the software into several modules, and then manually trigger the build analysis one by one, resulting in low integration and utilization.

[0004] It can be seen that how to solve the problem of low utilization rate of Polyspace in actual engineering is a technical problem that needs to be solved urgently by people in this field. Summary of the invention

[0005] The purpose of this application is to provide a Polyspace-based code analysis method, device and medium to solve the problem of low utilization of Polyspace in actual engineering.

[0006] To solve the above technical problems, the present application provides a Polyspace-based code analysis method, including:

[0007] Receive code analysis trigger commands and parameter settings;

[0008] Acquire source code files according to the code analysis trigger command;

[0009] Calling Polyspace to precompile the source code file;

[0010] The precompiled source code file is divided into a plurality of blacklist files according to preset conditions and then uploaded to the code warehouse;

[0011] Scan the blacklist files in batches and call Polyspace to perform static code analysis and detection;

[0012] Output analysis reports of all the source code files.

[0013] As an optional solution, in the above-mentioned Polyspace-based code analysis method, receiving the code analysis trigger command and parameter setting includes:

[0014] Receive code analysis trigger commands and parameter settings input by the user through the platform user interface;

[0015] Verify whether the code analysis trigger command complies with the predetermined format and permission requirements;

[0016] If so, it will be configured according to the parameter settings.

[0017] As an optional solution, in the above-mentioned Polyspace-based code analysis method, the step of obtaining the source code file according to the code analysis trigger command includes:

[0018] Establish a connection with the version control system;

[0019] Pull source code files from the version control system according to the branch and submission information specified in the code analysis trigger command;

[0020] Store the source code files in the Jenkins working directory.

[0021] As an optional solution, in the above-mentioned Polyspace-based code analysis method, calling Polyspace to precompile the source code file includes:

[0022] Configure the pre-compilation parameters of the Polyspace tool, including compiler type, compilation options, and optimization level;

[0023] Passing the source code file to Polyspace for pre-compilation;

[0024] Monitor the compilation process and capture the output compilation error information;

[0025] If the compilation error information exists, output the pre-compilation error information and the pre-compilation result;

[0026] If the compilation error message does not exist, proceed to the next step.

[0027] As an optional solution, in the above-mentioned Polyspace-based code analysis method, the pre-compiled source code file is divided into multiple blacklist files according to preset conditions and then uploaded to the code warehouse, including:

[0028] Determining whether the number of the source code files precompiled exceeds a preset number;

[0029] If yes, dividing the source code file into the preset number;

[0030] The divided source code files are respectively created into a plurality of blacklist files;

[0031] Generate a list containing the source file path and file name for each blacklist file;

[0032] Upload the generated blacklist file to the code repository and record the upload time and version information.

[0033] As an optional solution, in the above-mentioned Polyspace-based code analysis method, scanning the blacklist files in batches in sequence and calling Polyspace to perform static code analysis detection include:

[0034] Call Polyspace to perform code analysis on each batch of blacklist files in turn, including but not limited to data flow check, value check, static memory check, control flow check, and C++ check;

[0035] After each batch of file analysis is completed, the analysis of the next batch is automatically triggered until all blacklisted files are analyzed.

[0036] As an optional solution, in the above-mentioned Polyspace-based code analysis method, establishing a connection with a version control system includes:

[0037] Configure authentication information for the Jenkins continuous integration platform and version control system, including username, password or access token;

[0038] Test the validity of the connection;

[0039] Configure Jenkins jobs to automatically respond to code changes in your version control system.

[0040] In order to solve the above technical problems, the present application also provides a Polyspace-based code analysis device, comprising:

[0041] A receiving module, used for receiving code analysis trigger commands and parameter settings;

[0042] An acquisition module, used to acquire source code files according to the code analysis trigger command;

[0043] A pre-compilation module, used for calling Polyspace to pre-compile the source code file;

[0044] A division module, used for dividing the precompiled source code file into a plurality of blacklist files according to preset conditions and uploading the blacklist files to a code repository;

[0045] An analysis and detection module, used to scan the blacklist files in batches and call Polyspace to perform static code analysis and detection;

[0046] The output module is used to output analysis reports of all the source code files.

[0047] In order to solve the above technical problems, the present application also provides a Polyspace-based code analysis device, comprising:

[0048] Memory for storing computer programs;

[0049] A processor is used to implement the above-mentioned steps based on the Polyspace code analysis method when executing the computer program.

[0050] In order to solve the above technical problems, the present application also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the above Polyspace-based code analysis method are implemented.

[0051] The Polyspace-based code analysis method provided in this application is executed through the pre-built Jenkins continuous integration platform, and the method includes: receiving code analysis trigger commands and parameter settings; obtaining source code files according to code analysis trigger commands; calling Polyspace to precompile source code files; dividing the precompiled source code files into multiple blacklist files according to preset conditions and uploading them to the code repository; scanning the blacklist files in batches and calling Polyspace for static code analysis and detection; outputting analysis reports for all source code files. This application reduces manual operations and improves the efficiency of analysis through an automated code analysis process. In addition, the accuracy of analysis is improved and the quality of code is ensured through precompilation and batch scanning strategies. By dividing the blacklist files, resources and attention are focused on the code parts with the highest potential risks. The Polyspace analysis integrated in Jenkins allows continuous improvement in the continuous integration and continuous deployment processes.

[0052] In addition, the present application also provides a device and a medium, which correspond to the above-mentioned Polyspace-based code analysis method and have the same effect as above. BRIEF DESCRIPTION OF THE DRAWINGS

[0053] In order to more clearly illustrate the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0054] Figure 1 A flowchart of a Polyspace code analysis method provided in an embodiment of the present application;

[0055] Figure 2 A data analysis schematic diagram provided for an embodiment of the present application;

[0056] Figure 3 A structural diagram of a Polyspace-based code analysis device provided in an embodiment of the present application;

[0057] Figure 4 A structural diagram of another Polyspace-based code analysis device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0058] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0059] The core of this application is to provide a Polyspace-based code analysis method, device and medium.

[0060] In order to enable those skilled in the art to better understand the present application, the present application is further described in detail below in conjunction with the accompanying drawings and specific implementation methods.

[0061] To solve the above problems, the present application embodiment provides a Polyspace-based code analysis method, which is executed through a pre-built Jenkins continuous integration platform. Figure 1 A flowchart based on a Polyspace code analysis method is provided for an embodiment of the present application, such as Figure 1 As shown, the method includes:

[0062] S11: receiving code analysis trigger command and parameter setting;

[0063] S12: Acquire source code files according to the code analysis trigger command;

[0064] S13: calling Polyspace to precompile the source code file;

[0065] S14: The precompiled source code file is divided into multiple blacklist files according to preset conditions and then uploaded to the code warehouse;

[0066] S15: Scan the blacklist files in batches and call Polyspace to perform static code analysis and detection;

[0067] S16: Output analysis reports of all source code files.

[0068] In this embodiment, Jenkins is an open source software project, which is a continuous integration tool developed based on Java (an object-oriented programming language) for monitoring continuous and repetitive work, and aims to provide an open and easy-to-use software platform so that software projects can be continuously integrated. Jenkins is a tool for DevOps (a combination of Development and Operations, a collective name for a group of processes, methods and systems, used to promote the development of applications / software engineering, technical operations and quality assurance, and communication, collaboration and integration between departments) task construction scheduling, which is executed through the pre-built Jenkins continuous integration platform.

[0069] Step S11 receives the code analysis trigger command and parameter settings. Receiving the code analysis trigger command and parameter settings means that the Jenkins platform receives an external signal or user operation, which indicates the start of the code analysis process and is accompanied by necessary parameters. These parameters may include the depth, scope, specific code standards or security requirements of the analysis. It is implemented through Jenkins' build trigger, which can respond to Webhooks, scheduled tasks or other custom events. The purpose of this step is to ensure that code analysis can be performed according to the specific needs of the user.

[0070] Parameter settings are not limited to predefined options, but can also be user-defined parameters. It is common to use JSON (JavaScript Object Notation) or YAML (a markup language) files to pass these parameters.

[0071] Step S12 obtains the source code file according to the code analysis trigger command, and pulls the source code file from the version control system according to the branch and commit information specified in the code analysis trigger command. Source code files are the basis for code analysis, and they may contain multiple project files and modules. This step is implemented through the integration of Jenkins with version control systems such as Git (an open source distributed version control system) and SVN (subversion, an open source version control system) to obtain the latest or specified version of the code for accurate analysis. It is common to use Git as a version control system.

[0072] In this embodiment, the source code file can be written in any programming language and is not limited to one language.

[0073] Step S13 calls Polyspace to precompile the source code file. Precompiling the source code file by calling Polyspace means using the Polyspace tool to preliminarily process the source code in preparation for in-depth code analysis. Precompilation may include syntax checking, code formatting, and preliminary code optimization. It is implemented through Polyspace's API (application programming interface) or command line tools. The purpose is to identify and fix compile-time errors and improve the efficiency and accuracy of subsequent analysis. Precompilation parameters can be adjusted according to project requirements and are not limited to one configuration.

[0074] Step S14: Divide into multiple blacklist files and upload them to the code repository. According to preset conditions, dividing the precompiled source code files into multiple blacklist files means grouping the codes according to the complexity, risk level or other standards of the codes and marking them as blacklist files.

[0075] A blacklist is a list that prohibits access to specific resources or the execution of specific operations. Entities listed in the blacklist will be prohibited from accessing or executing specific operations. Other entities not included in the blacklist will be allowed by default. The blacklist mechanism is relatively loose, only listing disallowed entities, and all other entities are allowed by default. The division of the blacklist is completed through script processing.

[0076] The division of blacklist files is set according to different requirements. It may contain code areas that need to be focused on, such as modules with high security requirements or parts with more defects in history. It can also be divided according to the number of code files. Use Jenkins scripts to automate the file division and upload process. The preset conditions can be dynamically adjusted and optimized according to project progress and feedback. It is common to divide blacklist files according to the modules and functions of the code.

[0077] Step S15 scans the blacklist files in batches and calls Polyspace to perform static code analysis and detection. Scanning the blacklist files in batches means performing detailed analysis on the blacklist files in a certain order and batches, which can ensure the effective use of resources, especially when dealing with large projects.

[0078] Through Jenkins scheduling tasks and Polyspace's analysis engine, defects and security vulnerabilities in the code are deeply identified. Batch strategies can be adjusted based on analysis results and feedback. Automated scripts are usually used to manage the batch scanning process.

[0079] Step S16: Output the analysis report of all source code files. Outputting the analysis report of all source code files refers to summarizing the analysis results of Polyspace and generating a comprehensive report. It may include code defects, security vulnerabilities, performance issues and code improvement suggestions. The purpose is to provide clear feedback to developers to help them understand the status of the code and guide subsequent development and maintenance work. The format and content of the report can be customized according to user needs.

[0080] The Polyspace-based code analysis method provided by the embodiment of the present application is executed through the pre-built Jenkins continuous integration platform, and the method includes: receiving a code analysis trigger command and parameter settings; obtaining source code files according to the code analysis trigger command; calling Polyspace to precompile the source code files; dividing the precompiled source code files into multiple blacklist files according to preset conditions and uploading them to the code repository; scanning the blacklist files in batches in sequence, calling Polyspace for static code analysis and detection; outputting analysis reports for all source code files. The automated code analysis process of the present application reduces manual operations and improves the efficiency of analysis. In addition, the accuracy of the analysis is improved by proposing precompilation and batch scanning strategies, ensuring the quality of the code. By dividing the blacklist files, resources and attention are focused on the code parts with the highest potential risks. The Polyspace analysis integrated in Jenkins allows continuous improvement in the continuous integration and continuous deployment processes.

[0081] According to the above embodiment, in a specific implementation scheme, based on the Polyspace code analysis method, receiving a code analysis trigger command and parameter settings includes:

[0082] Receive code analysis trigger commands and parameter settings input by the user through the platform user interface;

[0083] Verify whether the code analysis trigger command complies with the predetermined format and permission requirements;

[0084] If yes, it will be configured according to the parameter settings.

[0085] The platform user interface receives the code analysis trigger command and parameter settings entered by the user, allowing the user to submit a code analysis request through the Jenkins platform user interface (UI). This usually involves filling out a form containing the necessary analysis parameters, such as analysis type, code branch, submission ID number, etc.

[0086] The user interface is designed to be intuitive and easy to use, ensuring that users can enter all necessary information without error.

[0087] Verify whether the code analysis trigger command complies with the predetermined format and permission requirements. After the system backend receives the command and parameters entered by the user, it first performs format verification to ensure that the input data complies with the predetermined structure and rules, such as JSON or YAML format. Next, the system checks the user's permissions to confirm whether the user has the right to trigger code analysis. This involves integration with the company's user authentication (SSO) system, such as the Lightweight Directory Access Protocol (LDAP) or an open protocol (Open Authorization, OAuth). If the command or parameter format entered is incorrect, the system will provide the user with an error message and ask for re-entry. If the user does not have sufficient permissions, the system will reject the request and provide the corresponding permission application process.

[0088] If yes, it will be configured according to the parameter settings. Once the verification is passed, Jenkins will configure the code analysis job according to the parameter settings provided by the user. This may include setting specific parameters for Polyspace analysis, such as code standards, security rules, optimization levels, etc. After the Jenkins job configuration is completed, the code analysis process will be automatically triggered. This may involve scheduling jobs, allocating computing resources, setting up the analysis environment, etc. The configuration information will be saved in the Jenkins build configuration for future auditing and historical tracking.

[0089] In this implementation, the entire process emphasizes the convenience of user interaction, strict input validation, and automation of job configuration. This design is intended to ensure the accuracy, security, and repeatability of the code analysis process while improving user efficiency.

[0090] According to the above embodiment, in a specific implementation scheme, based on the Polyspace code analysis method, obtaining the source code file according to the code analysis trigger command includes:

[0091] Establish a connection with the version control system;

[0092] Pull source code files from the version control system according to the branch and commit information specified in the code analysis trigger command;

[0093] Store the source code files in the Jenkins working directory.

[0094] Establish a connection with the version control system. The Jenkins job configuration contains connection information with the version control system (such as Git, SVN, etc.), which may include server address, access credentials (such as username and password or access token). In the code analysis trigger command, it will specify which configured connection to use or provide new connection parameters.

[0095] Jenkins uses this connection information to establish a secure connection with the version control system to ensure the security and integrity of data transmission.

[0096] Pull source code files from the version control system according to the branch and commit information specified in the code analysis trigger command. When triggering code analysis, the user needs to specify the specific version of the code to be analyzed, which usually includes the branch name and the commit ID number or tag.

[0097] Jenkins uses this information to initiate a request to the version control system to pull the specified source code files. This process may involve cloning the entire repository, pulling a specific branch, or downloading a specific commit snapshot.

[0098] Store the source code files in the Jenkins working directory. The pulled source code files are stored in the Jenkins predefined working directory, which is configured as part of the Jenkins job.

[0099] The storage path and structure of the source code files are retained to ensure that the subsequent build and analysis steps can correctly reference these files. Jenkins may perform some preprocessing on the source code files, such as decompression, reorganization of the file structure, etc., to meet the needs of subsequent steps.

[0100] Automatically obtain source code files from the version control system, reducing manual operation errors and improving efficiency. By specifying branches and commit information, it ensures that the correct code version is analyzed, improving the accuracy of the analysis. Support for multiple version control systems and multiple code versions improves the applicability and flexibility of the method.

[0101] According to the above embodiment, in a specific implementation scheme, based on the Polyspace code analysis method, calling Polyspace to precompile the source code file includes:

[0102] Configure the pre-compilation parameters of the Polyspace tool, including compiler type, compilation options, and optimization level;

[0103] Pass the source code file to Polyspace for precompilation;

[0104] Monitor the compilation process and capture the output compilation error information;

[0105] If there is a compilation error message, the precompilation error message is output, and the precompilation result is output;

[0106] If there is no compilation error message, go to the next step.

[0107] Configure the pre-compilation parameters of the Polyspace tool and select the appropriate compiler according to the language of the source code file and project requirements. For example, for C language (a process-oriented computer programming language) and C++ (c plus plus, a computer high-level programming language) projects, you can choose GCC (GNU Compiler Collection) or Clang (a lightweight compiler). Compilation options: Set specific options for the compiler to ensure that the compilation process can correctly find all dependencies. Optimization level: Set the optimization level according to project requirements and performance goals. The optimization level affects the performance and size of the compiled code. Implement these settings through Polyspace configuration files or command line parameters. To ensure that the pre-compilation process can be executed correctly and the generated code meets the project requirements.

[0108] Pass source code files to Polyspace for precompilation, and pass source code files to Polyspace through the Polyspace API or command line tools.

[0109] Monitor the compilation process and capture the output compilation error information. Capture compilation error information by monitoring Polyspace's output log or standard error stream to identify any problems in the pre-compilation process so that they can be fixed in time.

[0110] If there are compilation errors, output precompilation error information, output precompilation results, record error information in log files, and display them on the Jenkins interface. Inform developers of the reasons for precompilation failure so that they can fix these problems.

[0111] If there is no compilation error information, proceed to the next step, which is in-depth code analysis. This ensures that only successfully precompiled code will enter the subsequent analysis process, thereby improving the accuracy and efficiency of the analysis.

[0112] The pre-compilation step can detect and fix compile-time errors in advance, improving code quality. Pre-compilation can reduce error handling in the subsequent analysis process, saving computing resources and time. The automated pre-compilation step reduces manual operations and improves the efficiency of the entire code analysis process.

[0113] According to the above embodiment, in a specific implementation scheme, based on the Polyspace code analysis method, the precompiled source code file is divided into multiple blacklist files according to preset conditions and uploaded to the code warehouse, including:

[0114] Determine whether the number of precompiled source code files exceeds a preset number;

[0115] If so, divide the source code file into a preset number;

[0116] Create multiple blacklist files for the divided source code files;

[0117] Generate a list containing the source file path and file name for each blacklist file;

[0118] Upload the generated blacklist file to the code repository and record the upload time and version information.

[0119] Determine whether the number of precompiled source code files exceeds the preset number, specifically by writing a script or using a Jenkins plug-in to count the number of precompiled source code files and compare it with the preset number threshold. Determine whether the source code files need to be divided to avoid a single blacklist file being too large, which affects the efficiency of subsequent code analysis.

[0120] To ensure that each blacklist file contains an appropriate amount of source code files for easy management and analysis, if yes, the source code files are divided into a preset number. If the number of source code files exceeds the preset value, an automated script is used to divide the source code files into multiple batches based on criteria such as file size, module function or code complexity.

[0121] Create multiple blacklist files for each divided source file set. Create a blacklist file for each divided source file set. You can use text files or specific formats to store them, such as JSON or Extensible Markup Language (XML). Mark and organize source files so that Polyspace can perform more detailed analysis on each blacklist file.

[0122] Generate a list containing the source code file path and file name for each blacklist file, automatically generate a corresponding list file for each blacklist file, and record the path and name of all source code files contained therein. Provide clear file tracking and auditing to ensure that the content of each blacklist file is traceable.

[0123] Upload the generated blacklist file to the code repository and record the upload time and version information. Use the command line tool or API of the version control system to upload the blacklist file to the code repository and record the timestamp and version information of the upload operation. Ensure version control of the blacklist file to facilitate tracking of change history and collaboration.

[0124] By properly dividing source code files, the efficiency and accuracy of Polyspace code analysis can be improved. The list and version information of the blacklist file are generated and recorded to enhance the traceability of the code analysis process. The blacklist file uploaded to the code repository facilitates sharing and collaboration among team members.

[0125] According to the above embodiment, in a specific implementation scheme, based on the Polyspace code analysis method, the blacklist files are scanned in batches and in sequence, and Polyspace is called to perform static code analysis detection, including:

[0126] Call Polyspace to perform code analysis on each batch of blacklist files in turn, including but not limited to data flow check, value check, static memory check, control flow check, and C++ check;

[0127] After each batch of file analysis is completed, the analysis of the next batch is automatically triggered until all blacklisted files are analyzed.

[0128] Figure 2 A data analysis schematic diagram provided in an embodiment of the present application, such as Figure 2 As shown, Polyspace is called on each batch of blacklist files in turn to perform static code analysis. Data flow check: Analyze the data flow in the code to detect potential data errors and inconsistencies, such as uninitialized variables and incorrect data type usage. Numeric check: Check the numerical calculations in the code to identify possible numerical overflows, division by zero errors, and other numerical stability issues. Static memory check: Analyze the code to find memory leaks, illegal memory accesses, and incorrect memory management practices. Control flow check: Check the control flow structure of the code to identify possible logic errors, infinite loops, and incorrect conditional branches. C++ check: Perform in-depth analysis on C++-specific features, such as templates, multiple inheritance, etc., to find C++-specific code problems.

[0129] Through Polyspace's automated analysis tools, the source code in the blacklist file is analyzed according to the configured analysis type and parameters. The code quality is fully checked to ensure the security, stability and reliability of the code.

[0130] After each batch of file analysis is completed, the analysis of the next batch is automatically triggered. Set up a Jenkins job or write a script so that after each batch of file analysis is completed, the analysis of the next batch is automatically triggered.

[0131] Automated triggering is achieved through Jenkins build triggers and Polyspace APIs or command line tools. Ensure the continuity and automation of the analysis process, reduce manual intervention, and improve efficiency.

[0132] Ensure that all batches of blacklisted files have been analyzed by Polyspace without omission. After all files are analyzed, summarize the analysis results of all batches and generate a comprehensive analysis report. Provide a complete view of code quality to help developers understand the status of the entire code base.

[0133] Batch processing can effectively utilize computing resources and improve analysis efficiency. Automated batch triggering reduces waiting time and speeds up the entire analysis process. It ensures that all codes are analyzed and improves the comprehensiveness of code quality.

[0134] According to the above embodiment, in a specific implementation scheme, based on the Polyspace code analysis method, establishing a connection with a version control system includes:

[0135] Configure authentication information for the Jenkins continuous integration platform and version control system, including username, password or access token;

[0136] Test the validity of the connection;

[0137] Configure Jenkins jobs to automatically respond to code changes in your version control system.

[0138] In the system configuration of the Jenkins platform or the specific project configuration, enter the authentication information of the version control system (such as Git, SVN, etc.). This information may include username, password, personal access token (PAT) or secure shell protocol (SSH) key, etc. For multi-user environments, ensure the security of authentication information, such as using Jenkins's credential management plug-in to securely store and manage sensitive information. Ensure that Jenkins can securely access the version control system to obtain source code files and respond to code changes.

[0139] After configuring the authentication information, perform a test to verify that Jenkins can successfully connect to the version control system. This test may include trying to pull source code files from the version control system or checking the response status of the version control system. If the connection fails, the system should provide error information so that the user can diagnose and solve the problem. Make sure that the configured authentication information is correct and that Jenkins can establish a stable connection with the version control system.

[0140] Configure Jenkins jobs to automatically respond to code change events in the version control system, enabling it to automatically respond to code change events in the version control system. This can be achieved by configuring Webhooks, that is, when a code change occurs, the version control system automatically sends a Hypertext Transfer Protocol (HTTP) request to Jenkins to trigger a build. If the version control system does not support Webhooks, you can use Jenkins's periodic polling function to check for code changes. Configure Jenkins jobs to automatically execute predefined build and analysis processes when code changes are detected.

[0141] Automatic response is achieved through Jenkins build trigger configuration. The core concept of continuous integration is to quickly and automatically execute builds and analyses after code changes so that problems can be discovered and fixed in a timely manner.

[0142] The automated connection and response mechanism increases the speed of responding to code changes and reduces the need for manual operations. By securely managing authentication information, the security of the version control system and the Jenkins platform is protected. By testing the validity of the connection, it is ensured that the connection between Jenkins and the version control system is reliable.

[0143] In the above embodiments, the Polyspace code analysis method is described in detail, and the present application also provides an embodiment corresponding to the Polyspace code analysis device. It should be noted that the present application describes the embodiments of the device part from two perspectives, one is based on the functional module perspective, and the other is based on the hardware perspective.

[0144] From the perspective of functional modules, Figure 3 A structural diagram of a Polyspace code analysis device provided in an embodiment of the present application, such as Figure 3 As shown, a Polyspace-based code analysis device includes:

[0145] Receiving module 21, used for receiving code analysis trigger command and parameter setting;

[0146] An acquisition module 22 is used to acquire source code files according to a code analysis trigger command;

[0147] A pre-compilation module 23 is used to call Polyspace to pre-compile the source code file;

[0148] A division module 24 is used to divide the precompiled source code file into multiple blacklist files according to preset conditions and upload them to the code warehouse;

[0149] The analysis and detection module 25 is used to scan the blacklist files in batches and call Polyspace to perform static code analysis and detection;

[0150] The output module 26 is used to output analysis reports of all source code files.

[0151] Since the embodiments of the apparatus part correspond to the embodiments of the method part, please refer to the description of the embodiments of the method part for the embodiments of the apparatus part, which will not be repeated here.

[0152] Figure 4 Another structural diagram of a Polyspace code analysis device provided in an embodiment of the present application is shown in FIG. Figure 4 As shown, the Polyspace-based code analysis device includes: a memory 30 for storing a computer program;

[0153] The processor 31 is used to implement the steps of the method for obtaining user operation habit information in the above embodiment (based on the Polyspace code analysis method) when executing a computer program.

[0154] The Polyspace-based code analysis device provided in this embodiment may include but is not limited to a smart phone, a tablet computer, a laptop computer, or a desktop computer.

[0155] Among them, the processor 31 may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor 31 may be implemented in at least one hardware form of a digital signal processor (DSP), a field-programmable gate array (FPGA), and a programmable logic array (PLA). The processor 31 may also include a main processor and a coprocessor. The main processor is a processor for processing data in the awake state, also known as a central processing unit (CPU); the coprocessor is a low-power processor for processing data in the standby state. In some embodiments, the processor 31 may be integrated with a graphics processing unit (GPU), and the GPU is responsible for rendering and drawing the content to be displayed on the display screen. In some embodiments, the processor 31 may also include an artificial intelligence (AI) processor, which is used to process computing operations related to machine learning.

[0156] The memory 30 may include one or more computer-readable storage media, which may be non-transitory. The memory 30 may also include a high-speed random access memory, and a non-volatile memory, such as one or more disk storage devices, flash memory storage devices. In this embodiment, the memory 30 is at least used to store the following computer program 301, wherein, after the computer program is loaded and executed by the processor 31, it can implement the relevant steps of the Polyspace code analysis method disclosed in any of the aforementioned embodiments. In addition, the resources stored in the memory 30 may also include an operating system 302 and data 303, etc., and the storage method may be temporary storage or permanent storage. Among them, the operating system 302 may include Windows, Unix, Linux, etc. Data 303 may include but is not limited to data involved in implementing the Polyspace code analysis method, etc.

[0157] In some embodiments, the Polyspace-based code analysis device may further include a display screen 32 , an input / output interface 33 , a communication interface 34 , a power supply 35 , and a communication bus 36 .

[0158] Those skilled in the art will understand that Figure 4 The structure shown in the figure does not constitute a limitation on the Polyspace-based code analysis device, and may include more or fewer components than those shown in the figure.

[0159] The Polyspace-based code analysis device provided in an embodiment of the present application includes a memory and a processor. When the processor executes a program stored in the memory, it can implement the following method: a Polyspace-based code analysis method.

[0160] Finally, the present application also provides an embodiment corresponding to a computer-readable storage medium. The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps described in the above-mentioned embodiment of the Polyspace code analysis method are implemented.

[0161] It is understandable that if the method in the above embodiment is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium to execute all or part of the steps of the methods of each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk and other media that can store program code.

[0162] The computer-readable storage medium provided in this embodiment stores a computer program, and when a processor executes the program, the following method can be implemented: based on the Polyspace code analysis method.

[0163] The above is a detailed introduction to the Polyspace-based code analysis method, device and medium provided by the present application. The various embodiments in the specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same and similar parts between the embodiments can refer to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can refer to the method part description. It should be pointed out that for ordinary technicians in this technical field, without departing from the principles of the present application, several improvements and modifications can be made to the present application, and these improvements and modifications also fall within the scope of protection of the claims of the present application.

[0164] It should also be noted that, in this specification, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "comprise", "include" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the statement "comprises a ..." does not exclude the presence of other identical elements in the process, method, article or device including the element.

Claims

1. A Polyspace-based code analysis method, characterized in that: include: Receive code analysis trigger commands and parameter settings; Acquire source code files according to the code analysis trigger command; Calling Polyspace to precompile the source code file; Dividing the precompiled source code file into a plurality of blacklist files according to preset conditions and uploading them to a code warehouse; Scan the blacklist files in batches and call Polyspace to perform static code analysis and detection; Output analysis reports of all the source code files.

2. The Polyspace-based code analysis method according to claim 1, characterized in that: Receiving code analysis trigger commands and parameter settings include: Receive code analysis trigger commands and parameter settings input by the user through the platform user interface; Verify whether the code analysis trigger command complies with the predetermined format and permission requirements; If so, it will be configured according to the parameter settings.

3. The Polyspace-based code analysis method according to claim 1, characterized in that: The acquiring of the source code file according to the code analysis trigger command comprises: Establish a connection with the version control system; Pull source code files from the version control system according to the branch and submission information specified in the code analysis trigger command; Store the source code files in the Jenkins working directory.

4. The Polyspace-based code analysis method according to claim 3, characterized in that: Calling Polyspace to precompile the source code file includes: Configure the pre-compilation parameters of the Polyspace tool, including compiler type, compilation options, and optimization level; Passing the source code file to Polyspace for pre-compilation; Monitor the compilation process and capture the output compilation error information; If the compilation error information exists, output the pre-compilation error information and the pre-compilation result; If the compilation error message does not exist, proceed to the next step.

5. The Polyspace-based code analysis method according to claim 1, characterized in that: The precompiled source code file is divided into a plurality of blacklist files according to preset conditions and uploaded to the code warehouse, including: Determining whether the number of the source code files precompiled exceeds a preset number; If yes, dividing the source code file into the preset number; The divided source code files are respectively created into a plurality of blacklist files; Generate a list containing the source file path and file name for each blacklist file; Upload the generated blacklist file to the code repository and record the upload time and version information.

6. The Polyspace-based code analysis method according to claim 5, characterized in that: Scanning the blacklist files in batches in sequence and calling Polyspace to perform static code analysis and detection includes: Call Polyspace to perform code analysis on each batch of blacklist files in turn, including but not limited to data flow check, value check, static memory check, control flow check, and C++ check; After each batch of file analysis is completed, the analysis of the next batch is automatically triggered until all blacklisted files are analyzed.

7. The Polyspace-based code analysis method according to claim 3, characterized in that: The establishing of a connection with the version control system includes: Configure authentication information for the Jenkins continuous integration platform and version control system, including username, password or access token; Test the validity of the connection; Configure Jenkins jobs to automatically respond to code changes in your version control system.

8. A Polyspace-based code analysis device, characterized in that: include: A receiving module, used for receiving code analysis trigger commands and parameter settings; An acquisition module, used to acquire source code files according to the code analysis trigger command; A pre-compilation module, used for calling Polyspace to pre-compile the source code file; A division module, used for dividing the precompiled source code file into a plurality of blacklist files according to preset conditions and uploading the blacklist files to a code repository; An analysis and detection module, used to scan the blacklist files in batches and call Polyspace to perform static code analysis and detection; The output module is used to output analysis reports of all the source code files.

9. A Polyspace-based code analysis device, characterized in that: include: Memory for storing computer programs; A processor, configured to implement the steps of the Polyspace code analysis method according to any one of claims 1 to 7 when executing the computer program.

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 steps of the Polyspace-based code analysis method according to any one of claims 1 to 7 are implemented.