]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
tests: Add C++ self test binary.
authorMark Wielaard <mjw@redhat.com>
Tue, 24 Jul 2012 17:18:52 +0000 (19:18 +0200)
committerMark Wielaard <mjw@redhat.com>
Thu, 16 Aug 2012 20:26:23 +0000 (22:26 +0200)
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>
ChangeLog
configure.ac
m4/ChangeLog
m4/ax_cxx_compile_stdcxx_0x.m4 [new file with mode: 0644]
tests/ChangeLog
tests/Makefile.am
tests/cxx-various.cc [new file with mode: 0644]
tests/test-subr.sh
tests/testfile-cxx-various.bz2 [new file with mode: 0755]

index 5842492b8d620e6e5aca1ab0fb2cc549312e7e43..3be157c8d29b2c8dd0b379b340b7f08b2326fa12 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+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).
index 7932489751692a15b55dad40c1bb071a8fe0b40b..50db3430883f5abda983c4eef1798707b76a8b34 100644 (file)
@@ -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"
index d4f2bc1b2ad8b6996e72b33e2a477a0b3c988a09..af717c4317ec790ef105a3a29d357ff49acc2c43 100644 (file)
@@ -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 (file)
index 0000000..a4e556f
--- /dev/null
@@ -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
+])
index 8ca08ea6240197ae696c82a87108bcd20475df6e..bce27f4fc2c31115ae0b39a97d818fde210a62c3 100644 (file)
@@ -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.
index 05705698a0301c4ecd7cbff71ae2cdc942655862..4c0c7654ce37f0ec51c94a0f58d8da77465cac5a 100644 (file)
@@ -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 (file)
index 0000000..5ddfc30
--- /dev/null
@@ -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;
+}
index e05d22a525c97f7c03d8f495e2562b6db3cdeee5..c78795f286b86b31afde7b4704e66603ce71d00b 100644 (file)
@@ -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
new file mode 100755 (executable)
index 0000000..518bcf8
Binary files /dev/null and b/tests/testfile-cxx-various.bz2 differ