Disable tests which depend on unsupported compiler flags.

14 views
Skip to first unread message

Tor Didriksen

unread,
Nov 2, 2009, 9:49:59 AM11/2/09
to Google C++ Testing Framework
Hi.
When running with non-gcc compilers, can we simply disable the tests
which use 'fno-rtti' etc?
Here's a suggested patch.

-- didrik


dnl See whether $CXX supports flag in arg1.
dnl Set $2 to "yes" or "no" accordingly.
AC_DEFUN([TRY_COMPILER_FLAG], [
AC_MSG_CHECKING([whether $CXX supports $1])
save_CXXFLAGS="$CXXFLAGS"
CXXFLAGS="$CXXFLAGS $1"
AC_LINK_IFELSE([int main(void){ return 0;} ],
[$2=yes],
[$2=no])
CXXFLAGS="$save_CXXFLAGS"
AC_MSG_RESULT([$[$2]])
])

Index: configure.ac
===================================================================
--- configure.ac (revision 336)
+++ configure.ac (working copy)
@@ -1,4 +1,5 @@
m4_include(m4/acx_pthread.m4)
+m4_include(m4/compiler_flags.m4)

# At this point, the Xcode project assumes the version string will be three
# integers separated by periods and surrounded by square brackets (e.g.
@@ -28,6 +29,14 @@
AC_LANG([C++])
AC_PROG_LIBTOOL

+# Check for some compiler flags.
+TRY_COMPILER_FLAG("-fexceptions", exceptions_flag)
+TRY_COMPILER_FLAG("-fno-exceptions", no_exceptions_flag)
+TRY_COMPILER_FLAG("-fno-rtti", no_rtti_flag)
+AM_CONDITIONAL([HAVE_EXCEPTIONS_FLAG], [test "$exceptions_flag" == "yes"])
+AM_CONDITIONAL([HAVE_NO_EXCEPTIONS_FLAG], [test "$no_exceptions_flag"
== "yes"])
+AM_CONDITIONAL([HAVE_NO_RTTI_FLAG], [test "$no_rtti_flag" == "yes"])
+
# TODO(chan...@google.com): Currently we aren't running the Python tests
# against the interpreter detected by AM_PATH_PYTHON, and so we condition
# HAVE_PYTHON by requiring "python" to be in the PATH, and that interpreter's

===================================================================
--- Makefile.am (revision 336)
+++ Makefile.am (working copy)
@@ -285,12 +285,14 @@
test_gtest_test_part_test_SOURCES = test/gtest-test-part_test.cc
test_gtest_test_part_test_LDADD = lib/libgtest_main.la

+if HAVE_EXCEPTIONS_FLAG
TESTS += test/gtest_throw_on_failure_ex_test
check_PROGRAMS += test/gtest_throw_on_failure_ex_test
test_gtest_throw_on_failure_ex_test_SOURCES = \
test/gtest_throw_on_failure_ex_test.cc \
src/gtest-all.cc
test_gtest_throw_on_failure_ex_test_CXXFLAGS = $(AM_CXXFLAGS) -fexceptions
+endif

TESTS += test/gtest-typed-test_test
check_PROGRAMS += test/gtest-typed-test_test
@@ -315,12 +317,14 @@
test_gtest_listener_test_LDADD = lib/libgtest_main.la

# Verifies that Google Test works when RTTI is disabled.
+if HAVE_NO_RTTI_FLAG
TESTS += test/gtest_no_rtti_test
check_PROGRAMS += test/gtest_no_rtti_test
test_gtest_no_rtti_test_SOURCES = test/gtest_unittest.cc \
src/gtest-all.cc \
src/gtest_main.cc
test_gtest_no_rtti_test_CXXFLAGS = $(AM_CXXFLAGS) -fno-rtti -DGTEST_HAS_RTTI=0
+endif

# Verifies that Google Test's own TR1 tuple implementation works.
TESTS += test/gtest-tuple_test
@@ -403,6 +407,7 @@
check_SCRIPTS += test/gtest_shuffle_test.py
TESTS += test/gtest_shuffle_test.py

+if HAVE_NO_EXCEPTIONS_FLAG
check_PROGRAMS += test/gtest_throw_on_failure_test_
test_gtest_throw_on_failure_test__SOURCES = \
test/gtest_throw_on_failure_test_.cc \
@@ -410,6 +415,7 @@
test_gtest_throw_on_failure_test__CXXFLAGS = $(AM_CXXFLAGS) -fno-exceptions
check_SCRIPTS += test/gtest_throw_on_failure_test.py
TESTS += test/gtest_throw_on_failure_test.py
+endif

check_PROGRAMS += test/gtest_uninitialized_test_
test_gtest_uninitialized_test__SOURCES = test/gtest_uninitialized_test_.cc

Vlad Losev

unread,
Nov 6, 2009, 12:28:41 PM11/6/09
to Chandler Carruth, Tor Didriksen, Google C++ Testing Framework
Chandler,

Can you please comment on this? I'd rather see us sniffing out correct compile time options for controlling exceptions and RTTI on SunStudio but I'll be hard pressed to implement it. :-[
Thanks,
Vlad

Hady Zalek

unread,
Nov 6, 2009, 12:47:14 PM11/6/09
to Vlad Losev, Chandler Carruth, Tor Didriksen, Google C++ Testing Framework
Hello everyone,

I agree with Vlad, especially that the concerned tests pass on SS and VA. Can't we let the user specify the flag and default to the gcc flags otherwise? something like:

CXX_EH_FLAG="-features=except" CXX_NOEH_FLAG="-features=no%except" CXX_NORTTI_FLAG="-features=no%rtti" configure

I'm sure Tor's suggestion above could be tweaked to test for the user values, something like:

TRY_COMPILER_FLAG("$CXX_EH_FLAG", exceptions_flag)
TRY_COMPILER_FLAG("$CXX_NOEH_FLAG", no_exceptions_flag)
TRY_COMPILER_FLAG("CXX_NORTTI_FLAG", no_rtti_flag)

I'd propose a patch, but I haven't got much experience with autotools....

Cheers,
Hady


2009/11/6 Vlad Losev <vlad...@gmail.com>

Tor Didriksen

unread,
Nov 6, 2009, 1:19:07 PM11/6/09
to Hady Zalek, Vlad Losev, Chandler Carruth, Google C++ Testing Framework
On Fri, Nov 6, 2009 at 6:47 PM, Hady Zalek <hady....@gmail.com> wrote:
> Hello everyone,
>
> I agree with Vlad, especially that the concerned tests pass on SS and VA.
> Can't we let the user specify the flag and default to the gcc flags
> otherwise? something like:
>
> CXX_EH_FLAG="-features=except" CXX_NOEH_FLAG="-features=no%except"
> CXX_NORTTI_FLAG="-features=no%rtti" configure
>
> I'm sure Tor's suggestion above could be tweaked to test for the user
> values, something like:
>
> TRY_COMPILER_FLAG("$CXX_EH_FLAG", exceptions_flag)
> TRY_COMPILER_FLAG("$CXX_NOEH_FLAG", no_exceptions_flag)
> TRY_COMPILER_FLAG("CXX_NORTTI_FLAG", no_rtti_flag)

It should be fairly easy to extend my proposal to have a list of options to try,
and also to take input from the command line/environment.

-- didrik

Hady Zalek

unread,
Nov 6, 2009, 1:35:32 PM11/6/09
to Tor Didriksen, Vlad Losev, Chandler Carruth, Google C++ Testing Framework
Btw, is using autotools a 'must'. Can't we use something more 'modern' like CMake (http://www.cmake.org/)? I'll be more than happy to hack on it.

2009/11/6 Tor Didriksen <torm...@gmail.com>

Vlad Losev

unread,
Nov 6, 2009, 3:06:32 PM11/6/09
to Hady Zalek, Tor Didriksen, Chandler Carruth, Google C++ Testing Framework
Hi Hady,

On Fri, Nov 6, 2009 at 11:35 AM, Hady Zalek <hady....@gmail.com> wrote:
Btw, is using autotools a 'must'. Can't we use something more 'modern' like CMake (http://www.cmake.org/)? I'll be more than happy to hack on it.

We have build scripts for SCons available in the scons/ directory. This is what we currently are using internally for cross platform builds.
 
- Vlad

Chandler Carruth

unread,
Nov 6, 2009, 3:16:13 PM11/6/09
to Vlad Losev, Hady Zalek, Tor Didriksen, Google C++ Testing Framework
FYI, I'm going to look at this today, digging my way out from under
several other things, sorry for the delays....

Hady Zalek

unread,
Nov 18, 2009, 6:44:12 AM11/18/09
to Chandler Carruth, Vlad Losev, Tor Didriksen, Google C++ Testing Framework
Hi Chandler,

I've attached a patch that builds on Tor's initial work for guessing the correct RTTI and exception related flags. Hope that helps.

Cheers,
Hady

2009/11/6 Chandler Carruth <chan...@google.com>
test_flags.patch
Reply all
Reply to author
Forward
0 new messages