On Wed, Jun 14, 2017 at 9:48 AM, Ian Lance Taylor <i...@golang.org> wrote:
> This patch to the gotools Makefile adds a check target.  This initial
> implementation of the check target tests the go tool by running the
> existing testsuite in libgo/go/cmd/go.  Bootstrapped and ran Go
> testsuite on x86_64-pc-linux-gnu.
>
> Ian
>
> 2017-06-14  Ian Lance Taylor  <i...@golang.org>
>
> * Makefile.am (libgosrcdir): Define.
> (check-head, check-gccgo, check-go-tool): New targets.
> (CHECK_ENV): Define.
> (check): New target.
> (mostlyclean-local): New target.
> * Makefile.in: Rebuild.

Committed after further testing as follows.

Ian
Index: Makefile.am
===================================================================
--- Makefile.am (revision 249171)
+++ Makefile.am (working copy)
@@ -42,7 +42,8 @@ AM_GOCFLAGS = -I $(libgodir)
 AM_LDFLAGS = -L $(libgodir) -L $(libgodir)/.libs
 GOLINK = $(GOCOMPILER) $(GOCFLAGS) $(AM_GOCFLAGS) $(LDFLAGS) $(AM_LDFLAGS) -o 
$@
 
-cmdsrcdir = $(srcdir)/../libgo/go/cmd
+libgosrcdir = $(srcdir)/../libgo/go
+cmdsrcdir = $(libgosrcdir)/cmd
 
 go_cmd_go_files = \
        $(cmdsrcdir)/go/alldocs.go \
@@ -131,6 +132,89 @@ install-exec-local: cgo$(EXEEXT)
 uninstall-local:
        rm -f $(DESTDIR)$(libexecsubdir)/cgo$(exeext)
 
+# Run tests using the go tool, and frob the output to look like that
+# generated by DejaGNU.  The main output of this is two files:
+# gotools.sum and gotools.log.
+
+# check-head starts generating the log files in DejaGNU format.  This
+# is a separate target so that the date is approximately when we start
+# running the tests.
+check-head:
+       @echo "Test Run By $${USER} on `date`" > gotools.head
+       @echo "Native configuration is $(host_triplet)" >> gotools.head
+       @echo >> gotools.head
+       @echo "         === gotools tests ===" >> gotools.head
+       @echo >> gotools.head
+
+# check-gccgo is a little shell script that executes gccgo with the
+# options to pick up the newly built libgo.
+check-gccgo: Makefile
+       rm -f $@
+       echo "#!/bin/sh" > $@
+       abs_libgodir=`cd $(libgodir) && $(PWD_COMMAND)`; \
+       echo "$(GOCOMPILE)" '"$$@"' "-I $${abs_libgodir} -L $${abs_libgodir} -L 
$${abs_libgodir}/.libs" >> $@
+       chmod +x $@
+
+# CHECK_ENV sets up the environment to run the newly built go tool.
+CHECK_ENV = \
+       PATH=`echo $(abs_builddir):$${PATH} | sed 
's,::*,:,g;s,^:*,,;s,:*$$,,'`; \
+       export PATH; \
+       GCCGO="$(abs_builddir)/check-gccgo"; \
+       export GCCGO; \
+       GCCGOTOOLDIR="$(abs_builddir)"; \
+       export GCCGOTOOLDIR; \
+       GO_TESTING_GOTOOLS=yes; \
+       export GO_TESTING_GOTOOLS; \
+       abs_libgodir=`cd $(libgodir) && $(PWD_COMMAND)`; \
+       LD_LIBRARY_PATH=`echo $${abs_libgodir}/.libs:$${LD_LIBRARY_PATH} | sed 
's,::*,:,g;s,^:*,,;s,:*$$,,'`; \
+       export LD_LIBRARY_PATH;
+
+# check-go-tools runs `go test cmd/go` in our environment.
+check-go-tool: go$(EXEEXT) check-head check-gccgo
+       rm -rf check-go-dir
+       $(MKDIR_P) check-go-dir/src/cmd/go
+       cp $(cmdsrcdir)/go/*.go check-go-dir/src/cmd/go/
+       cp $(libgodir)/zstdpkglist.go check-go-dir/src/cmd/go/
+       cp zdefaultcc.go check-go-dir/src/cmd/go/
+       cp -r $(cmdsrcdir)/go/testdata check-go-dir/src/cmd/go/
+       $(CHECK_ENV) \
+       GOPATH=`cd check-go-dir && $(PWD_COMMAND)`; \
+       export GOPATH; \
+       (cd check-go-dir/src/cmd/go && $(abs_builddir)/go$(EXEEXT) test 
-test.short -test.v) >& cmd_go-testlog || true
+       grep '^--- ' cmd_go-testlog | sed -e 's/^--- \(.*\) ([^)]*)$$/\1/'
+
+# The check targets runs the tests and assembles the output files.
+check: check-head check-go-tool
+       mv gotools.head gotools.sum
+       cp gotools.sum gotools.log
+       for file in cmd_go-testlog; do \
+         testname=`echo $${file} | sed -e 's/-testlog//' -e 's|_|/|'`; \
+         echo "Running $${testname}" >> gotools.sum; \
+         echo "Running $${testname}" >> gotools.log; \
+         sed -e 's/^--- \(.*\) ([^)]*)$$/\1/' < $${file} >> gotools.log; \
+         grep '^--- ' $${file} | sed -e 's/^--- \(.*\) ([^)]*)$$/\1/' -e 
's/SKIP/UNTESTED/' >> gotools.sum; \
+       done
+       @echo >> gotools.sum
+       @echo "         === gotools Summary ===" >> gotools.sum
+       pass=`grep -c '^PASS' gotools.sum`; \
+       if test "$${pass}" -ne "0"; then \
+         echo "# of expected passes            $${pass}" >> gotools.sum; \
+       fi
+       fail=`grep -c '^FAIL' gotools.sum`; \
+       if test "$${fail}" -ne "0"; then \
+         echo "# of unexpected failures        $${fail}" >> gotools.sum; \
+       fi
+       untested=`grep -c '^UNTESTED' gotools.sum`; \
+       if test "$${untested}" -ne "0"; then \
+         echo "# of untested testcases         $${untested}" >> gotools.sum; \
+       fi
+       echo `echo $(GOC_FOR_TARGET) | sed -e 's/ .*//'`  `$(GOC_FOR_TARGET) -v 
2>&1 | grep " version" | sed -n -e 's/.* \(version.*$$\)/\1/p'` >> gotools.sum
+       echo >> gotools.log
+       echo "runtest completed at `date`" >> gotools.log
+       if grep '^FAIL' gotools.sum >/dev/null 2>&1; then exit 1; fi
+
+.PHONY: check check-head check-go-tool
+
 else
 
 # For a non-native build we have to build the programs using a
@@ -140,3 +224,6 @@ else
 # the go/build package.  Figure this out later.
 
 endif
+
+mostlyclean-local:
+       rm -rf check-go-dir

Reply via email to