tests: add C++ header compatibility smoke test

Compiling an empty C file with most headers included and -Wc++-compat
gives us a build error if we introduce some stupid C++-incompatible
change.

While this won't catch everything, it's a good start.

Signed-off-by: David Lamparter <equinox@diac24.net>
This commit is contained in:
David Lamparter 2019-02-11 13:22:49 +01:00 committed by Renato Westphal
parent 7f04943d6b
commit 8ed561e1f1
4 changed files with 123 additions and 1 deletions

View file

@ -147,7 +147,7 @@ dnl - specifically, options to control warnings
AC_USE_SYSTEM_EXTENSIONS
AC_DEFUN([AC_C_FLAG], [{
m4_pushdef([cachename],[m4_translit([frr_cv_$1],[ =-],[___])])
m4_pushdef([cachename],[m4_translit([frr_cv_$1],[ =-+],[____])])
AC_CACHE_CHECK([[whether $CC supports $1]], cachename, [
AC_LANG_PUSH([C])
ac_c_flag_save="$CFLAGS"
@ -261,6 +261,9 @@ fi
AC_C_FLAG([-Wno-unused-parameter])
AC_C_FLAG([-Wno-missing-field-initializers])
AC_C_FLAG([-Wc++-compat], [], [CXX_COMPAT_CFLAGS="-Wc++-compat"])
AC_SUBST([CXX_COMPAT_CFLAGS])
dnl ICC emits a broken warning for const char *x = a ? "b" : "c";
dnl for some reason the string consts get 'promoted' to char *,
dnl triggering a const to non-const conversion warning.

1
tests/.gitignore vendored
View file

@ -19,6 +19,7 @@
/lib/cli/test_commands
/lib/cli/test_commands_defun.c
/lib/northbound/test_oper_data
/lib/cxxcompat
/lib/test_buffer
/lib/test_checksum
/lib/test_graph

113
tests/lib/cxxcompat.c Normal file
View file

@ -0,0 +1,113 @@
/*
* C++ compatibility compile-time smoketest
* Copyright (C) 2019 David Lamparter for NetDEF, Inc.
*
* This program 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 2 of the License, or (at your option)
* any later version.
*
* This program 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; see the file COPYING; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "lib/zebra.h"
#include "lib/agg_table.h"
#include "lib/bfd.h"
#include "lib/bitfield.h"
#include "lib/buffer.h"
#include "lib/checksum.h"
#include "lib/command.h"
#include "lib/command_graph.h"
#include "lib/command_match.h"
#include "lib/compiler.h"
#include "lib/csv.h"
#include "lib/debug.h"
#include "lib/distribute.h"
#include "lib/event_counter.h"
#include "lib/ferr.h"
#include "lib/fifo.h"
#include "lib/filter.h"
#include "lib/frr_pthread.h"
#include "lib/frratomic.h"
#include "lib/frrstr.h"
#include "lib/getopt.h"
#include "lib/graph.h"
#include "lib/hash.h"
#include "lib/hook.h"
#include "lib/id_alloc.h"
#include "lib/if.h"
#include "lib/if_rmap.h"
#include "lib/imsg.h"
#include "lib/ipaddr.h"
#include "lib/jhash.h"
#include "lib/json.h"
#include "lib/keychain.h"
#include "lib/lib_errors.h"
#include "lib/libfrr.h"
#include "lib/libospf.h"
#include "lib/linklist.h"
#include "lib/log.h"
#include "lib/logicalrouter.h"
#include "lib/md5.h"
#include "lib/memory.h"
#include "lib/memory_vty.h"
#include "lib/mlag.h"
#include "lib/module.h"
#include "lib/monotime.h"
#include "lib/mpls.h"
#include "lib/network.h"
#include "lib/nexthop.h"
#include "lib/nexthop_group.h"
#include "lib/northbound.h"
#include "lib/northbound_cli.h"
#include "lib/northbound_db.h"
#include "lib/ns.h"
#include "lib/openbsd-tree.h"
#include "lib/pbr.h"
#include "lib/plist.h"
#include "lib/pqueue.h"
#include "lib/prefix.h"
#include "lib/privs.h"
#include "lib/ptm_lib.h"
#include "lib/pw.h"
#include "lib/qobj.h"
#include "lib/queue.h"
#include "lib/ringbuf.h"
#include "lib/routemap.h"
#include "lib/sbuf.h"
#include "lib/sha256.h"
#include "lib/sigevent.h"
#include "lib/skiplist.h"
#include "lib/sockopt.h"
#include "lib/sockunion.h"
#include "lib/spf_backoff.h"
#include "lib/srcdest_table.h"
#include "lib/stream.h"
#include "lib/table.h"
#include "lib/termtable.h"
#include "lib/thread.h"
#include "lib/vector.h"
#include "lib/vlan.h"
#include "lib/vrf.h"
#include "lib/vty.h"
#include "lib/vxlan.h"
#include "lib/wheel.h"
/* #include "lib/workqueue.h" -- macro problem with STAILQ_LAST */
#include "lib/yang.h"
#include "lib/yang_translator.h"
#include "lib/yang_wrappers.h"
#include "lib/zassert.h"
#include "lib/zclient.h"
int main(int argc, char **argv)
{
return 0;
}

View file

@ -46,6 +46,7 @@ tests/ospf6d/tests_ospf6d_test_lsdb-test_lsdb.$(OBJEXT): tests/ospf6d/test_lsdb_
tests/ospf6d/test_lsdb-test_lsdb.$(OBJEXT): tests/ospf6d/test_lsdb_clippy.c
check_PROGRAMS = \
tests/lib/cxxcompat \
tests/lib/test_buffer \
tests/lib/test_checksum \
tests/lib/test_heavy_thread \
@ -170,6 +171,10 @@ tests_isisd_test_isis_vertex_queue_CPPFLAGS = $(TESTS_CPPFLAGS)
tests_isisd_test_isis_vertex_queue_LDADD = $(ISISD_TEST_LDADD)
tests_isisd_test_isis_vertex_queue_SOURCES = tests/isisd/test_isis_vertex_queue.c
tests_lib_cxxcompat_CFLAGS = $(TESTS_CFLAGS) $(CXX_COMPAT_CFLAGS) $(WERROR)
tests_lib_cxxcompat_CPPFLAGS = $(TESTS_CPPFLAGS)
tests_lib_cxxcompat_SOURCES = tests/lib/cxxcompat.c
tests_lib_cxxcompat_LDADD = $(ALL_TESTS_LDADD)
tests_lib_cli_test_cli_CFLAGS = $(TESTS_CFLAGS)
tests_lib_cli_test_cli_CPPFLAGS = $(TESTS_CPPFLAGS)
tests_lib_cli_test_cli_LDADD = $(ALL_TESTS_LDADD)