2010-12-03 05:34:57 +01:00
|
|
|
#!/bin/sh
|
|
|
|
# Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
# Use of this source code is governed by a BSD-style
|
|
|
|
# license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
# Using all the *_test.go files in the current directory, write out a file
|
|
|
|
# _testmain.go that runs all its tests. Compile everything and run the
|
|
|
|
# tests.
|
|
|
|
# If files are named on the command line, use them instead of *_test.go.
|
|
|
|
|
|
|
|
# Makes egrep,grep work better in general if we put them
|
|
|
|
# in ordinary C mode instead of what the current language is.
|
2016-08-13 04:52:42 +02:00
|
|
|
LANG=C
|
|
|
|
LC_ALL=C
|
|
|
|
LC_CTYPE=C
|
|
|
|
export LANG LC_ALL LC_CTYPE
|
2010-12-03 05:34:57 +01:00
|
|
|
|
|
|
|
GC=${GC:-gccgo}
|
|
|
|
GL=${GL:-${GC-gccgo}}
|
2011-09-27 00:33:31 +02:00
|
|
|
GOLIBS=${GOLIBS:-}
|
2010-12-03 05:34:57 +01:00
|
|
|
export GC GL GOLIBS
|
|
|
|
|
2011-01-13 00:06:13 +01:00
|
|
|
NM=${NM:-nm}
|
|
|
|
|
2010-12-03 05:34:57 +01:00
|
|
|
# srcdir is where the source files are found. basedir is where the
|
|
|
|
# source file paths are relative to.
|
|
|
|
# gofiles are the test files. pkgfiles are the source files.
|
|
|
|
srcdir=.
|
|
|
|
basedir=.
|
2015-10-31 01:59:47 +01:00
|
|
|
goarch=""
|
2010-12-03 05:34:57 +01:00
|
|
|
gofiles=""
|
2015-10-31 01:59:47 +01:00
|
|
|
goos=""
|
2010-12-03 05:34:57 +01:00
|
|
|
pkgfiles=""
|
|
|
|
loop=true
|
|
|
|
keep=false
|
2012-05-15 00:08:42 +02:00
|
|
|
pkgpath=
|
2010-12-03 05:34:57 +01:00
|
|
|
prefix=
|
|
|
|
dejagnu=no
|
2020-04-20 09:35:43 +02:00
|
|
|
timeout=600
|
2011-04-01 01:03:20 +02:00
|
|
|
testname=""
|
2014-07-02 01:19:24 +02:00
|
|
|
bench=""
|
2011-09-16 17:47:21 +02:00
|
|
|
trace=false
|
2010-12-03 05:34:57 +01:00
|
|
|
while $loop; do
|
|
|
|
case "x$1" in
|
|
|
|
x--srcdir)
|
|
|
|
srcdir=$2
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
x--srcdir=*)
|
|
|
|
srcdir=`echo $1 | sed -e 's/^--srcdir=//'`
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
x--basedir)
|
|
|
|
basedir=$2
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
x--basedir=*)
|
|
|
|
basedir=`echo $1 | sed -e 's/^--basedir=//'`
|
|
|
|
shift
|
|
|
|
;;
|
2015-10-31 01:59:47 +01:00
|
|
|
x--goarch)
|
|
|
|
goarch=$2
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
x--goarch=*)
|
|
|
|
goarch=`echo $1 | sed -e 's/^--goarch=//'`
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
x--goos)
|
|
|
|
goos=$2
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
x--goos=*)
|
|
|
|
goos=`echo $1 | sed -e 's/^--goos=//'`
|
|
|
|
shift
|
|
|
|
;;
|
2012-05-15 00:08:42 +02:00
|
|
|
x--pkgpath)
|
|
|
|
pkgpath=$2
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
x--pkgpath=*)
|
|
|
|
pkgpath=`echo $1 | sed -e 's/^--pkgpath=//'`
|
|
|
|
shift
|
|
|
|
;;
|
2010-12-03 05:34:57 +01:00
|
|
|
x--prefix)
|
|
|
|
prefix=$2
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
x--prefix=*)
|
|
|
|
prefix=`echo $1 | sed -e 's/^--prefix=//'`
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
x--keep)
|
|
|
|
keep=true
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
x--pkgfiles)
|
|
|
|
pkgfiles=$2
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
x--pkgfiles=*)
|
|
|
|
pkgfiles=`echo $1 | sed -e 's/^--pkgfiles=//'`
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
x--dejagnu)
|
|
|
|
dejagnu=$2
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
x--dejagnu=*)
|
|
|
|
dejagnu=`echo $1 | sed -e 's/^--dejagnu=//'`
|
|
|
|
shift
|
|
|
|
;;
|
2011-04-01 00:36:10 +02:00
|
|
|
x--timeout)
|
|
|
|
timeout=$2
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
x--timeout=*)
|
|
|
|
timeout=`echo $1 | sed -e 's/^--timeout=//'`
|
|
|
|
shift
|
|
|
|
;;
|
2011-04-01 01:03:20 +02:00
|
|
|
x--testname)
|
|
|
|
testname=$2
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
x--testname=*)
|
|
|
|
testname=`echo $1 | sed -e 's/^--testname=//'`
|
|
|
|
shift
|
|
|
|
;;
|
2014-07-02 01:19:24 +02:00
|
|
|
x--bench)
|
|
|
|
bench=$2
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
x--bench=*)
|
|
|
|
bench=`echo $1 | sed -e 's/^--bench=//'`
|
|
|
|
shift
|
|
|
|
;;
|
2011-09-16 17:47:21 +02:00
|
|
|
x--trace)
|
|
|
|
trace=true
|
|
|
|
shift
|
|
|
|
;;
|
2010-12-03 05:34:57 +01:00
|
|
|
x-*)
|
|
|
|
loop=false
|
|
|
|
;;
|
|
|
|
x)
|
|
|
|
loop=false
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
gofiles="$gofiles $1"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
DIR=gotest$$
|
|
|
|
rm -rf $DIR
|
|
|
|
mkdir $DIR
|
|
|
|
|
|
|
|
cd $DIR
|
2012-04-24 22:13:12 +02:00
|
|
|
mkdir test
|
|
|
|
cd test
|
2010-12-03 05:34:57 +01:00
|
|
|
|
|
|
|
if test $keep = false; then
|
2012-04-24 22:13:12 +02:00
|
|
|
trap "cd ../..; rm -rf $DIR" 0 1 2 3 14 15
|
2010-12-03 05:34:57 +01:00
|
|
|
else
|
2012-04-24 22:13:12 +02:00
|
|
|
trap "cd ../..; echo Keeping $DIR" 0 1 2 3 14 15
|
2010-12-03 05:34:57 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
case "$srcdir" in
|
|
|
|
/*)
|
|
|
|
;;
|
|
|
|
*)
|
2012-04-24 22:13:12 +02:00
|
|
|
srcdir="../../$srcdir"
|
2010-12-03 05:34:57 +01:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
SRCDIR=$srcdir
|
|
|
|
export SRCDIR
|
|
|
|
|
|
|
|
case "$basedir" in
|
|
|
|
/*)
|
|
|
|
;;
|
|
|
|
*)
|
2012-04-24 22:13:12 +02:00
|
|
|
basedir="../../$basedir"
|
2010-12-03 05:34:57 +01:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
# Link all the files/directories in srcdir into our working directory,
|
|
|
|
# so that the tests do not have to refer to srcdir to find test data.
|
|
|
|
ln -s $srcdir/* .
|
|
|
|
|
2011-03-17 00:05:44 +01:00
|
|
|
# Some tests refer to a ../testdata directory.
|
|
|
|
if test -e $srcdir/../testdata; then
|
|
|
|
rm -f ../testdata
|
|
|
|
abssrcdir=`cd $srcdir && pwd`
|
|
|
|
ln -s $abssrcdir/../testdata ../testdata
|
|
|
|
fi
|
|
|
|
|
2010-12-03 05:34:57 +01:00
|
|
|
# Copy the .go files because io/utils_test.go expects a regular file.
|
|
|
|
case "x$gofiles" in
|
|
|
|
x)
|
|
|
|
case "x$pkgfiles" in
|
|
|
|
x)
|
|
|
|
for f in `cd $srcdir; ls *.go`; do
|
|
|
|
rm -f $f;
|
|
|
|
cp $srcdir/$f .
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
for f in $pkgfiles; do
|
2016-08-08 22:34:05 +02:00
|
|
|
case $f in
|
|
|
|
/*)
|
|
|
|
b=`basename $f`
|
|
|
|
rm -f $b
|
|
|
|
cp $f $b
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
if test -f $basedir/$f; then
|
|
|
|
b=`basename $f`
|
|
|
|
rm -f $b
|
|
|
|
cp $basedir/$f $b
|
|
|
|
elif test -f ../../$f; then
|
|
|
|
b=`basename $f`
|
|
|
|
rm -f $b
|
|
|
|
cp ../../$f $b
|
|
|
|
else
|
|
|
|
echo "file $f not found" 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
2010-12-03 05:34:57 +01:00
|
|
|
done
|
|
|
|
for f in `cd $srcdir; ls *_test.go`; do
|
|
|
|
rm -f $f
|
|
|
|
cp $srcdir/$f .
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
for f in $gofiles; do
|
|
|
|
b=`basename $f`
|
|
|
|
rm -f $b
|
|
|
|
cp $basedir/$f $b
|
|
|
|
done
|
|
|
|
case "x$pkgfiles" in
|
|
|
|
x)
|
|
|
|
for f in `cd $srcdir; ls *.go | grep -v *_test.go`; do
|
|
|
|
rm -f $f
|
|
|
|
cp $srcdir/$f .
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
for f in $pkgfiles; do
|
2016-08-08 22:34:05 +02:00
|
|
|
case $f in
|
|
|
|
/*)
|
|
|
|
b=`basename $f`
|
|
|
|
rm -f $b
|
|
|
|
cp $f $b
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
if test -f $basedir/$f; then
|
|
|
|
b=`basename $f`
|
|
|
|
rm -f $b
|
|
|
|
cp $basedir/$f $b
|
|
|
|
elif test -f ../../$f; then
|
|
|
|
b=`basename $f`
|
|
|
|
rm -f $b
|
|
|
|
cp ../../$f $b
|
|
|
|
else
|
|
|
|
echo "file $f not found" 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
2010-12-03 05:34:57 +01:00
|
|
|
done
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2022-02-11 23:53:56 +01:00
|
|
|
gobuild() {
|
|
|
|
line=$(echo "$1" | sed -e 's|//go:build ||')
|
|
|
|
line=$(echo "$line" | sed -e 's/go1\.[0-9]\+/1/g' -e 's/goexperiment\./goexperiment/')
|
|
|
|
line=" $line "
|
|
|
|
wrap='[ ()!&|]'
|
|
|
|
for ones in $goarch $goos cgo gccgo goexperimentfieldtrack; do
|
|
|
|
line=$(echo "$line" | sed -e "s/\\(${wrap}\\)${ones}\\(${wrap}\\)/"'\11\2/g')
|
|
|
|
done
|
|
|
|
# 386 is a special case since it looks like a number to the shell.
|
|
|
|
# We need it to be 0 if it's not $goarch.
|
|
|
|
if test "$goarch" != "386"; then
|
|
|
|
line=$(echo "$line" | sed -e "s/\\(${wrap}\\)386\\(${wrap}\\)/\10\2/g")
|
|
|
|
fi
|
|
|
|
(($line))
|
|
|
|
}
|
|
|
|
|
2010-12-03 05:34:57 +01:00
|
|
|
case "x$gofiles" in
|
|
|
|
x)
|
2015-10-31 01:59:47 +01:00
|
|
|
for f in `ls *_test.go`; do
|
|
|
|
tag1=`echo $f | sed -e 's/^.*_\([^_]*\)_test.go$/\1/'`
|
|
|
|
tag2=`echo $f | sed -e 's/^.*_\([^_]*\)_[^_]*_test.go$/\1/'`
|
|
|
|
if test x$tag1 = x$f; then
|
|
|
|
tag1=
|
|
|
|
fi
|
|
|
|
if test x$tag2 = x$f; then
|
|
|
|
tag2=
|
|
|
|
fi
|
|
|
|
|
|
|
|
case "$tag1" in
|
|
|
|
"") ;;
|
|
|
|
$goarch) ;;
|
|
|
|
$goos) ;;
|
2020-12-23 18:57:37 +01:00
|
|
|
aix | android | darwin | dragonfly | freebsd | hurd | ios | illumos | js | linux | nacl | netbsd | openbsd | plan9 | solaris | windows | zos)
|
2015-10-31 01:59:47 +01:00
|
|
|
tag1=nonmatchingtag
|
|
|
|
;;
|
2020-08-28 17:05:56 +02:00
|
|
|
386 | amd64 | amd64p32 | arm | armbe | arm64 | arm64be | alpha | ia64 | m68k | mips | mipsle | mips64 | mips64le | mips64p32 | mips64p32le | nios2 | ppc | ppc64 | ppc64le | riscv | riscv64 | s390 | s390x | sh | shbe | sparc | sparc64 | wasm)
|
2015-10-31 01:59:47 +01:00
|
|
|
tag1=nonmatchingtag
|
|
|
|
;;
|
2021-07-30 23:28:58 +02:00
|
|
|
*)
|
|
|
|
# File name like x_amd64_random.go, where tag1=random.
|
|
|
|
# Don't match based on tag2.
|
|
|
|
tag2=
|
|
|
|
;;
|
2015-10-31 01:59:47 +01:00
|
|
|
esac
|
|
|
|
|
|
|
|
case "$tag2" in
|
|
|
|
"") ;;
|
|
|
|
$goarch) ;;
|
|
|
|
$goos) ;;
|
2020-12-23 18:57:37 +01:00
|
|
|
aix | android | darwin | dragonfly | freebsd | hurd | ios | illumos | js | linux | nacl | netbsd | openbsd | plan9 | solaris | windows | zos)
|
2015-10-31 01:59:47 +01:00
|
|
|
tag2=nonmatchingtag
|
|
|
|
;;
|
2020-08-28 17:05:56 +02:00
|
|
|
386 | amd64 | amd64p32 | arm | armbe | arm64 | arm64be | alpha | ia64 | m68k | mips | mipsle | mips64 | mips64le | mips64p32 | mips64p32le | nios2 | ppc | ppc64 | ppc64le | riscv | riscv64 | s390 | s390x | sh | shbe | sparc | sparc64 | wasm)
|
2015-10-31 01:59:47 +01:00
|
|
|
tag2=nonmatchingtag
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2022-02-11 23:53:56 +01:00
|
|
|
if test x$tag1 = xnonmatchingtag -o x$tag2 = xnonmatchingtag; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Check for go:build line
|
|
|
|
build=$(sed '/^package /q' < $f | grep '^//go:build ' | cat)
|
|
|
|
if test -n "$build"; then
|
|
|
|
if $(gobuild "$build"); then
|
|
|
|
gofiles="$gofiles $f"
|
|
|
|
fi
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
# No go:build line, check for +build lines.
|
|
|
|
tags=`sed '/^package /q' < $f | grep '^// *+build '`
|
|
|
|
omatch=true
|
|
|
|
first=true
|
|
|
|
match=false
|
|
|
|
for tag in $tags; do
|
|
|
|
case $tag in
|
2016-08-04 00:46:06 +02:00
|
|
|
"//")
|
2022-02-11 23:53:56 +01:00
|
|
|
;;
|
2019-09-06 20:12:46 +02:00
|
|
|
"+build" | "//+build")
|
2016-08-04 00:46:06 +02:00
|
|
|
if test "$first" = "true"; then
|
|
|
|
first=false
|
|
|
|
elif test "$match" = "false"; then
|
|
|
|
omatch=false
|
|
|
|
fi
|
|
|
|
match=false
|
|
|
|
;;
|
2021-07-30 23:28:58 +02:00
|
|
|
$goos | $goarch | cgo | gccgo | goexperiment.fieldtrack | go1.[0-9] | go1.[0-9][0-9])
|
2016-08-04 00:46:06 +02:00
|
|
|
match=true
|
|
|
|
;;
|
2021-07-30 23:28:58 +02:00
|
|
|
"!"$goos | "!"$goarch | "!cgo" | "!gccgo" | "!goexperiment.fieldtrack" | "!"go1.[0-9] | "!"go1.1[0-7])
|
2016-08-06 02:36:33 +02:00
|
|
|
;;
|
2016-08-04 00:46:06 +02:00
|
|
|
*,*)
|
2016-08-06 02:36:33 +02:00
|
|
|
cmatch=true
|
2016-08-04 00:46:06 +02:00
|
|
|
for ctag in `echo $tag | sed -e 's/,/ /g'`; do
|
|
|
|
case $ctag in
|
2022-02-11 23:53:56 +01:00
|
|
|
$goos | $goarch | cgo | gccgo | goexperiment.fieldtrack | go1.[0-9] | go1.[0-9][0-9])
|
2016-08-04 00:46:06 +02:00
|
|
|
;;
|
2022-02-11 23:53:56 +01:00
|
|
|
"!"$goos | "!"$goarch | "!cgo" | "!gccgo" | "!goexperiment.fieldtrack" | "!"go1.[0-9] | "!"go1.1[0-7])
|
|
|
|
cmatch=false
|
|
|
|
;;
|
|
|
|
"!"*)
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
cmatch=false
|
|
|
|
;;
|
2016-08-04 00:46:06 +02:00
|
|
|
esac
|
|
|
|
done
|
2016-08-06 02:36:33 +02:00
|
|
|
if test "$cmatch" = "true"; then
|
2016-08-04 00:46:06 +02:00
|
|
|
match=true
|
2015-10-31 01:59:47 +01:00
|
|
|
fi
|
2016-08-06 02:36:33 +02:00
|
|
|
;;
|
|
|
|
"!"*)
|
|
|
|
match=true
|
|
|
|
;;
|
2022-02-11 23:53:56 +01:00
|
|
|
esac
|
|
|
|
done
|
2015-10-31 01:59:47 +01:00
|
|
|
|
2022-02-11 23:53:56 +01:00
|
|
|
if test "$match" = "false" -a "$first" = "false"; then
|
|
|
|
omatch=false
|
|
|
|
fi
|
2016-08-04 00:46:06 +02:00
|
|
|
|
2022-02-11 23:53:56 +01:00
|
|
|
if test "$omatch" = "true"; then
|
|
|
|
gofiles="$gofiles $f"
|
2015-10-31 01:59:47 +01:00
|
|
|
fi
|
|
|
|
done
|
2013-02-02 16:40:14 +01:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
xgofiles=$gofiles
|
|
|
|
gofiles=
|
|
|
|
for f in $xgofiles; do
|
|
|
|
gofiles="$gofiles `basename $f`"
|
|
|
|
done
|
2010-12-03 05:34:57 +01:00
|
|
|
esac
|
|
|
|
|
|
|
|
case "x$gofiles" in
|
|
|
|
x)
|
|
|
|
echo 'no test files found' 1>&2
|
|
|
|
exit 1
|
2013-02-02 16:40:14 +01:00
|
|
|
;;
|
2010-12-03 05:34:57 +01:00
|
|
|
esac
|
|
|
|
|
|
|
|
case "x$pkgfiles" in
|
|
|
|
x)
|
2011-04-05 21:53:33 +02:00
|
|
|
pkgbasefiles=`ls *.go | grep -v _test.go 2>/dev/null`
|
2010-12-03 05:34:57 +01:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
for f in $pkgfiles; do
|
|
|
|
pkgbasefiles="$pkgbasefiles `basename $f`"
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
case "x$pkgfiles" in
|
|
|
|
x)
|
|
|
|
echo 'no source files found' 1>&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
# Split $gofiles into external gofiles (those in *_test packages)
|
|
|
|
# and internal ones (those in the main package).
|
2013-02-02 16:40:14 +01:00
|
|
|
xgofiles=
|
2019-09-11 14:44:12 +02:00
|
|
|
xpackage=
|
2012-01-25 21:56:26 +01:00
|
|
|
for f in $gofiles; do
|
|
|
|
package=`grep '^package[ ]' $f | sed 1q`
|
|
|
|
case "$package" in
|
|
|
|
*_test)
|
2019-09-11 14:44:12 +02:00
|
|
|
xpackage=`echo $package | sed -e 's/package[ ]//' -e 's/[ ]*$//'`
|
2012-01-25 21:56:26 +01:00
|
|
|
xgofiles="$xgofiles $f"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
ngofiles="$ngofiles $f"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
gofiles=$ngofiles
|
2010-12-03 05:34:57 +01:00
|
|
|
|
|
|
|
# External $O file
|
|
|
|
xofile=""
|
|
|
|
havex=false
|
|
|
|
if [ "x$xgofiles" != "x" ]; then
|
|
|
|
xofile="_xtest_.o"
|
|
|
|
havex=true
|
|
|
|
fi
|
|
|
|
|
2015-01-15 01:27:56 +01:00
|
|
|
testmain=
|
|
|
|
if $havex && fgrep 'func TestMain(' $xgofiles >/dev/null 2>&1; then
|
|
|
|
package=`grep '^package[ ]' $xgofiles | sed 1q | sed -e 's/.* //'`
|
|
|
|
testmain="${package}.TestMain"
|
|
|
|
elif test -n "$gofiles" && fgrep 'func TestMain(' $gofiles >/dev/null 2>&1; then
|
|
|
|
package=`grep '^package[ ]' $gofiles | sed 1q | sed -e 's/.* //'`
|
|
|
|
testmain="${package}.TestMain"
|
|
|
|
fi
|
|
|
|
|
2010-12-03 05:34:57 +01:00
|
|
|
set -e
|
|
|
|
|
|
|
|
package=`echo ${srcdir} | sed -e 's|^.*libgo/go/||'`
|
|
|
|
|
2012-05-15 00:08:42 +02:00
|
|
|
pkgpatharg=
|
|
|
|
xpkgpatharg=
|
2010-12-03 05:34:57 +01:00
|
|
|
prefixarg=
|
2012-05-15 00:08:42 +02:00
|
|
|
if test -n "$pkgpath"; then
|
|
|
|
pkgpatharg="-fgo-pkgpath=$pkgpath"
|
|
|
|
xpkgpatharg="-fgo-pkgpath=${pkgpath}_test"
|
|
|
|
elif test -n "$prefix"; then
|
2010-12-03 05:34:57 +01:00
|
|
|
prefixarg="-fgo-prefix=$prefix"
|
|
|
|
fi
|
|
|
|
|
2011-09-16 17:47:21 +02:00
|
|
|
if test "$trace" = "true"; then
|
2012-05-15 00:08:42 +02:00
|
|
|
echo $GC -g $pkgpatharg $prefixarg -c -I . -fno-toplevel-reorder -o _gotest_.o $gofiles $pkgbasefiles
|
2011-09-16 17:47:21 +02:00
|
|
|
fi
|
2012-05-15 00:08:42 +02:00
|
|
|
$GC -g $pkgpatharg $prefixarg -c -I . -fno-toplevel-reorder -o _gotest_.o $gofiles $pkgbasefiles
|
2011-09-16 17:47:21 +02:00
|
|
|
|
2010-12-03 05:34:57 +01:00
|
|
|
if $havex; then
|
|
|
|
mkdir -p `dirname $package`
|
|
|
|
cp _gotest_.o `dirname $package`/lib`basename $package`.a
|
2019-09-11 14:44:12 +02:00
|
|
|
|
|
|
|
# Force the test version of the package to be imported first,
|
2020-01-10 00:14:57 +01:00
|
|
|
# so that its type definitions will be used, in case any new
|
2019-09-11 14:44:12 +02:00
|
|
|
# methods appear in export_test.go files.
|
|
|
|
echo "package $xpackage" > _first_test.go
|
|
|
|
echo 'import _ "'$package'"' >> _first_test.go
|
|
|
|
|
2011-09-16 17:47:21 +02:00
|
|
|
if test "$trace" = "true"; then
|
2019-09-11 14:44:12 +02:00
|
|
|
echo $GC -g $xpkgpatharg -c -I . -fno-toplevel-reorder -o $xofile _first_test.go $xgofiles
|
2011-09-16 17:47:21 +02:00
|
|
|
fi
|
2019-09-11 14:44:12 +02:00
|
|
|
$GC -g $xpkgpatharg -c -I . -fno-toplevel-reorder -o $xofile _first_test.go $xgofiles
|
2010-12-03 05:34:57 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
# They all compile; now generate the code to call them.
|
2011-03-25 00:46:17 +01:00
|
|
|
|
2012-10-23 06:31:11 +02:00
|
|
|
testname() {
|
|
|
|
# Remove the package from the name used with the -test option.
|
|
|
|
echo $1 | sed 's/^.*\.//'
|
|
|
|
}
|
|
|
|
|
2011-03-25 00:46:17 +01:00
|
|
|
localname() {
|
|
|
|
# The package main has been renamed to __main__ when imported.
|
|
|
|
# Adjust its uses.
|
2020-11-17 05:06:53 +01:00
|
|
|
# Also demangle underscores.
|
|
|
|
echo $1 | sed 's/^main\./__main__./' | sed 's/__/_/'
|
2011-03-25 00:46:17 +01:00
|
|
|
}
|
|
|
|
|
2018-10-26 00:18:08 +02:00
|
|
|
# Takes a list of tests derived from 'nm' output (whose symbols are mangled)
|
|
|
|
# and emits a demangled list of tests, using only the terminal package.
|
|
|
|
# Example:
|
|
|
|
#
|
|
|
|
# Original symbol: foo/bar/leaf.Mumble
|
2020-11-17 05:06:53 +01:00
|
|
|
# Mangled symbol: foo_1fbar_1leaf.Mumble
|
2018-10-26 00:18:08 +02:00
|
|
|
# Returned: leaf.Mumble
|
|
|
|
#
|
|
|
|
symtogo() {
|
2018-10-26 18:58:13 +02:00
|
|
|
result=""
|
2019-02-15 01:36:50 +01:00
|
|
|
for tp in $*; do
|
2019-06-26 02:17:32 +02:00
|
|
|
# Discard symbols with a leading dot.
|
|
|
|
# On AIX, this will remove function text symbols (with a leading dot).
|
|
|
|
# Therefore, only function descriptor symbols (without this leading dot)
|
|
|
|
# will be used to retrieve the go symbols, avoiding duplication.
|
|
|
|
if expr "$tp" : '^\.' >/dev/null 2>&1; then
|
2020-01-23 00:52:23 +01:00
|
|
|
continue
|
|
|
|
fi
|
|
|
|
# Skip type descriptors. These are normally skipped because they
|
|
|
|
# are weak symbols, but if not using GNU nm we may see them here.
|
|
|
|
if expr "$tp" : '^type\.\.' >/dev/null 2>&1; then
|
2019-06-26 02:17:32 +02:00
|
|
|
continue
|
|
|
|
fi
|
2020-11-17 05:06:53 +01:00
|
|
|
s=$(echo "$tp" | sed -e 's/_1/%/g' | sed -e 's/.*%//')
|
2019-02-15 01:36:50 +01:00
|
|
|
# Screen out methods (X.Y.Z).
|
2018-10-26 04:43:35 +02:00
|
|
|
if ! expr "$s" : '^[^.]*\.[^.]*$' >/dev/null 2>&1; then
|
2018-10-26 00:18:08 +02:00
|
|
|
continue
|
|
|
|
fi
|
2019-02-15 01:36:50 +01:00
|
|
|
tname=$(testname $s)
|
|
|
|
# Skip TestMain.
|
|
|
|
if test x$tname = xTestMain; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
# Check that the function is defined in a test file,
|
|
|
|
# not an ordinary non-test file.
|
|
|
|
if grep "^func $tname(" $gofiles $xgofiles >/dev/null 2>&1; then
|
|
|
|
echo "$s"
|
|
|
|
fi
|
2018-10-26 00:18:08 +02:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2022-02-11 23:53:56 +01:00
|
|
|
# Find Go benchmark/fuzz/example functions.
|
|
|
|
# The argument is the function name prefix.
|
|
|
|
findfuncs() {
|
|
|
|
pattern='$1([^a-z].*)?'
|
|
|
|
syms=$($NM -p -v _gotest_.o | egrep " $text .*\."$pattern'$' | fgrep -v ' __go_' | egrep -v '\.\.\w+$' | sed 's/.* //')
|
|
|
|
if $havex; then
|
|
|
|
xsyms=$($NM -p -v $xofile | egrep " $text .*\."$pattern'$' | fgrep -v ' __go_' | egrep -v '\.\.\w+$' | sed 's/.* //')
|
|
|
|
syms="$syms $xsyms"
|
|
|
|
fi
|
|
|
|
$(symtogo "$benchmarksyms")
|
|
|
|
}
|
|
|
|
|
2020-01-10 00:14:57 +01:00
|
|
|
# Takes an example name and puts any output into the file example.txt.
|
|
|
|
# It strips comment markers but does not otherwise change the output.
|
|
|
|
exampleoutput() {
|
2020-01-10 16:28:20 +01:00
|
|
|
n=$(testname $1)
|
2020-01-10 00:14:57 +01:00
|
|
|
for f in $gofiles $xgofiles; do
|
|
|
|
if ! grep "^func $n(" $f >/dev/null 2>&1; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
# Copy the output comment, if any, into example.txt.
|
|
|
|
# Remove the comment markers.
|
|
|
|
sed -n "/^func $n(/,/^}$/ p" $f |
|
|
|
|
sed -n '\|// \([Uu]nordered \)\?[Oo]utput:|,$ p' |
|
|
|
|
sed -n '\|//| s|[ ]*// \?||p' > example.txt
|
|
|
|
# Check whether we found an output comment.
|
|
|
|
if ! sed -n '1p' < example.txt | grep '[Oo]utput:' >/dev/null 2>&1; then
|
|
|
|
rm -f example.txt
|
|
|
|
fi
|
|
|
|
return
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2010-12-03 05:34:57 +01:00
|
|
|
{
|
2018-04-20 22:40:27 +02:00
|
|
|
# On systems using PPC64 ELF ABI v1 function symbols show up
|
2019-02-15 01:36:50 +01:00
|
|
|
# as descriptors in the data section.
|
|
|
|
text="[TD]"
|
2012-04-03 20:26:57 +02:00
|
|
|
|
2010-12-03 05:34:57 +01:00
|
|
|
# test functions are named TestFoo
|
|
|
|
# the grep -v eliminates methods and other special names
|
|
|
|
# that have multiple dots.
|
|
|
|
pattern='Test([^a-z].*)?'
|
2011-03-10 01:51:14 +01:00
|
|
|
# The -p option tells GNU nm not to sort.
|
|
|
|
# The -v option tells Solaris nm to sort by value.
|
2020-01-10 00:14:57 +01:00
|
|
|
testsyms=$($NM -p -v _gotest_.o | egrep " $text .*\."$pattern'$' | fgrep -v ' __go_' | egrep -v '\.\.\w+$' | sed 's/.* //')
|
|
|
|
testxsyms=
|
|
|
|
if $havex; then
|
|
|
|
testxsyms=$($NM -p -v $xofile | egrep " $text .*\."$pattern'$' | fgrep -v ' __go_' | egrep -v '\.\.\w+$' | sed 's/.* //')
|
|
|
|
testsyms="$testsyms $testxsyms"
|
|
|
|
fi
|
2018-10-26 00:18:08 +02:00
|
|
|
tests=$(symtogo "$testsyms")
|
2010-12-03 05:34:57 +01:00
|
|
|
if [ "x$tests" = x ]; then
|
|
|
|
echo 'gotest: warning: no tests matching '$pattern in _gotest_.o $xofile 1>&2
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
2022-02-11 23:53:56 +01:00
|
|
|
benchmarks=$(findfuncs Benchmark)
|
|
|
|
fuzztargets=$(findfuncs Fuzz)
|
|
|
|
examples=$(findfuncs Example)
|
2011-10-27 01:57:58 +02:00
|
|
|
|
2010-12-03 05:34:57 +01:00
|
|
|
# package spec
|
|
|
|
echo 'package main'
|
|
|
|
echo
|
|
|
|
# imports
|
|
|
|
if echo "$tests" | egrep -v '_test\.' >/dev/null; then
|
|
|
|
echo 'import "./_gotest_"'
|
|
|
|
fi
|
|
|
|
if $havex; then
|
2020-01-10 00:14:57 +01:00
|
|
|
needxtest=false
|
|
|
|
if test -n "$testxsyms" -o -n "$benchmarkxsyms"; then
|
|
|
|
needxtest=true
|
|
|
|
else
|
|
|
|
# Check whether any example has output.
|
|
|
|
for i in $(symtogo "$examplexsyms"); do
|
|
|
|
exampleoutput $i
|
|
|
|
if test -f example.txt; then
|
|
|
|
rm -f example.txt
|
|
|
|
needxtest=true
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
if test x$needxtest = xtrue; then
|
2010-12-03 05:34:57 +01:00
|
|
|
echo 'import "./_xtest_"'
|
2020-01-10 00:14:57 +01:00
|
|
|
else
|
|
|
|
echo 'import _ "./_xtest_"'
|
|
|
|
fi
|
2010-12-03 05:34:57 +01:00
|
|
|
fi
|
2020-01-03 00:05:27 +01:00
|
|
|
if test "$package" != "testing"; then
|
|
|
|
echo 'import "testing"'
|
|
|
|
fi
|
2017-01-14 01:05:42 +01:00
|
|
|
echo 'import "testing/internal/testdeps"'
|
2015-01-15 01:27:56 +01:00
|
|
|
if ! test -n "$testmain"; then
|
|
|
|
echo 'import __os__ "os"'
|
|
|
|
fi
|
2010-12-03 05:34:57 +01:00
|
|
|
# test array
|
|
|
|
echo
|
|
|
|
echo 'var tests = []testing.InternalTest {'
|
2019-02-15 01:36:50 +01:00
|
|
|
for i in $tests; do
|
2012-10-23 06:31:11 +02:00
|
|
|
n=$(testname $i)
|
2019-02-15 01:36:50 +01:00
|
|
|
j=$(localname $i)
|
|
|
|
echo ' {"'$n'", '$j'},'
|
2010-12-03 05:34:57 +01:00
|
|
|
done
|
|
|
|
echo '}'
|
2011-10-27 01:57:58 +02:00
|
|
|
|
2011-03-25 00:46:17 +01:00
|
|
|
# benchmark array
|
|
|
|
# The comment makes the multiline declaration
|
|
|
|
# gofmt-safe even when there are no benchmarks.
|
2020-01-10 00:14:57 +01:00
|
|
|
echo 'var benchmarks = []testing.InternalBenchmark{'
|
2019-02-15 01:36:50 +01:00
|
|
|
for i in $benchmarks; do
|
2012-10-23 06:31:11 +02:00
|
|
|
n=$(testname $i)
|
2011-03-25 00:46:17 +01:00
|
|
|
j=$(localname $i)
|
2012-10-23 06:31:11 +02:00
|
|
|
echo ' {"'$n'", '$j'},'
|
2011-03-25 00:46:17 +01:00
|
|
|
done
|
2010-12-03 05:34:57 +01:00
|
|
|
echo '}'
|
2011-10-27 01:57:58 +02:00
|
|
|
|
2022-02-11 23:53:56 +01:00
|
|
|
# fuzz array
|
|
|
|
echo 'var fuzzTargets = []testing.InternalFuzzTarget{'
|
|
|
|
for i in $fuzztargets; do
|
|
|
|
n=$(testname $i)
|
|
|
|
j=$(localname $i)
|
|
|
|
echo ' {"'$n'", '$j'},'
|
|
|
|
done
|
|
|
|
echo '}'
|
|
|
|
|
2011-10-27 01:57:58 +02:00
|
|
|
# examples array
|
2020-01-10 00:14:57 +01:00
|
|
|
echo 'var examples = []testing.InternalExample{'
|
2019-02-15 01:36:50 +01:00
|
|
|
for i in $examples; do
|
|
|
|
n=$(testname $i)
|
|
|
|
j=$(localname $i)
|
|
|
|
# Look for a //output comment.
|
|
|
|
hasoutput=false
|
|
|
|
unordered=false
|
|
|
|
output=
|
2020-01-10 00:14:57 +01:00
|
|
|
exampleoutput $i
|
|
|
|
if ! test -f example.txt; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
# Check whether the output can be unordered.
|
|
|
|
unordered=false
|
|
|
|
if sed -n '1p' < example.txt | grep -i unordered >/dev/null 2>&1; then
|
|
|
|
unordered=true
|
2019-02-15 01:36:50 +01:00
|
|
|
fi
|
2020-01-10 00:14:57 +01:00
|
|
|
# Remove the output header.
|
|
|
|
# Quote backslashes.
|
|
|
|
# Quote quotation characters.
|
|
|
|
# Turn tab into \t.
|
|
|
|
# Turn pairs of spaces into " \x20", because $() will
|
|
|
|
# drop duplicate spaces.
|
|
|
|
# Drop trailing spaces, and turn newlines into \n.
|
|
|
|
# Remove leading and trailing \n.
|
|
|
|
sed '1 s/\([Uu]nordered \)\?[Oo]utput:[ ]*//' < example.txt |
|
|
|
|
sed -e 's/\\/\\\\/g' \
|
|
|
|
-e 's/"/\\"/g' \
|
|
|
|
-e 's/ /\\t/g' \
|
|
|
|
-e 's/ / \\x20/g' \
|
|
|
|
-e 's/[ ]*$/\\n/g' |
|
|
|
|
tr -d '\n' |
|
|
|
|
sed -e 's/^\(\\n\)*//' \
|
|
|
|
-e 's/\(\\n\)*$//' > example2.txt
|
|
|
|
hasoutput=true
|
|
|
|
echo ' {"'$n'", '$j','
|
|
|
|
sed -e 's/^/ "/' -e 's/$/", /' < example2.txt
|
|
|
|
echo $unordered'},'
|
|
|
|
rm -f example.txt example2.txt
|
2019-02-15 01:36:50 +01:00
|
|
|
done
|
2011-10-27 01:57:58 +02:00
|
|
|
echo '}'
|
|
|
|
|
2011-03-25 00:46:17 +01:00
|
|
|
# body
|
|
|
|
echo \
|
|
|
|
'
|
|
|
|
func main() {
|
2022-02-11 23:53:56 +01:00
|
|
|
m := testing.MainStart(testdeps.TestDeps{}, tests, benchmarks, fuzzTargets, examples)
|
2015-01-15 01:27:56 +01:00
|
|
|
'
|
|
|
|
if test -n "$testmain"; then
|
|
|
|
echo " ${testmain}(m)"
|
|
|
|
else
|
|
|
|
echo ' __os__.Exit(m.Run())'
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo '}'
|
2010-12-03 05:34:57 +01:00
|
|
|
}>_testmain.go
|
|
|
|
|
|
|
|
case "x$dejagnu" in
|
|
|
|
xno)
|
2011-09-16 17:47:21 +02:00
|
|
|
if test "$trace" = "true"; then
|
|
|
|
echo ${GC} -g -c _testmain.go
|
|
|
|
fi
|
2010-12-03 05:34:57 +01:00
|
|
|
${GC} -g -c _testmain.go
|
2011-09-16 17:47:21 +02:00
|
|
|
|
|
|
|
if test "$trace" = "true"; then
|
|
|
|
echo ${GL} *.o ${GOLIBS}
|
|
|
|
fi
|
2010-12-03 05:34:57 +01:00
|
|
|
${GL} *.o ${GOLIBS}
|
2011-04-05 23:11:35 +02:00
|
|
|
|
2015-08-20 19:10:45 +02:00
|
|
|
set +e
|
2014-07-02 01:19:24 +02:00
|
|
|
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
|
2016-01-11 18:55:39 +01:00
|
|
|
sleeppid=`ps -o pid,ppid,comm | grep " $alarmpid " | grep sleep | sed -e 's/ *\([0-9]*\) .*$/\1/'`
|
2015-08-20 19:10:45 +02:00
|
|
|
kill $alarmpid
|
|
|
|
wait $alarmpid
|
|
|
|
if test "$sleeppid" != ""; then
|
|
|
|
kill $sleeppid
|
2015-08-07 12:10:00 +02:00
|
|
|
fi
|
2014-07-02 01:19:24 +02:00
|
|
|
fi
|
|
|
|
else
|
|
|
|
if test "$trace" = "true"; then
|
|
|
|
echo ./a.out -test.run=^\$ -test.bench="${bench}" "$@"
|
|
|
|
fi
|
|
|
|
./a.out -test.run=^\$ -test.bench="${bench}" "$@"
|
|
|
|
status=$?
|
2011-04-05 23:11:35 +02:00
|
|
|
fi
|
|
|
|
exit $status
|
2010-12-03 05:34:57 +01:00
|
|
|
;;
|
|
|
|
xyes)
|
2012-04-24 22:13:12 +02:00
|
|
|
rm -rf ../../testsuite/*.o
|
2011-01-12 22:56:10 +01:00
|
|
|
files=`echo *`
|
|
|
|
for f in $files; do
|
|
|
|
if test "$f" = "_obj" || test "$f" = "_test"; then
|
|
|
|
continue
|
|
|
|
fi
|
2012-04-24 22:13:12 +02:00
|
|
|
rm -rf ../../testsuite/$f
|
2011-01-12 22:56:10 +01:00
|
|
|
if test -f $f; then
|
2012-04-24 22:13:12 +02:00
|
|
|
cp $f ../../testsuite/
|
2011-01-12 22:56:10 +01:00
|
|
|
else
|
2012-04-24 22:13:12 +02:00
|
|
|
ln -s ../$DIR/test/$f ../../testsuite/
|
2011-01-12 22:56:10 +01:00
|
|
|
fi
|
|
|
|
done
|
2012-04-24 22:13:12 +02:00
|
|
|
cd ../../testsuite
|
2011-01-12 22:56:10 +01:00
|
|
|
rm -rf _obj _test
|
|
|
|
mkdir _obj _test
|
2011-04-01 01:03:20 +02:00
|
|
|
if test "$testname" != ""; then
|
|
|
|
GOTESTNAME="$testname"
|
|
|
|
export GOTESTNAME
|
|
|
|
fi
|
2012-04-24 22:13:12 +02:00
|
|
|
$MAKE check RUNTESTFLAGS="$RUNTESTFLAGS GOTEST_TMPDIR=$DIR/test"
|
2010-12-03 05:34:57 +01:00
|
|
|
# Useful when using make check-target-libgo
|
|
|
|
cat libgo.log >> libgo-all.log
|
|
|
|
cat libgo.sum >> libgo-all.sum
|
2011-01-12 22:56:10 +01:00
|
|
|
rm -rf $files
|
2010-12-03 05:34:57 +01:00
|
|
|
;;
|
|
|
|
esac
|