Tutorial 1 - Introducing Checker Studio

From current

Custom checkers > Tutorial 1 - Introducing Checker Studio

Contents

Checker Studio is where you:

  • browse the Abstract Syntax Tree (AST) structure of your code sample
  • view context-sensitive help for specific AST nodes of interest
  • navigate between the code sample and the AST structure
  • test your KAST expression

The following tutorial provides an overview of how to add a test case (code snippet) to Checker Studio, browse the AST structure and test a KAST expression (pattern).

Step 1: Browse the Abstract Syntax tree

  1. Double-click the Checker Studio icon on your desktop or on the command line, type:
    kwstudio
  2. Make sure that the appropriate language is selected (C, C++, or Java).
    Checker Studio.png
  3. Paste your code snippet into the Source Code pane. Later, you'll add the code snippet to your testcase.cc file.
  4. If you don't see the Abstract Syntax Tree display immediately to the left, click Update Tree Update tree button.jpg or Automatic Tree Update Automatic tree update.jpg.
    Note: If the Update Tree button is disabled, then Automatic Tree Update is enabled.
  5. Navigate the AST by:
    • clicking a node in the AST to see the corresponding code fragment highlighted, or
    • clicking a code fragment to see the corresponding node highlighted in the AST.
  6. To view context-sensitive help, either select a tree node and press F1 or go to View > Context Help Window. Context-sensitive help displays below the Source Code pane, providing more node information such as supertypes and subtypes where applicable.
  7. To view attributes in the Attributes table, click Show/Hide Attributes Show Hide Attributes button.jpg.

Step 2: Test your KAST expression

Once you have identified your nodes of interest from your test case, you can create and test a KAST expression in Checker Studio.

  1. Type or paste your KAST expression in the Pattern pane.
  2. Click Apply Pattern Apply Pattern button.jpg.
    If the Apply Pattern button is grayed out, then Automatic Pattern Application Automatic Pattern.jpg is enabled. Just wait a moment while the KAST expression searches the AST to locate the node(s) of interest.
  3. If further edits are required, update the KAST expression and apply it again. If the KAST expression passes the test, you can:
    • add the expression to the checkers.xml file, or
    • create false-positive test cases to ensure that the checker does not generate errors for certain conditions, or
    • create more complex test cases, or
    • draft another KAST expression

Documentation for custom C/C++ checkers

Overview

How-to

Tutorials

Examples

Deployment

Reference