diff mbox

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

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

Commit Message

Bodireddy, Bhanuprakash July 5, 2016, 4:34 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>/

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.

Signed-off-by: Bhanuprakash Bodireddy <bhanuprakash.bodireddy@intel.com>
---
 INSTALL.md  | 21 +++++++++++++++++++++
 Makefile.am |  7 +++++++
 2 files changed, 28 insertions(+)

Comments

Lance Richardson July 5, 2016, 4:53 p.m. UTC | #1
----- Original Message -----
> From: "Bhanuprakash Bodireddy" <bhanuprakash.bodireddy@intel.com>
> To: dev@openvswitch.org
> Cc: blp@ovn.org, lrichard@redhat.com, "Bhanuprakash Bodireddy" <bhanuprakash.bodireddy@intel.com>
> Sent: Tuesday, July 5, 2016 12:34:54 PM
> Subject: [PATCH v4] Makefile.am: Add clang static analysis support
> 
> 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>/
> 
> 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.
> 
> Signed-off-by: Bhanuprakash Bodireddy <bhanuprakash.bodireddy@intel.com>
> ---
>  INSTALL.md  | 21 +++++++++++++++++++++
>  Makefile.am |  7 +++++++
>  2 files changed, 28 insertions(+)
> 
> diff --git a/INSTALL.md b/INSTALL.md
> index f4d232b..c2a2021 100644
> --- a/INSTALL.md
> +++ b/INSTALL.md
> @@ -746,6 +746,27 @@ 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
> +4. scan-view --host=IPADDR host --port PORT
> +    $OVS_DIR>/clang-analyzer-results/yyyy-mm-dd-114251-1027-1
> --allow-all-hosts
> +5. Visit http://ipaddr:PORT/ for analysis report.
> +
>  Bug Reporting
>  =============
>  
> diff --git a/Makefile.am b/Makefile.am
> index b2c1126..7fcd672 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -401,6 +401,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)
> --
> 2.4.11
> 
> 

Acked-By: Lance Richardson <lrichard@redhat.com>
Ben Pfaff July 14, 2016, 4:25 p.m. UTC | #2
Thanks for sending a new version.

On Tue, Jul 05, 2016 at 05:34:54PM +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>/
>
> 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.

Please don't include the internal patch change log as part of the commit
message.  Put it after ---, instead.

> Signed-off-by: Bhanuprakash Bodireddy <bhanuprakash.bodireddy@intel.com>
> ---
>  INSTALL.md  | 21 +++++++++++++++++++++
>  Makefile.am |  7 +++++++
>  2 files changed, 28 insertions(+)
> 
> diff --git a/INSTALL.md b/INSTALL.md
> index f4d232b..c2a2021 100644
> --- a/INSTALL.md
> +++ b/INSTALL.md
> @@ -746,6 +746,27 @@ 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

OK, the above works for me now.  Thanks.

> +4. scan-view --host=IPADDR host --port PORT
> +    $OVS_DIR>/clang-analyzer-results/yyyy-mm-dd-114251-1027-1 --allow-all-hosts

The above doesn't seem right.  "host" is spurious and the specific
digits you include are different (I think that they are the time of
day).

The last line of output from "make clang-analyze" lists a command to
run:

    scan-build: Run 'scan-view /home/blp/nicira/ovs/tests/clang-analyzer-results/2016-07-14-091820-11158-1' to examine bug reports.

It's probably easiest to advise the user to just run that command.

> +5. Visit http://ipaddr:PORT/ for analysis report.

For me, at least, when I run the command above, the URL automatically
pops up in my web browser, so that I don't have to do anything extra.
Bodireddy, Bhanuprakash July 15, 2016, 6:48 p.m. UTC | #3
>> +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
>
>OK, the above works for me now.  Thanks.
>
>> +4. scan-view --host=IPADDR host --port PORT
>> +    $OVS_DIR>/clang-analyzer-results/yyyy-mm-dd-114251-1027-1
>> +--allow-all-hosts
>
>The above doesn't seem right.  "host" is spurious and the specific digits you
>include are different (I think that they are the time of day).
>
>The last line of output from "make clang-analyze" lists a command to
>run:
>
>    scan-build: Run 'scan-view /home/blp/nicira/ovs/tests/clang-analyzer-
>results/2016-07-14-091820-11158-1' to examine bug reports.
>
>It's probably easiest to advise the user to just run that command.
>
>> +5. Visit http://ipaddr:PORT/ for analysis report.
>
>For me, at least, when I run the command above, the URL automatically pops
>up in my web browser, so that I don't have to do anything extra.

Hello Ben,
I have sent out V5 patch with the modifications you suggested in this thread.

Regards,
Bhanu Prakash.
diff mbox

Patch

diff --git a/INSTALL.md b/INSTALL.md
index f4d232b..c2a2021 100644
--- a/INSTALL.md
+++ b/INSTALL.md
@@ -746,6 +746,27 @@  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
+4. scan-view --host=IPADDR host --port PORT
+    $OVS_DIR>/clang-analyzer-results/yyyy-mm-dd-114251-1027-1 --allow-all-hosts
+5. Visit http://ipaddr:PORT/ for analysis report.
+
 Bug Reporting
 =============
 
diff --git a/Makefile.am b/Makefile.am
index b2c1126..7fcd672 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -401,6 +401,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)