diff mbox

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

Message ID 1467559360-32462-1-git-send-email-bhanuprakash.bodireddy@intel.com
State Changes Requested
Headers show

Commit Message

Bodireddy, Bhanuprakash July 3, 2016, 3:22 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
scan-view --host=<ip address> --port <PORT>
  $OVS_DIR>/clang-analyzer-results/yyyy-mm-dd-114251-1027-1>
  --allow-all-hosts

Results can be viewed on browser: http://<ip address>:<PORT>/

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.

Signed-off-by: Bhanuprakash Bodireddy <bhanuprakash.bodireddy@intel.com>
---
 Makefile.am | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Ben Pfaff July 3, 2016, 6:28 p.m. UTC | #1
On Sun, Jul 03, 2016 at 04:22:40PM +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.
> 
> ./boot.sh
> For Clang: ./configure CC=clang --with-dpdk
> For GCC: ./configure CC=gcc --with-dpdk CFLAGS="-std=gnu99"
> make clang-analyze
> scan-view --host=<ip address> --port <PORT>
>   $OVS_DIR>/clang-analyzer-results/yyyy-mm-dd-114251-1027-1>
>   --allow-all-hosts
> 
> Results can be viewed on browser: http://<ip address>:<PORT>/
> 
> 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.
> 
> Signed-off-by: Bhanuprakash Bodireddy <bhanuprakash.bodireddy@intel.com>

This version works for me as long as I'm using Clang as the compiler.

Why is /usr/bin/clang hard-coded as the analyzer, even though "which"
will look throughout $PATH?

$(CC) needs to be written '$(CC)' in case there are spaces.

Please add a note to INSTALL.md explaining that this is available.
diff mbox

Patch

diff --git a/Makefile.am b/Makefile.am
index 8cb8523..df95f90 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -400,6 +400,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) --use-analyzer=/usr/bin/clang $(MAKE)
+.PHONY: clang-analyze
+
 dist-hook: $(DIST_HOOKS)
 all-local: $(ALL_LOCAL)
 clean-local: $(CLEAN_LOCAL)