Start here

Home
About Klocwork
What's new
Fixed issues
Release notes
Installation

Reference

C/C++ checkers
Java checkers
C# checkers
MISRA C 2004 checkers
MISRA C++ 2008 checkers
MISRA C 2012 checkers
MISRA C 2012 checkers with Amendment 1
Commands
Metrics
Troubleshooting
Reference

Product components

C/C++ Integration build analysis
Java Integration build analysis
Desktop analysis
Refactoring
Klocwork Static Code Analysis
Klocwork Code Review
Structure101
Tuning
Custom checkers

Coding environments

Visual Studio
Eclipse for C/C++
Eclipse for Java
IntelliJ IDEA
Other

Administration

Project configuration
Build configuration
Administration
Analysis performance
Server performance
Security/permissions
Licensing
Klocwork Static Code Analysis Web API
Klocwork Code Review Web API

Community

View help online
Visit RogueWave.com
Klocwork Support
Rogue Wave Videos

Legal

Legal information

Creating C# KAST checkers

Creating C# KAST checkers

You can watch a demo of Checker Studio here.

The basic steps involved in creating a KAST checker are:

  1. Run kwcreatechecker to create the files for your checker.
  2. Create the simplest test case.
  3. Use Checker Studio to find the KAST nodes of interest.
  4. Draft the KAST expression.
  5. Test the expression.
  6. Add more complexity and test cases to the test case.
  7. Add the KAST expression to the checkers.xml file.
  8. Create help documentation for the checker in the help.xml file.
  9. Build the checker.
  10. The checker is now ready for deployment.

These steps are covered in the C# KAST tutorial.

Workflow: Creating a custom checker

The basic steps involved in creating a KAST checker are:

1. Run kwcreatechecker to create the files for your checker:

kwcreatechecker --language cs --type kast --code <checker_name> 
where<checker_name> is the name you want to call your checker
The command creates the stub files you need for creating your checker and places them in a <checker_name> directory. At this stage, the files contain template material, which you will replace with your own data as the process continues:
  • testcase.cs, which will contain your testcase
  • checkers.xml, which will contain your XPath-like KAST expression defining the checker
  • help.xml, which will contain help for your checker
  • Makefile, which is the build file for your checkers
  • buildspec.out, which is a build specification file you can use in kwcheck or kwbuildproject to test your checker

2. Create a simple test case that contains the issue you want the checker to find, and place it in the testcase.cs file.

3. Use Checker Studio to:

  • create the KAST expression that defines your checker
  • test the expression
  • add more complexity to your test case
Checker Studio takes your test case as source code, presenting a visual representation of its hierarchical structure in an Abstract Syntax Tree (AST). As the studio builds the tree structure, the built-in compiler creates a 'node' for each item of source code. Connected through parent-child relationships, nodes can be the whole code sample, through a number of intermediate levels like statements or declarations, to simple constructs like an operator sign.
Using the tree, you can identify nodes of interest and select qualifiers, conditions, variables, and iterative sequences to create the checker expression. The studio also provides a method of testing your expression, so that you finish up with a KAST expression that navigates through the tree and successfully pinpoints the defect in the source code.

4. Edit the template stub files.

Place the KAST expression in the checkers.xml file by replacing the sample KAST expression in the <pattern> tag with yours. Create help documentation for your checker (at least a description), and place it in the help.xml file.

5. Build the checker.

In this step, you generate the build specification for your test case and import it into your local project:
  • On Unix:make install
  • On Windows: nmake install from the Visual Studio prompt
The build process generates a checker deployment package with the following file:
  • a zip file containing your checker files

6. Test the checker by installing the checker on your desktop and test it until you're sure of the results. Do one of the following:

  • If you're using Visual Studio, extract the zip file into your <username>/.klocwork/plugins directory.
  • If you're using Klocwork Desktop (kwgcheck command), or the kwcheck command, extract the zip file into your <username>/.klocwork/plugins/csharp directory.

7. Deploy the checker.

When you're ready to deploy the checker in your server project, use kwdeploy for the deployment. See Deploying custom checkers.

What's next?