[PATCH] Run selftests for C++ as well as C

David Malcolm dmalcolm@redhat.com
Fri Oct 12 18:17:00 GMT 2018


[re this thread "ToT build failure?":
  https://gcc.gnu.org/ml/gcc-patches/2017-07/msg00344.html ]

On Thu, 2017-07-06 at 20:58 +0200, Jakub Jelinek wrote:
> On Thu, Jul 06, 2017 at 01:45:42PM -0400, David Malcolm wrote:
> > Given that the previous status quo of the selftests was to require
> > the
> > C frontend, I committed the attached patch (as r250036), under the
> > "obvious" rule, retaining the ability to optionally run the
> > selftests
> > within the C++ frontend.
>
> You should do something similar for how we make check etc.:
> CHECK_TARGETS = @check_languages@
>
> check: $(CHECK_TARGETS)
>
> and then each Make-lang.in defining its check-<lang> goal.
> So similarly to that s-selftest-c++ should be in cp/Make-lang.in
> and based on the configured languages should include the s-selftest-
> <lang>
> dependencies.
>
> 	Jakub

Thanks.

I attemped the above, but it required each Make-lang.in to define
a check-<lang> goal, but there are only two that make sense to run
(those that set LANG_HOOKS_RUN_LANG_SELFTESTS: C and C++).

Rather than add one to every Make-lang.in, I borrowing the "append"
approach used by "lang_checks", so that only the Make-lang.in files
that opt-in to having selftests need to do anything, appending
their s-selftest-<LANG> to lang_selftests.

Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
I manually verified that the self-tests were run 6 times: C and C++,
for each of the three stages (each run taking well under a second).

OK for trunk?

gcc/ChangeLog:
	* Makefile.in (lang_selftests): New.
	(selftest) Change from s-selftest-c to $(lang_selftests).
	(C_SELFTEST_FLAGS, C_SELFTEST_DEPS, s-selftest-c, selftest-c-gdb)
	(selftest-gdb, selftest-c-valgrind, selftest-valgrind): Move to
	c/Make-lang.in.
	(CPP_SELFTEST_FLAGS, CPP_SELFTEST_DEPS, s-selftest-c++)
	(selftest-c++-gdb, selftest-c++-valgrind): Move to
	cp/Make-lang.in.

gcc/c/ChangeLog:
	* Make-lang.in: Append s-selftest-c to lang_selftests.
	(C_SELFTEST_FLAGS, C_SELFTEST_DEPS, s-selftest-c, selftest-c-gdb)
	(selftest-gdb, selftest-c-valgrind, selftest-valgrind): Move here
	from gcc/Makefile.in.

gcc/cp/ChangeLog:
	* Make-lang.in: Append s-selftest-c++ to lang_selftests.
	(CPP_SELFTEST_FLAGS, CPP_SELFTEST_DEPS, s-selftest-c++)
	(selftest-c++-gdb, selftest-c++-valgrind): Move here from
	gcc/Makefile.in.
---
 gcc/Makefile.in     | 51 ++++-----------------------------------------------
 gcc/c/Make-lang.in  | 32 ++++++++++++++++++++++++++++++++
 gcc/cp/Make-lang.in | 26 ++++++++++++++++++++++++++
 3 files changed, 62 insertions(+), 47 deletions(-)

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 116ed6e..dd4ae67 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -566,6 +566,7 @@ xm_defines=@xm_defines@
 lang_checks=
 lang_checks_parallelized=
 lang_opt_files=@lang_opt_files@ $(srcdir)/c-family/c.opt $(srcdir)/common.opt
+lang_selftests=
 lang_specs_files=@lang_specs_files@
 lang_tree_files=@lang_tree_files@
 target_cpu_default=@target_cpu_default@
@@ -1935,62 +1936,18 @@ DEVNULL=$(if $(findstring mingw,$(build)),nul,/dev/null)
 SELFTEST_FLAGS = -nostdinc $(DEVNULL) -S -o $(DEVNULL) \
 	-fself-test=$(srcdir)/testsuite/selftests
 
-C_SELFTEST_FLAGS = -xc $(SELFTEST_FLAGS)
-CPP_SELFTEST_FLAGS = -xc++ $(SELFTEST_FLAGS)
-
 SELFTEST_DEPS = $(GCC_PASSES) stmp-int-hdrs $(srcdir)/testsuite/selftests
 
-C_SELFTEST_DEPS = cc1$(exeext) $(SELFTEST_DEPS)
-CPP_SELFTEST_DEPS = cc1plus$(exeext) $(SELFTEST_DEPS)
-
 # Run the selftests during the build once we have a driver and the frontend,
 # so that self-test failures are caught as early as possible.
 # Use "s-selftest-FE" to ensure that we only run the selftests if the
 # driver, frontend, or selftest data change.
 .PHONY: selftest
 
-# By default, only run the selftests within the C frontend
-selftest: s-selftest-c
-
-# C selftests
-s-selftest-c: $(C_SELFTEST_DEPS)
-	$(GCC_FOR_TARGET) $(C_SELFTEST_FLAGS)
-	$(STAMP) $@
-
-# Convenience methods for running C selftests under gdb:
-.PHONY: selftest-c-gdb
-selftest-c-gdb: $(C_SELFTEST_DEPS)
-	$(GCC_FOR_TARGET) $(C_SELFTEST_FLAGS) \
-	  -wrapper gdb,--args
-
-.PHONY: selftest-gdb
-selftest-gdb: selftest-c-gdb
-
-# Convenience methods for running C selftests under valgrind:
-.PHONY: selftest-c-valgrind
-selftest-c-valgrind: $(C_SELFTEST_DEPS)
-	$(GCC_FOR_TARGET) $(C_SELFTEST_FLAGS) \
-	  -wrapper valgrind,--leak-check=full
-
-.PHONY: selftest-valgrind
-selftest-valgrind: selftest-c-valgrind
-
-# C++ selftests
-s-selftest-c++: $(CPP_SELFTEST_DEPS)
-	$(GCC_FOR_TARGET) $(CPP_SELFTEST_FLAGS)
-	$(STAMP) $@
+# The various FE/Make-lang.in can require the selftests to be run for
+# a given FE by appending "s-selftest-FE" to lang_selftests.
 
-# Convenience method for running C++ selftests under gdb:
-.PHONY: selftest-c++-gdb
-selftest-c++-gdb: $(CPP_SELFTEST_DEPS)
-	$(GCC_FOR_TARGET) $(CPP_SELFTEST_FLAGS) \
-	  -wrapper gdb,--args
-
-# Convenience method for running C++ selftests under valgrind:
-.PHONY: selftest-c++-valgrind
-selftest-c++-valgrind: $(CPP_SELFTEST_DEPS)
-	$(GCC_FOR_TARGET) $(CPP_SELFTEST_FLAGS) \
-	  -wrapper valgrind,--leak-check=full
+selftest: $(lang_selftests)
 
 # Recompile all the language-independent object files.
 # This is used only if the user explicitly asks for it.
diff --git a/gcc/c/Make-lang.in b/gcc/c/Make-lang.in
index 180923f..8a11e50 100644
--- a/gcc/c/Make-lang.in
+++ b/gcc/c/Make-lang.in
@@ -110,6 +110,38 @@ c.tags: force
 c.man:
 c.srcman:
 
+# C selftests
+
+# If C++ is enabled, require the selftests to be run for it
+# at each stage of the build:
+lang_selftests += s-selftest-c
+
+C_SELFTEST_FLAGS = -xc $(SELFTEST_FLAGS)
+C_SELFTEST_DEPS = cc1$(exeext) $(SELFTEST_DEPS)
+
+# Run the C selftests:
+s-selftest-c: $(C_SELFTEST_DEPS)
+	$(GCC_FOR_TARGET) $(C_SELFTEST_FLAGS)
+	$(STAMP) $@
+
+# Convenience methods for running C selftests under gdb:
+.PHONY: selftest-c-gdb
+selftest-c-gdb: $(C_SELFTEST_DEPS)
+	$(GCC_FOR_TARGET) $(C_SELFTEST_FLAGS) \
+	  -wrapper gdb,--args
+
+.PHONY: selftest-gdb
+selftest-gdb: selftest-c-gdb
+
+# Convenience methods for running C selftests under valgrind:
+.PHONY: selftest-c-valgrind
+selftest-c-valgrind: $(C_SELFTEST_DEPS)
+	$(GCC_FOR_TARGET) $(C_SELFTEST_FLAGS) \
+	  -wrapper valgrind,--leak-check=full
+
+.PHONY: selftest-valgrind
+selftest-valgrind: selftest-c-valgrind
+
 # List of targets that can use the generic check- rule and its // variant.
 lang_checks += check-gcc
 lang_checks_parallelized += check-gcc
diff --git a/gcc/cp/Make-lang.in b/gcc/cp/Make-lang.in
index fa8c1e6..dc1ebca 100644
--- a/gcc/cp/Make-lang.in
+++ b/gcc/cp/Make-lang.in
@@ -164,6 +164,32 @@ c++.man: doc/g++.1
 c++.srcman: doc/g++.1
 	-cp -p $^ $(srcdir)/doc
 
+# C++ selftests
+
+# If C++ is enabled, require the selftests to be run for it
+# at each stage of the build:
+lang_selftests += s-selftest-c++
+
+CPP_SELFTEST_DEPS = cc1plus$(exeext) $(SELFTEST_DEPS)
+CPP_SELFTEST_FLAGS = -xc++ $(SELFTEST_FLAGS)
+
+# Run the C++ selftests
+s-selftest-c++: $(CPP_SELFTEST_DEPS)
+	$(GCC_FOR_TARGET) $(CPP_SELFTEST_FLAGS)
+	$(STAMP) $@
+
+# Convenience method for running C++ selftests under gdb:
+.PHONY: selftest-c++-gdb
+selftest-c++-gdb: $(CPP_SELFTEST_DEPS)
+	$(GCC_FOR_TARGET) $(CPP_SELFTEST_FLAGS) \
+	  -wrapper gdb,--args
+
+# Convenience method for running C++ selftests under valgrind:
+.PHONY: selftest-c++-valgrind
+selftest-c++-valgrind: $(CPP_SELFTEST_DEPS)
+	$(GCC_FOR_TARGET) $(CPP_SELFTEST_FLAGS) \
+	  -wrapper valgrind,--leak-check=full
+
 # 'make check' in gcc/ looks for check-c++, as do all toplevel C++-related
 # check targets.  However, our DejaGNU framework requires 'check-g++' as its
 # entry point.  We feed the former to the latter here.
-- 
1.8.5.3



More information about the Gcc-patches mailing list