Commit b64ca2ce by Ian Lance Taylor Committed by Ian Lance Taylor

Update to current version of Go testsuite.

	* go.test/go-test.exp: Update for latest version of Go testsuite.

From-SVN: r191858
parent 4e57a5c3
2012-09-29 Ian Lance Taylor <iant@google.com>
* go.test/go-test.exp: Update for latest version of Go testsuite.
2012-09-29 Thomas König <tkoenig@gcc.gnu.org>
PR fortran/52724
......
// $G $F.go && $L $F.$A && ./$A.out
// run
// 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.
// Solve the 2,3,5 problem (print all numbers with 2, 3, or 5 as factor) using channels.
// Test the solution, silently.
package main
type T chan uint64
......
// $G $D/$F.go && $L $F.$A && ./$A.out >tmp.go &&
// $G tmp.go && $L tmp.$A && ./$A.out || echo BUG: 64bit
// rm -f tmp.go
// runoutput
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
......
// errchk $G -e $D/$F.go
// errorcheck
// Copyright 2011 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.
package main
// Test that error messages say what the source file says
// (uint8 vs byte, int32 vs. rune).
// Does not compile.
package main
import (
"fmt"
......
// $G $D/$F.go && $L $F.$A && ./$A.out
// run
// Copyright 2011 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.
package main
// Test that dynamic interface checks treat byte=uint8
// and rune=int or rune=int32.
package main
func main() {
var x interface{}
......
// $G $F.go && $L $F.$A && ./$A.out
// run
// Copyright 2010 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.
// Semi-exhaustive test for append()
// Semi-exhaustive test for the append predeclared function.
package main
......@@ -27,6 +27,7 @@ func main() {
}
verifyStruct()
verifyInterface()
verifyType()
}
......@@ -230,3 +231,17 @@ func verifyInterface() {
verify("interface l", append(s), s)
verify("interface m", append(s, e...), r)
}
type T1 []int
type T2 []int
func verifyType() {
// The second argument to append has type []E where E is the
// element type of the first argument. Test that the compiler
// accepts two slice types that meet that requirement but are
// not assignment compatible. The return type of append is
// the type of the first argument.
t1 := T1{1}
t2 := T2{2}
verify("T1", append(t1, t2...), T1{1, 2})
}
// $G $F.go && $L $F.$A && ./$A.out arg1 arg2
// NOTE: This test is not run by 'run.go' and so not run by all.bash.
// To run this test you must use the ./run shell script.
// 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.
// Test os.Args.
package main
import "os"
......
// errchk $G -e $D/$F.go
// errorcheck
// 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.
// Verify simple assignment errors are caught by the compiler.
// Does not compile.
package main
import "sync"
......
// errchk $G -e $D/$F.go
// errorcheck
// 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.
// Verify assignment rules are enforced by the compiler.
// Does not compile.
package main
type (
......
......@@ -2,27 +2,22 @@
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
include ../../../src/Make.inc
ALL=\
parser\
peano\
tree\
tree2\
all: $(addsuffix .out, $(ALL))
%.$O: %.go stats.go
$(GC) $(GCFLAGS) $(GCIMPORTS) $*.go stats.go
all: $(ALL)
%.out: %.$O
$(LD) -o $@ $*.$O
%: %.go
go build $*.go stats.go
%.bench: %.out
time ./$*.out
%.bench: %
time ./$*
bench: $(addsuffix .bench, $(ALL))
clean:
rm -f *.[$(OS)] $(addsuffix .out, $(ALL))
rm -f $(ALL)
......@@ -73,7 +73,7 @@ func parseDir(dirpath string) map[string]*ast.Package {
}
func main() {
st := &runtime.MemStats
st := new(runtime.MemStats)
packages = append(packages, packages...)
packages = append(packages, packages...)
n := flag.Int("n", 4, "iterations")
......@@ -83,14 +83,17 @@ func main() {
var lastParsed []map[string]*ast.Package
var t0 time.Time
var numGC uint32
var pauseTotalNs uint64
pkgroot := runtime.GOROOT() + "/src/pkg/"
for pass := 0; pass < 2; pass++ {
// Once the heap is grown to full size, reset counters.
// This hides the start-up pauses, which are much smaller
// than the normal pauses and would otherwise make
// the average look much better than it actually is.
st.NumGC = 0
st.PauseTotalNs = 0
runtime.ReadMemStats(st)
numGC = st.NumGC
pauseTotalNs = st.PauseTotalNs
t0 = time.Now()
for i := 0; i < *n; i++ {
......@@ -107,6 +110,9 @@ func main() {
}
t1 := time.Now()
runtime.ReadMemStats(st)
st.NumGC -= numGC
st.PauseTotalNs -= pauseTotalNs
fmt.Printf("Alloc=%d/%d Heap=%d Mallocs=%d PauseTime=%.3f/%d = %.3f\n",
st.Alloc, st.TotalAlloc,
st.Sys,
......@@ -142,9 +148,7 @@ var packages = []string{
"container/list",
"container/ring",
"crypto/aes",
"crypto/blowfish",
"crypto/hmac",
"crypto/md4",
"crypto/md5",
"crypto/rand",
"crypto/rc4",
......@@ -155,7 +159,6 @@ var packages = []string{
"crypto/subtle",
"crypto/tls",
"crypto/x509",
"crypto/xtea",
"debug/dwarf",
"debug/macho",
"debug/elf",
......@@ -164,7 +167,6 @@ var packages = []string{
"encoding/ascii85",
"encoding/base64",
"encoding/binary",
"encoding/git85",
"encoding/hex",
"encoding/pem",
"os/exec",
......@@ -193,8 +195,6 @@ var packages = []string{
"mime",
"net",
"os",
"os/signal",
"patch",
"path",
"math/rand",
"reflect",
......@@ -214,11 +214,9 @@ var packages = []string{
"testing",
"testing/iotest",
"testing/quick",
"testing/script",
"time",
"unicode",
"unicode/utf8",
"unicode/utf16",
"websocket",
"encoding/xml",
}
// $G $F.go && $L $F.$A && ./$A.out
// run
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
......
......@@ -12,17 +12,23 @@ import (
)
func gcstats(name string, n int, t time.Duration) {
st := &runtime.MemStats
fmt.Printf("garbage.%sMem Alloc=%d/%d Heap=%d NextGC=%d Mallocs=%d\n", name, st.Alloc, st.TotalAlloc, st.Sys, st.NextGC, st.Mallocs)
fmt.Printf("garbage.%s %d %d ns/op\n", name, n, t.Nanoseconds()/int64(n))
fmt.Printf("garbage.%sLastPause 1 %d ns/op\n", name, st.PauseNs[(st.NumGC-1)%uint32(len(st.PauseNs))])
fmt.Printf("garbage.%sPause %d %d ns/op\n", name, st.NumGC, int64(st.PauseTotalNs)/int64(st.NumGC))
st := new(runtime.MemStats)
runtime.ReadMemStats(st)
nprocs := runtime.GOMAXPROCS(-1)
cpus := ""
if nprocs != 1 {
cpus = fmt.Sprintf("-%d", nprocs)
}
fmt.Printf("garbage.%sMem%s Alloc=%d/%d Heap=%d NextGC=%d Mallocs=%d\n", name, cpus, st.Alloc, st.TotalAlloc, st.Sys, st.NextGC, st.Mallocs)
fmt.Printf("garbage.%s%s %d %d ns/op\n", name, cpus, n, t.Nanoseconds()/int64(n))
fmt.Printf("garbage.%sLastPause%s 1 %d ns/op\n", name, cpus, st.PauseNs[(st.NumGC-1)%uint32(len(st.PauseNs))])
fmt.Printf("garbage.%sPause%s %d %d ns/op\n", name, cpus, st.NumGC, int64(st.PauseTotalNs)/int64(st.NumGC))
nn := int(st.NumGC)
if nn >= len(st.PauseNs) {
nn = len(st.PauseNs)
}
t1, t2, t3, t4, t5 := tukey5(st.PauseNs[0:nn])
fmt.Printf("garbage.%sPause5: %d %d %d %d %d\n", name, t1, t2, t3, t4, t5)
fmt.Printf("garbage.%sPause5%s: %d %d %d %d %d\n", name, cpus, t1, t2, t3, t4, t5)
// fmt.Printf("garbage.%sScan: %v\n", name, st.ScanDist)
}
......
......@@ -11,6 +11,7 @@ import (
"os"
"runtime"
"runtime/pprof"
"time"
"unsafe"
)
......@@ -30,6 +31,7 @@ var (
heap *Object
calls [20]int
numobjects int64
memstats runtime.MemStats
)
func buildHeap() {
......@@ -55,10 +57,10 @@ func buildTree(objsize, size float64, depth int) (*Object, float64) {
func gc() {
runtime.GC()
runtime.UpdateMemStats()
pause := runtime.MemStats.PauseTotalNs
inuse := runtime.MemStats.Alloc
free := runtime.MemStats.TotalAlloc - inuse
runtime.ReadMemStats(&memstats)
pause := memstats.PauseTotalNs
inuse := memstats.Alloc
free := memstats.TotalAlloc - inuse
fmt.Printf("gc pause: %8.3f ms; collect: %8.0f MB; heapsize: %8.0f MB\n",
float64(pause-lastPauseNs)/1e6,
float64(free-lastFree)/1048576,
......@@ -71,9 +73,9 @@ func main() {
flag.Parse()
buildHeap()
runtime.GOMAXPROCS(*cpus)
runtime.UpdateMemStats()
lastPauseNs = runtime.MemStats.PauseTotalNs
lastFree = runtime.MemStats.TotalAlloc - runtime.MemStats.Alloc
runtime.ReadMemStats(&memstats)
lastPauseNs = memstats.PauseTotalNs
lastFree = memstats.TotalAlloc - memstats.Alloc
if *cpuprofile != "" {
f, err := os.Create(*cpuprofile)
if err != nil {
......@@ -82,7 +84,12 @@ func main() {
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
}
for i := 0; i < 10; i++ {
const N = 10
var t0 time.Time
for i := 0; i < N; i++ {
t0 = time.Now()
gc()
}
// Standard gotest benchmark output, collected by build dashboard.
gcstats("BenchmarkTree2", N, time.Now().Sub(t0))
}
include $(GOROOT)/src/Make.inc
TARG=go1
GOFILES=\
dummy.go\
include $(GOROOT)/src/Make.pkg
package main
import target "go1"
import "testing"
import "regexp"
var tests = []testing.InternalTest{
}
var benchmarks = []testing.InternalBenchmark{
{"go1.BenchmarkBinaryTree17", target.BenchmarkBinaryTree17},
{"go1.BenchmarkFannkuch11", target.BenchmarkFannkuch11},
{"go1.BenchmarkGobDecode", target.BenchmarkGobDecode},
{"go1.BenchmarkGobEncode", target.BenchmarkGobEncode},
{"go1.BenchmarkGzip", target.BenchmarkGzip},
{"go1.BenchmarkGunzip", target.BenchmarkGunzip},
{"go1.BenchmarkJSONEncode", target.BenchmarkJSONEncode},
{"go1.BenchmarkJSONDecode", target.BenchmarkJSONDecode},
{"go1.BenchmarkRevcomp25M", target.BenchmarkRevcomp25M},
{"go1.BenchmarkTemplate", target.BenchmarkTemplate},
}
var examples = []testing.InternalExample{}
var matchPat string
var matchRe *regexp.Regexp
func matchString(pat, str string) (result bool, err error) {
if matchRe == nil || matchPat != pat {
matchPat = pat
matchRe, err = regexp.Compile(matchPat)
if err != nil {
return
}
}
return matchRe.MatchString(str), nil
}
func main() {
testing.Main(matchString, tests, benchmarks, examples)
}
package go1
// Nothing to see here: everything is in the _test files.
......@@ -4,9 +4,24 @@
package go1
import "runtime"
// Not a benchmark; input for revcomp.
var fasta25m = fasta(25e6)
var fastabytes = makefasta()
func makefasta() []byte {
var n int = 25e6
if runtime.GOARCH == "arm" {
// TODO(dfc) remove this limitation after precise gc.
// A value of 25e6 consumes 465mb of heap on 32bit
// platforms, which is too much for most ARM systems.
// A value of 25e5 produces a memory layout that
// confuses the gc on 32bit platforms. So 25e4 it is.
n = 25e4
}
return fasta(n)
}
func fasta(n int) []byte {
out := make(fastaBuffer, 0, 11*n)
......
......@@ -21,9 +21,7 @@ var (
gobdata *JSONResponse
)
func gobinit() {
// gobinit is called after json's init,
// because it uses jsondata.
func init() {
gobdata = gobResponse(&jsondata)
var buf bytes.Buffer
......
......@@ -21,20 +21,14 @@ var (
func init() {
var buf bytes.Buffer
c, err := gz.NewWriter(&buf)
if err != nil {
panic(err)
}
c := gz.NewWriter(&buf)
c.Write(jsongunz)
c.Close()
jsongz = buf.Bytes()
}
func gzip() {
c, err := gz.NewWriter(ioutil.Discard)
if err != nil {
panic(err)
}
c := gz.NewWriter(ioutil.Discard)
if _, err := c.Write(jsongunz); err != nil {
panic(err)
}
......
......@@ -17,11 +17,11 @@ import (
)
var (
jsonbytes []byte
jsondata JSONResponse
jsonbytes = makeJsonBytes()
jsondata = makeJsonData()
)
func init() {
func makeJsonBytes() []byte {
var r io.Reader
r = strings.NewReader(jsonbz2_base64)
r = base64.NewDecoder(base64.StdEncoding, r)
......@@ -30,12 +30,15 @@ func init() {
if err != nil {
panic(err)
}
jsonbytes = b
return b
}
if err := json.Unmarshal(jsonbytes, &jsondata); err != nil {
func makeJsonData() JSONResponse {
var v JSONResponse
if err := json.Unmarshal(jsonbytes, &v); err != nil {
panic(err)
}
gobinit()
return v
}
type JSONResponse struct {
......
// Copyright 2012 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.
// This benchmark, taken from the shootuot, tests floating point performance.
package go1
import "testing"
func mandelbrot(n int) int {
const Iter = 50
const Zero float64 = 0
const Limit = 2.0
ok := 0
for y := 0; y < n; y++ {
for x := 0; x < n; x++ {
Zr, Zi, Tr, Ti := Zero, Zero, Zero, Zero
Cr := (2*float64(x)/float64(n) - 1.5)
Ci := (2*float64(y)/float64(n) - 1.0)
for i := 0; i < Iter && (Tr+Ti <= Limit*Limit); i++ {
Zi = 2*Zr*Zi + Ci
Zr = Tr - Ti + Cr
Tr = Zr * Zr
Ti = Zi * Zi
}
if Tr+Ti <= Limit*Limit {
ok++
}
}
}
return ok
}
func BenchmarkMandelbrot200(b *testing.B) {
for i := 0; i < b.N; i++ {
mandelbrot(200)
}
}
// Copyright 2012 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.
package go1
// go parser benchmark based on go/parser/performance_test.go
import (
"compress/bzip2"
"encoding/base64"
"go/parser"
"go/token"
"io"
"io/ioutil"
"strings"
"testing"
)
var (
parserbytes = makeParserBytes()
)
func makeParserBytes() []byte {
var r io.Reader
r = strings.NewReader(parserbz2_base64)
r = base64.NewDecoder(base64.StdEncoding, r)
r = bzip2.NewReader(r)
b, err := ioutil.ReadAll(r)
if err != nil {
panic(err)
}
return b
}
func BenchmarkParse(b *testing.B) {
b.SetBytes(int64(len(parserbytes)))
for i := 0; i < b.N; i++ {
if _, err := parser.ParseFile(token.NewFileSet(), "", parserbytes, parser.ParseComments); err != nil {
b.Fatalf("benchmark failed due to parse error: %s", err)
}
}
}
......@@ -77,9 +77,9 @@ func revcomp(data []byte) {
}
}
func BenchmarkRevcomp25M(b *testing.B) {
b.SetBytes(int64(len(fasta25m)))
func BenchmarkRevcomp(b *testing.B) {
b.SetBytes(int64(len(fastabytes)))
for i := 0; i < b.N; i++ {
revcomp(fasta25m)
revcomp(fastabytes)
}
}
# Copyright 2011 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.
include ../../../src/Make.inc
all:
@echo "make clean or timing"
timing:
./timing.sh
clean:
rm -f [568].out *.[568]
......@@ -36,7 +36,6 @@ POSSIBILITY OF SUCH DAMAGE.
icc -O3 -ip -unroll -static binary-trees.c -lm
*/
#include <malloc.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
......
......@@ -221,7 +221,7 @@ main ()
free(s);
g_ptr_array_foreach(roots, free, NULL);
g_ptr_array_foreach(roots, (GFunc)free, NULL);
g_ptr_array_free(roots, TRUE);
return 0;
......
......@@ -50,21 +50,21 @@ func main() {
out := bufio.NewWriter(os.Stdout)
defer out.Flush()
w := *n
h := *n
w := float64(*n)
h := float64(*n)
bit_num := 0
byte_acc := byte(0)
const Iter = 50
const Zero float64 = 0
const Limit = 2.0
fmt.Fprintf(out, "P4\n%d %d\n", w, h)
fmt.Fprintf(out, "P4\n%d %d\n", *n, *n)
for y := 0; y < h; y++ {
for x := 0; x < w; x++ {
for y := 0.0; y < h; y++ {
for x := 0.0; x < w; x++ {
Zr, Zi, Tr, Ti := Zero, Zero, Zero, Zero
Cr := (2*float64(x)/float64(w) - 1.5)
Ci := (2*float64(y)/float64(h) - 1.0)
Cr := (2*x/w - 1.5)
Ci := (2*y/h - 1.0)
for i := 0; i < Iter && (Tr+Ti <= Limit*Limit); i++ {
Zi = 2*Zr*Zi + Ci
......@@ -85,7 +85,7 @@ func main() {
byte_acc = 0
bit_num = 0
} else if x == w-1 {
byte_acc <<= uint(8 - w%8)
byte_acc <<= uint(8 - uint(*n)%8)
out.WriteByte(byte_acc)
byte_acc = 0
bit_num = 0
......
......@@ -34,6 +34,7 @@ POSSIBILITY OF SUCH DAMAGE.
* contributed by Premysl Hruby
*/
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
......@@ -57,7 +58,7 @@ static struct stack stacks[THREADS];
static void* thread(void *num)
{
int l = (int)num;
int l = (int)(uintptr_t)num;
int r = (l+1) % THREADS;
int token;
......@@ -94,7 +95,7 @@ int main(int argc, char **argv)
pthread_mutex_lock(mutex + i);
pthread_attr_setstack(&stack_attr, &stacks[i], sizeof(struct stack));
pthread_create(&cthread, &stack_attr, thread, (void*)i);
pthread_create(&cthread, &stack_attr, thread, (void*)(uintptr_t)i);
}
pthread_mutex_unlock(mutex + 0);
......
......@@ -900,3 +900,264 @@ threadring 50000000
chameneos 6000000
gc chameneosredux 7.41u 0.00s 7.42r # -3%
# A complete run at the Go 1 release.
# Significant changes:
# - gccgo is now enabled for all tests (goroutines are cheap enough)
# - threadring and chameneos are 14% faster, probably due to runtime changes
# - regex-dna 36% faster
# - fannkuch-parallel (only) slowed down 40%
# - gccgo on binary-tree-freelist is still optimized to nothing
# Other changes are modest.
fasta -n 25000000
gcc -O2 fasta.c 1.45u 0.02s 1.48r
gccgo -O2 fasta.go 1.46u 0.00s 1.47r
gc fasta 1.99u 0.01s 2.00r
gc_B fasta 1.99u 0.01s 2.01r
reverse-complement < output-of-fasta-25000000
gcc -O2 reverse-complement.c 0.95u 0.48s 4.99r
gccgo -O2 reverse-complement.go 0.93u 0.16s 1.09r
gc reverse-complement 1.20u 0.19s 1.39r
gc_B reverse-complement 1.04u 0.16s 1.20r
nbody -n 50000000
gcc -O2 -lm nbody.c 13.02u 0.00s 13.05r
gccgo -O2 nbody.go 14.46u 0.00s 14.49r
gc nbody 21.79u 0.00s 21.84r
gc_B nbody 21.74u 0.00s 21.79r
binary-tree 15 # too slow to use 20
gcc -O2 binary-tree.c -lm 0.60u 0.01s 0.61r
gccgo -O2 binary-tree.go 1.30u 0.01s 1.32r
gccgo -O2 binary-tree-freelist.go 0.00u 0.00s 0.00r
gc binary-tree 1.84u 0.01s 1.86r
gc binary-tree-freelist 0.33u 0.00s 0.33r
fannkuch 12
gcc -O2 fannkuch.c 45.24u 0.00s 45.34r
gccgo -O2 fannkuch.go 59.76u 0.01s 59.90r
gccgo -O2 fannkuch-parallel.go 218.20u 0.01s 61.60r
gc fannkuch 103.92u 0.00s 104.16r
gc fannkuch-parallel 221.61u 0.00s 60.49r
gc_B fannkuch 53.17u 0.00s 53.30r
regex-dna 100000
gcc -O2 regex-dna.c -lpcre 0.47u 0.00s 0.48r
gccgo -O2 regex-dna.go 6.52u 0.00s 6.54r
gccgo -O2 regex-dna-parallel.go 14.40u 0.73s 4.35r
gc regex-dna 2.63u 0.02s 2.66r # -36%
gc regex-dna-parallel 2.87u 0.01s 1.11r
gc_B regex-dna 2.65u 0.00s 2.66r
spectral-norm 5500
gcc -O2 spectral-norm.c -lm 15.78u 0.00s 15.82r
gccgo -O2 spectral-norm.go 15.79u 0.00s 15.83r
gc spectral-norm 19.76u 0.00s 19.80r
gc_B spectral-norm 19.73u 0.01s 19.78r
k-nucleotide 1000000
gcc -O2 k-nucleotide.c 5.59u 0.03s 5.63r
gccgo -O2 k-nucleotide.go 4.09u 0.03s 4.13r
gccgo -O2 k-nucleotide-parallel.go 4.50u 0.06s 1.63r
gc k-nucleotide 9.23u 0.02s 9.27r
gc k-nucleotide-parallel 9.87u 0.03s 3.55r
gc_B k-nucleotide 9.20u 0.00s 9.22r
mandelbrot 16000
gcc -O2 mandelbrot.c 36.09u 0.00s 36.18r
gccgo -O2 mandelbrot.go 41.69u 0.01s 41.80r
gc mandelbrot 60.91u 0.02s 61.07r
gc_B mandelbrot 60.90u 0.00s 61.04r
meteor 2098
gcc -O2 meteor-contest.c 0.09u 0.00s 0.09r
gccgo -O2 meteor-contest.go 0.09u 0.00s 0.09r
gc meteor-contest 0.14u 0.00s 0.15r
gc_B meteor-contest 0.14u 0.00s 0.14r
pidigits 10000
gcc -O2 pidigits.c -lgmp 2.27u 0.00s 2.27r
gccgo -O2 pidigits.go 8.65u 0.00s 8.67r
gc pidigits 3.70u 0.04s 3.75r
gc_B pidigits 3.72u 0.02s 3.75r
threadring 50000000
gcc -O2 threadring.c 40.91u 369.85s 323.31r
gccgo -O2 threadring.go 26.97u 30.82s 57.93r
gc threadring 12.81u 0.01s 12.85r # -13%
chameneos 6000000
gcc -O2 chameneosredux.c -lpthread 9.44u 72.90s 12.65r
gccgo -O2 chameneosredux.go 7.73u 7.53s 15.30r
gc chameneosredux 6.51u 0.00s 6.53r # - 14%
# After http://codereview.appspot.com/6248049, moving panicindex
# calls out of line (putting the likely code into a single path and shortening
# loops). Significant changes since the last run (note: some are slower for
# unrelated and as yet undiagnosed reasons):
nbody -n 50000000
gc nbody 19.10u 0.01s 19.19r # -12%
gc_B nbody 19.19u 0.00s 19.23r # -12%
binary-tree 15 # too slow to use 20
gc binary-tree 1.49u 0.01s 1.51r # -19%
fannkuch 12
gc fannkuch 60.79u 0.00s 60.92r # -41%
gc fannkuch-parallel 183.51u 0.01s 51.75r # -14%
gc_B fannkuch 51.68u 0.00s 51.79r # -3%
k-nucleotide 1000000
gc k-nucleotide 9.74u 0.04s 9.80r # +6%
gc k-nucleotide-parallel 9.89u 0.05s 3.59r # +1%
gc_B k-nucleotide 9.39u 0.02s 9.43r # +2%
mandelbrot (much slower, due to unrelated http://codereview.appspot.com/6209077)
gc mandelbrot 100.98u 0.00s 101.20r # +65%
gc_B mandelbrot 100.90u 0.01s 101.17r # +65%
meteor 2098
gc meteor-contest 0.13u 0.00s 0.13r # -13%
gc_B meteor-contest 0.13u 0.00s 0.13r # -7%
# May 30, 2012.
# After http://codereview.appspot.com/6261051, restoring old code generated
# for floating-point constants. Mandelbrot is back to its previous numbers.
mandelbrot 16000
gcc -O2 mandelbrot.c 36.07u 0.00s 36.16r
gccgo -O2 mandelbrot.go 41.72u 0.01s 41.90r
gc mandelbrot 60.62u 0.00s 60.76r
gc_B mandelbrot 60.68u 0.00s 60.82r
# May 30, 2012.
# After http://codereview.appspot.com/6248068, better FP code
# by avoiding MOVSD between registers.
# Plus some other timing changes that have crept in from other speedups,
# from garbage collection to Printf.
fasta -n 25000000
gc fasta 1.76u 0.00s 1.76r # -12%
gc_B fasta 1.71u 0.00s 1.72r # -12%
nbody -n 50000000
gc nbody 17.56u 0.00s 17.60r # -8%
gc_B nbody 17.30u 0.00s 17.34r # -10%
fannkuch 12
gc fannkuch-parallel 155.92u 0.01s 44.05r # -15%
k-nucleotide 1000000
gc k-nucleotide 9.22u 0.01s 9.26r # -5%
gc k-nucleotide-parallel 9.23u 0.03s 3.26r # -9%
gc_B k-nucleotide 9.22u 0.03s 9.28r # -2%
mandelbrot 16000
gc mandelbrot 44.80u 0.00s 44.90r # -27%
gc_B mandelbrot 44.81u 0.00s 44.92r # -26%
pidigits 10000
gc pidigits 3.51u 0.00s 3.52r # -6%
gc_B pidigits 3.51u 0.00s 3.52r # -6%
# Aug 28, 2012
# After some assembler work in package big.
pidigits 10000
gc pidigits 2.85u 0.02s 2.88r # -22%
gc_B pidigits 2.88u 0.01s 2.90r # -21%
# Sep 26, 2012
# 64-bit ints, plus significantly better floating-point code.
# Interesting details:
# Generally something in the 0-10% slower range, some (binary tree) more
# Floating-point noticeably faster:
# nbody -25%
# mandelbrot -37% relative to Go 1.
# Other:
# regex-dna +47%
fasta -n 25000000
gcc -O2 fasta.c 1.43u 0.03s 1.46r
gccgo -O2 fasta.go 1.47u 0.00s 1.47r
gc fasta 1.78u 0.01s 1.80r
gc_B fasta 1.76u 0.00s 1.76r
reverse-complement < output-of-fasta-25000000
gcc -O2 reverse-complement.c 1.14u 0.39s 11.19r
gccgo -O2 reverse-complement.go 0.91u 0.17s 1.09r
gc reverse-complement 1.12u 0.18s 1.31r
gc_B reverse-complement 1.12u 0.15s 1.28r
nbody -n 50000000
gcc -O2 nbody.c -lm 13.02u 0.00s 13.05r
gccgo -O2 nbody.go 13.90u 0.00s 13.93r
gc nbody 17.05u 0.00s 17.09r
gc_B nbody 16.30u 0.00s 16.34r
binary-tree 15 # too slow to use 20
gcc -O2 binary-tree.c -lm 0.61u 0.00s 0.61r
gccgo -O2 binary-tree.go 1.24u 0.04s 1.29r
gccgo -O2 binary-tree-freelist.go 0.21u 0.01s 0.22r
gc binary-tree 1.93u 0.02s 1.96r
gc binary-tree-freelist 0.32u 0.00s 0.33r
fannkuch 12
gcc -O2 fannkuch.c 45.19u 0.00s 45.29r
gccgo -O2 fannkuch.go 60.32u 0.00s 60.45r
gccgo -O2 fannkuch-parallel.go 185.59u 0.00s 59.49r
gc fannkuch 72.14u 0.00s 72.30r
gc fannkuch-parallel 172.54u 0.00s 43.59r
gc_B fannkuch 53.55u 0.00s 53.67r
regex-dna 100000
gcc -O2 regex-dna.c -lpcre 0.47u 0.00s 0.47r
gccgo -O2 regex-dna.go 6.49u 0.05s 6.56r
gccgo -O2 regex-dna-parallel.go 14.60u 0.67s 4.42r
gc regex-dna 3.91u 0.00s 3.92r
gc regex-dna-parallel 4.01u 0.03s 1.56r
gc_B regex-dna 3.91u 0.00s 3.92r
spectral-norm 5500
gcc -O2 spectral-norm.c -lm 15.85u 0.00s 15.89r
gccgo -O2 spectral-norm.go 15.86u 0.00s 15.89r
gc spectral-norm 19.72u 0.00s 19.76r
gc_B spectral-norm 19.68u 0.01s 19.74r
k-nucleotide 1000000
gcc -O2 k-nucleotide.c -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -lglib-2.0 4.90u 0.01s 4.93r
gccgo -O2 k-nucleotide.go 4.78u 0.01s 4.80r
gccgo -O2 k-nucleotide-parallel.go 6.49u 0.02s 2.18r
gc k-nucleotide 9.05u 0.02s 9.09r
gc k-nucleotide-parallel 9.27u 0.01s 3.29r
gc_B k-nucleotide 8.95u 0.03s 9.00r
mandelbrot 16000
gcc -O2 mandelbrot.c 36.11u 0.00s 36.19r
gccgo -O2 mandelbrot.go 43.67u 0.00s 43.77r
gc mandelbrot 38.57u 0.00s 38.66r
gc_B mandelbrot 38.59u 0.00s 38.68r
meteor 2098
gcc -O2 meteor-contest.c 0.09u 0.00s 0.09r
gccgo -O2 meteor-contest.go 0.09u 0.00s 0.09r
gc meteor-contest 0.13u 0.00s 0.14r
gc_B meteor-contest 0.12u 0.00s 0.13r
pidigits 10000
gcc -O2 pidigits.c -lgmp 2.26u 0.00s 2.27r
gccgo -O2 pidigits.go 9.05u 0.00s 9.07r
gc pidigits 2.88u 0.02s 2.90r
gc_B pidigits 2.89u 0.00s 2.90r
threadring 50000000
gcc -O2 threadring.c -lpthread 37.30u 327.81s 289.28r
gccgo -O2 threadring.go 42.83u 26.15s 69.14r
gc threadring 13.00u 0.00s 13.03r
chameneos 6000000
gcc -O2 chameneosredux.c -lpthread 8.80u 71.67s 12.19r
gccgo -O2 chameneosredux.go 11.28u 6.68s 18.00r
gc chameneosredux 6.94u 0.00s 6.96r
......@@ -5,7 +5,11 @@
set -e
eval $(gomake --no-print-directory -f ../../../src/Make.inc go-env)
eval $(go tool dist env)
O=$GOCHAR
GC="go tool ${O}g"
LD="go tool ${O}l"
PATH=.:$PATH
havegccgo=false
......@@ -93,7 +97,7 @@ revcomp() {
nbody() {
runonly echo 'nbody -n 50000000'
run 'gcc -O2 -lm nbody.c' a.out 50000000
run 'gcc -O2 nbody.c -lm' a.out 50000000
run 'gccgo -O2 nbody.go' a.out -n 50000000
run 'gc nbody' $O.out -n 50000000
run 'gc_B nbody' $O.out -n 50000000
......@@ -103,7 +107,7 @@ binarytree() {
runonly echo 'binary-tree 15 # too slow to use 20'
run 'gcc -O2 binary-tree.c -lm' a.out 15
run 'gccgo -O2 binary-tree.go' a.out -n 15
run 'gccgo -O2 binary-tree-freelist.go' $O.out -n 15
run 'gccgo -O2 binary-tree-freelist.go' a.out -n 15
run 'gc binary-tree' $O.out -n 15
run 'gc binary-tree-freelist' $O.out -n 15
}
......@@ -143,7 +147,9 @@ knucleotide() {
runonly gcc -O2 fasta.c
runonly a.out 1000000 > x # should be using 25000000
runonly echo 'k-nucleotide 1000000'
run 'gcc -O2 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include k-nucleotide.c -lglib-2.0' a.out <x
if [ $mode = run ]; then
run "gcc -O2 k-nucleotide.c $(pkg-config glib-2.0 --cflags --libs)" a.out <x
fi
run 'gccgo -O2 k-nucleotide.go' a.out <x
run 'gccgo -O2 k-nucleotide-parallel.go' a.out <x
run 'gc k-nucleotide' $O.out <x
......
// $G $D/$F.go && $L $F.$A && ./$A.out
// run
// 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.
// Test the internal "algorithms" for objects larger than a word: hashing, equality etc.
package main
type T struct {
......
// $G $F.go && $L $F.$A && ./$A.out
// run
// 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.
// Internally a map holds elements in up to 255 bytes of key+value.
// When key or value or both are too large, it uses pointers to key+value
// instead. Test all the combinations.
package main
func seq(x, y int) [1000]byte {
......@@ -31,4 +35,105 @@ func main() {
cmp(m[1], seq(11, 13))
cmp(m[2], seq(2, 9))
cmp(m[3], seq(3, 17))
{
type T [1]byte
type V [1]byte
m := make(map[T]V)
m[T{}] = V{1}
m[T{1}] = V{2}
if x, y := m[T{}][0], m[T{1}][0]; x != 1 || y != 2 {
println(x, y)
panic("bad map")
}
}
{
type T [100]byte
type V [1]byte
m := make(map[T]V)
m[T{}] = V{1}
m[T{1}] = V{2}
if x, y := m[T{}][0], m[T{1}][0]; x != 1 || y != 2 {
println(x, y)
panic("bad map")
}
}
{
type T [1]byte
type V [100]byte
m := make(map[T]V)
m[T{}] = V{1}
m[T{1}] = V{2}
if x, y := m[T{}][0], m[T{1}][0]; x != 1 || y != 2 {
println(x, y)
panic("bad map")
}
}
{
type T [1000]byte
type V [1]byte
m := make(map[T]V)
m[T{}] = V{1}
m[T{1}] = V{2}
if x, y := m[T{}][0], m[T{1}][0]; x != 1 || y != 2 {
println(x, y)
panic("bad map")
}
}
{
type T [1]byte
type V [1000]byte
m := make(map[T]V)
m[T{}] = V{1}
m[T{1}] = V{2}
if x, y := m[T{}][0], m[T{1}][0]; x != 1 || y != 2 {
println(x, y)
panic("bad map")
}
}
{
type T [1000]byte
type V [1000]byte
m := make(map[T]V)
m[T{}] = V{1}
m[T{1}] = V{2}
if x, y := m[T{}][0], m[T{1}][0]; x != 1 || y != 2 {
println(x, y)
panic("bad map")
}
}
{
type T [200]byte
type V [1]byte
m := make(map[T]V)
m[T{}] = V{1}
m[T{1}] = V{2}
if x, y := m[T{}][0], m[T{1}][0]; x != 1 || y != 2 {
println(x, y)
panic("bad map")
}
}
{
type T [1]byte
type V [200]byte
m := make(map[T]V)
m[T{}] = V{1}
m[T{1}] = V{2}
if x, y := m[T{}][0], m[T{1}][0]; x != 1 || y != 2 {
println(x, y)
panic("bad map")
}
}
{
type T [200]byte
type V [200]byte
m := make(map[T]V)
m[T{}] = V{1}
m[T{1}] = V{2}
if x, y := m[T{}][0], m[T{1}][0]; x != 1 || y != 2 {
println(x, y)
panic("bad map")
}
}
}
// $G $D/$F.go && $L $F.$A && ./$A.out
// run
// 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.
// Test behavior of the blank identifier (_).
package main
import _ "fmt"
......@@ -111,7 +113,7 @@ type I interface {
type TI struct{}
func (TI) M(x int, y int) {
func (_ TI) M(x int, y int) {
if x != y {
println("invalid M call:", x, y)
panic("bad M")
......
// errchk $G -e $D/$F.go
// errorcheck
// 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.
// Test that incorrect uses of the blank identifer are caught.
// Does not compile.
package _ // ERROR "invalid package name _"
func main() {
......
// runoutput
// Copyright 2011 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.
// Test source file beginning with a byte order mark.
package main
import (
"fmt"
"strings"
)
func main() {
prog = strings.Replace(prog, "BOM", "\uFEFF", -1)
fmt.Print(prog)
}
var prog = `BOM
package main
func main() {
}
`
// errorcheck
// Copyright 2012 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.
// Here for reference, but hard to test automatically
// because the BOM muddles the
// processing done by ../run.
package main
func main() {
// There's a bom here. // ERROR "BOM"
// And here. // ERROR "BOM"
/* And here.*/ // ERROR "BOM"
println("hi there") // and here // ERROR "BOM"
}
// errorcheck -0 -m -l
// Copyright 2012 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.
// Test, using compiler diagnostic flags, that bounds check elimination
// is eliminating the correct checks.
package foo
var (
s []int
a1 [1]int
a1k [1000]int
a100k [100000]int
p1 *[1]int
p1k *[1000]int
p100k *[100000]int
i int
ui uint
i8 int8
ui8 uint8
i16 int16
ui16 uint16
i32 int32
ui32 uint32
i64 int64
ui64 uint64
)
func main() {
// Most things need checks.
use(s[i])
use(a1[i])
use(a1k[i])
use(a100k[i])
use(p1[i])
use(p1k[i])
use(p100k[i])
use(s[ui])
use(a1[ui])
use(a1k[ui])
use(a100k[ui])
use(p1[ui])
use(p1k[ui])
use(p100k[ui])
use(s[i8])
use(a1[i8])
use(a1k[i8])
use(a100k[i8])
use(p1[i8])
use(p1k[i8])
use(p100k[i8])
// Unsigned 8-bit numbers don't need checks for len >= 2⁸.
use(s[ui8])
use(a1[ui8])
use(a1k[ui8]) // ERROR "index bounds check elided"
use(a100k[ui8]) // ERROR "index bounds check elided"
use(p1[ui8])
use(p1k[ui8]) // ERROR "index bounds check elided"
use(p100k[ui8]) // ERROR "index bounds check elided"
use(s[i16])
use(a1[i16])
use(a1k[i16])
use(a100k[i16])
use(p1[i16])
use(p1k[i16])
use(p100k[i16])
// Unsigned 16-bit numbers don't need checks for len >= 2¹⁶.
use(s[ui16])
use(a1[ui16])
use(a1k[ui16])
use(a100k[ui16]) // ERROR "index bounds check elided"
use(p1[ui16])
use(p1k[ui16])
use(p100k[ui16]) // ERROR "index bounds check elided"
use(s[i32])
use(a1[i32])
use(a1k[i32])
use(a100k[i32])
use(p1[i32])
use(p1k[i32])
use(p100k[i32])
use(s[ui32])
use(a1[ui32])
use(a1k[ui32])
use(a100k[ui32])
use(p1[ui32])
use(p1k[ui32])
use(p100k[ui32])
use(s[i64])
use(a1[i64])
use(a1k[i64])
use(a100k[i64])
use(p1[i64])
use(p1k[i64])
use(p100k[i64])
use(s[ui64])
use(a1[ui64])
use(a1k[ui64])
use(a100k[ui64])
use(p1[ui64])
use(p1k[ui64])
use(p100k[ui64])
// Mod truncates the maximum value to one less than the argument,
// but signed mod can be negative, so only unsigned mod counts.
use(s[i%999])
use(a1[i%999])
use(a1k[i%999])
use(a100k[i%999])
use(p1[i%999])
use(p1k[i%999])
use(p100k[i%999])
use(s[ui%999])
use(a1[ui%999])
use(a1k[ui%999]) // ERROR "index bounds check elided"
use(a100k[ui%999]) // ERROR "index bounds check elided"
use(p1[ui%999])
use(p1k[ui%999]) // ERROR "index bounds check elided"
use(p100k[ui%999]) // ERROR "index bounds check elided"
use(s[i%1000])
use(a1[i%1000])
use(a1k[i%1000])
use(a100k[i%1000])
use(p1[i%1000])
use(p1k[i%1000])
use(p100k[i%1000])
use(s[ui%1000])
use(a1[ui%1000])
use(a1k[ui%1000]) // ERROR "index bounds check elided"
use(a100k[ui%1000]) // ERROR "index bounds check elided"
use(p1[ui%1000])
use(p1k[ui%1000]) // ERROR "index bounds check elided"
use(p100k[ui%1000]) // ERROR "index bounds check elided"
use(s[i%1001])
use(a1[i%1001])
use(a1k[i%1001])
use(a100k[i%1001])
use(p1[i%1001])
use(p1k[i%1001])
use(p100k[i%1001])
use(s[ui%1001])
use(a1[ui%1001])
use(a1k[ui%1001])
use(a100k[ui%1001]) // ERROR "index bounds check elided"
use(p1[ui%1001])
use(p1k[ui%1001])
use(p100k[ui%1001]) // ERROR "index bounds check elided"
// Bitwise and truncates the maximum value to the mask value.
// The result (for a positive mask) cannot be negative, so elision
// applies to both signed and unsigned indexes.
use(s[i&999])
use(a1[i&999])
use(a1k[i&999]) // ERROR "index bounds check elided"
use(a100k[i&999]) // ERROR "index bounds check elided"
use(p1[i&999])
use(p1k[i&999]) // ERROR "index bounds check elided"
use(p100k[i&999]) // ERROR "index bounds check elided"
use(s[ui&999])
use(a1[ui&999])
use(a1k[ui&999]) // ERROR "index bounds check elided"
use(a100k[ui&999]) // ERROR "index bounds check elided"
use(p1[ui&999])
use(p1k[ui&999]) // ERROR "index bounds check elided"
use(p100k[ui&999]) // ERROR "index bounds check elided"
use(s[i&1000])
use(a1[i&1000])
use(a1k[i&1000])
use(a100k[i&1000]) // ERROR "index bounds check elided"
use(p1[i&1000])
use(p1k[i&1000])
use(p100k[i&1000]) // ERROR "index bounds check elided"
use(s[ui&1000])
use(a1[ui&1000])
use(a1k[ui&1000])
use(a100k[ui&1000]) // ERROR "index bounds check elided"
use(p1[ui&1000])
use(p1k[ui&1000])
use(p100k[ui&1000]) // ERROR "index bounds check elided"
// Right shift cuts the effective number of bits in the index,
// but only for unsigned (signed stays negative).
use(s[i32>>22])
use(a1[i32>>22])
use(a1k[i32>>22])
use(a100k[i32>>22])
use(p1[i32>>22])
use(p1k[i32>>22])
use(p100k[i32>>22])
use(s[ui32>>22])
use(a1[ui32>>22])
use(a1k[ui32>>22])
use(a100k[ui32>>22]) // ERROR "index bounds check elided"
use(p1[ui32>>22])
use(p1k[ui32>>22])
use(p100k[ui32>>22]) // ERROR "index bounds check elided"
use(s[i32>>23])
use(a1[i32>>23])
use(a1k[i32>>23])
use(a100k[i32>>23])
use(p1[i32>>23])
use(p1k[i32>>23])
use(p100k[i32>>23])
use(s[ui32>>23])
use(a1[ui32>>23])
use(a1k[ui32>>23]) // ERROR "index bounds check elided"
use(a100k[ui32>>23]) // ERROR "index bounds check elided"
use(p1[ui32>>23])
use(p1k[ui32>>23]) // ERROR "index bounds check elided"
use(p100k[ui32>>23]) // ERROR "index bounds check elided"
// Division cuts the range like right shift does.
use(s[i/1e6])
use(a1[i/1e6])
use(a1k[i/1e6])
use(a100k[i/1e6])
use(p1[i/1e6])
use(p1k[i/1e6])
use(p100k[i/1e6])
use(s[ui/1e6])
use(a1[ui/1e6])
use(a1k[ui/1e6])
use(p1[ui/1e6])
use(p1k[ui/1e6])
use(s[i/1e7])
use(a1[i/1e7])
use(a1k[i/1e7])
use(a100k[i/1e7])
use(p1[i/1e7])
use(p1k[i/1e7])
use(p100k[i/1e7])
use(s[ui/1e7])
use(a1[ui/1e7])
use(p1[ui/1e7])
}
var sum int
func use(x int) {
sum += x
}
// echo bug395 is broken # takes 90+ seconds to break
// # $G $D/$F.go || echo bug395
// NOTE: This test is not run by 'run.go' and so not run by all.bash.
// To run this test you must use the ./run shell script.
// Copyright 2011 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.
......
// Copyright 2012 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.
package one
// Issue 3552
type T struct { int }
func (t T) F() int { return t.int }
type U struct { int int }
func (u U) F() int { return u.int }
type lint int
type V struct { lint }
func (v V) F() int { return int(v.lint) }
type W struct { lint lint }
func (w W) F() int { return int(w.lint) }
// Copyright 2012 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.
// Use the functions in one.go so that the inlined
// forms get type-checked.
package two
import "./one"
func use() {
var t one.T
var u one.U
var v one.V
var w one.W
_ = t.F()
_ = u.F()
_ = v.F()
_ = w.F()
}
// $G $D/$F.dir/one.go && $G $D/$F.dir/two.go || echo BUG:bug434
// NOTE: This test is not run by 'run.go' and so not run by all.bash.
// To run this test you must use the ./run shell script.
// Copyright 2011 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.
package ignored
// $G $D/$F.go && $L $F.$A && ./$A.out
// run
// 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.
// This test is designed to flush out the case where two cases of a select can
// Test the situation in which two cases of a select can
// both end up running. See http://codereview.appspot.com/180068.
package main
import (
......
// $G $D/$F.go && $L $F.$A && ./$A.out
// run
// 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.
// Verify that unbuffered channels act as pure fifos.
// Test that unbuffered channels act as pure fifos.
package main
......
// $G $D/$F.go && $L $F.$A && ./$A.out
// run
// 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.
// make a lot of goroutines, threaded together.
// tear them down cleanly.
// Torture test for goroutines.
// Make a lot of goroutines, threaded together, and tear them down cleanly.
package main
......
// $G $D/$F.go && $L $F.$A && ./$A.out
// run
// 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.
// Verify channel operations that test for blocking
// Use several sizes and types of operands
// Test channel operations that test for blocking.
// Use several sizes and types of operands.
package main
......
// errchk $G -e $D/$F.go
// errorcheck
// 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.
// Test various correct and incorrect permutations of send-only,
// receive-only, and bidirectional channels.
// Does not compile.
package main
var (
......
// $G $D/$F.go && $L $F.$A && ./$A.out
// run
// 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.
// Test concurrency primitives: power series.
// Power series package
// A power series is a channel, along which flow rational
// coefficients. A denominator of zero signifies the end.
......
// $G $D/$F.go && $L $F.$A && ./$A.out
// run
// 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.
// Test concurrency primitives: power series.
// Like powser1.go but uses channels of interfaces.
// Has not been cleaned up as much as powser1.go, to keep
// it distinct and therefore a different test.
// Power series package
// A power series is a channel, along which flow rational
// coefficients. A denominator of zero signifies the end.
// Original code in Newsqueak by Doug McIlroy.
// See Squinting at Power Series by Doug McIlroy,
// http://www.cs.bell-labs.com/who/rsc/thread/squint.pdf
// Like powser1.go but uses channels of interfaces.
// Has not been cleaned up as much as powser1.go, to keep
// it distinct and therefore a different test.
package main
......
// $G $D/$F.go && $L $F.$A && ./$A.out
// run
// 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.
// Test simple select.
package main
var counter uint
......
// $G $D/$F.go && $L $F.$A && ./$A.out
// run
// Copyright 2010 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.
// Test that selects do not consume undue memory.
package main
import "runtime"
......
// $G $D/$F.go && $L $F.$A && ./$A.out
// run
// Copyright 2010 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.
// Tests verifying the semantics of the select statement
// Test the semantics of the select statement
// for basic empty/non-empty cases.
package main
......@@ -197,13 +197,13 @@ func main() {
})
testBlock(never, func() {
select {
case x := <-closedch:
case x := (<-closedch):
_ = x
}
})
testBlock(never, func() {
select {
case x, ok := <-closedch:
case x, ok := (<-closedch):
_, _ = x, ok
}
})
......
// $G $D/$F.go && $L $F.$A && ./$A.out
// run
// Copyright 2010 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
// Test that a select statement proceeds when a value is ready.
package main
......
// $G $D/$F.go && $L $F.$A && ./$A.out >tmp.go &&
// $G tmp.go && $L tmp.$A && ./$A.out || echo BUG: select5
// rm -f tmp.go
// runoutput
// Copyright 2011 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.
// Generate test of channel operations and simple selects.
// Only doing one real send or receive at a time, but phrased
// The output of this program is compiled and run to do the
// actual test.
// Each test does only one real send or receive at a time, but phrased
// in various ways that the compiler may or may not rewrite
// into simpler expressions.
......
// $G $D/$F.go && $L $F.$A && ./$A.out
// run
// Copyright 2011 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.
// Issue 2075
// Test for select: Issue 2075
// A bug in select corrupts channel queues of failed cases
// if there are multiple waiters on those channels and the
// select is the last in the queue. If further waits are made
......
// $G $D/$F.go && $L $F.$A && ./$A.out
// run
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
......
// $G $D/$F.go && $L $F.$A && ./$A.out
// run
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
......
// $G $D/$F.go && $L $F.$A && ./$A.out
// run
// 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.
// Test concurrency primitives: classical inefficient concurrent prime sieve.
// Generate primes up to 100 using channels, checking the results.
// This sieve consists of a linear chain of divisibility filters,
// equivalent to trial-dividing each n by all primes p ≤ n.
......
// $G $D/$F.go && $L $F.$A && ./$A.out
// run
// 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.
// Test concurrency primitives: prime sieve of Eratosthenes.
// Generate primes up to 100 using channels, checking the results.
// This sieve is Eratosthenesque and only considers odd candidates.
// See discussion at <http://blog.onideas.ws/eratosthenes.go>.
......
// $G $D/$F.go && $L $F.$A && ./$A.out
// run
// Copyright 2011 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.
// Making channels of a zero-sized type should not panic.
// Test making channels of a zero-sized type.
package main
......
// $G $D/$F.go && $L $F.$A && ./$A.out
// run
// 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.
// Test the cap predeclared function applied to channels.
package main
func main() {
......
// $G $F.go && $L $F.$A &&./$A.out
// run
// 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.
// Test character literal syntax.
package main
import "os"
......
// errchk $G -e $F.go
// errorcheck
// 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.
// Verify that illegal character literals are detected.
// Does not compile.
package main
const (
......
// $G $D/$F.go && $L $F.$A && ./$A.out
// run
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
......
// $G $D/$F.go && $L $F.$A && ./$A.out
// run
// 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.
// Test the behavior of closures.
package main
import "runtime"
......@@ -79,6 +81,7 @@ func h() {
func newfunc() func(int) int { return func(x int) int { return x } }
func main() {
runtime.GOMAXPROCS(1)
var fail bool
go f()
......@@ -92,8 +95,9 @@ func main() {
go h()
check([]int{100, 200, 101, 201, 500, 101, 201, 500})
runtime.UpdateMemStats()
n0 := runtime.MemStats.Mallocs
memstats := new(runtime.MemStats)
runtime.ReadMemStats(memstats)
n0 := memstats.Mallocs
x, y := newfunc(), newfunc()
if x(1) != 1 || y(2) != 2 {
......@@ -101,8 +105,8 @@ func main() {
fail = true
}
runtime.UpdateMemStats()
if n0 != runtime.MemStats.Mallocs {
runtime.ReadMemStats(memstats)
if n0 != memstats.Mallocs {
println("newfunc allocated unexpectedly")
fail = true
}
......@@ -110,7 +114,7 @@ func main() {
ff(1)
if fail {
panic("fail")
panic("fail")
}
}
......
// $G $D/$F.go && $L $F.$A && ./$A.out
// run
// 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.
// Test equality and inequality operations.
package main
import "unsafe"
......@@ -281,6 +283,25 @@ func main() {
isfalse(ix != z)
isfalse(iz != x)
}
// structs with _ fields
{
var x = struct {
x int
_ []int
y float64
_ float64
z int
}{
x: 1, y: 2, z: 3,
}
var ix interface{} = x
istrue(x == x)
istrue(x == ix)
istrue(ix == x)
istrue(ix == ix)
}
// arrays
{
......
// errchk $G -e $D/$F.go
// errorcheck
// Copyright 2010 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.
// Verify that incorrect comparisons are detected.
// Does not compile.
package main
func use(bool) {}
......@@ -15,6 +18,10 @@ type T3 struct{ z []int }
var t3 T3
type T4 struct { _ []int; a float64 }
var t4 T4
func main() {
// Arguments to comparison must be
// assignable one to the other (or vice versa)
......@@ -46,6 +53,7 @@ func main() {
// Comparison of structs should have a good message
use(t3 == t3) // ERROR "struct|expected"
use(t4 == t4) // ok; the []int is a blank field
// Slices, functions, and maps too.
var x []int
......
// errchk $G -e $D/$F.go
// errorcheck
// Copyright 2010 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.
// Verify that incorrect invocations of the complex predeclared function are detected.
// Does not compile.
package main
var (
......
......@@ -51,6 +51,7 @@ main(void)
int i, j, k, l;
double complex n, d, q;
printf("// skip\n");
printf("// # generated by cmplxdivide.c\n");
printf("\n");
printf("package main\n");
......
// $G $D/$F.go $D/cmplxdivide1.go && $L $D/$F.$A && ./$A.out
// run cmplxdivide1.go
// Copyright 2010 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
......
// skip
// # generated by cmplxdivide.c
package main
......
// $G $F.go && $L $F.$A && ./$A.out
// run
// 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.
// Test composite literals.
package main
type T struct {
......
// errchk $G -e $D/$F.go
// errorcheck
// Copyright 2011 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.
// Verify that illegal composite literals are detected.
// Does not compile.
package main
var m map[int][3]int
......
// $G $D/$F.go && $L $F.$A && ./$A.out || echo BUG: compos
// run
// 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.
// Test that returning &T{} from a function causes an allocation.
package main
type T struct {
......
// $G $F.go && $L $F.$A && ./$A.out
// run
// 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.
// Test simple boolean and numeric constants.
package main
const (
......
// errchk $G -e $F.go
// errorcheck
// 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.
// Verify overflow is detected when using numeric constants.
// Does not compile.
package main
type I interface{}
......@@ -13,11 +16,11 @@ const (
Int8 int8 = 101
Minus1 int8 = -1
Uint8 uint8 = 102
Const = 103
Const = 103
Float32 float32 = 104.5
Float64 float64 = 105.5
ConstFloat = 106.5
ConstFloat = 106.5
Big float64 = 1e300
String = "abc"
......@@ -35,32 +38,35 @@ var (
a8 = Int8 * Const / 100 // ERROR "overflow"
a9 = Int8 * (Const / 100) // OK
b1 = Uint8 * Uint8 // ERROR "overflow"
b2 = Uint8 * -1 // ERROR "overflow"
b3 = Uint8 - Uint8 // OK
b4 = Uint8 - Uint8 - Uint8 // ERROR "overflow"
b5 = uint8(^0) // ERROR "overflow"
b6 = ^uint8(0) // OK
b7 = uint8(Minus1) // ERROR "overflow"
b8 = uint8(int8(-1)) // ERROR "overflow"
b8a = uint8(-1) // ERROR "overflow"
b9 byte = (1 << 10) >> 8 // OK
b10 byte = (1 << 10) // ERROR "overflow"
b11 byte = (byte(1) << 10) >> 8 // ERROR "overflow"
b12 byte = 1000 // ERROR "overflow"
b13 byte = byte(1000) // ERROR "overflow"
b14 byte = byte(100) * byte(100) // ERROR "overflow"
b15 byte = byte(100) * 100 // ERROR "overflow"
b16 byte = byte(0) * 1000 // ERROR "overflow"
b16a byte = 0 * 1000 // OK
b17 byte = byte(0) * byte(1000) // ERROR "overflow"
b18 byte = Uint8 / 0 // ERROR "division by zero"
b1 = Uint8 * Uint8 // ERROR "overflow"
b2 = Uint8 * -1 // ERROR "overflow"
b3 = Uint8 - Uint8 // OK
b4 = Uint8 - Uint8 - Uint8 // ERROR "overflow"
b5 = uint8(^0) // ERROR "overflow"
b5a = int64(^0) // OK
b6 = ^uint8(0) // OK
b6a = ^int64(0) // OK
b7 = uint8(Minus1) // ERROR "overflow"
b8 = uint8(int8(-1)) // ERROR "overflow"
b8a = uint8(-1) // ERROR "overflow"
b9 byte = (1 << 10) >> 8 // OK
b10 byte = (1 << 10) // ERROR "overflow"
b11 byte = (byte(1) << 10) >> 8 // ERROR "overflow"
b12 byte = 1000 // ERROR "overflow"
b13 byte = byte(1000) // ERROR "overflow"
b14 byte = byte(100) * byte(100) // ERROR "overflow"
b15 byte = byte(100) * 100 // ERROR "overflow"
b16 byte = byte(0) * 1000 // ERROR "overflow"
b16a byte = 0 * 1000 // OK
b17 byte = byte(0) * byte(1000) // ERROR "overflow"
b18 byte = Uint8 / 0 // ERROR "division by zero"
c1 float64 = Big
c2 float64 = Big * Big // ERROR "overflow"
c3 float64 = float64(Big) * Big // ERROR "overflow"
c4 = Big * Big // ERROR "overflow"
c5 = Big / 0 // ERROR "division by zero"
c1 float64 = Big
c2 float64 = Big * Big // ERROR "overflow"
c3 float64 = float64(Big) * Big // ERROR "overflow"
c4 = Big * Big // ERROR "overflow"
c5 = Big / 0 // ERROR "division by zero"
c6 = 1000 % 1e3 // ERROR "floating-point % operation|expected integer type"
)
func f(int)
......
// errchk $G $D/$F.go
// errorcheck
// 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.
// Verify that large integer constant expressions cause overflow.
// Does not compile.
package main
const (
A int = 1
B byte; // ERROR "type without expr|expected .=."
)
const LargeA = 1000000000000000000
const LargeB = LargeA * LargeA * LargeA
const LargeC = LargeB * LargeB * LargeB // GC_ERROR "constant multiplication overflow"
const AlsoLargeA = LargeA << 400 << 400 >> 400 >> 400 // GC_ERROR "constant shift overflow"
// $G $D/$F.go && $L $F.$A && ./$A.out
// run
// 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.
// Test typed integer constants.
package main
import "fmt"
......
// run
// Copyright 2011 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.
// Test len constants and non-constants, http://golang.org/issue/3244.
package main
var b struct {
a[10]int
}
var m map[string][20]int
var s [][30]int
const (
n1 = len(b.a)
n2 = len(m[""])
n3 = len(s[10])
)
// Non-constants (see also const5.go).
var (
n4 = len(f())
n5 = len(<-c)
n6 = cap(g())
n7 = cap(<-c1)
)
var calledF = false
func f() *[40]int {
calledF = true
return nil
}
var c = func() chan *[50]int {
c := make(chan *[50]int, 2)
c <- nil
c <- new([50]int)
return c
}()
var calledG = false
func g() *[60]int {
calledG = true
return nil
}
var c1 = func() chan *[70]int {
c := make(chan *[70]int, 2)
c <- nil
c <- new([70]int)
return c
}()
func main() {
if n1 != 10 || n2 != 20 || n3 != 30 || n4 != 40 || n5 != 50 || n6 != 60 || n7 != 70 {
println("BUG:", n1, n2, n3, n4, n5, n6, n7)
}
if !calledF {
println("BUG: did not call f")
}
if <-c == nil {
println("BUG: did not receive from c")
}
if !calledG {
println("BUG: did not call g")
}
if <-c1 == nil {
println("BUG: did not receive from c1")
}
}
// errorcheck
// Copyright 2011 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.
// Test that len non-constants are not constants, http://golang.org/issue/3244.
package p
var b struct {
a[10]int
}
var m map[string][20]int
var s [][30]int
func f() *[40]int
var c chan *[50]int
const (
n1 = len(b.a)
n2 = len(m[""])
n3 = len(s[10])
n4 = len(f()) // ERROR "must be constant|is not constant"
n5 = len(<-c) // ERROR "must be constant|is not constant"
n6 = cap(f()) // ERROR "must be constant|is not constant"
n7 = cap(<-c) // ERROR "must be constant|is not constant"
)
// run
// Copyright 2012 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.
// Test conversion from non-interface types to the empty interface.
package main
type J interface {
Method()
}
type (
U16 uint16
U32 uint32
U64 uint64
U128 [2]uint64
F32 float32
F64 float64
C128 complex128
S string
B []byte
M map[int]int
C chan int
Z struct{}
)
func (U16) Method() {}
func (U32) Method() {}
func (U64) Method() {}
func (U128) Method() {}
func (F32) Method() {}
func (F64) Method() {}
func (C128) Method() {}
func (S) Method() {}
func (B) Method() {}
func (M) Method() {}
func (C) Method() {}
func (Z) Method() {}
var (
u16 = U16(1)
u32 = U32(2)
u64 = U64(3)
u128 = U128{4, 5}
f32 = F32(6)
f64 = F64(7)
c128 = C128(8 + 9i)
s = S("10")
b = B("11")
m = M{12: 13}
c = make(C, 14)
z = Z{}
p = &z
pp = &p
)
var (
iu16 interface{} = u16
iu32 interface{} = u32
iu64 interface{} = u64
iu128 interface{} = u128
if32 interface{} = f32
if64 interface{} = f64
ic128 interface{} = c128
is interface{} = s
ib interface{} = b
im interface{} = m
ic interface{} = c
iz interface{} = z
ip interface{} = p
ipp interface{} = pp
ju16 J = u16
ju32 J = u32
ju64 J = u64
ju128 J = u128
jf32 J = f32
jf64 J = f64
jc128 J = c128
js J = s
jb J = b
jm J = m
jc J = c
jz J = z
jp J = p // The method set for *T contains the methods for T.
// pp does not implement error.
)
func second(a ...interface{}) interface{} {
return a[1]
}
func main() {
// Test equality.
if u16 != iu16 {
panic("u16 != iu16")
}
if u16 != ju16 {
panic("u16 != ju16")
}
if u32 != iu32 {
panic("u32 != iu32")
}
if u32 != ju32 {
panic("u32 != ju32")
}
if u64 != iu64 {
panic("u64 != iu64")
}
if u64 != ju64 {
panic("u64 != ju64")
}
if u128 != iu128 {
panic("u128 != iu128")
}
if u128 != ju128 {
panic("u128 != ju128")
}
if f32 != if32 {
panic("f32 != if32")
}
if f32 != jf32 {
panic("f32 != jf32")
}
if f64 != if64 {
panic("f64 != if64")
}
if f64 != jf64 {
panic("f64 != jf64")
}
if c128 != ic128 {
panic("c128 != ic128")
}
if c128 != jc128 {
panic("c128 != jc128")
}
if s != is {
panic("s != is")
}
if s != js {
panic("s != js")
}
if c != ic {
panic("c != ic")
}
if c != jc {
panic("c != jc")
}
// There are no tests for b and m, as slices and maps are not comparable by ==.
if z != iz {
panic("z != iz")
}
if z != jz {
panic("z != jz")
}
if p != ip {
panic("p != ip")
}
if p != jp {
panic("p != jp")
}
if pp != ipp {
panic("pp != ipp")
}
// pp does not implement J.
// Test that non-interface types can be used as ...interface{} arguments.
if got := second(z, p, pp, u16, u32, u64, u128, f32, f64, c128, s, b, m, c); got != ip {
println("second: got", got, "want", ip)
panic("fail")
}
// Test that non-interface types can be sent on a chan interface{}.
const n = 100
uc := make(chan interface{})
go func() {
for i := 0; i < n; i++ {
select {
case uc <- nil:
case uc <- u32:
case uc <- u64:
case uc <- u128:
}
}
}()
for i := 0; i < n; i++ {
if got := <-uc; got != nil && got != u32 && got != u64 && got != u128 {
println("recv: i", i, "got", got)
panic("fail")
}
}
}
// $G $D/$F.go && $L $F.$A && ./$A.out
// run
// 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.
// Test types of constant expressions, using reflect.
package main
import "reflect"
......
// errchk $G -e $D/$F.go
// errorcheck
// Copyright 2011 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.
// Verify that illegal conversions involving strings are detected.
// Does not compile.
package main
type Tbyte []byte
......
// errchk $G $D/$F.go
// errorcheck
// 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.
// Verify allowed and disallowed conversions.
// Does not compile.
package main
// everything here is legal except the ERROR line
......
// errchk $G -e $D/$F.go
// errorcheck
// 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.
// Verify that illegal assignments with both explicit and implicit conversions of literals are detected.
// Does not compile.
package main
// explicit conversion of constants is work in progress.
// the ERRORs in this block are debatable, but they're what
// the language spec says for now.
// explicit conversion of constants
var x1 = string(1)
var x2 string = string(1)
var x3 = int(1.5) // ERROR "convert|truncate"
......
// errchk $G $D/$F.go
// errorcheck
// 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.
// Verify that illegal uses of composite literals are detected.
// Does not compile.
package main
var a = []int { "a" }; // ERROR "conver|incompatible|cannot"
......
// $G $F.go && $L $F.$A && ./$A.out
// run
// 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.
// Semi-exhaustive test for copy()
// Semi-exhaustive test for the copy predeclared function.
package main
......
// $G $D/$F.go && $L $F.$A && ./$A.out >tmp.go &&
// $G tmp.go && $L tmp.$A && ./$A.out
// rm -f tmp.go
// runoutput
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
......
// $G $D/$F.go && $L $F.$A && ./$A.out
// run
// Copyright 2010 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.
// Test variadic functions and calls (dot-dot-dot).
package main
func sum(args ...int) int {
......@@ -58,6 +60,10 @@ type U struct {
*T
}
type I interface {
Sum(...int) int
}
func main() {
if x := sum(1, 2, 3); x != 6 {
println("sum 6", x)
......@@ -205,7 +211,14 @@ func main() {
println("i(=u).Sum", x)
panic("fail")
}
/* TODO(rsc): Enable once nested method expressions work.
var s struct {
I
}
s.I = &u
if x := s.Sum(2, 3, 5, 8); x != 18 {
println("s{&u}.Sum", x)
panic("fail")
}
if x := (*U).Sum(&U{}, 1, 3, 5, 2); x != 11 {
println("(*U).Sum", x)
panic("fail")
......@@ -214,5 +227,4 @@ func main() {
println("U.Sum", x)
panic("fail")
}
*/
}
// errchk $G -e $D/$F.go
// errorcheck
// Copyright 2010 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.
// Verify that illegal uses of ... are detected.
// Does not compile.
package main
import "unsafe"
......@@ -19,6 +22,16 @@ var (
_ = sum([]int{1}) // ERROR "\[\]int literal.*as type int|incompatible"
)
func sum3(int, int, int) int { return 0 }
func tuple() (int, int, int) { return 1, 2, 3 }
var (
_ = sum(tuple())
_ = sum(tuple()...) // ERROR "multiple-value|[.][.][.]"
_ = sum3(tuple())
_ = sum3(tuple()...) // ERROR "multiple-value|[.][.][.]" "not enough"
)
type T []T
func funny(args ...T) int { return 0 }
......
// true
// skip
// Copyright 2010 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.
// This file is compiled and then imported by ddd3.go.
package ddd
func Sum(args ...int) int {
......
// $G $D/ddd2.go && $G $D/$F.go && $L $F.$A && ./$A.out
// NOTE: This test is not run by 'run.go' and so not run by all.bash.
// To run this test you must use the ./run shell script.
// Copyright 2010 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.
// Test that variadic functions work across package boundaries.
package main
import "./ddd2"
......
// $G $F.go && $L $F.$A && ./$A.out
// run
// 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.
// Correct short declarations and redeclarations.
// Test correct short declarations and redeclarations.
package main
......
// errchk $G -e $F.go
// errorcheck
// 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.
// Incorrect short declarations and redeclarations.
// Test that incorrect short declarations and redeclarations are detected.
// Does not compile.
package main
......@@ -38,6 +39,13 @@ func main() {
_, _, _ = i, f, s
}
{
// multiline no new variables
i := f1
i := func() { // ERROR "redeclared|no new|incompatible"
}
_ = i
}
{
// single redeclaration
i, f, s := f3()
i := 1 // ERROR "redeclared|no new|incompatible"
......
// $G $F.go && $L $F.$A && ./$A.out
// run
// 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.
// Test defer.
package main
import "fmt"
......
// $G $D/$F.go && $L $F.$A && ./$A.out 2>&1 | cmp - $D/$F.out
// cmpout
// Copyright 2010 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.
// Test that we can defer the predeclared functions print and println.
package main
func main() {
defer println(42, true, false, true, 1.5, "world", (chan int)(nil), []int(nil), (map[string]int)(nil), (func())(nil), byte(255))
defer println(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20)
// defer panic("dead")
// Disabled so the test doesn't crash but left here for reference.
// defer panic("dead")
defer print("printing: ")
}
// $G $D/$F.go && $L $F.$A && ./$A.out
// run
// Copyright 2011 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.
// divide corner cases
// Test divide corner cases.
package main
......
// $G $D/$F.go && $L $F.$A && ./$A.out
// run
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment