DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Integration of C-STAT Code Analysis with Automated Jenkins CI Build

Integration of C-STAT Code Analysis with Automated Jenkins CI Build

Take a look at how you can futher you static code analysis by integrating with Jenkins.

Sankara M user avatar by
Sankara M
·
Apr. 02, 19 · Tutorial
Like (5)
Save
Tweet
Share
10.75K Views

Join the DZone community and get the full member experience.

Join For Free

Introduction

Most of us are aware there is always a limitation or challenge in setting up CI/CD for embedded software, and we have also seen in some cases there are still no alternate options available, which leads to manual effort and misses in code quality.

In this article, we are going to see one such embedded development tool (IAR Embedded workbench) and how we can integrate C-STAT static code analysis with a continuous integration build (Jenkins), as well as how to set some quality gates with an automated build.

Prerequisites:

a. IAR Embedded Workbench (IDE)

b. C-STAT license

c. Jenkins Setup

IAR Embedded workbench tool provides us the command line execution options to achieve the static code analysis of the IAR project. Now we will see how it works.

IAR Command Line Utility

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

C:\Program Files (x86) \IAR Systems\Embedded Workbench 8.1\common\bin\

Run Code Analysis:

First navigate to the above path in the command path and execute the below command to analyse the complete project.

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


Where,

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

  •  -cstat_analyze  is the command to analyze

  •  Debug is the configuration mode of the project

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

Note The next time you run the code analysis, if you have made any changes to your source code files since the previous analysis, then you must first clear the database to avoid issues due to mixing of old and new data in the database file.

Clear Analysis Results

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

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


Generate Report

To generate a 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 produce the HTML report of previous code analyses performed by the C-STAT.

The report represents statistical data both in numbers and as tables. Two different types of reports can be generated:

● An outline that features info regarding, for example, project-wide enabled checks, the total amount of messages, suppressed checks (if any), messages for each check, etc.

● A full report that contains the constant info such as the outline, and additional info regarding all suppressed and non-suppressed messages at the conclusion of the report. The tables can be collapsed and expanded, and the columns can be sorted

To generate the full HTML report, we can execute the below 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 contains four parameters:

 --db specifies the path of the database file the report is based on

 --project specifies the project file

 --full generates full report containing information about suppressed and non-suppressed checks.

 --output specifies the name of the output result file.

Integrating the C-STAT With Jenkins CI build:

There is no direct plugin or method available to integrate this CSTAT to any CI tools. But we can achieve the custom integration in the below method,

So now we know the commands for analyzing, cleaning and generatingthe report file. Using these command, 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 come across the scenario where we need to define the gateway in the CI build by setting the threshold value for Low, Medium and High issues. If the value is greater then set value, then we can make the build as a failure.

By default, C-STAT doesn’t provide us the option to set this value. But we can achieve this using custom scripting as below.

So we can get the HTML report containing the analysis result of Low, medium and high issue count. These values are captured inside the HTML result file in the format data: [0-9, 0-9 ,0-9].

Please refer to the below screen shot of batch scripting to understand how I get these values in a variable and then validate it with sea t threshold value.

Image title

Jenkins Build Result

Given below the build log from Jenkins CI build for your reference. You can see the build is failed due to 19 issues identified as Medium priority.

Image title

Conclusion

Here, we have seen how to automate the C-STAT analysis with the Jenkins CI build and how to set the threshold gateway to determine the build status. I hope this blog will be helpful for those who are working with IAR embedded workbench and would like to automate the C-STAT with your CI build system.

Continuous Integration/Deployment Jenkins (software) Integration Database Command (computing)

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Utilize OpenAI API to Extract Information From PDF Files
  • Continuous Development: Building the Thing Right, to Build the Right Thing
  • The Role of Data Governance in Data Strategy: Part II
  • API Design Patterns Review

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: