Code quality test automatic configuration method and related equipment
Through the automatic configuration code quality testing method, the problem of manual configuration errors in the complex environment of automotive controller software is solved, efficient and accurate code testing is achieved, and development and testing efficiency and software stability are improved.
Patent Information
- Application Number
- CN202410695567.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-31
- Publication Date
- 2024-09-24
AI Technical Summary
Existing technologies make it difficult to effectively evaluate and discover potential defects in automotive controller software, especially in complex platform and multi-processor hardware environments. Manual configuration of code quality testing is prone to errors, resulting in inefficiency and delays.
An automatic configuration method for code quality testing is proposed. By inputting the code to be tested into the target compiler, generating intermediate files, and obtaining the configuration file library and keyword library, the configuration information of the code testing software is automatically configured to ensure that each source file is compiled correctly. , dependencies are accurately reflected, reducing human errors and improving processing speed and test coverage.
By automating the compilation process, we reduce human errors, ensure accurate dependencies, improve development and testing efficiency, increase the stability and reliability of software release, adapt to different testing needs and tools, easily add new file types and compilation options, and reduce configuration differences and Delay.
Smart Images

Figure CN118689762A
Abstract
Description
Technical Field
[0001] The present invention relates to the field of code quality testing, and more specifically, to a method for automatically configuring a code quality test and related equipment. Background Art
[0002] Due to the high reliability of automotive-grade controllers and the need for functional safety and information security, major OEMs have long stopped focusing on the functional implementation of controller software. In addition, due to the limitations of functional testing itself, it is difficult to evaluate the test coverage at the code level, and the limited test cases make it impossible to traverse all input conditions, making it difficult to discover potential defects in controller software. According to the ISO 9126 software quality model, there are six dimensions for evaluating software quality: functionality, reliability, ease of use, efficiency, maintainability, and portability.
[0003] The main means of evaluating software reliability is to conduct code quality testing: find defective code, erroneous statements, code with operational risks, and code that does not meet programming specifications, etc. Since current vehicle control software is generally platform-based, most of them use the AUTOSAR platform, which is compatible with multiple processor hardware and multiple projects. This directly leads to a more complex software architecture and a sharp increase in the amount of code. For example, the amount of code for the power domain controller software of an AUTOSAR platform can reach several GBytes, with more than 3,000 source files (.c / .cpp) and more than 1,000 header files (.h).
[0004] At present, the most commonly used programming language for automotive controllers is still C language. When doing code quality testing, you first need to extract the source files involved in the compilation of the project (such as .C files) and the header files .h files contained in the source files involved in the compilation. When the amount of project code is not large, the number of files is relatively small, and this part of the work can be completed manually. With the increase in the complexity of the software, the complexity of this part of the work increases exponentially and is prone to errors. For example, if source files and header files that are not involved in the compilation are added by mistake, or if source files and header files that are not involved in the compilation are added less, it will cause compilation errors in the code quality test project and low efficiency. In view of this, it is necessary to propose a method for automatic configuration of code quality testing. Summary of the invention
[0005] A series of simplified concepts are introduced in the Summary of the Invention section, which will be further described in detail in the Detailed Description of the Invention section. The Summary of the Invention section of this application does not mean to attempt to define the key features and essential technical features of the claimed technical solution, nor does it mean to attempt to determine the scope of protection of the claimed technical solution.
[0006] In a first aspect, the present application proposes a method for automatically configuring a code quality test, comprising:
[0007] Input the code to be tested into the target compiler and perform a compile operation according to the file generation rule to generate an intermediate file, wherein the intermediate file is generated during the compilation process of the source file corresponding to the code to be tested and the file with dependency relationship;
[0008] Obtain a configuration file library, wherein the configuration file library includes platform information, source file extensions, dependent file extensions, code test software engineering configuration file paths, and macro definitions of the target compiler;
[0009] A type configuration keyword library based on the target code test software, wherein the keyword library includes source file configuration keywords, source file format keywords, header file configuration keywords, header file format keywords, macro definition configuration keywords, and macro definition format keywords;
[0010] Based on the configuration file library, the keyword library and the intermediate file, the configuration information of the target code testing software is automatically configured.
[0011] In a feasible implementation, the intermediate file includes a target file and a dependent file. The target file is a compiled file corresponding to the source file. The target file and the source file have the same file name. The dependent file is a compiled file corresponding to a file having a dependency relationship with the source file. The dependent file and the file having a dependency relationship with the source file have the same file name.
[0012] In a feasible implementation, the above-mentioned file generation rules include target file generation rules and dependent file generation rules. The above-mentioned target file generation rules include the mapping relationship between the source file initial name suffix information and the target file suffix information. The above-mentioned dependent file generation rules include the mapping relationship between the suffix information of the file that has a dependency relationship with the above-mentioned source file and the dependent file suffix information.
[0013] In a feasible implementation manner, the automatic configuration of the configuration information of the target code software based on the configuration file library, the keyword library, and the intermediate file includes:
[0014] According to the platform information of the target compiler, the source file extension, and the target file generation rule, the intermediate file is traversed and screened to obtain the source file path information;
[0015] According to the platform information of the target compiler, the dependent file extension, and the dependent file generation rule, the intermediate file is traversed and screened to obtain the dependent file path information;
[0016] According to the source file path information, the dependent file path information and the keyword library, the configuration information of the target code testing software is automatically configured.
[0017] In a feasible implementation, it also includes:
[0018] When the platform information of the target compiler is Windows platform and the extension of the original file is .c, the .obj files are traversed and filtered in the intermediate files to obtain the source file path information.
[0019] In a feasible implementation, it also includes:
[0020] When the platform information of the target compiler is Linux platform and the extension of the original file is .c, the .o files are traversed and filtered in the intermediate files to obtain the source file path information.
[0021] In a feasible implementation manner, the above-mentioned traversal and screening in the above-mentioned intermediate file according to the platform information of the above-mentioned target compiler, the above-mentioned dependent file extension, and the above-mentioned dependent file generation rule to obtain the dependent file path information includes:
[0022] According to the platform information of the target compiler, the dependent file extension, and the dependent file generation rule, the intermediate file is traversed and screened to obtain the dependent file content;
[0023] The first n lines of the above dependency file content are discarded to obtain the above dependency file path information.
[0024] In a second aspect, the present application proposes a code quality test automatic configuration device, comprising:
[0025] A compiling unit, used for inputting the code to be tested into a target compiler and performing a compiling operation according to a file generation rule to generate an intermediate file, wherein the intermediate file is generated during the compilation process of the source file corresponding to the code to be tested and the files having a dependency relationship;
[0026] An acquisition unit, used for acquiring a configuration file library, wherein the configuration file library includes platform information of the target compiler, source file extensions, dependent file extensions, code test software engineering configuration file paths and macro definitions;
[0027] A first configuration unit is used to configure a keyword library based on the type of the target code test software, wherein the keyword library includes source file configuration keywords, source file format keywords, header file configuration keywords, header file format keywords, macro definition configuration keywords, and macro definition format keywords;
[0028] The second configuration unit is used to automatically configure the configuration information of the target code testing software based on the configuration file library, the keyword library and the intermediate file.
[0029] In a third aspect, an electronic device comprises: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor is used to implement the steps of the automatic configuration method for code quality testing as described in any one of the first aspects above when executing the computer program stored in the memory.
[0030] In a fourth aspect, the present application further proposes a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the method for automatically configuring code quality testing according to any one of the first aspects is implemented.
[0031] In summary, the automatic configuration method of the code quality test of the embodiment of the present application includes: inputting the code to be tested into the target compiler and compiling according to the file generation rule to generate an intermediate file, wherein the intermediate file is generated in the compilation process for the source file corresponding to the code to be tested and the file with dependency relationship; obtain a configuration file library, wherein the configuration file library includes the platform information, source file extension, dependency file extension, code test software engineering configuration file path and macro definition of the target compiler; based on the type configuration keyword library of the target code test software, wherein the keyword library includes source file configuration keywords, source file format keywords, header file configuration keywords, header file format keywords, macro definition configuration keywords, macro definition format keywords; based on the configuration file library, the keyword library, the intermediate file, the configuration information of the target code test software is automatically configured. The method proposed in the embodiment of the present application reduces human errors through the automated compilation process, ensures that each source file is correctly compiled, and the dependency relationship is accurately reflected. Automatic compilation and generation of intermediate files greatly improves the processing speed when the number of source files is large. Centrally manage compiler platform information, file extensions, test configuration paths, etc., to ensure that all project components use consistent settings and reduce problems caused by configuration differences. The keyword library allows custom configuration of code test software to adapt to different test needs and tools. As the project develops, new file types and compilation options can be easily added to the keyword library without refactoring the existing test configuration. Automatic configuration of test software ensures complete test coverage including all necessary files, reducing the risk of missing or incorrectly including files. In a typical automotive-grade controller software project, such as a power domain controller based on the AUTOSAR platform, the amount of code and files can be very large. Traditional manual configuration methods are not only time-consuming but also prone to errors, especially in an environment where source files or header files are frequently updated. By automating this process, this solution can significantly improve the efficiency of development and testing, reduce delays caused by configuration errors, and increase the stability and reliability of software releases.
[0032] The code quality test automatic configuration method proposed in this application, and other advantages, objectives and features of this application will be reflected in part through the following description, and in part will also be understood by technical personnel in this field through research and practice of this application. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] Various other advantages and benefits will become apparent to those of ordinary skill in the art by reading the detailed description of the preferred embodiments below. The accompanying drawings are only for the purpose of illustrating the preferred embodiments and are not to be considered as limiting the present specification. Also, the same reference symbols are used throughout the accompanying drawings to represent the same components. In the accompanying drawings:
[0034] Figure 1 A schematic diagram of a method for automatically configuring a code quality test process provided by an embodiment of the present application;
[0035] Figure 2 A schematic diagram of a code quality test automatic configuration principle provided in an embodiment of the present application;
[0036] Figure 3 A schematic diagram of the structure of a code quality test automatic configuration device provided in an embodiment of the present application;
[0037] Figure 4 A schematic diagram of the structure of an electronic device for automatically configuring a code quality test provided in an embodiment of the present application. DETAILED DESCRIPTION
[0038] The terms "first", "second", "third", "fourth", etc. (if any) in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices. The technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all of the embodiments.
[0039] The conventional approach to code quality testing is to conduct a forward analysis based on the compilation methods of embedded software projects, such as makefile script compilation, python script compilation, and CodeWarrior compiler IDE interface, and to study the contents of the makefile script, python script, and CodeWarrior compiler IDE interface of a specific project, and obtain the source files and header files involved in the compilation of the entire project. In addition, the software with the IDE interface can usually only be viewed manually (it is more intuitive when there are fewer project source files, and the work is more cumbersome and prone to errors when there are more project source files). Since the compilation methods used in the early software process are various and cannot be unified, and are related to the specific hardware IC, AUTOSAR platform version, etc., it is impossible to change all projects to one compilation method. Usually, due to the large workload of transplantation, the compilation environment is not easily changed in the actual development work, which brings troubles to the subsequent development code quality testing project and is difficult to achieve automation.
[0040] See also Figure 1 , which is a flow chart of a method for automatically configuring a code quality test provided by an embodiment of the present application, which may specifically include:
[0041] S110, inputting the code to be tested into a target compiler and performing a compiling operation according to a file generation rule to generate an intermediate file, wherein the intermediate file is generated during the compilation process of the source file corresponding to the code to be tested and the files having a dependency relationship;
[0042] Exemplarily, the code to be tested is input into the target compiler, and a compilation operation is performed according to the file generation rule to generate an intermediate file. The intermediate file is formed by the source file and the header file information it depends on during the compilation process.
[0043] S120, obtaining a configuration file library, wherein the configuration file library includes platform information of the target compiler, source file extension, dependent file extension, code test software engineering configuration file path and macro definition;
[0044] For example, the configuration file library is obtained, including the platform information of the target compiler, the source file extension, the dependent file extension, the code test software engineering configuration file path and macro definition, etc. The configuration file library may include information such as Windows platform or Linux platform, source file extension .c, dependent file extension .d, Polyspace configuration file path, etc.
[0045] S130, configuring a keyword library based on the type of the target code test software, wherein the keyword library includes source file configuration keywords, source file format keywords, header file configuration keywords, header file format keywords, macro definition configuration keywords, and macro definition format keywords;
[0046] Exemplarily, keywords and formats for automatically configuring code testing software are defined to ensure that the correct information can be extracted from intermediate files. Keywords include configuration keywords and formats of source files and header files. These keywords are used to parse and format entries in test configuration files.
[0047] S140. Automatically configure the configuration information of the target code testing software based on the configuration file library, the keyword library, and the intermediate file.
[0048] Exemplarily, the configuration file of the code quality testing tool is automatically filled or updated by utilizing the defined configuration file library and keyword library in combination with the information extracted from the intermediate file.
[0049] In summary, the method proposed in the embodiment of the present application reduces human errors through the automated compilation process, ensures that each source file is compiled correctly, and the dependencies are accurately reflected. Automatic compilation and generation of intermediate files (target files and dependent files) greatly improves the processing speed when there are many source files. Centrally manage compiler platform information, file extensions, and test configuration paths, etc., to ensure that all project components use consistent settings and reduce problems caused by configuration differences. The keyword library allows custom configuration code test software to adapt to different test requirements and tools. As the project develops, new file types and compilation options can be easily added to the keyword library without reconstructing the existing test configuration. Automatic configuration test software ensures complete test coverage including all necessary files, reducing the risk of missing or incorrectly including files. In a typical automotive-grade controller software project, such as a power domain controller based on the AUTOSAR platform, the number of codes and files may be very large. Traditional manual configuration methods are not only time-consuming but also error-prone, especially in environments where source files or header files are frequently updated. This solution can significantly improve the efficiency of development and testing by automating this process, reduce delays caused by configuration errors, and increase the stability and reliability of software releases.
[0050] In some examples, the intermediate files include a target file and a dependent file. The target file is a compiled file corresponding to the source file, and the target file and the source file have the same file name. The dependent file is a compiled file corresponding to a file having a dependency relationship with the source file, and the dependent file and the file having a dependency relationship with the source file have the same file name.
[0051] Exemplarily, the target file is a binary file generated after the source file is compiled, and is usually used to generate an executable file in the linking stage. Each source file (such as a .c or .cpp file) generates a corresponding target file (such as a .o file).
[0052] Each object file has the same base file name as its corresponding source file, differing only in the extension. For example, the object file for the source file main.c would be main.o.
[0053] Dependency files contain the relationship between source files and the header files (.h files) they depend on. These files are designed to optimize the compilation process and ensure that when header files are updated, source files that depend on these header files can be recompiled.
[0054] The naming method of dependency files is similar to that of target files, and is generated based on the source file name. For example, the dependency file of the source file main.c will be main.d, which lists all the header files that main.c depends on.
[0055] Use commands such as gcc -c main.co main.o to generate the object file.
[0056] Use commands such as gcc-M main.c to generate dependency files, and usually process the output through some scripts to generate formatted .d files, which are used to automatically check dependencies in subsequent compilations.
[0057] By reading the information in the .d file, the automated tool can understand which source files and header files are associated, thereby ensuring that all related files are included in the code quality analysis. Although the target files are not used directly in the code quality test, their generation ensures that the source files are compilable and the compilation environment is configured correctly.
[0058] According to the compilation platform and compiler information (obtained from the configuration file library), set the appropriate compilation flags and paths. Use the keyword library to define configuration items such as source file paths, header file paths, and macro definitions required by the test tool.
[0059] Automatically populate configuration files for code quality testing tools (such as Polyspace, Coverity, etc.) with correct file paths, compilation flags, and other necessary settings using dependencies resolved from intermediate .d files and information obtained from the configuration file repository.
[0060] This automated approach reduces the need for manual intervention, reduces the possibility of configuration errors, and can save a lot of time and effort in large-scale projects. Automatic analysis of dependencies ensures the integrity of the test, and each time the source file or header file is updated, the relevant code quality tests can be automatically re-performed to ensure continuous monitoring and improvement of project quality.
[0061] In some examples, the above-mentioned file generation rules include target file generation rules and dependent file generation rules. The above-mentioned target file generation rules include a mapping relationship between the source file initial name suffix information and the target file suffix information. The above-mentioned dependent file generation rules include a mapping relationship between the suffix information of the file that has a dependency relationship with the above-mentioned source file and the dependent file suffix information.
[0062] For example, regarding the generation rules of target files and dependent files, they all involve how to convert source files (such as .c files) into corresponding target files (such as .o files) and dependent files (such as .d files) through the compiler. These rules not only ensure the correct execution of the compilation process, but also provide the necessary information for the automated tools to configure code quality testing.
[0063] Specifically, the generation rules for defining the target file can be:
[0064] %.o:%.c
[0065] gcc -co$@$<
[0066] The generation rules for defining dependent files can be:
[0067] %d:%c
[0068] gcc-M$(CPPFLAGS)$<>$@.$$$$;\
[0069] sed's,\($*\)\.o[:]*,\1.o$@:,g'<$@.$$$$>$@;\
[0070] rm -f$@.$$$$
[0071] According to the above method, the compiler will generate the intermediate files we need when the embedded project is compiled.
[0072] In some examples, the automatic configuration of the configuration information of the target code software based on the configuration file library, the keyword library, and the intermediate file includes:
[0073] According to the platform information of the target compiler, the source file extension, and the target file generation rule, the intermediate file is traversed and screened to obtain the source file path information;
[0074] According to the platform information of the target compiler, the dependent file extension, and the dependent file generation rule, the intermediate file is traversed and screened to obtain the dependent file path information;
[0075] According to the source file path information, the dependent file path information and the keyword library, the configuration information of the target code testing software is automatically configured.
[0076] Exemplarily, the intermediate files are traversed using the platform information of the target compiler, the source file extension and the target file generation rules. Through this information, it is possible to determine which source files are compiled into target files according to the target file generation rules, thereby accurately identifying all compiled source files.
[0077] According to the platform information of the compiler, the extension of the dependent file, and the dependent file generation rule, the dependent file is filtered out from the intermediate file, and the path information of the dependent file is obtained.
[0078] Automatically configure the code testing software based on the collected file path information and the preset keyword library. Integrate the path information of source files and dependent files, and fill in the configuration file according to the requirements of the test software.
[0079] The method proposed in the embodiment of the present application greatly reduces manpower input and configuration errors through automated configuration. Any changes to source files or dependent files can be quickly reflected in the test configuration, keeping the test environment updated in real time. It can automatically track dependencies to ensure that no files are missed, thereby improving the comprehensiveness of the test. The core of this method is to use the information naturally generated during the compilation process to support the test process and ensure the timeliness and comprehensiveness of the test.
[0080] In some examples, this also includes:
[0081] When the platform information of the target compiler is Windows platform and the extension of the original file is .c, the .obj files are traversed and filtered in the intermediate files to obtain the source file path information.
[0082] Exemplarily, on Windows platforms, the target files generated by C language compilation usually have an .obj extension. The source file is .c and the target file is .obj. The intermediate files are traversed and the directories containing the compiled .obj files are scanned. The path of the corresponding .c source file is inferred from the name and location of each .obj file. The .obj file and its corresponding .c file have the same base file name.
[0083] In some examples, this also includes:
[0084] When the platform information of the target compiler is Linux platform and the extension of the original file is .c, the .o files are traversed and filtered in the intermediate files to obtain the source file path information.
[0085] Exemplarily, on a Linux platform, the target file generated by C language compilation usually has a .o extension. The source file is .c and the target file is .o. The directory containing the compiled .o files is scanned. The path of the corresponding .c source file is inferred from the name and location of each .o file. Similar to Windows, a .o file and its corresponding .c file usually have the same base file name.
[0086] In some examples, the above-mentioned traversing and screening in the above-mentioned intermediate file according to the platform information of the above-mentioned target compiler, the above-mentioned dependent file extension, and the above-mentioned dependent file generation rule to obtain the dependent file path information includes:
[0087] According to the platform information of the target compiler, the dependent file extension, and the dependent file generation rule, the intermediate file is traversed and screened to obtain the dependent file content;
[0088] The first n lines of the above dependency file content are discarded to obtain the above dependency file path information.
[0089] Exemplarily, traverse all files in the controller software project, obtain all dependent files according to the extension of the dependent files, and read the contents of all dependent files. Generally, the first two (n) lines are the absolute paths of the source files and the target files, which need to be discarded. Only the absolute paths of all header files (.h files) need to be extracted, and the specific h file names and duplications need to be removed. What is finally obtained is the path of all header files that the compilation depends on and does not include the file names.
[0090] In some examples, since the compiler needs to generate target files (machine code) when compiling, the embedded compiler will search for header files (dependencies) in the include directory of the embedded project when compiling. Therefore, the embedded compiler is configured to generate target files with the same file name according to each compiled source file, and generate dependency files with the same file name according to the dependencies of each compiled source file; the files generated by the embedded compiler are referred to as intermediate files generated by the compiler during compilation. The specific implementation principle is as follows: Figure 2 As shown, the specific steps include:
[0091] S210, in order to configure the embedded compiler to generate a target file with the same file name according to each compiled source file, and to generate a dependency file with the same file name according to the dependency relationship of each compiled source file. Since most of the currently used embedded compilation environments use makefile to schedule the compiler, use python's scons module to schedule the compiler, and use IDE interfaces of various manufacturers, the specific environment configuration methods may be different; here, the most commonly used makefile file is used to schedule the GCC compiler as an example, and the implementation code is as follows:
[0092] Define the generation rules of the target file:
[0093] %.o:%.c
[0094] gcc -co$@$<
[0095] Define the generation rules of dependent files:
[0096] %d:%c
[0097] gcc-M$(CPPFLAGS)$<>$@.$$$$;\
[0098] sed's,\($*\)\.o[:]*,\1.o$@:,g'<$@.$$$$>$@;\
[0099] rm -f$@.$$$$
[0100] According to the above method, the compiler will generate the intermediate files we need when the embedded project is compiled.
[0101] The input of the test is a complete controller software project file that can be compiled using an embedded compiler. For example, a controller software project whose source file is in C language includes .c files (source files), .h files (header files), compilation scripts, and intermediate files generated by the compiler during compilation.
[0102] S220, configuration file library: the user fills in the basic information of the project, including the platform compiled by the embedded compiler (Windows platform or Linux platform); the source file extension (for example, .c); the extension of the dependent file output by the compiler (for example, .d); the code quality test software project configuration file and path (for example, the Polyspace software configuration file and path is D:\CodeTest\demo.psprj, for the specific project configuration file extension, refer to the software help manual, and the specific path is related to the path selected by the user when creating a new project); macro definitions, etc. (including but not limited to the above configuration information).
[0103] S230, source file extraction module involved in compilation: query the platform compiled by the embedded compiler in the configuration file, if it is a Windows platform, search for files with an extension of .obj, if it is a Linux platform, search for files with an extension of .o, traverse all files in the controller software project, obtain the file names of all target files according to the extension of the target file, and then search for source files with the same name as each target file and the extension of the source file extension queried in the configuration file library, and obtain their absolute paths. The content obtained is the path containing the source file names involved in the compilation.
[0104] S240, dependency header file extraction module for source files involved in compilation: query the extension of the dependency file output by the compiler in the configuration file (for example, .d), traverse all files in the controller software project, obtain all dependency files according to the extension of the dependency file, and read the contents of all dependency files. Generally, the first two lines are the absolute paths of the source file and the target file, which need to be discarded. Only the absolute paths of all header files (.h files) need to be extracted, and the specific h file name is removed. Remove duplication, and the final result is the path of all header files that the compilation depends on and does not include the file name. A macro is a line of code that controls the compilation process.
[0105] S250, Project Configuration Keyword Library: The user fills in the specific project configuration keyword content according to different code quality testing software. Source file configuration keywords (for example: <source> ); source file format keywords (for example:<filepath="SourcePath" / > ); header file configuration keywords (for example: <include>); header file format keywords (for example:<file path="IncludePath"order="%d" / > ); macro definition configuration keywords (such as<optionflagname="-D"> ), macro definition format keywords (such as <element> Macro< / element> ); including but not limited to the above keywords, the specific keyword content is obtained according to the help manual of the specific code quality testing software used.
[0106] S260, Code Quality Test Engineering Automation Configuration Module:
[0107] Read the contents of the source file configuration keywords in the project configuration keyword library. For example, the contents read are: <source> ; Read the source file format keyword, for example, the content read is<file path="SourcePath" / > ;
[0108] Read the code quality test software engineering configuration file in the configuration file library according to the path. For example, the content read is: D:\CodeTest\demo.psprj. Read the specific content of this file and find the content of the source file configuration keyword, such as <source> , below this line in the format of the source file format keyword (for example:<file path="SourcePath" / > ) Write all the paths containing source file names involved in the compilation obtained in S230 line by line (one line for each path), and replace SourcePath in the writing format with the path of each source file. For example, write:<filepath="D:\CodeTest\source\demo.c" / >
[0109] Look for header file configuration keywords in the code quality testing software engineering configuration file (for example: <include>), and below this line, type the header file format keyword (for example:<file path="IncludePath"order="%d" / > ) Write the paths of all the header files that the compilation depends on obtained in S240 line by line (one line for each path), and replace IncludePath in the writing format with the path of each header file that depends on it, and replace %d with a number, starting from 0, and adding 1 to each record in sequence. For example, write the first record:<file path="D:\CodeTest\inc"order="0" / > , and so on for the others.
[0110] Look for macro definition configuration keywords in the code quality testing software engineering configuration file (for example:<optionflagname="-D"> ), and below this line, define the macro format keywords (for example <element> Macro< / element> ), write the macro definitions in the configuration file library in S220 line by line (one macro definition per line), and replace the Macro in the write format with each macro. For example, for the macro definition USECANIF, write: <element> USECANIF< / element> .
[0111] The above embodiment takes the Polyspace software of Mathworks as an example. For other different code quality testing software with more special configurations, please refer to the above embodiment, which will not be described in detail here.
[0112] like Figure 3 As shown, this application proposes a code quality test automatic configuration device, including:
[0113] A compiling unit 21 is used to input the code to be tested into a target compiler and perform a compiling operation according to a file generation rule to generate an intermediate file, wherein the intermediate file is generated during the compilation process of the source file corresponding to the code to be tested and the files having a dependency relationship;
[0114] The acquisition unit 22 is used to acquire a configuration file library, wherein the configuration file library includes the platform information of the target compiler, the source file extension, the dependent file extension, the code test software engineering configuration file path and macro definition;
[0115] A first configuration unit 23 is used to configure a keyword library based on the type of the target code test software, wherein the keyword library includes source file configuration keywords, source file format keywords, header file configuration keywords, header file format keywords, macro definition configuration keywords, and macro definition format keywords;
[0116] The second configuration unit 24 is used to automatically configure the configuration information of the target code testing software based on the configuration file library, the keyword library and the intermediate file.
[0117] like Figure 4 As shown, an embodiment of the present application also provides an electronic device 300, including a memory 310, a processor 320, and a computer program 311 stored in the memory 310 and executable on the processor, and when the processor 320 executes the computer program 311, the steps of any method of automatic configuration of the above-mentioned code quality test are implemented.
[0118] Since the electronic device introduced in this embodiment is a device used to implement a code quality test automatic configuration device in the embodiment of the present application, based on the method introduced in the embodiment of the present application, technical personnel in this field can understand the specific implementation method of the electronic device of this embodiment and its various variations. Therefore, how the electronic device implements the method in the embodiment of the present application is not introduced in detail here. As long as the equipment used by technical personnel in this field to implement the method in the embodiment of the present application is within the scope of protection of this application.
[0119] In the specific implementation process, when the computer program 311 is executed by the processor, it can achieve Figure 1 Any implementation manner in the corresponding embodiments.
[0120] It should be noted that in the above embodiments, the description of each embodiment has its own emphasis, and for parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0121] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0122] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded computer, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0123] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0124] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0125] An embodiment of the present application also provides a computer program product, which includes computer software instructions. When the computer software instructions are executed on a processing device, the processing device executes the process of automatic configuration of code quality testing in the corresponding embodiment.
[0126] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on the computer, the process or function according to the embodiment of the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from a website site, a computer, a server or a data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (digital subscriber line, DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, server or data center. The computer-readable storage medium can be any available medium that a computer can store or a data storage device such as a server or a data center that includes one or more available media integration. The available medium can be a magnetic medium, (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid state drive (SSD)), etc.
[0127] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0128] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0129] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0130] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0131] If the integrated unit 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, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, ROM), random access memory (Random Access Memory, RAM), disk or optical disk and other media that can store program codes.
[0132] The above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application.< / include> < / include>
Claims
1. A method for automatic configuration of code quality testing, characterized in that: include: Input the code to be tested into the target compiler and perform a compile operation according to the file generation rule to generate an intermediate file, wherein the intermediate file is generated during the compilation process of the source file corresponding to the code to be tested and the file with dependency relationship; Obtain a configuration file library, wherein the configuration file library includes platform information of the target compiler, source file extensions, dependent file extensions, code test software engineering configuration file paths, and macro definitions; A type configuration keyword library based on the target code test software, wherein the keyword library includes source file configuration keywords, source file format keywords, header file configuration keywords, header file format keywords, macro definition configuration keywords, and macro definition format keywords; Based on the configuration file library, the keyword library, and the intermediate file, the configuration information of the target code testing software is automatically configured.
2. The method for automatic configuration of code quality testing according to claim 1, characterized in that: The intermediate file includes a target file and a dependent file. The target file is a compiled file corresponding to the source file, and the target file and the source file have the same file name. The dependent file is a compiled file corresponding to a file that has a dependency relationship with the source file, and the dependent file and the file that has a dependency relationship with the source file have the same file name.
3. The method for automatic configuration of code quality test according to claim 2, characterized in that: The file generation rules include target file generation rules and dependent file generation rules. The target file generation rules include a mapping relationship between the source file initial name suffix information and the target file suffix information. The dependent file generation rules include a mapping relationship between the suffix information of a file that has a dependency relationship with the source file and the dependent file suffix information.
4. The method for automatic configuration of code quality test according to claim 3, characterized in that: The automatic configuration of the target code software configuration information based on the configuration file library, the keyword library, and the intermediate file includes: According to the platform information of the target compiler, the source file extension, and the target file generation rule, the intermediate file is traversed and screened to obtain the source file path information; According to the platform information of the target compiler, the dependent file extension, and the dependent file generation rule, the intermediate file is traversed and screened to obtain dependent file path information; The configuration information of the target code testing software is automatically configured according to the source file path information, the dependent file path information and the keyword library.
5. The method for automatic configuration of code quality test according to claim 4, characterized in that: Also includes: When the platform information of the target compiler is Windows platform and the extension of the original file is .c, the .obj files are traversed and filtered in the intermediate file to obtain the source file path information.
6. The method for automatically configuring code quality testing according to claim 4, characterized in that: Also includes: When the platform information of the target compiler is Linux platform and the extension of the original file is .c, the .o files are traversed and filtered in the intermediate files to obtain the source file path information.
7. The method for automatically configuring code quality testing according to claim 4, characterized in that: The traversing and screening the intermediate file according to the platform information of the target compiler, the dependent file extension, and the dependent file generation rule to obtain dependent file path information includes: According to the platform information of the target compiler, the dependent file extension, and the dependent file generation rule, the intermediate file is traversed and screened to obtain the dependent file content; The first n lines of the dependent file content are discarded to obtain the dependent file path information.
8. A code quality test automatic configuration device, characterized in that: include: A compiling unit, used for inputting the code to be tested into a target compiler and performing a compiling operation according to a file generation rule to generate an intermediate file, wherein the intermediate file is generated during the compilation process of the source file corresponding to the code to be tested and the file having a dependency relationship; An acquisition unit, used for acquiring a configuration file library, wherein the configuration file library includes platform information of the target compiler, source file extension, dependent file extension, code test software engineering configuration file path and macro definition; A first configuration unit is used to configure a keyword library based on the type of the target code test software, wherein the keyword library includes source file configuration keywords, source file format keywords, header file configuration keywords, header file format keywords, macro definition configuration keywords, and macro definition format keywords; The second configuration unit is used to automatically configure the configuration information of the target code testing software based on the configuration file library, the keyword library, and the intermediate file.
9. An electronic device, comprising: A memory and a processor, wherein the processor is used to implement the steps of the automatic configuration method for code quality testing as described in any one of claims 1 to 7 when executing a computer program stored in the memory.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the code quality test automatic configuration method according to any one of claims 1 to 7 are implemented.
