boost test_unit problem when using gcc 4.0.1
boost test_unit problem when using gcc 4.0.1
- Subject: boost test_unit problem when using gcc 4.0.1
- From: Ananda Tallur <email@hidden>
- Date: Wed, 22 Feb 2006 17:32:52 +0100
Hello,
I would like to submit a problem we recently discovered, when using :
* gcc 4.0.1 : Apple version coming with XCode 2.2.1 (build 5250) or
gcc 4.0.2 delivered by darwinports.
* boost library, tried with 1.33.1, 1.33.0
* using optimization level, either -O, -O1 or -O2
The problem does not occur when :
* using Apple gcc 3.3, both with or without optimization
* not using optimization (-O0)
Below is the sample program :
---- file boost_unit_test_gcc4_pb_sample.cpp ---
#include <iostream>
#include <boost/test/unit_test.hpp>
using boost::unit_test_framework::test_suite;
using boost::unit_test_framework::test_case;
using namespace std;
class SampleTest {
public:
SampleTest (int val) :
a (val)
{
}
int a;
void sampleTest ()
{
std::cout << "a : " << a << std::endl;
BOOST_CHECK_EQUAL (a, 12345);
}
};
test_suite*
init_unit_test_suite( int argc, char* argv[] )
{
test_suite* test= BOOST_TEST_SUITE( "Sample test" );
boost::shared_ptr<SampleTest> instance (new SampleTest (12345));
test->add (BOOST_CLASS_TEST_CASE ( & SampleTest::sampleTest,
instance));
return test;
}
---- end-of-file boost_unit_test_gcc4_pb_sample.cpp ---
And the command used for compiling :
BOOST_PATH=<path-to-your-boost-install>
/usr/bin/g++-4.0 -O2 -I${BOOST_PATH}/include -L${BOOST_PATH}/lib -
lboost_unit_test_framework boost_unit_test_gcc4_pb_sample.cpp -o
boost_unit_test_gcc4_pb_sample
When compiled when the above command, and running the program :
export DYLD_LIBRARY_PATH=${BOOST_PATH}/lib
./boost_unit_test_gcc4_pb_sample
The result is the following :
----
Running 1 test case...a : 13691
boost_unit_test_gcc4_pb_sample.cpp(18): error in "
SampleTest::sampleTest": check a == 12345 failed [13691 != 12345]
*** 1 failure detected in test suite "Sample test"
---
When compiled without optimization (-O0), and running, the result is :
----
Running 1 test case...a : 12345
*** No errors detected
----
It seems that when sampleTest () method is called by unit_test
framework, adress of "a" variable is wrong, leading to a test failure.
When, instead of using a class or struct attribute for variable "a",
either a global, or class static variable is used, the problem
disappears.
Has anyone some experience using Boost unit_test framework on Mac OS
X, using gcc 4 ?
Any help would be greatly appreciated !
Regards,
Anand
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden