Boost.Test: automatic test cases inside a static library

I'm trying to get something like the following to work: test_case1.cpp and test_cast2.cpp are compiled into a static library (libtest.a). They use BOOST_AUTO_TEST_CASE for test cases. test_main.cpp contains: #define BOOST_AUTO_TEST_MAIN #include <boost/test/auto_unit_test.hpp> However, when I compile test_main.cpp and link libtest.a into it, none of the test cases run. The test cases do run if test_main.cpp #includes test_case1.cpp and test_case2.cpp, but I'd rather not do that if it's not necessary. Any ideas? Thanks! Joe Van Dyk

On Friday 07 July 2006 04:40, Joe Van Dyk wrote:
I'm trying to get something like the following to work:
test_case1.cpp and test_cast2.cpp are compiled into a static library (libtest.a). They use BOOST_AUTO_TEST_CASE for test cases.
test_main.cpp contains: #define BOOST_AUTO_TEST_MAIN #include <boost/test/auto_unit_test.hpp>
However, when I compile test_main.cpp and link libtest.a into it, none of the test cases run.
The test cases do run if test_main.cpp #includes test_case1.cpp and test_case2.cpp, but I'd rather not do that if it's not necessary.
Any ideas? <snip>
I'm guessing here :) Registration of tests with the runner is done using file-static instances of some generic factory or other registration mechanism. If none of the symbols of given object file is referenced outside itself, the linker does not include the code from the object file in the final executable. Use dynamic libs, or link the object files instead of the archives. HTH, Marc -- Marc Mutz -- marc@klaralvdalens-datakonsult.se, mutz@kde.org Klarälvdalens Datakonsult AB, Platform-independent software solutions

On 7/9/06, Marc Mutz <marc@klaralvdalens-datakonsult.se> wrote:
On Friday 07 July 2006 04:40, Joe Van Dyk wrote:
I'm trying to get something like the following to work:
test_case1.cpp and test_cast2.cpp are compiled into a static library (libtest.a). They use BOOST_AUTO_TEST_CASE for test cases.
test_main.cpp contains: #define BOOST_AUTO_TEST_MAIN #include <boost/test/auto_unit_test.hpp>
However, when I compile test_main.cpp and link libtest.a into it, none of the test cases run.
The test cases do run if test_main.cpp #includes test_case1.cpp and test_case2.cpp, but I'd rather not do that if it's not necessary.
Any ideas? <snip>
I'm guessing here :) Registration of tests with the runner is done using file-static instances of some generic factory or other registration mechanism. If none of the symbols of given object file is referenced outside itself, the linker does not include the code from the object file in the final executable. Use dynamic libs, or link the object files instead of the archives.
Hm, I'll try that. I don't think that fits as nicely into our build system, but I'll have to check on Monday. Can anyone else chime in on this? Thanks for the information, Joe

"Joe Van Dyk" <joevandyk@gmail.com> wrote in message news:c715e640607091915m2142172bo6d437e4c04d7ff5b@mail.gmail.com...
On 7/9/06, Marc Mutz <marc@klaralvdalens-datakonsult.se> wrote:
On Friday 07 July 2006 04:40, Joe Van Dyk wrote:
I'm trying to get something like the following to work:
test_case1.cpp and test_cast2.cpp are compiled into a static library (libtest.a). They use BOOST_AUTO_TEST_CASE for test cases.
test_main.cpp contains: #define BOOST_AUTO_TEST_MAIN #include <boost/test/auto_unit_test.hpp>
However, when I compile test_main.cpp and link libtest.a into it, none of the test cases run.
The test cases do run if test_main.cpp #includes test_case1.cpp and test_case2.cpp, but I'd rather not do that if it's not necessary.
Any ideas? <snip>
I'm guessing here :) Registration of tests with the runner is done using file-static instances of some generic factory or other registration mechanism. If none of the symbols of given object file is referenced outside itself, the linker does not include the code from the object file in the final executable. Use dynamic libs, or link the object files instead of the archives.
This could be the reason. But to employ the dynamic build you will need current CVS version. 1.33.1 won't work.
Hm, I'll try that. I don't think that fits as nicely into our build system, but I'll have to check on Monday.
Can anyone else chime in on this?
Maybe you could use some compiler options to avoid unused static files discard? Gennadiy

On 7/9/06, Gennadiy Rozental <gennadiy.rozental@thomson.com> wrote:
"Joe Van Dyk" <joevandyk@gmail.com> wrote in message news:c715e640607091915m2142172bo6d437e4c04d7ff5b@mail.gmail.com...
On 7/9/06, Marc Mutz <marc@klaralvdalens-datakonsult.se> wrote:
On Friday 07 July 2006 04:40, Joe Van Dyk wrote:
I'm trying to get something like the following to work:
test_case1.cpp and test_cast2.cpp are compiled into a static library (libtest.a). They use BOOST_AUTO_TEST_CASE for test cases.
test_main.cpp contains: #define BOOST_AUTO_TEST_MAIN #include <boost/test/auto_unit_test.hpp>
However, when I compile test_main.cpp and link libtest.a into it, none of the test cases run.
The test cases do run if test_main.cpp #includes test_case1.cpp and test_case2.cpp, but I'd rather not do that if it's not necessary.
Any ideas? <snip>
I'm guessing here :) Registration of tests with the runner is done using file-static instances of some generic factory or other registration mechanism. If none of the symbols of given object file is referenced outside itself, the linker does not include the code from the object file in the final executable. Use dynamic libs, or link the object files instead of the archives.
This could be the reason. But to employ the dynamic build you will need current CVS version. 1.33.1 won't work.
Hm, I'll try that. I don't think that fits as nicely into our build system, but I'll have to check on Monday.
Can anyone else chime in on this?
Maybe you could use some compiler options to avoid unused static files discard?
Hm, I've never heard of that option. I'll look into it. Joe

On 7/10/06, Joe Van Dyk <joevandyk@gmail.com> wrote:
On 7/9/06, Gennadiy Rozental <gennadiy.rozental@thomson.com> wrote:
"Joe Van Dyk" <joevandyk@gmail.com> wrote in message news:c715e640607091915m2142172bo6d437e4c04d7ff5b@mail.gmail.com...
On 7/9/06, Marc Mutz <marc@klaralvdalens-datakonsult.se> wrote:
On Friday 07 July 2006 04:40, Joe Van Dyk wrote:
I'm trying to get something like the following to work:
test_case1.cpp and test_cast2.cpp are compiled into a static library (libtest.a). They use BOOST_AUTO_TEST_CASE for test cases.
test_main.cpp contains: #define BOOST_AUTO_TEST_MAIN #include <boost/test/auto_unit_test.hpp>
However, when I compile test_main.cpp and link libtest.a into it, none of the test cases run.
The test cases do run if test_main.cpp #includes test_case1.cpp and test_case2.cpp, but I'd rather not do that if it's not necessary.
Any ideas? <snip>
I'm guessing here :) Registration of tests with the runner is done using file-static instances of some generic factory or other registration mechanism. If none of the symbols of given object file is referenced outside itself, the linker does not include the code from the object file in the final executable. Use dynamic libs, or link the object files instead of the archives.
This could be the reason. But to employ the dynamic build you will need current CVS version. 1.33.1 won't work.
Hm, I'll try that. I don't think that fits as nicely into our build system, but I'll have to check on Monday.
Can anyone else chime in on this?
Maybe you could use some compiler options to avoid unused static files discard?
Hm, I've never heard of that option. I'll look into it.
Any chance you could tell me what flags the GNU GCC compiler would do the trick? I can't find anything that resembles "avoid unused static files discard".

"Joe Van Dyk" <joevandyk@gmail.com> wrote in message news:c715e640607101320k4caccc35kd102eee4cf383e02@mail.gmail.com...
Maybe you could use some compiler options to avoid unused static files discard?
Hm, I've never heard of that option. I'll look into it.
Any chance you could tell me what flags the GNU GCC compiler would do the trick? I can't find anything that resembles "avoid unused static files discard".
Looks like these may work: -fkeep-static-consts -fno-toplevel-reorder -fno-unit-at-a-time (?) Gennadiy

On 7/10/06, Gennadiy Rozental <gennadiy.rozental@thomson.com> wrote:
"Joe Van Dyk" <joevandyk@gmail.com> wrote in message news:c715e640607101320k4caccc35kd102eee4cf383e02@mail.gmail.com...
Maybe you could use some compiler options to avoid unused static files discard?
Hm, I've never heard of that option. I'll look into it.
Any chance you could tell me what flags the GNU GCC compiler would do the trick? I can't find anything that resembles "avoid unused static files discard".
Looks like these may work:
-fkeep-static-consts -fno-toplevel-reorder -fno-unit-at-a-time (?)
Thanks, I'll try that. Can you explain the problem with static linking that makes these options necessary? Joe

"Joe Van Dyk" <joevandyk@gmail.com> wrote in message news:c715e640607101451i6dcffeb8s7b99bf6c82e50a1e@mail.gmail.com...
On 7/10/06, Gennadiy Rozental <gennadiy.rozental@thomson.com> wrote:
"Joe Van Dyk" <joevandyk@gmail.com> wrote in message news:c715e640607101320k4caccc35kd102eee4cf383e02@mail.gmail.com...
Maybe you could use some compiler options to avoid unused static files discard?
Hm, I've never heard of that option. I'll look into it.
Any chance you could tell me what flags the GNU GCC compiler would do the trick? I can't find anything that resembles "avoid unused static files discard".
Looks like these may work:
-fkeep-static-consts -fno-toplevel-reorder -fno-unit-at-a-time (?)
Thanks, I'll try that. Can you explain the problem with static linking that makes these options necessary?
Automatic registration is implemented with use of file level static variables that never used, but in a constructor register test cases. Once these variable removed, no registration occurs. Gennadiy
participants (3)
-
Gennadiy Rozental
-
Joe Van Dyk
-
Marc Mutz