CN116893960A - Code quality detection method, apparatus, computer device and storage medium - Google Patents

Code quality detection method, apparatus, computer device and storage medium Download PDF

Info

Publication number
CN116893960A
CN116893960A CN202310784106.4A CN202310784106A CN116893960A CN 116893960 A CN116893960 A CN 116893960A CN 202310784106 A CN202310784106 A CN 202310784106A CN 116893960 A CN116893960 A CN 116893960A
Authority
CN
China
Prior art keywords
code
detected
test case
static analysis
running
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202310784106.4A
Other languages
Chinese (zh)
Inventor
林楠
林维城
郭享
陈容
宋冰蕊
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Industrial Bank Co Ltd
CIB Fintech Services Shanghai Co Ltd
Original Assignee
Industrial Bank Co Ltd
CIB Fintech Services Shanghai Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Industrial Bank Co Ltd, CIB Fintech Services Shanghai Co Ltd filed Critical Industrial Bank Co Ltd
Priority to CN202310784106.4A priority Critical patent/CN116893960A/en
Publication of CN116893960A publication Critical patent/CN116893960A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3604Software analysis for verifying properties of programs
    • G06F11/3616Software analysis for verifying properties of programs using software metrics
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3684Test management for test design, e.g. generating new test cases
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3688Test management for test execution, e.g. scheduling of test suites
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Software Systems (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The present application relates to a code quality detection method, apparatus, computer device, storage medium and computer program product. The method comprises the steps of carrying out static analysis on a code to be detected through a pre-configured static analysis tool to obtain a static analysis result, generating a test case according to the code to be detected, further operating the test case, obtaining dynamic log information in the operation process of the test case, and finally generating a quality detection result of the code to be detected according to the static analysis result and the dynamic log information. By combining static analysis with dynamic analysis, the automatic code quality detection can be realized, the code detection efficiency can be improved, and the labor cost can be reduced.

Description

Code quality detection method, apparatus, computer device and storage medium
Technical Field
The present application relates to the field of software testing technology, and in particular, to a code quality detection method, apparatus, computer device, storage medium, and computer program product.
Background
In the process of software development, software testing is an indispensable important link. After the software code completes a version, a software test link is entered, and static test, namely static analysis, of the unit of the code is needed first. After static analysis of the code, the tester feeds back the coding rule problem to the software encoder. And confirming and changing the test problem by a software encoder.
However, the current testing method relies on the full connection and communication between the tester and the encoder, which not only consumes a large labor cost, but also has low testing efficiency.
Disclosure of Invention
In view of the foregoing, it is desirable to provide a code quality detection method, apparatus, computer device, computer-readable storage medium, and computer program product that can improve code detection efficiency.
In a first aspect, the present application provides a code quality detection method. The method comprises the following steps:
performing static analysis on the code to be detected through a pre-configured static analysis tool to obtain a static analysis result;
generating a test case according to the code to be detected;
running the test case and acquiring dynamic log information in the running process of the test case;
and generating a quality detection result of the code to be detected according to the static analysis result and the dynamic log information.
In one embodiment, the generating a test case according to the code to be detected includes: and generating a test case for the code to be detected through an automatic test generation tool based on the target detection requirement.
In one embodiment, the running the test case, obtaining the dynamic log information in the running process of the test case includes: loading an LLVM compiler of a bottom virtual machine, and compiling the code to be detected through the LLVM compiler; and running the compiled code to be detected based on the test case, and acquiring dynamic log information in the running process.
In one embodiment, the running the test case, obtaining the dynamic log information in the running process of the test case includes: compiling the code to be detected by adopting a target compiler; running the compiled code to be detected based on the test case, and generating a profiling data file after the code to be detected is run; analyzing the analysis data file through a preset performance analysis tool to obtain corresponding log dynamic information.
In one embodiment, the target compiler is a compiler with a-pg compilation option.
In one embodiment, the quality detection result includes an improvement scheme of the code to be detected; after the quality detection result of the code to be detected is generated, the method further comprises: and updating the code to be detected according to the improved scheme to obtain updated target code.
In a second aspect, the application further provides a code quality detection device. The device comprises:
the static analysis module is used for carrying out static analysis on the code to be detected through a pre-configured static analysis tool to obtain a static analysis result;
the test case generation module is used for generating a test case according to the code to be detected;
the dynamic analysis module is used for running the test case and acquiring dynamic log information in the running process of the test case;
and the detection result generation module is used for generating a quality detection result of the code to be detected according to the static analysis result and the dynamic log information.
In a third aspect, the present application also provides a computer device. The computer device comprises a memory storing a computer program and a processor implementing the steps of the method according to the first aspect above when the processor executes the computer program.
In a fourth aspect, the present application also provides a computer-readable storage medium. The computer readable storage medium having stored thereon a computer program which, when executed by a processor, implements the steps of the method as described in the first aspect above.
In a fifth aspect, the present application also provides a computer program product. The computer program product comprising a computer program which, when executed by a processor, implements the steps of the method as described in the first aspect above.
According to the code quality detection method, the code quality detection device, the computer equipment, the storage medium and the computer program product, static analysis is carried out on the code to be detected through the pre-configured static analysis tool, a static analysis result is obtained, a test case is generated according to the code to be detected, the test case is further operated, dynamic log information in the operation process of the test case is obtained, and finally a quality detection result of the code to be detected is generated according to the static analysis result and the dynamic log information. By combining static analysis with dynamic analysis, the automatic code quality detection can be realized, the code detection efficiency can be improved, and the labor cost can be reduced.
Drawings
FIG. 1 is a flow chart of a code quality detection method in one embodiment;
FIG. 2 is a flowchart illustrating steps for obtaining dynamic log information in one embodiment;
FIG. 3 is a flowchart illustrating a step of obtaining dynamic log information according to another embodiment;
FIG. 4 is a block diagram of a code quality detection apparatus in one embodiment;
fig. 5 is an internal structural diagram of a computer device in one embodiment.
Detailed Description
The present application will be described in further detail with reference to the drawings and examples, in order to make the objects, technical solutions and advantages of the present application more apparent. It should be understood that the specific embodiments described herein are for purposes of illustration only and are not intended to limit the scope of the application.
In one embodiment, as shown in fig. 1, a code quality detection method is provided, and the method can be applied to a computer device, and specifically can include the following steps:
and 102, performing static analysis on the code to be detected through a pre-configured static analysis tool to obtain a static analysis result.
The code to be detected may be a source code to be subjected to quality detection. The static analysis tool may be a preset relevant configuration or plug-in for static quality detection of source code, for example, including but not limited to Clang-Tidy (a class-based static code analysis framework), cppcheck (a C/c++ code defect static inspection tool), and the like. The static analysis result is the potential quality problem in the source code, such as grammar error, full name specification, annotation specification, etc., obtained after the static quality detection of the source code.
In this embodiment, when the quality of the source code to be detected is detected, the computer device may perform static analysis on the code to be detected through a pre-configured static analysis tool, so as to obtain a static analysis result.
And 104, generating a test case according to the code to be detected.
The test case refers to the description of a test task for a specific software product, and the test scheme, method, technology and strategy are embodied. The content of the method comprises a test target, a test environment, input data, a test step, an expected result, a test script and the like, and finally a document is formed. Briefly, a test case is a set of test inputs, execution conditions, and expected results tailored for a particular goal to verify that a particular software requirement is met.
In this embodiment, the computer device may generate the corresponding test case according to the target detection requirement of the code to be detected.
And 106, running the test case, and acquiring dynamic log information in the running process of the test case.
The dynamic log information is related information collected during the running process of the test case and used for representing the dynamic detection process of the code to be detected, and for example, the information comprises execution time, memory occupation, function call times and the like.
In this embodiment, after the computer device generates the corresponding test case based on the above steps, the test case may be run, and the dynamic log information in the running process of the test case may be obtained.
And step 108, generating a quality detection result of the code to be detected according to the static analysis result and the dynamic log information.
The static analysis result is a result of potential quality problems in the source code obtained after static quality detection of the source code, and the dynamic log information is related information which is collected in the running process of the test case and is used for representing the dynamic detection process of the code to be detected, so that the computer equipment obtains the quality detection result of the code to be detected by analyzing and integrating the static analysis result and the dynamic log information. Specifically, the quality detection result can show the corresponding code quality score and the improvement scheme of the code in a visual report mode.
In the code quality detection method, static analysis is carried out on the code to be detected through a pre-configured static analysis tool to obtain a static analysis result, a test case is generated according to the code to be detected, the test case is further operated, dynamic log information in the operation process of the test case is obtained, and finally a quality detection result of the code to be detected is generated according to the static analysis result and the dynamic log information. By combining static analysis with dynamic analysis, the automatic code quality detection can be realized, the code detection efficiency can be improved, and the labor cost can be reduced.
In one embodiment, in step 104, generating a test case according to the code to be detected may specifically include: based on target detection requirements, generating test cases for the codes to be detected through an automatic test generation tool. The target detection requirements include, but are not limited to, code coverage, specific project requirements (i.e., the project to which the code to be detected applies), and the like. In this embodiment, when the test case is generated, the test case may be automatically generated based on the automatic test generation tool.
In one scenario, the automatic Test generation tool is a Google Test (Google c++ unit Test framework), which further illustrates the generation process of Test cases. In this embodiment, the Google Test may be installed by cloning the GitHub (a managed platform oriented to open source and proprietary software items) repository and building libraries, or by a package manager (e.g., apt, yum, etc.). Then, under the project root directory, a folder named "tests" is created, and a source file, such as test_sample. And then introducing a Google Test header file and defining a Test case in the test_sample.cpp, thereby obtaining the Test case of the code to be detected. According to the embodiment, the test cases are generated for the code to be detected by means of the automatic test generation tool, so that the workload of manually generating the test cases can be reduced, and the overall test efficiency is improved.
In one embodiment, as shown in fig. 2, in step 106, the test case is run, and the dynamic log information in the running process of the test case is obtained, which specifically includes the following steps:
step 202, loading an LLVM compiler of the bottom virtual machine, and compiling the code to be detected through the LLVM compiler.
LLVM (Low Level Virtual Machine, underlying virtual machine) compilers are written in C++ for optimizing the compile time (common-time), link time (link-time), run time (run-time), and idle time (idle-time) of programs written in arbitrary programming languages, remain open to developers, and are compatible with existing scripts.
In this embodiment, the code to be detected may be compiled by installing a load LLVM compiler on the computer device and compiling the code by the LLVM compiler. Specifically, LLVM compilers can include clang (a lightweight compiler in C language, C++, objective-C language), clang++ (C++ compiler), and the like. And then a clang compiler with Sanitizer Coverage options can be used for compiling the code to be detected, so that the compiled code is obtained.
Step 204, running the compiled code to be detected based on the test case, and acquiring dynamic log information in the running process.
Specifically, the computer device may run the code to be detected compiled in the above steps based on the test case, thereby obtaining the dynamic log information in the running process. Therefore, the method and the device collect the dynamic log information in the code dynamic analysis process in a code instrumentation mode, and further improve the code detection efficiency.
In one embodiment, as shown in fig. 3, in step 106, the test case is run, and the dynamic log information in the running process of the test case is obtained, which specifically includes the following steps:
step 302, compiling the code to be detected by using a target compiler.
Wherein the target compiler may be a compiler with a-pg compilation option. In this embodiment, the computer device may compile the code to be detected using a target compiler with a-pg compilation option, resulting in compiled code.
And step 304, running the compiled code to be detected based on the test case, and generating a profiling data file after the code to be detected is run.
Wherein the profile data file may be collected code runtime data. Specifically, the computer device may run the code to be detected compiled in the above steps based on the test case, and when the running of the code to be detected is completed, generate the profile data file. In this embodiment, the profile data file may have a corresponding file name, e.g. "gmon. Out".
Step 306, analyzing the parsed data file by a preset performance analysis tool to obtain corresponding log dynamic information.
The preset performance analysis tool may be gprof, which is a program time monitoring tool provided by GNU (a Unix-like operating system composed of free software), and may count the number of times, time, and function call graph of each function.
In this embodiment, the computer device may analyze the profile data file generated in the above steps through a preset performance analysis tool, so as to obtain the corresponding log dynamic information. Therefore, the dynamic log information in the dynamic analysis process of the code is collected in a performance analysis mode, and the detection efficiency of the code is improved.
In one embodiment, in step 102, the static analysis is performed on the code to be detected by using a preconfigured static analysis tool to obtain a static analysis result, which may specifically include:
firstly, a corresponding static analysis tool can be configured according to project requirements and coding specifications, and the embodiment takes the static analysis tool as a Clang-Tidy as an example for explanation. A configuration file named ". Clang-Tidy" is further created and stored under the project root directory for Clang-Tidy to automatically read the configuration when executed. And add inspection rules to be enabled, such as clang-analyzer (an official static code analysis tool developed based on clang for finding code problems in advance in compiling stage), cppcocoguiding lines (c++ core criteria), google, etc., in the ". Clang-tidy" file. And then the checking rule is customized according to the requirement, and static analysis is carried out on the code to be detected based on the customized checking rule, so that potential code quality problems such as grammar errors, naming specifications, annotation specifications and the like are checked, and a static analysis result is obtained. So as to realize automatic static analysis of the code to be detected and save detection cost.
In one embodiment, the quality detection result can also comprise an improvement scheme of the code to be detected; then, in step 108, after generating a quality detection result of the code to be detected, the method may further include: and updating the code to be detected according to the improved scheme to obtain the updated target code. The improvement scheme can be determined based on the static analysis result and the dynamic log information after further analysis, and can have performance bottlenecks and possibly problematic code portions. The computer device may update the code to be detected according to the improvement scheme, thereby obtaining updated object code. Thereby realizing the repair of the problems in the source code and improving the code quality.
In one embodiment, the above-described code quality detection methods and related tools may also be integrated into integrated development environment (IDE, integrated Development Environment) and continuous integration (CI, continuous integration) flows, enabling automated source code quality assessment and optimization, enabling code development teams to continuously monitor and improve code quality throughout the software development cycle.
It should be understood that, although the steps in the flowcharts related to the embodiments described above are sequentially shown as indicated by arrows, these steps are not necessarily sequentially performed in the order indicated by the arrows. The steps are not strictly limited to the order of execution unless explicitly recited herein, and the steps may be executed in other orders. Moreover, at least some of the steps in the flowcharts described in the above embodiments may include a plurality of steps or a plurality of stages, which are not necessarily performed at the same time, but may be performed at different times, and the order of the steps or stages is not necessarily performed sequentially, but may be performed alternately or alternately with at least some of the other steps or stages.
Based on the same inventive concept, the embodiment of the application also provides a code quality detection device for realizing the above related code quality detection method. The implementation of the solution provided by the device is similar to the implementation described in the above method, so the specific limitation in the embodiments of the code quality detection device or devices provided below may be referred to the limitation of the code quality detection method hereinabove, and will not be repeated here.
In one embodiment, as shown in fig. 4, there is provided a code quality detecting apparatus including: a static analysis module 402, a test case generation module 404, a dynamic analysis module 406, and a detection result generation module 408, wherein:
the static analysis module 402 is configured to perform static analysis on the code to be detected through a preconfigured static analysis tool to obtain a static analysis result;
the test case generating module 404 is configured to generate a test case according to the code to be detected;
the dynamic analysis module 406 is configured to run the test case, and obtain dynamic log information in the running process of the test case;
and the detection result generating module 408 is configured to generate a quality detection result of the code to be detected according to the static analysis result and the dynamic log information.
In one embodiment, the test case generation module is specifically configured to: and generating a test case for the code to be detected through an automatic test generation tool based on the target detection requirement.
In one embodiment, the dynamic analysis module is specifically configured to: loading an LLVM compiler of a bottom virtual machine, and compiling the code to be detected through the LLVM compiler; and running the compiled code to be detected based on the test case, and acquiring dynamic log information in the running process.
In one embodiment, the dynamic analysis module is specifically further configured to: compiling the code to be detected by adopting a target compiler; running the compiled code to be detected based on the test case, and generating a profiling data file after the code to be detected is run; analyzing the analysis data file through a preset performance analysis tool to obtain corresponding log dynamic information.
In one embodiment, the target compiler is a compiler with a-pg compilation option.
In one embodiment, the quality detection result includes an improvement scheme of the code to be detected; the device further comprises a code updating module for updating the code to be detected according to the improvement scheme to obtain updated target code.
The respective modules in the above-described code quality detection apparatus may be implemented in whole or in part by software, hardware, or a combination thereof. The above modules may be embedded in hardware or may be independent of a processor in the computer device, or may be stored in software in a memory in the computer device, so that the processor may call and execute operations corresponding to the above modules.
In one embodiment, a computer device is provided, which may be a terminal, and the internal structure of which may be as shown in fig. 5. The computer device includes a processor, a memory, an input/output interface, a communication interface, a display unit, and an input means. The processor, the memory and the input/output interface are connected through a system bus, and the communication interface, the display unit and the input device are connected to the system bus through the input/output interface. Wherein the processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage media. The input/output interface of the computer device is used to exchange information between the processor and the external device. The communication interface of the computer device is used for carrying out wired or wireless communication with an external terminal, and the wireless mode can be realized through WIFI, a mobile cellular network, NFC (near field communication) or other technologies. The computer program is executed by a processor to implement a code quality detection method. The display unit of the computer device is used for forming a visual picture, and can be a display screen, a projection device or a virtual reality imaging device. The display screen can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer equipment can be a touch layer covered on the display screen, can also be a key, a track ball or a touch pad arranged on the shell of the computer equipment, and can also be an external keyboard, a touch pad or a mouse and the like.
It will be appreciated by those skilled in the art that the structure shown in FIG. 5 is merely a block diagram of some of the structures associated with the present inventive arrangements and is not limiting of the computer device to which the present inventive arrangements may be applied, and that a particular computer device may include more or fewer components than shown, or may combine some of the components, or have a different arrangement of components.
In one embodiment, a computer device is provided comprising a memory and a processor, the memory having stored therein a computer program, the processor when executing the computer program performing the steps of:
performing static analysis on the code to be detected through a pre-configured static analysis tool to obtain a static analysis result;
generating a test case according to the code to be detected;
running the test case and acquiring dynamic log information in the running process of the test case;
and generating a quality detection result of the code to be detected according to the static analysis result and the dynamic log information.
In one embodiment, the processor when executing the computer program further performs the steps of: and generating a test case for the code to be detected through an automatic test generation tool based on the target detection requirement.
In one embodiment, the processor when executing the computer program further performs the steps of: loading an LLVM compiler of a bottom virtual machine, and compiling the code to be detected through the LLVM compiler; and running the compiled code to be detected based on the test case, and acquiring dynamic log information in the running process.
In one embodiment, the processor when executing the computer program further performs the steps of: compiling the code to be detected by adopting a target compiler; running the compiled code to be detected based on the test case, and generating a profiling data file after the code to be detected is run; analyzing the analysis data file through a preset performance analysis tool to obtain corresponding log dynamic information.
In one embodiment, the quality detection result includes an improvement scheme of the code to be detected; the processor when executing the computer program also implements the steps of: and updating the code to be detected according to the improved scheme to obtain updated target code.
In one embodiment, a computer readable storage medium is provided having a computer program stored thereon, which when executed by a processor, performs the steps of:
performing static analysis on the code to be detected through a pre-configured static analysis tool to obtain a static analysis result;
generating a test case according to the code to be detected;
running the test case and acquiring dynamic log information in the running process of the test case;
and generating a quality detection result of the code to be detected according to the static analysis result and the dynamic log information.
In one embodiment, the computer program when executed by the processor further performs the steps of: and generating a test case for the code to be detected through an automatic test generation tool based on the target detection requirement.
In one embodiment, the computer program when executed by the processor further performs the steps of: loading an LLVM compiler of a bottom virtual machine, and compiling the code to be detected through the LLVM compiler; and running the compiled code to be detected based on the test case, and acquiring dynamic log information in the running process.
In one embodiment, the computer program when executed by the processor further performs the steps of: compiling the code to be detected by adopting a target compiler; running the compiled code to be detected based on the test case, and generating a profiling data file after the code to be detected is run; analyzing the analysis data file through a preset performance analysis tool to obtain corresponding log dynamic information.
In one embodiment, the quality detection result includes an improvement scheme of the code to be detected; the computer program when executed by the processor also performs the steps of: and updating the code to be detected according to the improved scheme to obtain updated target code.
In one embodiment, a computer program product is provided comprising a computer program which, when executed by a processor, performs the steps of:
performing static analysis on the code to be detected through a pre-configured static analysis tool to obtain a static analysis result;
generating a test case according to the code to be detected;
running the test case and acquiring dynamic log information in the running process of the test case;
and generating a quality detection result of the code to be detected according to the static analysis result and the dynamic log information.
In one embodiment, the computer program when executed by the processor further performs the steps of: and generating a test case for the code to be detected through an automatic test generation tool based on the target detection requirement.
In one embodiment, the computer program when executed by the processor further performs the steps of: loading an LLVM compiler of a bottom virtual machine, and compiling the code to be detected through the LLVM compiler; and running the compiled code to be detected based on the test case, and acquiring dynamic log information in the running process.
In one embodiment, the computer program when executed by the processor further performs the steps of: compiling the code to be detected by adopting a target compiler; running the compiled code to be detected based on the test case, and generating a profiling data file after the code to be detected is run; analyzing the analysis data file through a preset performance analysis tool to obtain corresponding log dynamic information.
In one embodiment, the quality detection result includes an improvement scheme of the code to be detected; the computer program when executed by the processor also performs the steps of: and updating the code to be detected according to the improved scheme to obtain updated target code.
Those skilled in the art will appreciate that implementing all or part of the above described methods may be accomplished by way of a computer program stored on a non-transitory computer readable storage medium, which when executed, may comprise the steps of the embodiments of the methods described above. Any reference to memory, database, or other medium used in embodiments provided herein may include at least one of non-volatile and volatile memory. The nonvolatile Memory may include Read-Only Memory (ROM), magnetic tape, floppy disk, flash Memory, optical Memory, high density embedded nonvolatile Memory, resistive random access Memory (ReRAM), magnetic random access Memory (Magnetoresistive Random Access Memory, MRAM), ferroelectric Memory (Ferroelectric Random Access Memory, FRAM), phase change Memory (Phase Change Memory, PCM), graphene Memory, and the like. Volatile memory can include random access memory (Random Access Memory, RAM) or external cache memory, and the like. By way of illustration, and not limitation, RAM can be in the form of a variety of forms, such as static random access memory (Static Random Access Memory, SRAM) or dynamic random access memory (Dynamic Random Access Memory, DRAM), and the like. The databases referred to in the embodiments provided herein may include at least one of a relational database and a non-relational database. The non-relational database may include, but is not limited to, a blockchain-based distributed database, and the like. The processor referred to in the embodiments provided in the present application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic unit, a data processing logic unit based on quantum computing, or the like, but is not limited thereto.
The technical features of the above embodiments may be arbitrarily combined, and all possible combinations of the technical features in the above embodiments are not described for brevity of description, however, as long as there is no contradiction between the combinations of the technical features, they should be considered as the scope of the description.
The foregoing examples illustrate only a few embodiments of the application and are described in detail herein without thereby limiting the scope of the application. It should be noted that it will be apparent to those skilled in the art that several variations and modifications can be made without departing from the spirit of the application, which are all within the scope of the application. Accordingly, the scope of the application should be assessed as that of the appended claims.

Claims (10)

1. A method for detecting code quality, the method comprising:
performing static analysis on the code to be detected through a pre-configured static analysis tool to obtain a static analysis result;
generating a test case according to the code to be detected;
running the test case and acquiring dynamic log information in the running process of the test case;
and generating a quality detection result of the code to be detected according to the static analysis result and the dynamic log information.
2. The method of claim 1, wherein the generating test cases from the code to be detected comprises:
and generating a test case for the code to be detected through an automatic test generation tool based on the target detection requirement.
3. The method of claim 1, wherein the running the test case, obtaining dynamic log information during the running of the test case, comprises:
loading an LLVM compiler of a bottom virtual machine, and compiling the code to be detected through the LLVM compiler;
and running the compiled code to be detected based on the test case, and acquiring dynamic log information in the running process.
4. The method of claim 1, wherein the running the test case, obtaining dynamic log information during the running of the test case, comprises:
compiling the code to be detected by adopting a target compiler;
running the compiled code to be detected based on the test case, and generating a profiling data file after the code to be detected is run;
analyzing the analysis data file through a preset performance analysis tool to obtain corresponding log dynamic information.
5. The method of claim 4, wherein the target compiler is a compiler with a-pg compilation option.
6. The method according to any one of claims 1 to 5, wherein the quality detection result comprises an improvement to the code to be detected; after the quality detection result of the code to be detected is generated, the method further comprises:
and updating the code to be detected according to the improved scheme to obtain updated target code.
7. A code quality detection apparatus, the apparatus comprising:
the static analysis module is used for carrying out static analysis on the code to be detected through a pre-configured static analysis tool to obtain a static analysis result;
the test case generation module is used for generating a test case according to the code to be detected;
the dynamic analysis module is used for running the test case and acquiring dynamic log information in the running process of the test case;
and the detection result generation module is used for generating a quality detection result of the code to be detected according to the static analysis result and the dynamic log information.
8. A computer device comprising a memory and a processor, the memory storing a computer program, characterized in that the processor implements the steps of the method of any of claims 1 to 6 when the computer program is executed.
9. A computer readable storage medium, on which a computer program is stored, characterized in that the computer program, when being executed by a processor, implements the steps of the method of any of claims 1 to 6.
10. A computer program product comprising a computer program, characterized in that the computer program, when being executed by a processor, implements the steps of the method of any of claims 1 to 6.
CN202310784106.4A 2023-06-29 2023-06-29 Code quality detection method, apparatus, computer device and storage medium Pending CN116893960A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310784106.4A CN116893960A (en) 2023-06-29 2023-06-29 Code quality detection method, apparatus, computer device and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310784106.4A CN116893960A (en) 2023-06-29 2023-06-29 Code quality detection method, apparatus, computer device and storage medium

Publications (1)

Publication Number Publication Date
CN116893960A true CN116893960A (en) 2023-10-17

Family

ID=88314290

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310784106.4A Pending CN116893960A (en) 2023-06-29 2023-06-29 Code quality detection method, apparatus, computer device and storage medium

Country Status (1)

Country Link
CN (1) CN116893960A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117707987A (en) * 2024-02-06 2024-03-15 暗物智能科技(广州)有限公司 Test case detection method and device, electronic equipment and storage medium

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117707987A (en) * 2024-02-06 2024-03-15 暗物智能科技(广州)有限公司 Test case detection method and device, electronic equipment and storage medium
CN117707987B (en) * 2024-02-06 2024-06-11 暗物智能科技(广州)有限公司 Test case detection method and device, electronic equipment and storage medium

Similar Documents

Publication Publication Date Title
WO2021098148A1 (en) Software compiling method and apparatus, and electronic device and storage medium
KR101989802B1 (en) Method for performing test using test case and apparatus for the same
US9158514B2 (en) Method and apparatus for providing change-related information
US7861226B1 (en) Constraint solver to code based test data generation for improving software reliability and security
US9898387B2 (en) Development tools for logging and analyzing software bugs
US9202005B2 (en) Development and debug environment in a constrained random verification
US20070011669A1 (en) Software migration
US20060253739A1 (en) Method and apparatus for performing unit testing of software modules with use of directed automated random testing
CN113742119A (en) Call stack backtracking method and device of embedded system and computer equipment
CN110554965A (en) automated fuzz testing method, related equipment and computer readable storage medium
CN103186463B (en) Determine the method and system of the test specification of software
CN105446874A (en) Method and device for detecting resource configuration file
JP6303749B2 (en) Method and system for analyzing a software program and non-transitory computer readable medium
US20150269061A1 (en) Method and system for code analysis using symbolic types
US8898649B2 (en) Application program analysis method, analysis system and recording medium for identifying a contributing factor for an invalid operation of an application program
CN111897727A (en) Software testing method and device, computer equipment and storage medium
CN116893960A (en) Code quality detection method, apparatus, computer device and storage medium
CN113094252B (en) Test case generation method and device, computer equipment and storage medium
US9582397B2 (en) Method and system for obtaining run-time information associated with executing an executable
US8291383B1 (en) Code analysis via dual branch exploration
US20210326243A1 (en) Dynamic reordering of test case execution
CN110928760A (en) Unit testing method and device in embedded system
US8930765B2 (en) Systems and methods for feedback driven regression testing
CN117273171A (en) Deep learning framework adaptation method, deep learning framework adaptation device, computer equipment and storage medium
US20130111432A1 (en) Validation of a system model including an activity diagram

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination