Add parameter to allow enabling/disabling selftests via configure
authorSergio Durigan Junior <sergiodj@redhat.com>
Mon, 17 Sep 2018 19:58:55 +0000 (15:58 -0400)
committerSergio Durigan Junior <sergiodj@redhat.com>
Wed, 10 Oct 2018 20:23:56 +0000 (16:23 -0400)
This is a follow-up of:

  https://sourceware.org/ml/gdb-patches/2018-08/msg00347.html

Instead of going throttle and always enabling our selftests (even in
non-development builds), this patch is a bit more conservative and
introduces a configure option ("--enable-unit-tests") that allows the
user to choose whether she wants unit tests in the build or not.  Note
that the current behaviour is retained: if no option is provided, GDB
will have selftests included in a development build, and will *not*
have selftests included in a non-development build.

The rationale for having this option is still the same: due to the
many racy testcases and random failures we see when running the GDB
testsuite, it is unfortunately not possible to perform a full test
when one is building a downstream package.  As the Fedora GDB
maintainer and one of the Debian GDB uploaders, I feel like this
situation could be improved by, at least, executing our selftests
after the package has been built.

This patch introduces no regressions to our build.

OK?

gdb/ChangeLog:
2018-10-10  Sergio Durigan Junior  <sergiodj@redhat.com>
    Simon Marchi <simark@simark.ca>

* README (`configure' options): Add documentation for new
"--enable-unit-tests" option.
* acinclude.m4: Include "selftest.m4".
* configure: Regenerate.
* configure.ac: Use "GDB_AC_SELFTEST".
* maint.c (maintenance_selftest): Update message informing
that selftests have been disabled.
(maintenance_info_selftests): Likewise.
* selftest.m4: New file.

gdb/gdbserver/ChangeLog:
2018-10-10  Sergio Durigan Junior  <sergiodj@redhat.com>
    Simon Marchi <simark@simark.ca>

* acinclude.m4: Include "../selftest.m4".
* configure: Regenerate.
* configure.ac: Use "GDB_AC_SELFTEST".
* configure.srv: Use "$enable_unittests" instead of
"$development" when checking whether unit tests have been
enabled.
* server.c (captured_main): Update message informing that
selftests have been disabled.

gdb/testsuite/ChangeLog:
2018-10-10  Sergio Durigan Junior  <sergiodj@redhat.com>

* gdb.gdb/unittest.exp: Update expected message informing that
selftests have been disabled.
* gdb.server/unittest.exp: Likewise.

squash! Add parameter to allow enabling/disabling selftests via configure

16 files changed:
gdb/ChangeLog
gdb/README
gdb/acinclude.m4
gdb/configure
gdb/configure.ac
gdb/gdbserver/ChangeLog
gdb/gdbserver/acinclude.m4
gdb/gdbserver/configure
gdb/gdbserver/configure.ac
gdb/gdbserver/configure.srv
gdb/gdbserver/server.c
gdb/maint.c
gdb/selftest.m4 [new file with mode: 0644]
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.gdb/unittest.exp
gdb/testsuite/gdb.server/unittest.exp

index aac5b7a09a80bd677be85a21964ecbb5ca81fcdb..e28b464f207fc743ab3f238ba84f1fe08369fd80 100644 (file)
@@ -1,3 +1,16 @@
+2018-10-10  Sergio Durigan Junior  <sergiodj@redhat.com>
+           Simon Marchi <simark@simark.ca>
+
+       * README (`configure' options): Add documentation for new
+       "--enable-unit-tests" option.
+       * acinclude.m4: Include "selftest.m4".
+       * configure: Regenerate.
+       * configure.ac: Use "GDB_AC_SELFTEST".
+       * maint.c (maintenance_selftest): Update message informing
+       that selftests have been disabled.
+       (maintenance_info_selftests): Likewise.
+       * selftest.m4: New file.
+
 2018-10-10  Gary Benson <gbenson@redhat.com>
 
        * remote.c (remote_target::remote_send_printf): Add
index 69ba0eb8dfe078bafba950a08dd4583de7cdaf6f..8a91aab2a4c644690782d34f7b33835cc8d65440 100644 (file)
@@ -545,6 +545,12 @@ more obscure GDB `configure' options are not listed here.
      behavior.  It has a performance cost, so if you are looking at
      GDB's performance, you should disable it.
 
+`--enable-unit-tests[=yes|no]'
+     Enable (i.e., include) support for unit tests when compiling GDB
+     and GDBServer.  Note that if this option is not passed, GDB will
+     have selftests if it is a development build, and will *not* have
+     selftests if it is a non-development build.
+
 `configure' accepts other options, for compatibility with configuring
 other GNU tools recursively.
 
index 52ba3f9ed6e10a9745a1ce1bd41db8881e31d0f8..d21dd76fab9c2f27a88639b8eeeeedb8e6550b25 100644 (file)
@@ -18,6 +18,9 @@ sinclude(warning.m4)
 # AM_GDB_UBSAN
 sinclude(sanitize.m4)
 
+# This gets GDB_AC_SELFTEST.
+sinclude(selftest.m4)
+
 dnl gdb/configure.in uses BFD_NEED_DECLARATION, so get its definition.
 sinclude(../bfd/bfd.m4)
 
index adb26e5d4d3fa30ea5e374746133f511e4c5ac17..3652455322f5bfe5f9caf967ddc6f785372eb976 100755 (executable)
@@ -896,6 +896,7 @@ enable_sim
 enable_gdbserver
 with_babeltrace
 with_libbabeltrace_prefix
+enable_unit_tests
 '
       ac_precious_vars='build_alias
 host_alias
@@ -1561,6 +1562,8 @@ Optional Features:
   --enable-sim            link gdb with simulator
   --enable-gdbserver      automatically build gdbserver (yes/no/auto, default
                           is auto)
+  --enable-unit-tests     Enable the inclusion of unit tests when compiling
+                          GDB
 
 Optional Packages:
   --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
@@ -17838,15 +17841,37 @@ ac_config_links="$ac_config_links $ac_config_links_1"
 $as_echo "#define GDB_DEFAULT_HOST_CHARSET \"UTF-8\"" >>confdefs.h
 
 
-if $development; then
+
+# Check whether we will enable the inclusion of unit tests when
+# compiling GDB.
+#
+# The default value of this option changes depending whether we're on
+# development mode (in which case it's "true") or not (in which case
+# it's "false").
+# Check whether --enable-unit-tests was given.
+if test "${enable_unit_tests+set}" = set; then :
+  enableval=$enable_unit_tests; case "${enableval}" in
+  yes)  enable_unittests=true  ;;
+  no)   enable_unittests=false ;;
+  *)    as_fn_error $? "bad value ${enableval} for --{enable,disable}-unit-tests option" "$LINENO" 5 ;;
+esac
+else
+  enable_unittests=$development
+fi
+
+
+if $enable_unittests; then
 
 $as_echo "#define GDB_SELF_TEST 1" >>confdefs.h
 
+
   CONFIG_OBS="$CONFIG_OBS \$(SUBDIR_UNITTESTS_OBS) common/selftest.o selftest-arch.o"
   CONFIG_SRCS="$CONFIG_SRCS \$(SUBDIR_UNITTESTS_SRCS) common/selftest.c selftest-arch.c"
+
 fi
 
 
+
   gdb_ac_transform=`echo "$program_transform_name" | sed -e 's/\\$\\$/\\$/g'`
   GDB_TRANSFORM_NAME=`echo gdb | sed -e "$gdb_ac_transform"`
   if test "x$GDB_TRANSFORM_NAME" = x; then
index dfb7c87171306d120750b88604dbe6a025f5d679..b2343a90e5fa6d2810465caff9441ce042f51282 100644 (file)
@@ -2247,12 +2247,10 @@ dnl  At the moment, we just assume it's UTF-8.
 AC_DEFINE(GDB_DEFAULT_HOST_CHARSET, "UTF-8",
           [Define to be a string naming the default host character set.])
 
-if $development; then
-  AC_DEFINE(GDB_SELF_TEST, 1,
-            [Define if self-testing features should be enabled])
+GDB_AC_SELFTEST([
   CONFIG_OBS="$CONFIG_OBS \$(SUBDIR_UNITTESTS_OBS) common/selftest.o selftest-arch.o"
   CONFIG_SRCS="$CONFIG_SRCS \$(SUBDIR_UNITTESTS_SRCS) common/selftest.c selftest-arch.c"
-fi
+])
 
 GDB_AC_TRANSFORM([gdb], [GDB_TRANSFORM_NAME])
 GDB_AC_TRANSFORM([gcore], [GCORE_TRANSFORM_NAME])
index da4c24f225120cb2c1e223e82a2e7b6fb34e7b87..27f7ab55dbcdac08d5e54c3d56a426c13a68e8ce 100644 (file)
@@ -1,3 +1,15 @@
+2018-10-10  Sergio Durigan Junior  <sergiodj@redhat.com>
+           Simon Marchi <simark@simark.ca>
+
+       * acinclude.m4: Include "../selftest.m4".
+       * configure: Regenerate.
+       * configure.ac: Use "GDB_AC_SELFTEST".
+       * configure.srv: Use "$enable_unittests" instead of
+       "$development" when checking whether unit tests have been
+       enabled.
+       * server.c (captured_main): Update message informing that
+       selftests have been disabled.
+
 2018-10-04  Tom Tromey  <tom@tromey.com>
 
        * configure: Rebuild.
index c75d783f57bb860536c2fe1dad938b89241c240b..fc3e344a611a12e0a77563289d164aaf2dc11781 100644 (file)
@@ -31,6 +31,9 @@ m4_include(../ptrace.m4)
 
 m4_include(../ax_cxx_compile_stdcxx.m4)
 
+dnl For GDB_AC_SELFTEST.
+m4_include(../selftest.m4)
+
 dnl Check for existence of a type $1 in libthread_db.h
 dnl Based on BFD_HAVE_SYS_PROCFS_TYPE in bfd/bfd.m4.
 
index a46b865f612a8e164c497ffa264e701166bfa2c3..1ddbd6b27e0adcd825f467f377accf2eabfc3b4a 100755 (executable)
@@ -722,6 +722,7 @@ enable_option_checking
 enable_maintainer_mode
 enable_largefile
 enable_libmcheck
+enable_unit_tests
 with_ust
 with_ust_include
 with_ust_lib
@@ -1367,6 +1368,8 @@ Optional Features:
                           sometimes confusing) to the casual installer
   --disable-largefile     omit support for large files
   --enable-libmcheck      Try linking with -lmcheck if available
+  --enable-unit-tests     Enable the inclusion of unit tests when compiling
+                          GDB
   --enable-werror         treat compile warnings as errors
   --enable-build-warnings enable build-time compiler warnings if gcc is used
   --enable-gdb-build-warnings
@@ -5889,13 +5892,35 @@ fi
   fi
 
 
-if $development; then
-  srv_selftest_objs="common/selftest.o"
+
+# Check whether we will enable the inclusion of unit tests when
+# compiling GDB.
+#
+# The default value of this option changes depending whether we're on
+# development mode (in which case it's "true") or not (in which case
+# it's "false").
+# Check whether --enable-unit-tests was given.
+if test "${enable_unit_tests+set}" = set; then :
+  enableval=$enable_unit_tests; case "${enableval}" in
+  yes)  enable_unittests=true  ;;
+  no)   enable_unittests=false ;;
+  *)    as_fn_error $? "bad value ${enableval} for --{enable,disable}-unit-tests option" "$LINENO" 5 ;;
+esac
+else
+  enable_unittests=$development
+fi
+
+
+if $enable_unittests; then
 
 $as_echo "#define GDB_SELF_TEST 1" >>confdefs.h
 
+
+  srv_selftest_objs="common/selftest.o"
+
 fi
 
+
  case ${build_alias} in
   "") build_noncanonical=${build} ;;
   *) build_noncanonical=${build_alias} ;;
index fa3ca53efdc0cd68dc2fa94beadeb25b19bd6532..f1dfa4546cce09adbc4d6444db0d90d20fe590ce 100644 (file)
@@ -54,11 +54,9 @@ else
 fi
 GDB_AC_LIBMCHECK(${libmcheck_default})
 
-if $development; then
+GDB_AC_SELFTEST([
   srv_selftest_objs="common/selftest.o"
-  AC_DEFINE(GDB_SELF_TEST, 1,
-            [Define if self-testing features should be enabled])
-fi
+])
 
 ACX_NONCANONICAL_TARGET
 ACX_NONCANONICAL_HOST
index 72e6a0d87f46d7af052cac841582849089d14734..636d830f1a2feda72dc7f65aa852ebb125506392 100644 (file)
@@ -24,7 +24,7 @@
 # Default hostio_last_error implementation
 srv_hostio_err_objs="hostio-errno.o"
 
-if $development; then
+if $enable_unittests; then
    srv_i386_linux_regobj="i386-linux.o i386-avx-linux.o i386-avx-avx512-linux.o i386-avx-mpx-avx512-pku-linux.o i386-mpx-linux.o i386-avx-mpx-linux.o i386-mmx-linux.o linux-x86-tdesc-selftest.o"
    srv_amd64_linux_regobj="amd64-linux.o amd64-avx-linux.o amd64-avx-avx512-linux.o amd64-avx-mpx-avx512-pku-linux.o amd64-mpx-linux.o amd64-avx-mpx-linux.o x32-linux.o x32-avx-linux.o x32-avx-avx512-linux.o"
 else
index d711c53e5fd6520648ef973552bf893344eff774..4ec3548d64444ac11e5417f4d7b40acb6dcfe27d 100644 (file)
@@ -3790,7 +3790,7 @@ captured_main (int argc, char *argv[])
 #if GDB_SELF_TEST
       selftests::run_tests (selftest_filter);
 #else
-      printf (_("Selftests are not available in a non-development build.\n"));
+      printf (_("Selftests have been disabled for this build.\n"));
 #endif
       throw_quit ("Quit");
     }
index 19db8a850b3a8e1bd85584a2a06cac13c377923e..01a80f5d732645ba03357c59cbfcf58cd9292bb1 100644 (file)
@@ -943,7 +943,7 @@ maintenance_selftest (const char *args, int from_tty)
   selftests::run_tests (args);
 #else
   printf_filtered (_("\
-Selftests are not available in a non-development build.\n"));
+Selftests have been disabled for this build.\n"));
 #endif
 }
 
@@ -957,7 +957,7 @@ maintenance_info_selftests (const char *arg, int from_tty)
   });
 #else
   printf_filtered (_("\
-Selftests are not available in a non-development build.\n"));
+Selftests have been disabled for this build.\n"));
 #endif
 }
 
diff --git a/gdb/selftest.m4 b/gdb/selftest.m4
new file mode 100644 (file)
index 0000000..acf4050
--- /dev/null
@@ -0,0 +1,45 @@
+dnl Copyright (C) 2018 Free Software Foundation, Inc.
+dnl
+dnl This file is part of GDB.
+dnl
+dnl This program is free software; you can redistribute it and/or modify
+dnl it under the terms of the GNU General Public License as published by
+dnl the Free Software Foundation; either version 3 of the License, or
+dnl (at your option) any later version.
+dnl
+dnl This program is distributed in the hope that it will be useful,
+dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
+dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+dnl GNU General Public License for more details.
+dnl
+dnl You should have received a copy of the GNU General Public License
+dnl along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+dnl GDB_AC_SELFTEST(ACTION-IF-ENABLED)
+dnl
+dnl Enable the unit/self tests if needed.  If they are enabled, AC_DEFINE
+dnl the GDB_SELF_TEST macro, and execute ACTION-IF-ENABLED.
+
+AC_DEFUN([GDB_AC_SELFTEST],[
+# Check whether we will enable the inclusion of unit tests when
+# compiling GDB.
+#
+# The default value of this option changes depending whether we're on
+# development mode (in which case it's "true") or not (in which case
+# it's "false").
+AC_ARG_ENABLE(unit-tests,
+AS_HELP_STRING([--enable-unit-tests],
+[Enable the inclusion of unit tests when compiling GDB]),
+[case "${enableval}" in
+  yes)  enable_unittests=true  ;;
+  no)   enable_unittests=false ;;
+  *)    AC_MSG_ERROR(
+[bad value ${enableval} for --{enable,disable}-unit-tests option]) ;;
+esac], [enable_unittests=$development])
+
+if $enable_unittests; then
+  AC_DEFINE(GDB_SELF_TEST, 1,
+            [Define if self-testing features should be enabled])
+  $1
+fi
+])
index c6275787149d5e66117ec807a3649b85f37b6bf3..f907323f9615cb7d54b5e49c9df457ad3902a139 100644 (file)
@@ -1,3 +1,9 @@
+2018-10-10  Sergio Durigan Junior  <sergiodj@redhat.com>
+
+       * gdb.gdb/unittest.exp: Update expected message informing that
+       selftests have been disabled.
+       * gdb.server/unittest.exp: Likewise.
+
 2018-10-09  Tom de Vries  <tdevries@suse.de>
 
        * lib/gdb.exp (target_supports_scheduler_locking): Replace gdb_start_cmd
index 1c835850b8d30ef9cb0ddebddf70ee79ec56f473..8e3e9a1761c9621619e3ac853c7ad5afd71cfac3 100644 (file)
@@ -24,7 +24,7 @@ gdb_test_multiple $test $test {
        gdb_assert "$num_ran > 0" $test
   }
 
-  -re "Selftests are not available in a non-development build.\r\n$gdb_prompt $" {
+  -re "Selftests have been disabled for this build.\r\n$gdb_prompt $" {
        unsupported $test
   }
 }
index e947ff2c30f97651f70b3f8cb1d98062d1133a2e..b0a7c6ae565ab146414091a79f9e750a0819df7f 100644 (file)
@@ -38,7 +38,7 @@ gdb_expect {
        gdb_assert "$num_ran > 0" $test
     }
 
-    -re "Selftests are not available in a non-development build.\r\n$" {
+    -re "Selftests have been disabled for this build.\r\n$" {
        unsupported $test
     }
 
This page took 0.050829 seconds and 4 git commands to generate.