Introduction to Static Analysis
|Line 96:||Line 96:|
Latest revision as of 17:35, 8 March 2017
Introduction to Static Analysis
Participants write a unit test (in GoogleTest) and corresponding C++ code to pass the test to verify the test passes
GoogleTest needed to have been installed (as instructed in Unit Test With GoogleTest Activity) and intermediate C++ expertise.
Participant should be able to learn how to follow "Red light, green light" Test-Driven Development process and reflect over the approach.
- In this exercise, we will set up and start exploring a static analysis tool packaged with the Clang compiler.
Downloading Clang and dependencies
- You already have Clang and all the other dependencies installed. However, you need to install the Static Analyzer by downloading the packaged build of checker here.
- After fully downloaded, I recommend then extracting the files from the tarball (checker-278.tar.bz2) as a new directory in your
/usr/local folder, such as
- If you are using sh, ksh, or bash shell, type the command:
export PATH=$PATH:/usr/local/checker-278/binbut replace
/usr/local/checker-278/binwith the location of where the static analyzer was installed, followed by
/binsince that is where the binary (executable) files are
- You will have to first download and build Clang and LLVM by following these directions.
- Once you are done, follow the instructions to build the analyzer from source.
- Navigate to where you stored (or freshly clone) your ConnectX code
- To start with a fresh build, first
- If you get a command not found error, your
PATHis not correctly set (see instructions above).
- Once run, it should take a moment to analyze the code. Does it identify any bugs? What does the scan-build output results means?
Exploring bug types
- Navigate to your Minefield project or make a new clone of the github repo so you have it locally
scan-buildon the Minefield project and confirm that it has no bugs found
- Read over the different checks that the scan-build static analyzer available checks.
- Within the
Fieldclass, try to create a bug as described by one of the available checks. However, don't just use the example code the documentation provides. Instead, try to incorporate one of those types of errors into the
Field.cppfile so that if someone else looked at the code they might not immediately recognize the bug. Try to make a bug but "hide" it in a clever way.
- Once you've created a "hidden bug," run
scan-buildon the project and make sure it identifies the bug that you think it should.
A revised C++ class with a bug injected into it
The bug the student created should force a static analysis message if run again
|Knowledge Area/Knowledge Unit||
Software Engineering / SE Static Analysis
|Level of Difficulty||
Understanding types of static analysis messages and creating a new bug requires intermediate programming expertise
|Estimated Time to Completion||
Installation may take up to 30 minutes for computers running *nix operating systems and is suggested to assign for homework before class. The rest of the activity should take 15-30 minutes, not counting discussion.
Need to have a working C++ development environment
Licensed CC BY-SA 4.0
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License