[test] Using the Boost Unit Test Framework with shared libs

Hi I am using Boost.Test from the current boost 1.38 , on cygwin ( gcc ) and I want to use it with multiple test files and with shared libs ( in order to speed up the compilation time which is too long for me when using the header include variant ). What is the recommended way ? ( I read the doc, several times and I read the _long_ threads on the mailing list concerning the static/shared library issue, but I am not sure that I understood all the details). I did the following: *in mainTest.cpp:* #define BOOST_TEST_DYN_LINK #define BOOST_TEST_MAIN #include "../inc/globalFixture.hpp" #include "../inc/testfile1.hpp" #include "../inc/testfile2.hpp" *testfile1.hpp:* #include "globalFixture.hpp" BOOST_FIXTURE_TEST_SUITE(ATlib1, Fixture) BOOST_AUTO_TEST_CASE(Resource_Manager) { ... ....BOOST_CHECK .... } BOOST_AUTO_TEST_SUITE_END() *testfile2.hpp:* #include "globalFixture.hpp" BOOST_FIXTURE_TEST_SUITE(ATlib2, Fixture) BOOST_AUTO_TEST_CASE(FileManager { ... BOOST_CHECK .... } BOOST_AUTO_TEST_SUITE_END() *globalfixture.hpp: *#ifndef _GLOBALFIXTURE_HPP #define _GLOBALFIXTURE_HPP #define BOOST_TEST_MODULE ATlib #include <iostream> #include <boost/test/unit_test.hpp> #include <boost/test/detail/unit_test_parameters.hpp> #include <boost/bind.hpp> #include <boost/test/output_test_stream.hpp> using namespace boost::unit_test; struct GlobalConfig { GlobalConfig() { std::cout << "GlobalConfig setup\n"; using namespace boost::unit_test; if (runtime_config::log_level() < log_warnings) unit_test_log.set_threshold_level(log_successful_tests); }; ~GlobalConfig() { std::cout << "GlobalConfig teardown\n"; } }; BOOST_GLOBAL_FIXTURE(GlobalConfig); struct Fixture { Fixture() { BOOST_TEST_MESSAGE("setup Fixture"); using namespace boost::unit_test; unit_test_log.set_threshold_level(log_successful_tests); } ~Fixture() { BOOST_TEST_MESSAGE("teardown Fixture"); } }; #endif /* _GLOBALFIXTURE_HPP */* *I then link to boost_unit_test_framework-gcc34-mt-1_38.so The link passes , but I get a warning from gcc++ 3.4.4 that auto-linking has been enabled ( I will provide the exact details if useful ). I can execute the resulting mainTest.exe without problems, but the compiler warnings tells that something is not quite right. Is the above example the right way to use multiple test files ? Are the flags for shared libs correctly set ? Thanks for your help. PS: I think that Boost.Test is not easy to grasp ( at least for me ). I think this is partially due to a lack of complete examples ( involving for examples a test suite with more than one test file ). Also the static/shared library topic and the related macros ( BOOST_TEST_DYN_LINK etc ) could do with a concrete example. Maybe the mentioned case above could serve as an example after clarification. Peter

AMDG Peter wrote:
I am using Boost.Test from the current boost 1.38 , on cygwin ( gcc ) and I want to use it with multiple test files and with shared libs ( in order to speed up the compilation time which is too long for me when using the header include variant ).
What is the recommended way ? ( I read the doc, several times and I read the _long_ threads on the mailing list concerning the static/shared library issue, but I am not sure that I understood all the details).
I did the following:
*in mainTest.cpp:*
#define BOOST_TEST_DYN_LINK #define BOOST_TEST_MAIN
#include "../inc/globalFixture.hpp" #include "../inc/testfile1.hpp" #include "../inc/testfile2.hpp"
If you're going to use multiple files, it's better not to include everything in a single translation unit. As long as BOOST_TEST_MAIN and BOOST_TEST_MODULE are only defined in one translation unit you can link multiple translation units together. BOOST_TEST_DYN_LINK needs to be defined in every translation unit.
*I then link to boost_unit_test_framework-gcc34-mt-1_38.so The link passes , but I get a warning from gcc++ 3.4.4 that auto-linking has been enabled ( I will provide the exact details if useful ).
If you mean auto-import, that's normal on cygwin. In Christ, Steven Watanabe

Hi Thanks for you help.
*I then link to boost_unit_test_framework-gcc34-mt-1_38.so The link passes , but I get a warning from gcc++ 3.4.4 that auto-linking has been enabled ( I will provide the exact details if useful ).
If you mean auto-import, that's normal on cygwin.
Yes , thats what I meant : warning: auto-importing has been activated without --enable-auto-import specified on the command line. This should work unless it involves constant data structures referencing symbols from auto-imported DLLs.Info: resolving vtable for boost::unit_test::unit_test_log_tby linking to __imp___ZTVN5boost9unit_test15unit_test_log_tE (auto-import) Is this really normal ? And is it really good ? I once had exactly the same sort of warning ( compiling stuff not related to boost ) and it turned out that I linked against a dll with Visual C++ Symbols ( that were not exported in a way that gcc can handle them correctly ). The resulting executable was basically undefined behavior. In any case, I do not want to live with compiler/linker warnings. Usually, as far as I know, on windows ( and also on cygwin on windows ) the standard way would be to create a .dll and then use that to create an import library .lib that is linked against. The .dll itself is not required for the linking process. Am I missing something ? Is there a way to use shared libs in Boost.Test without linker warnings ( that I know from experience have to be taken very seriously in this particular case ) ? Again, thanks for help
In Christ, Steven Watanabe
Peter

Peter wrote:
Hi I am using Boost.Test from the current boost 1.38 , on cygwin ( gcc ) and I want to use it with multiple test files and with shared libs ( in order to speed up the compilation time which is too long for me when using the header include variant ).
How much time speedup do you see?
I did the following:
...
*I then link to boost_unit_test_framework-gcc34-mt-1_38.so The link passes , but I get a warning from gcc++ 3.4.4 that auto-linking has been enabled ( I will provide the exact details if useful ). I can execute the resulting mainTest.exe without problems, but the compiler warnings tells that something is not quite right.
Is the above example the right way to use multiple test files ?
Umm. Not really. There should be multiple translation units. BOOST_TEST_MAIN/BOOST_TEST_MODULE should be defined in only one of them. This way you should be able to speedup compilation even more.
Are the flags for shared libs correctly set ?
Compile time? Looks file. Can't tell you about link flags. What r u using as make system?
Thanks for your help.
PS: I think that Boost.Test is not easy to grasp ( at least for me ). I think this is partially due to a lack of complete examples ( involving for examples a test suite with more than one test file ).
There is one - example #10
Also the static/shared library topic and the related macros ( BOOST_TEST_DYN_LINK etc ) could do with a concrete example. Maybe the
I believe there are couple in docs. Gennadiy
participants (3)
-
Gennadiy Rozental
-
Peter
-
Steven Watanabe