diff options
author | Mark Wielaard <mjw@redhat.com> | 2012-07-24 19:18:52 +0200 |
---|---|---|
committer | Mark Wielaard <mjw@redhat.com> | 2012-08-16 22:26:23 +0200 |
commit | a985e57862fa0aed33314de079cd44908a6b59cc (patch) | |
tree | 48cf2608fa327f91af1552febfb0ccdaef1cf3d8 | |
parent | f75e849377bc5a8402fb794622f22d9fd4f661be (diff) | |
download | elfutils-a985e57862fa0aed33314de079cd44908a6b59cc.tar.gz |
tests: Add C++ self test binary.
Only build and tested by self tests if a g++ with C++x0 is available.
Almost empty C++ program, can be extended to test more features.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | configure.ac | 5 | ||||
-rw-r--r-- | m4/ChangeLog | 4 | ||||
-rw-r--r-- | m4/ax_cxx_compile_stdcxx_0x.m4 | 107 | ||||
-rw-r--r-- | tests/ChangeLog | 10 | ||||
-rw-r--r-- | tests/Makefile.am | 6 | ||||
-rw-r--r-- | tests/cxx-various.cc | 65 | ||||
-rw-r--r-- | tests/test-subr.sh | 12 | ||||
-rwxr-xr-x | tests/testfile-cxx-various.bz2 | bin | 0 -> 11377 bytes |
9 files changed, 213 insertions, 0 deletions
@@ -1,5 +1,9 @@ 2012-07-24 Mark Wielaard <mjw@redhat.com> + * configure.ac: Add AX_CXX_COMPILE_STDCXX_0X check. + +2012-07-24 Mark Wielaard <mjw@redhat.com> + * TODO: Add note on shdrs after elf_cntl (ELF_C_FDREAD). 2012-06-22 Mark Wielaard <mjw@redhat.com> diff --git a/configure.ac b/configure.ac index 79324897..50db3430 100644 --- a/configure.ac +++ b/configure.ac @@ -72,6 +72,11 @@ AC_PROG_RANLIB AC_PROG_YACC AM_PROG_LEX +# Check whether we can use g++ with -std=c++0x for the test. +AC_PROG_CXX +AX_CXX_COMPILE_STDCXX_0X +AM_CONDITIONAL(HAVE_STDCXX_0X, test "x$ax_cv_cxx_compile_cxx0x_cxx" == "xyes") + AC_CACHE_CHECK([for gcc with C99 support], ac_cv_c99, [dnl old_CFLAGS="$CFLAGS" CFLAGS="$CFLAGS -std=gnu99" diff --git a/m4/ChangeLog b/m4/ChangeLog index d4f2bc1b..af717c43 100644 --- a/m4/ChangeLog +++ b/m4/ChangeLog @@ -1,3 +1,7 @@ +2012-07-24 Mark Wielaard <mjw@redhat.com> + + * ax_cxx_compile_stdcxx_0x.m4: Add from autoconf-archive. + 2010-04-14 Roland McGrath <roland@redhat.com> * gettext.m4: Upgrade to gettext-0.17. diff --git a/m4/ax_cxx_compile_stdcxx_0x.m4 b/m4/ax_cxx_compile_stdcxx_0x.m4 new file mode 100644 index 00000000..a4e556ff --- /dev/null +++ b/m4/ax_cxx_compile_stdcxx_0x.m4 @@ -0,0 +1,107 @@ +# ============================================================================ +# http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_0x.html +# ============================================================================ +# +# SYNOPSIS +# +# AX_CXX_COMPILE_STDCXX_0X +# +# DESCRIPTION +# +# Check for baseline language coverage in the compiler for the C++0x +# standard. +# +# LICENSE +# +# Copyright (c) 2008 Benjamin Kosnik <bkoz@redhat.com> +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 7 + +AU_ALIAS([AC_CXX_COMPILE_STDCXX_0X], [AX_CXX_COMPILE_STDCXX_0X]) +AC_DEFUN([AX_CXX_COMPILE_STDCXX_0X], [ + AC_CACHE_CHECK(if g++ supports C++0x features without additional flags, + ax_cv_cxx_compile_cxx0x_native, + [AC_LANG_SAVE + AC_LANG_CPLUSPLUS + AC_TRY_COMPILE([ + template <typename T> + struct check + { + static_assert(sizeof(int) <= sizeof(T), "not big enough"); + }; + + typedef check<check<bool>> right_angle_brackets; + + int a; + decltype(a) b; + + typedef check<int> check_type; + check_type c; + check_type&& cr = static_cast<check_type&&>(c);],, + ax_cv_cxx_compile_cxx0x_native=yes, ax_cv_cxx_compile_cxx0x_native=no) + AC_LANG_RESTORE + ]) + + AC_CACHE_CHECK(if g++ supports C++0x features with -std=c++0x, + ax_cv_cxx_compile_cxx0x_cxx, + [AC_LANG_SAVE + AC_LANG_CPLUSPLUS + ac_save_CXXFLAGS="$CXXFLAGS" + CXXFLAGS="$CXXFLAGS -std=c++0x" + AC_TRY_COMPILE([ + template <typename T> + struct check + { + static_assert(sizeof(int) <= sizeof(T), "not big enough"); + }; + + typedef check<check<bool>> right_angle_brackets; + + int a; + decltype(a) b; + + typedef check<int> check_type; + check_type c; + check_type&& cr = static_cast<check_type&&>(c);],, + ax_cv_cxx_compile_cxx0x_cxx=yes, ax_cv_cxx_compile_cxx0x_cxx=no) + CXXFLAGS="$ac_save_CXXFLAGS" + AC_LANG_RESTORE + ]) + + AC_CACHE_CHECK(if g++ supports C++0x features with -std=gnu++0x, + ax_cv_cxx_compile_cxx0x_gxx, + [AC_LANG_SAVE + AC_LANG_CPLUSPLUS + ac_save_CXXFLAGS="$CXXFLAGS" + CXXFLAGS="$CXXFLAGS -std=gnu++0x" + AC_TRY_COMPILE([ + template <typename T> + struct check + { + static_assert(sizeof(int) <= sizeof(T), "not big enough"); + }; + + typedef check<check<bool>> right_angle_brackets; + + int a; + decltype(a) b; + + typedef check<int> check_type; + check_type c; + check_type&& cr = static_cast<check_type&&>(c);],, + ax_cv_cxx_compile_cxx0x_gxx=yes, ax_cv_cxx_compile_cxx0x_gxx=no) + CXXFLAGS="$ac_save_CXXFLAGS" + AC_LANG_RESTORE + ]) + + if test "$ax_cv_cxx_compile_cxx0x_native" = yes || + test "$ax_cv_cxx_compile_cxx0x_cxx" = yes || + test "$ax_cv_cxx_compile_cxx0x_gxx" = yes; then + AC_DEFINE(HAVE_STDCXX_0X,,[Define if g++ supports C++0x features. ]) + fi +]) diff --git a/tests/ChangeLog b/tests/ChangeLog index 8ca08ea6..bce27f4f 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,13 @@ +2012-07-24 Mark Wielaard <mjw@redhat.com> + + * testfile-cxx-various.bz2: New testfile. + * cxx-various.cxx: New test source. + * Makefile.am (cxx_various_SOURCES): New. + (HAVE_STDCXX_0X): Add cxx-various and -std=c++0x if exists. + (EXTRA_DIST): Add cxx-various.cxx and testfile-cxx-various.bz2. + * test-subr.sh: Add testfile-cxx-various and cxx-various to + self_test_files if they exist. + 2012-07-19 Mark Wielaard <mjw@redhat.com> * run-readelf-unknown-self.sh: New test. diff --git a/tests/Makefile.am b/tests/Makefile.am index 05705698..4c0c7654 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -97,6 +97,11 @@ check_PROGRAMS += $(asm_TESTS) TESTS += $(asm_TESTS) endif +if HAVE_STDCXX_0X +check_PROGRAMS += cxx-various +AM_CXXFLAGS = -std=c++0x +cxx_various_SOURCES = cxx-various.cc +endif EXTRA_DIST = run-arextract.sh run-arsymtest.sh \ run-show-die-info.sh run-get-files.sh run-get-lines.sh \ @@ -134,6 +139,7 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh \ run-readelf-test1.sh run-readelf-test2.sh run-readelf-test3.sh \ run-readelf-test4.sh run-readelf-twofiles.sh \ run-readelf-unknown-self.sh \ + cxx-various.cc testfile-cxx-various.bz2 \ run-bug1-test.sh testfile28.bz2 testfile28.rdwr.bz2 \ testfile29.bz2 testfile29.rdwr.bz2 \ testfile30.bz2 testfile31.bz2 testfile32.bz2 testfile33.bz2 \ diff --git a/tests/cxx-various.cc b/tests/cxx-various.cc new file mode 100644 index 00000000..5ddfc308 --- /dev/null +++ b/tests/cxx-various.cc @@ -0,0 +1,65 @@ +/* Test program for testing C++11 features are recognized. + Copyright (C) 2012 Red Hat, Inc. + This file is part of elfutils. + + This file is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + elfutils is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +// NOTE this file is the source of the binary testfile-cxx-various created +// with g++ -std=c++0x -g -o testfile-cxx-various cxx-various.cc +// +// When you edit this file to add more C++ contructs either create +// a new source file, or regenerate the binary test file. We always +// want to include the source code of all our test binaries. + +#include <iostream> +using namespace std; + +// Make sure we recognize the encoding of some of the standard types. +// char16_t and char_32_t use DW_ATE_UTF. +char c; +signed char sc; +unsigned char uc; +int i; +float f; +double d; +wchar_t wc; +char16_t c16; +char32_t c32; +long l; + +long +standard_types_func (char ac, signed char asc, unsigned char auc, + int ai, float af, double ad, wchar_t awc, + char16_t ac16, char32_t ac32, long al) +{ + c = ac; + sc = asc; + uc = auc; + i = ai; + f = af; + d = ad; + wc = awc; + c16 = ac16; + c32 = ac32; + l = al; + return ac + asc + auc + ai + af + ad + awc + ac16 + ac32 + al; +} + +int main () +{ + long answer; + answer = standard_types_func (1, 2, 3, 4, 5.0, 6.0, 7, 8, 9, -10L); + cout << "answer: " << answer << endl; + return 0; +} diff --git a/tests/test-subr.sh b/tests/test-subr.sh index e05d22a5..c78795f2 100644 --- a/tests/test-subr.sh +++ b/tests/test-subr.sh @@ -109,11 +109,21 @@ self_test_files=`echo ../src/addr2line ../src/elfcmp ../src/elflint \ ../src/size ../src/strip ../libelf/libelf.so ../libdw/libdw.so \ ../libasm/libasm.so ../backends/libebl_*.so` +# Prebuild binary in case we don't have a C++11 capable compiler around. +extra_self_test_files=testfile-cxx-various +self_test_files="$self_test_files $extra_self_test_files" + +# This file might not exist if we don't have a C++ compiler around. +if test -f cxx-various; then + self_test_files="$self_test_files cxx-various" +fi + # Provide a command to run on all self-test files with testrun. testrun_on_self() { exit_status=0 + testfiles $extra_self_test_files for file in $self_test_files; do testrun $* $file \ || { echo "*** failure in $* $file"; exit_status=1; } @@ -128,6 +138,7 @@ testrun_on_self_quiet() { exit_status=0 + testfiles $extra_self_test_files for file in $self_test_files; do testrun $* $file > /dev/null \ || { echo "*** failure in $* $file"; exit_status=1; } @@ -148,6 +159,7 @@ testrun_on_self_nomatch() exit_status=0 tempfiles self_matches.in self_matches.out + testfiles $extra_self_test_files for file in $self_test_files; do testrun "$@" $file > self_matches.in # egrep should fail to match anything, but we also want to show diff --git a/tests/testfile-cxx-various.bz2 b/tests/testfile-cxx-various.bz2 Binary files differnew file mode 100755 index 00000000..518bcf8b --- /dev/null +++ b/tests/testfile-cxx-various.bz2 |