# Code coverage on nginx using lcov (gcov)

**URL:** <https://www.ruby-forum.com/t/code-coverage-on-nginx-using-lcov-gcov/220392>\
**Category:** NGINX\
**Created:** [June 7, 2012, 7:57pm UTC](https://www.ruby-forum.com/t/code-coverage-on-nginx-using-lcov-gcov/220392 "2012-06-07T19:57:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [June 7, 2012, 7:57pm UTC](https://www.ruby-forum.com/t/code-coverage-on-nginx-using-lcov-gcov/220392/1 "2012-06-07T19:57:48Z")

</div>

Hi

I am trying to measure code coverage on nginx with lcov (gcov) tool. So  
far I am able to get code coverage results, but they are always the  
same. Here is a short recap on what I’ve done.

Downloaded source code.

$ cd /opt  
$ wget [http://nginx.org/download/nginx-1.2.1.tar.gz](http://nginx.org/download/nginx-1.2.1.tar.gz)  
$ tar xzvf nginx-1.2.1.tar.gz  
$ cd nginx-1.2.1  
$ chmod -R 777 .

Compiled source code with following compiler and linker flags.

$ ./configure --with-cc-opt=–coverage --with-ld-opt=-lgcov  
$ make  
$ make install

I have done code coverage measurements in following order.

$ lcov --directory /opt/nginx-1.2.1 --zerocounters  
$ /usr/local/nginx/sbin/nginx

Made an HTTP request to nginx server.  
$ lynx [http://localhost:80](http://localhost:80)

$ /usr/local/nginx/sbin/nginx/nginx -s quit  
$ lcov --directory /opt/nginx-1.2.1 --capture --output-file app.info  
–base-directory /opt/nginx-1.2.1  
$ genhtml -o /opt/report1 app.info

Here are the code coverage results.  
lines…: 15.1% (4159 of 27467 lines)  
functions…: 22.6% (262 of 1158 functions)  
branches…: 11.7% (2231 of 19121 branches)

My problem is that I get exactly the same code coverage result when I  
don’t even make the HTTP request. I think the code coverage in this case  
should be smaller than when an HTTP request has been made.

And I get exactly the same code coverage result even if I use several  
different request methods (GET, HEAD, PUT, DELETE, POST and TRACE). I  
think the code coverage in this case should be bigger than when only one  
HTTP request has been made.

Could someone please give an advice on this?

Posted at Nginx Forum:

> **[Code coverage on nginx using lcov (gcov)](https://forum.nginx.org/read.php?2,227329,227329#msg-227329)**
>
> Hi I am trying to measure code coverage on nginx with lcov (gcov) tool. So far I am able to get code coverage results, but they are always the same. Here is a short recap on what I've done. Downloaded source code. $ cd /opt $ wget http://nginx.org/

---

<div class="post-metadata">

**Author:** ![parttis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/76d3ee/32.png) [@parttis](https://www.ruby-forum.com/u/parttis)\
**Post date:** [June 13, 2012, 8:29pm UTC](https://www.ruby-forum.com/t/code-coverage-on-nginx-using-lcov-gcov/220392/2 "2012-06-13T20:29:57Z")

</div>

Valentin V. Bartenev Wrote:

> wbr, Valentin V. Bartenev  
> Thank you Valentin for your kind help.  
> Now I am able to do code coverage measurements.

Posted at Nginx Forum:  
[http://forum.nginx.org/read.php?2,227329,227504#msg-227504](http://forum.nginx.org/read.php?2,227329,227504#msg-227504)

---

<div class="post-metadata">

**Author:** ![parttis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/76d3ee/32.png) [@parttis](https://www.ruby-forum.com/u/parttis)\
**Post date:** [June 7, 2012, 11:00pm UTC](https://www.ruby-forum.com/t/code-coverage-on-nginx-using-lcov-gcov/220392/3 "2012-06-07T23:00:46Z")

</div>

On Thursday 07 June 2012 21:57:05 parttis wrote:

> $ tar xzvf nginx-1.2.1.tar.gz
> 
> different request methods (GET, HEAD, PUT, DELETE, POST and TRACE). I  
> think the code coverage in this case should be bigger than when only one  
> HTTP request has been made.
> 
> Could someone please give an advice on this?

Looks like it measures only the master process, which does not  
process requests. I don’t know much about gcov, probably it can  
measure multi-process applications, but also you can set the  
“master\_process” directive to “off”.

> **[Core functionality](http://nginx.org/en/docs/ngx_core_module.html#master_process)**
>
> Determines whether worker processes are started. This directive is intended for nginx developers.

wbr, Valentin V. Bartenev
