Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to automatically build Integration with C-STAT Code Analysis by Jenkins CI

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly shows you "how to automatically build Jenkins CI and C-STAT code analysis integration", the content is easy to understand, clear, hope to help you solve your doubts, the following let Xiaobian lead you to study and learn "how to automatically build Jenkins CI integration with C-STAT code analysis" this article.

Prerequisites:

A. IAR embedded workbench IDE b. C-STAT license c. Jenkins installation

The IAR embedded workbench tool provides us with command-line execution options for static code analysis of IAR projects. Now, we will understand how it works.

IAR command line application

The IAR system provides us with an application called IarBuild.exe, which is used to perform analysis on the command line. You can find the IarBuild.exe application in the installation path, as shown below.

C:\ Program Files (x86)\ IAR Systems\ Embedded Workbench 8.1\ common\ bin\ run the code analysis:

First switch to the above path in the command path, and then execute the following command to analyze the entire project.

IarBuild.exe D:\ sample\ project\ setup\ sample.ewp-cstat_analyze Debug

D:\ sample\ project\ setup\ sample.ewp is your IAR project file path

-cstat_analyze is the command to execute the analysis

Set the project mode to Debug

By executing the above command, it will perform a static code analysis on the entire project, and the results will be stored in the cproject.db file under the path... project\ setup\ Debug\ Obj\.

Note that the next time you run a code analysis, if you have made any changes to the source code file since the last analysis, you must first clean up the database to avoid problems caused by mixing old and new data in the database file.

Clear analysis results

To clear the database file using the command line, execute the following command

IarBuild.exe D:\ sample\ project\ setup\ sample.ewp-cstat_clean Debug generate report

To generate the report, we can use the IREPORT tool provided by IAR, which you can find in the same installation directory. The IREPORT tool is used to generate HTML reports of previous code analysis performed by C-STAT.

The report presents statistics in digital and tabular form. You can generate two different types of reports:

An outline with relevant information, such as information about checks enabled within the project, total number of messages, canceled checks (if any), messages for each check, and so on.

A complete report containing constant information such as outlines, as well as other information about all suppressed and unsuppressed messages at the end of the report. Tables can be collapsed and expanded, and columns can be sorted

To generate a complete HTML report, we can execute the following command

Ireport.exe-- db D:\ sample\ project\ setup\ Debug\ Obj\ cstat.db-- project D:\ sample\ project\ setup\ sample.ewp-- full-- output D:\ sample\ result.html

The above command takes four parameters:

-- db specifies the path to the database file on which the report is based. -- project specifies the project file. -- full generates a complete report that contains information about prohibited and non-prohibited checks. -- output specifies the name of the output result file.

Integrate C-STAT with Jenkins CI builds:

There are no direct plug-ins or methods available for integrating this CSTAT into any CI tool. However, we can achieve custom integration in the following ways.

Now we know the commands for analyzing, cleaning, and generating report files. With these commands, we can easily write a batch script file (.bat) file, and then call this batch file in Jenkins as a pre-build command execution step.

Set threshold gateway

We will encounter scenarios where we need to define gateways in the CI build by setting thresholds for "low", "medium", and "high" issues. If the value is greater than the set value, you can make the build fail.

By default, C-STAT does not give us the option to set this value. However, we can use the following custom script to do this.

We can get HTML reports containing the results of low, medium, and high problem count analysis. These values are displayed in the HTML result file in the format data: [0-9, 0-9, 0-9].

See the script below to see how I get these values in a variable and validate them with the sea t threshold.

Results of Jenkins construction

The following is the Jenkins CI build log for your reference. You can see that the build failed due to 19 issues identified as medium priority.

This is all the content of the article "how Jenkins CI automatically builds Integration with C-STAT Code Analysis". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report