Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unit test on program which has lots of macros

Recently, I need to add unit test to one legacy program.

But in it, there are lots of macros, like

#ifdef CONFIG_XXX
do xxx
#endif

#ifdef CONFIG_YYY
do yyy
#endif

Currently, the generic program path are covered by unit tests. So, I want to add tests to cover the inside macro parts (different program path).

It seems that I need to compile and run my program with certain macros each time, and how to design the composition of macros to cover the program path and reduce compilation times is really not easy.

So, I plan to move all the hardware related code to arch folder, now, macros were moved from c files to makefile, but still need to compile with certain macros each time to get UT work.

Does anyone have experiences on this problem before?

Thanks for your comments.

like image 739
Chris Zheng Avatar asked Aug 26 '11 02:08

Chris Zheng


1 Answers

i think you can just use gcc -D to generate many version of the binary program. compile and run them with a script to do that :)

like image 110
auxten Avatar answered Oct 28 '22 22:10

auxten