From ffa98da4709d365d291955d8564b8be683d56ed7 Mon Sep 17 00:00:00 2001
From: Ian Lance Taylor <ian@gcc.gnu.org>
Date: Tue, 1 Jul 2014 23:19:24 +0000
Subject: [PATCH] runtime: introduce build targets for running benchmarks

This introduces the "bench" build target, which can be used to run
all benchmarks.

It is also possible to run subsets of benchmarks with the
"package/check" build targets by setting GOBENCH to a matching regex.

From-SVN: r212212
---
 libgo/Makefile.am      |  6 ++++++
 libgo/Makefile.in      |  6 ++++++
 libgo/testsuite/gotest | 46 +++++++++++++++++++++++++++++-------------
 3 files changed, 44 insertions(+), 14 deletions(-)

diff --git a/libgo/Makefile.am b/libgo/Makefile.am
index a88f0b7f24c3..7466a1770883 100644
--- a/libgo/Makefile.am
+++ b/libgo/Makefile.am
@@ -1996,6 +1996,7 @@ BUILDPACKAGE = \
 	$(LTGOCOMPILE) -I . -c -fgo-pkgpath=`echo $@ | sed -e 's/.lo$$//' -e 's/-go$$//'` -o $@ $$files
 
 GOTESTFLAGS =
+GOBENCH = 
 
 # Check a package.
 CHECK = \
@@ -2015,6 +2016,8 @@ CHECK = \
 	rm -f $@-testsum $@-testlog; \
 	if test "$(USE_DEJAGNU)" = "yes"; then \
 	  $(SHELL) $(srcdir)/testsuite/gotest --dejagnu=yes --basedir=$(srcdir) --srcdir=$(srcdir)/go/$(@D) --pkgpath="$(@D)" --pkgfiles="$(go_$(subst /,_,$(@D))_files)" --testname="$(@D)" --goarch="$(GOARCH)" $(GOTESTFLAGS) $(go_$(subst /,_,$(@D))_test_files); \
+	elif test "$(GOBENCH)" != ""; then \
+	  $(SHELL) $(srcdir)/testsuite/gotest --basedir=$(srcdir) --srcdir=$(srcdir)/go/$(@D) --pkgpath="$(@D)" --pkgfiles="$(go_$(subst /,_,$(@D))_files)" --goarch="$(GOARCH)" --bench="$(GOBENCH)" $(GOTESTFLAGS) $(go_$(subst /,_,$(@D))_test_files); \
 	else \
 	  if $(SHELL) $(srcdir)/testsuite/gotest --basedir=$(srcdir) --srcdir=$(srcdir)/go/$(@D) --pkgpath="$(@D)" --pkgfiles="$(go_$(subst /,_,$(@D))_files)" --goarch="$(GOARCH)" $(GOTESTFLAGS) $(go_$(subst /,_,$(@D))_test_files) >>$@-testlog 2>&1; then \
 	    echo "PASS: $(@D)" >> $@-testlog; \
@@ -3845,6 +3848,9 @@ check-am:
 check-multi:
 	$(MULTIDO) $(AM_MAKEFLAGS) DO=check-am multi-do # $(MAKE)
 
+bench:
+	-@$(MAKE) -k $(TEST_PACKAGES) GOBENCH=.
+
 MOSTLYCLEAN_FILES = libgo.head libgo.sum.sep libgo.log.sep
 
 mostlyclean-local:
diff --git a/libgo/Makefile.in b/libgo/Makefile.in
index 73620f772d88..dd94285f1d59 100644
--- a/libgo/Makefile.in
+++ b/libgo/Makefile.in
@@ -2066,6 +2066,7 @@ BUILDPACKAGE = \
 	$(LTGOCOMPILE) -I . -c -fgo-pkgpath=`echo $@ | sed -e 's/.lo$$//' -e 's/-go$$//'` -o $@ $$files
 
 GOTESTFLAGS = 
+GOBENCH = 
 
 # Check a package.
 CHECK = \
@@ -2085,6 +2086,8 @@ CHECK = \
 	rm -f $@-testsum $@-testlog; \
 	if test "$(USE_DEJAGNU)" = "yes"; then \
 	  $(SHELL) $(srcdir)/testsuite/gotest --dejagnu=yes --basedir=$(srcdir) --srcdir=$(srcdir)/go/$(@D) --pkgpath="$(@D)" --pkgfiles="$(go_$(subst /,_,$(@D))_files)" --testname="$(@D)" --goarch="$(GOARCH)" $(GOTESTFLAGS) $(go_$(subst /,_,$(@D))_test_files); \
+	elif test "$(GOBENCH)" != ""; then \
+	  $(SHELL) $(srcdir)/testsuite/gotest --basedir=$(srcdir) --srcdir=$(srcdir)/go/$(@D) --pkgpath="$(@D)" --pkgfiles="$(go_$(subst /,_,$(@D))_files)" --goarch="$(GOARCH)" --bench="$(GOBENCH)" $(GOTESTFLAGS) $(go_$(subst /,_,$(@D))_test_files); \
 	else \
 	  if $(SHELL) $(srcdir)/testsuite/gotest --basedir=$(srcdir) --srcdir=$(srcdir)/go/$(@D) --pkgpath="$(@D)" --pkgfiles="$(go_$(subst /,_,$(@D))_files)" --goarch="$(GOARCH)" $(GOTESTFLAGS) $(go_$(subst /,_,$(@D))_test_files) >>$@-testlog 2>&1; then \
 	    echo "PASS: $(@D)" >> $@-testlog; \
@@ -6083,6 +6086,9 @@ check-am:
 check-multi:
 	$(MULTIDO) $(AM_MAKEFLAGS) DO=check-am multi-do # $(MAKE)
 
+bench:
+	-@$(MAKE) -k $(TEST_PACKAGES) GOBENCH=.
+
 mostlyclean-local:
 	find . -name '*.lo' -print | xargs $(LIBTOOL) --mode=clean rm -f
 	find . -name '*.$(OBJEXT)' -print | xargs rm -f
diff --git a/libgo/testsuite/gotest b/libgo/testsuite/gotest
index 155c7a8619ae..39beac393c6c 100755
--- a/libgo/testsuite/gotest
+++ b/libgo/testsuite/gotest
@@ -36,6 +36,7 @@ dejagnu=no
 GOARCH=""
 timeout=240
 testname=""
+bench=""
 trace=false
 while $loop; do
 	case "x$1" in
@@ -124,6 +125,15 @@ while $loop; do
 		testname=`echo $1 | sed -e 's/^--testname=//'`
 		shift
 		;;
+	x--bench)
+		bench=$2
+		shift
+		shift
+		;;
+	x--bench=*)
+		bench=`echo $1 | sed -e 's/^--bench=//'`
+		shift
+		;;
 	x--trace)
 		trace=true
 		shift
@@ -473,20 +483,28 @@ xno)
 	fi
 	${GL} *.o ${GOLIBS}
 
-	if test "$trace" = "true"; then
-	    echo ./a.out -test.short -test.timeout=${timeout}s "$@"
-	fi
-	./a.out -test.short -test.timeout=${timeout}s "$@" &
-	pid=$!
-	(sleep `expr $timeout + 10`
-	    echo > gotest-timeout
-	    echo "timed out in gotest" 1>&2
-	    kill -9 $pid) &
-	alarmpid=$!
-	wait $pid
-	status=$?
-	if ! test -f gotest-timeout; then
-	    kill $alarmpid
+	if test "$bench" = ""; then
+		if test "$trace" = "true"; then
+		    echo ./a.out -test.short -test.timeout=${timeout}s "$@"
+		fi
+		./a.out -test.short -test.timeout=${timeout}s "$@" &
+		pid=$!
+		(sleep `expr $timeout + 10`
+		    echo > gotest-timeout
+		    echo "timed out in gotest" 1>&2
+		    kill -9 $pid) &
+		alarmpid=$!
+		wait $pid
+		status=$?
+		if ! test -f gotest-timeout; then
+		    kill $alarmpid
+		fi
+	else
+		if test "$trace" = "true"; then
+		    echo ./a.out -test.run=^\$ -test.bench="${bench}" "$@"
+		fi
+		./a.out -test.run=^\$ -test.bench="${bench}" "$@"
+		status=$?
 	fi
 	exit $status
 	;;
-- 
GitLab