You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Stefan Fritsch <sf...@sfritsch.de> on 2012/05/04 23:27:25 UTC

Adding unit tests to httpd?

Hi,

there are some parts of httpd where unit tests would allow easier 
testing or more complete test coverage than tests written for the perl 
framework. Examples include the ap_pcfg_* functions, the varbuf API, 
the regex plus API, and new interfaces that are not yet used by any 
module.

Therefore, I am thinking about adding unit tests to httpd. For maximum 
usefulness, such unit tests should be able to access functions that 
are not exported (including static functions). I could think of a few 
ways to achive this:

1) Add some preprocessor magic that exports the required functions 
when compiled with a special configure option. Then, put the unit 
tests into a separate module that executes them during server startup 
(and exits instead of allowing the startup to continue).

2) Put the unit tests into a separate executable using source files 
that #include the .c file(s) that contains the tested functions. This 
is a very hackish approach and has problems with source file 
interdependencies. It would likely require special linking magic.

3) Put the unit tests into the same httpd source files that contain 
the functions to be tested. They would only be compiled in with a 
special configure option. Httpd would then, if some magic -D variable 
is defined, execute the tests during server startup and exit instead 
of allowing the startup to continue.

I think option 3) is the least hackish approach. Is it problematic if 
the unit tests are compiled into the httpd executable and modules, 
increasing their size? Of course, one could also compile everything 
twice, once for unit testing and once for production use. Newer gcc 
versions also have attribute "cold" that can put functions into a 
separate section, which would prevent the unit tests from using 
significant memory or reducing cache locality during normal operation.

Any comments?

Cheers,
Stefan

Re: Adding unit tests to httpd?

Posted by Igor Galić <i....@brainsware.org>.

----- Original Message -----
> On Sun, May 6, 2012 at 3:18 PM, Eric Covener <co...@gmail.com>
> wrote:
> >> Of course it would also be a possibility that we simply mark the
> >> functions to be tested as non-static. Personally, I think that is
> >> ugly, though.
> 
> Sorry, sent draft instead of discarding.
> 
> Could they have some AP_XXX macro that resulted in "static" in real
> builds and exported symbols when building UT binaries?

I'm wondering how non of the Subversion devs chimes in ;)
Maybe we should CC the thread to dev@subversion.apache.org
to get their attention!

> --
> Eric Covener
> covener@gmail.com

i

-- 
Igor Galić

Tel: +43 (0) 664 886 22 883
Mail: i.galic@brainsware.org
URL: http://brainsware.org/
GPG: 6880 4155 74BD FD7C B515  2EA5 4B1D 9E08 A097 C9AE


Re: Adding unit tests to httpd?

Posted by Eric Covener <co...@gmail.com>.
On Sun, May 6, 2012 at 3:18 PM, Eric Covener <co...@gmail.com> wrote:
>> Of course it would also be a possibility that we simply mark the
>> functions to be tested as non-static. Personally, I think that is
>> ugly, though.

Sorry, sent draft instead of discarding.

Could they have some AP_XXX macro that resulted in "static" in real
builds and exported symbols when building UT binaries?

-- 
Eric Covener
covener@gmail.com

Re: Adding unit tests to httpd?

Posted by Eric Covener <co...@gmail.com>.
> Of course it would also be a possibility that we simply mark the
> functions to be tested as non-static. Personally, I think that is
> ugly, though.

Re: Adding unit tests to httpd?

Posted by Stefan Fritsch <sf...@sfritsch.de>.
On Friday 04 May 2012, Igor Galić wrote:
> ----- Original Message -----
> 
> > Hi,
> > 
> > there are some parts of httpd where unit tests would allow easier
> > testing or more complete test coverage than tests written for the
> > perl
> > framework. Examples include the ap_pcfg_* functions, the varbuf
> > API, the regex plus API, and new interfaces that are not yet
> > used by any module.
> > 
> > Therefore, I am thinking about adding unit tests to httpd. For
> > maximum
> > usefulness, such unit tests should be able to access functions
> > that are not exported (including static functions). I could
> > think of a few
> 
> > ways to achive this:
> [snip]
> 
> > Any comments?
> 
> I know the Subversion project has a very complete unit test suit.
> How do they approach this?

I am not sure. It seems they only use the test suite to test exported 
interfaces, but some of those interfaces are considered private in 
that the header files are not installed on the target system.

Of course it would also be a possibility that we simply mark the 
functions to be tested as non-static. Personally, I think that is 
ugly, though.

Re: Adding unit tests to httpd?

Posted by Igor Galić <i....@brainsware.org>.

----- Original Message -----
> Hi,
> 
> there are some parts of httpd where unit tests would allow easier
> testing or more complete test coverage than tests written for the
> perl
> framework. Examples include the ap_pcfg_* functions, the varbuf API,
> the regex plus API, and new interfaces that are not yet used by any
> module.
> 
> Therefore, I am thinking about adding unit tests to httpd. For
> maximum
> usefulness, such unit tests should be able to access functions that
> are not exported (including static functions). I could think of a few
> ways to achive this:
[snip] 
> Any comments?

I know the Subversion project has a very complete unit test suit.
How do they approach this?

> Cheers,
> Stefan

i

-- 
Igor Galić

Tel: +43 (0) 664 886 22 883
Mail: i.galic@brainsware.org
URL: http://brainsware.org/
GPG: 6880 4155 74BD FD7C B515  2EA5 4B1D 9E08 A097 C9AE