URL
https://opencores.org/ocsvn/openrisc/openrisc/trunk
Subversion Repositories openrisc
[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [testsuite/] [gotest] - Rev 747
Compare with Previous | Blame | View Log
#!/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.unset LANGexport LC_ALL=Cexport LC_CTYPE=CGC=${GC:-gccgo}GL=${GL:-${GC-gccgo}}GOLIBS=${GOLIBS:-}export GC GL GOLIBSNM=${NM:-nm}# 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=.gofiles=""pkgfiles=""loop=truekeep=falseprefix=dejagnu=notimeout=240testname=""trace=falsewhile $loop; docase "x$1" inx--srcdir)srcdir=$2shiftshift;;x--srcdir=*)srcdir=`echo $1 | sed -e 's/^--srcdir=//'`shift;;x--basedir)basedir=$2shiftshift;;x--basedir=*)basedir=`echo $1 | sed -e 's/^--basedir=//'`shift;;x--prefix)prefix=$2shiftshift;;x--prefix=*)prefix=`echo $1 | sed -e 's/^--prefix=//'`shift;;x--keep)keep=trueshift;;x--pkgfiles)pkgfiles=$2shiftshift;;x--pkgfiles=*)pkgfiles=`echo $1 | sed -e 's/^--pkgfiles=//'`shift;;x--dejagnu)dejagnu=$2shiftshift;;x--dejagnu=*)dejagnu=`echo $1 | sed -e 's/^--dejagnu=//'`shift;;x--timeout)timeout=$2shiftshift;;x--timeout=*)timeout=`echo $1 | sed -e 's/^--timeout=//'`shift;;x--testname)testname=$2shiftshift;;x--testname=*)testname=`echo $1 | sed -e 's/^--testname=//'`shift;;x--trace)trace=trueshift;;x-*)loop=false;;x)loop=false;;*)gofiles="$gofiles $1"shift;;esacdoneDIR=gotest$$rm -rf $DIRmkdir $DIRcd $DIRif test $keep = false; thentrap "cd ..; rm -rf $DIR" 0 1 2 3 14 15elsetrap "cd ..; echo Keeping $DIR" 0 1 2 3 14 15ficase "$srcdir" in/*);;*)srcdir="../$srcdir";;esacSRCDIR=$srcdirexport SRCDIRcase "$basedir" in/*);;*)basedir="../$basedir";;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/* .# Some tests refer to a ../testdata directory.if test -e $srcdir/../testdata; thenrm -f ../testdataabssrcdir=`cd $srcdir && pwd`ln -s $abssrcdir/../testdata ../testdatafi# Copy the .go files because io/utils_test.go expects a regular file.case "x$gofiles" inx)case "x$pkgfiles" inx)for f in `cd $srcdir; ls *.go`; dorm -f $f;cp $srcdir/$f .done;;*)for f in $pkgfiles; doif test -f $basedir/$f; thenb=`basename $f`rm -f $bcp $basedir/$f $belif test -f ../$f; thenb=`basename $f`rm -f $bcp ../$f $belseecho "file $f not found" 1>&2exit 1fidonefor f in `cd $srcdir; ls *_test.go`; dorm -f $fcp $srcdir/$f .done;;esac;;*)for f in $gofiles; dob=`basename $f`rm -f $bcp $basedir/$f $bdonecase "x$pkgfiles" inx)for f in `cd $srcdir; ls *.go | grep -v *_test.go`; dorm -f $fcp $srcdir/$f .done;;*)for f in $pkgfiles; doif test -f $basedir/$f; thenb=`basename $f`rm -f $bcp $basedir/$f $belif test -f ../$f; thenb=`basename $f`rm -f $bcp ../$f $belseecho "file $f not found" 1>&2exit 1fidone;;esac;;esac# Some tests expect the _obj directory created by the gc Makefiles.mkdir _obj# Some tests expect the _test directory created by the gc Makefiles.mkdir _testcase "x$gofiles" inx)gofiles=`ls *_test.go 2>/dev/null`esaccase "x$gofiles" inx)echo 'no test files found' 1>&2exit 1esac# Run any commands given in sources, like# // gotest: $GC foo.go# to build any test-only dependencies.holdGC="$GC"GC="$GC -g -c -I ."sed -n 's/^\/\/ gotest: //p' $gofiles | shGC="$holdGC"case "x$pkgfiles" inx)pkgbasefiles=`ls *.go | grep -v _test.go 2>/dev/null`;;*)for f in $pkgfiles; dopkgbasefiles="$pkgbasefiles `basename $f`"done;;esaccase "x$pkgfiles" inx)echo 'no source files found' 1>&2exit 1;;esac# Split $gofiles into external gofiles (those in *_test packages)# and internal ones (those in the main package).for f in $gofiles; dopackage=`grep '^package[ ]' $f | sed 1q`case "$package" in*_test)xgofiles="$xgofiles $f";;*)ngofiles="$ngofiles $f";;esacdonegofiles=$ngofiles# External $O filexofile=""havex=falseif [ "x$xgofiles" != "x" ]; thenxofile="_xtest_.o"havex=truefiset -epackage=`echo ${srcdir} | sed -e 's|^.*libgo/go/||'`prefixarg=if test -n "$prefix"; thenprefixarg="-fgo-prefix=$prefix"fiif test "$trace" = "true"; thenecho $GC -g $prefixarg -c -I . -fno-toplevel-reorder -o _gotest_.o $gofiles $pkgbasefilesfi$GC -g $prefixarg -c -I . -fno-toplevel-reorder -o _gotest_.o $gofiles $pkgbasefilesif $havex; thenmkdir -p `dirname $package`cp _gotest_.o `dirname $package`/lib`basename $package`.aif test "$trace" = "true"; thenecho $GC -g -c -I . -fno-toplevel-reorder -o $xofile $xgofilesfi$GC -g -c -I . -fno-toplevel-reorder -o $xofile $xgofilesfi# They all compile; now generate the code to call them.localname() {# The package main has been renamed to __main__ when imported.# Adjust its uses.echo $1 | sed 's/^main\./__main__./'}{# test functions are named TestFoo# the grep -v eliminates methods and other special names# that have multiple dots.pattern='Test([^a-z].*)?'# The -p option tells GNU nm not to sort.# The -v option tells Solaris nm to sort by value.tests=$($NM -p -v _gotest_.o $xofile | egrep ' T .*\.'$pattern'$' | grep -v '\..*\..*\.' | fgrep -v '$' | sed 's/.* //' | sed 's/.*\.\(.*\.\)/\1/')if [ "x$tests" = x ]; thenecho 'gotest: warning: no tests matching '$pattern in _gotest_.o $xofile 1>&2exit 2fi# benchmarks are named BenchmarkFoo.pattern='Benchmark([^a-z].*)?'benchmarks=$($NM -p -v _gotest_.o $xofile | egrep ' T .*\.'$pattern'$' | grep -v '\..*\..*\.' | fgrep -v '$' | sed 's/.* //' | sed 's/.*\.\(.*\.\)/\1/')# examples are named ExampleFoopattern='Example([^a-z].*)?'examples=$($NM -p -v _gotest_.o $xofile | egrep ' T .*\.'$pattern'$' | grep -v '\..*\..*\.' | fgrep -v '$' | sed 's/.* //' | sed 's/.*\.\(.*\.\)/\1/')# package spececho 'package main'echo# importsif echo "$tests" | egrep -v '_test\.' >/dev/null; thenecho 'import "./_gotest_"'fiif $havex; thenecho 'import "./_xtest_"'fiecho 'import "testing"'echo 'import __regexp__ "regexp"' # rename in case tested package is called regexp# test arrayechoecho 'var tests = []testing.InternalTest {'for i in $testsdoj=$(localname $i)echo ' {"'$i'", '$j'},'doneecho '}'# benchmark array# The comment makes the multiline declaration# gofmt-safe even when there are no benchmarks.echo 'var benchmarks = []testing.InternalBenchmark{ //'for i in $benchmarksdoj=$(localname $i)echo ' {"'$i'", '$j'},'doneecho '}'# examples arrayecho 'var examples = []testing.InternalExample{ //'# This doesn't work because we don't pick up the output.#for i in $examples#do# j=$(localname $i)# echo ' {"'$i'", '$j', ""},'#doneecho '}'# bodyecho \'var matchPat stringvar matchRe *__regexp__.Regexpfunc matchString(pat, str string) (result bool, err error) {if matchRe == nil || matchPat != pat {matchPat = patmatchRe, err = __regexp__.Compile(matchPat)if err != nil {return}}return matchRe.MatchString(str), nil}func main() {testing.Main(matchString, tests, benchmarks, examples)}'}>_testmain.gocase "x$dejagnu" inxno)if test "$trace" = "true"; thenecho ${GC} -g -c _testmain.gofi${GC} -g -c _testmain.goif test "$trace" = "true"; thenecho ${GL} *.o ${GOLIBS}fi${GL} *.o ${GOLIBS}if test "$trace" = "true"; thenecho ./a.out -test.short -test.timeout=${timeout}s "$@"fi./a.out -test.short -test.timeout=${timeout}s "$@" &pid=$!(sleep `expr $timeout + 10`echo > gotest-timeoutecho "timed out in gotest" 1>&2kill -9 $pid) &alarmpid=$!wait $pidstatus=$?if ! test -f gotest-timeout; thenkill $alarmpidfiexit $status;;xyes)rm -rf ../testsuite/*.ofiles=`echo *`for f in $files; doif test "$f" = "_obj" || test "$f" = "_test"; thencontinuefirm -rf ../testsuite/$fif test -f $f; thencp $f ../testsuite/elseln -s ../$DIR/$f ../testsuite/fidonecd ../testsuiterm -rf _obj _testmkdir _obj _testif test "$testname" != ""; thenGOTESTNAME="$testname"export GOTESTNAMEfi$MAKE check RUNTESTFLAGS="$RUNTESTFLAGS GOTEST_TMPDIR=$DIR"# Useful when using make check-target-libgocat libgo.log >> libgo-all.logcat libgo.sum >> libgo-all.sumrm -rf $files;;esac
