[asterisk-dev] [Code Review] Unit Test Framework

Russell Bryant russell at digium.com
Thu Dec 17 13:28:34 CST 2009



> On 2009-12-17 08:59:10, Matthew Nicholson wrote:
> > /trunk/include/asterisk/test.h, line 111
> > <https://reviewboard.asterisk.org/r/447/diff/2/?file=7567#file7567line111>
> >
> >     The problem with embedded commas can be avoided if this is defined as follows:
> >     
> >     #define AST_TEST_DEFINE(hdr) static enum ast_test_result_state hdr(struct ast_test_info *info, enum ast_test_command cmd, struct ast_test_args *args)
> >     
> >     And used like this:
> >     
> >     AST_TEST_DEFINE(my_awesome_test)
> >     {
> >        int a, b, c;
> >        return AST_TEST_NOT_RUN;
> >     }
> >     
> >     Notice AST_TEST_DEFINE() only takes a single argument now and the body is simply provided after the macro.
> 
> Matthew Nicholson wrote:
>     Note: I culled this idea from boost.test.
> 
> Matthew Nicholson wrote:
>     After further consideration, I have realized this method causes problems for conditional compilation.  So far, the only way around this I have been able to think of is manually using #ifdef TEST_FRAMEWORK.
>     
>     #ifdef TEST_FRAMEWORK
>     
>     AST_TEST_DEFINE(my_awesome_test)
>     {
>        int a, b, c;
>        return AST_TEST_NOT_RUN;
>     }
>     
>     /* additional tests here */
>     
>     #endif
> 
> Matthew Nicholson wrote:
>     If the functions defined with AST_TEST_DEFINE are never called, in theory the compiler will remove them from the resulting binary.  I am not sure about this though, and the test functions would still affect compile times.
> 
> David Vossel wrote:
>     I was trying to avoid #ifdef blocks for the test defines, but this may need to be reconsidered now that we're running into the whole ',' thing.

I have another idea.  If the function is not used, the compiler will optimize it out.  However, it will generate a compiler warning by default.  You could do:

AST_TEST_DEFINE(my_test) { my test body }
and
#define AST_TEST_DEFINE(test) static return_type attribute_unused test(args)

The attribute_unused will prevent the compiler warning.  Leave your register/unregister macros the same and I think that will meet our goals.


- Russell


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviewboard.asterisk.org/r/447/#review1321
-----------------------------------------------------------


On 2009-12-17 12:07:21, David Vossel wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://reviewboard.asterisk.org/r/447/
> -----------------------------------------------------------
> 
> (Updated 2009-12-17 12:07:21)
> 
> 
> Review request for Asterisk Developers and Russell Bryant.
> 
> 
> Summary
> -------
> 
> The Unit Test Framework is a new API that manages registration and execution of unit tests in Asterisk with the purpose of verifying the operation of C functions.
> 
> The Framework consists of a single test manager accompanied by a list of registered test functions defined within the code.  A test is defined, registered, and unregistered from the framework using a set of macros which allow the test code to only be compiled within asterisk when the TEST_FRAMEWORK flag is enabled in menuselect.  This allows the test code to exist in the same file as the C functions it intends to verify.  Registered tests may be viewed and executed via a set of new CLI commands.  CLI commands are also present for generating and exporting test results into xml and txt formats.
> 
> For more information and use cases please refer to the documentation provided at the beginning of the test.h file.
> 
> 
> Diffs
> -----
> 
>   /trunk/build_tools/cflags-devmode.xml 235408 
>   /trunk/include/asterisk/_private.h 235408 
>   /trunk/include/asterisk/test.h PRE-CREATION 
>   /trunk/main/asterisk.c 235408 
>   /trunk/main/test.c PRE-CREATION 
>   /trunk/tests/test_heap.c 235408 
> 
> Diff: https://reviewboard.asterisk.org/r/447/diff
> 
> 
> Testing
> -------
> 
> test_heap.c has been modified to take advantage of the Test Framework.  I have executed and generated reports for these tests. 
> 
> 
> Thanks,
> 
> David
> 
>




More information about the asterisk-dev mailing list