diff mbox

[ovs-dev,v5] Makefile.am: Add clang static analysis support

Message ID 1468608204-13639-1-git-send-email-bhanuprakash.bodireddy@intel.com
State Accepted
Headers show

Commit Message

Bodireddy, Bhanuprakash July 15, 2016, 6:43 p.m. UTC
Clang Static Analyzer is a source code analysis tool to find bugs. This
patch adds make target to trigger static analysis using below commands.

./boot.sh
For Clang: ./configure CC=clang --with-dpdk
For GCC: ./configure CC=gcc --with-dpdk CFLAGS="-std=gnu99"
make clang-analyze

Run 'scan-view <results dir>' command to examine the bug report.

Signed-off-by: Bhanuprakash Bodireddy <bhanuprakash.bodireddy@intel.com>
Acked-By: Lance Richardson <lrichard@redhat.com>
---

v4->v5: Minor fixes in INSTALL.md

v3->v4:
* Add "Static Code Analysis" to INSTALL.md
* Remove redundant --use-analyzer option

v2->v3:
* Refactor the code as suggested.
* Add --use-cc to scan-build.

v1->v2:
* Change the output directory to tests/clang-analyzer-results
* Remove '-j' make option, This might potentially hang some system
  while spawning infinite jobs.

 INSTALL.md  | 22 ++++++++++++++++++++++
 Makefile.am |  7 +++++++
 2 files changed, 29 insertions(+)

Comments

Ben Pfaff July 26, 2016, 6:10 p.m. UTC | #1
On Fri, Jul 15, 2016 at 07:43:24PM +0100, Bhanuprakash Bodireddy wrote:
> Clang Static Analyzer is a source code analysis tool to find bugs. This
> patch adds make target to trigger static analysis using below commands.

Thanks, applied to master.
diff mbox

Patch

diff --git a/INSTALL.md b/INSTALL.md
index f4d232b..47126a3 100644
--- a/INSTALL.md
+++ b/INSTALL.md
@@ -746,6 +746,28 @@  Instructions to setup travis-ci for your GitHub repository:
 4. Pushing a commit to the repository which breaks the build or the
    testsuite will now trigger a email sent to mylist@mydomain.org
 
+Static Code Analysis
+--------------------
+
+Static Analysis is a method of debugging Software by examining code rather
+than actually executing it. This can be done through 'scan-build' commandline
+utility which internally uses clang (or) gcc to compile the code and also
+invokes a static analyzer to do the code analysis. At the end of the build, the
+reports are aggregated in to a common folder and can later be analyzed using
+'scan-view'.
+
+Open vSwitch includes a Makefile target to trigger static code Analysis and
+the instructions are below.
+
+1. ./boot.sh
+2. ./configure CC=clang (when using clang compiler)
+   ./configure CC=gcc CFLAGS="-std=gnu99" (when using GCC)
+3. make clang-analyze
+
+You should invoke scan-view to view analysis results. The last line of output
+from 'make clang-analyze' shall list the command (containing results directory)
+that you should invoke to view the results on a browser.
+
 Bug Reporting
 =============
 
diff --git a/Makefile.am b/Makefile.am
index be42921..e913679 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -402,6 +402,13 @@  ovsext_clean: datapath-windows/ovsext.sln
 endif
 .PHONY: ovsext
 
+clang-analyze: clean
+	@which clang scan-build >/dev/null 2>&1 || \
+		(echo "Unable to find clang/scan-build, Install clang,clang-analyzer packages"; exit 1)
+	@$(MKDIR_P) "$(srcdir)/tests/clang-analyzer-results"
+	@scan-build -o $(srcdir)/tests/clang-analyzer-results --use-cc=$(CC) $(MAKE)
+.PHONY: clang-analyze
+
 dist-hook: $(DIST_HOOKS)
 all-local: $(ALL_LOCAL)
 clean-local: $(CLEAN_LOCAL)