Update to current Go testsuite.

* go.test/go-test.exp (filecmp): New procedure.
	(errchk): Handle quoted square brackets.
	(go-gc-tests): Set go_compile_args. Handle various new test
	lines.  Skip a few new tests.
	* lib/go-torture.exp (go-torture-execute): Use go_compile_args.

From-SVN: r183502
This commit is contained in:
Ian Lance Taylor 2012-01-25 00:04:13 +00:00 committed by Ian Lance Taylor
parent d1cab3a615
commit efcf639fab
234 changed files with 9163 additions and 1166 deletions

View File

@ -1,3 +1,11 @@
2012-01-24 Ian Lance Taylor <iant@google.com>
* go.test/go-test.exp (filecmp): New procedure.
(errchk): Handle quoted square brackets.
(go-gc-tests): Set go_compile_args. Handle various new test
lines. Skip a few new tests.
* lib/go-torture.exp (go-torture-execute): Use go_compile_args.
2012-01-24 Richard Sandiford <rdsandiford@googlemail.com>
* lib/target-supports.exp (proc check_effective_target_vect_perm)

View File

@ -34,6 +34,38 @@
load_lib go-dg.exp
load_lib go-torture.exp
# Compare two files
proc filecmp { file1 file2 testname } {
set f1 [open $file1 r]
set f2 [open $file2 r]
set ok 1
while { [gets $f1 line1] >= 0 } {
if { [gets $f2 line2] < 0 } {
verbose -log "output mismatch: $file2 shorter than $file1"
set ok 0
break
}
if { $line1 != $line2 } {
verbose -log "output mismatch comparing $file1 and $file2"
verbose -log "expected \"$line1\""
verbose -log "got \"$line2\""
set ok 0
break
}
}
if { [gets $f2 line2] >= 0 } {
verbose -log "output mismatch: $file1 shorter than $file2"
set ok 0
}
close $f1
close $f2
if { ! $ok } {
fail $testname
} else {
pass $testname
}
}
# Implement errchk
proc errchk { test opts } {
global dg-do-what-default
@ -56,6 +88,14 @@ proc errchk { test opts } {
continue
}
regsub "// \(GCCGO_\)?ERROR \"\(\[^\"\]*\)\".*$" $copy_line "// \{ dg-error \"\\2\" \}" out_line
if [string match "*dg-error*\\\[*" $out_line] {
set index [string first "dg-error" $out_line]
regsub -start $index -all "\\\\\\\[" $out_line "\\\\\\\\\\\[" out_line
}
if [string match "*dg-error*\\\]*" $out_line] {
set index [string first "dg-error" $out_line]
regsub -start $index -all "\\\\\\\]" $out_line "\\\\\\\\\\\]" out_line
}
if [string match "*dg-error*.\**" $out_line] {
# I worked out the right number of backslashes by
# experimentation, not analysis.
@ -199,6 +239,7 @@ proc go-gc-tests { } {
global TOOL_OPTIONS
global TORTURE_OPTIONS
global dg-do-what-default
global go_compile_args
global go_execute_args
global target_triplet
@ -230,13 +271,10 @@ proc go-gc-tests { } {
continue
}
# Skip the files in bench and garbage; they are not tests.
# Skip the files in bench; they are not tests.
if [string match "*go.test/test/bench/*" $test] {
continue
}
if [string match "*go.test/test/garbage/*" $test] {
continue
}
# Skip files in sub-subdirectories: they are components of
# other tests.
@ -274,6 +312,20 @@ proc go-gc-tests { } {
continue
}
if { [file tail $test] == "init1.go" } {
# This tests whether GC runs during init, which for gccgo
# it currently does not.
untested $name
continue
}
if { [file tail $test] == "closure.go" } {
# This tests whether function closures do any memory
# allocation, which for gccgo they currently do.
untested $name
continue
}
set fd [open $test r]
set lines_ok 1
@ -290,7 +342,8 @@ proc go-gc-tests { } {
if { [ string match "*nacl*exit 0*" $test_line ] \
|| [ string match "*exit 0*nacl*" $test_line ] \
|| [ string match "*Android*exit 0*" $test_line ] \
|| [ string match "*exit 0*Android*" $test_line ] } {
|| [ string match "*exit 0*Android*" $test_line ] \
|| [ string match "*\"\$GOOS\" == windows*" $test_line ] } {
continue
}
@ -320,8 +373,9 @@ proc go-gc-tests { } {
close $fd
set go_compile_args ""
set go_execute_args ""
if { [regexp ".*\\\$A.out (\[^|&>\].*)\$" $test_line match progargs] } {
if { [regexp ".*\\\$A.out (\[^|&>2\].*)\$" $test_line match progargs] } {
set go_execute_args $progargs
verbose -log "$test: go_execute_args is $go_execute_args"
set index [string last " $progargs" $test_line]
@ -393,6 +447,33 @@ proc go-gc-tests { } {
# This is a vanilla execution test.
go-torture-execute $test
file delete core [glob -nocomplain core.*]
} elseif { $test_line == "// \$G \$D/\$F.go && \$L \$F.\$A && ./\$A.out 2>&1 | cmp - \$D/\$F.out" \
|| $test_line == "// (\$G \$D/\$F.go && \$L \$F.\$A && ./\$A.out 2>&1 | cmp - \$D/\$F.out)" } {
# This is an execution test for which we need to check the
# program output.
set hold_runtests $runtests
set runtests "go-test.exp"
set dg-do-what-default "link"
dg-test -keep-output $test "-O" "-w $DEFAULT_GOCFLAGS"
set output_file "./[file rootname [file tail $test]].exe"
set base "[file rootname [file tail $test]]"
if [isnative] {
verbose -log "$output_file >$base.p 2>&1"
if { [catch "exec $output_file 2>$base.p" catcherr] != 0 } {
verbose -log $catcherr
fail "$name execution"
untested "$name compare"
} else {
pass "$name execution"
regsub "\\.go$" $test ".out" expect
filecmp $expect $base.p "$name compare"
}
#file delete $base.p
} else {
untested "$name execution"
untested "$name compare"
}
set runtests $hold_runtests
} elseif { [string match \
"// \$G \$D/\$F.go && \$L \$F.\$A || echo BUG*" \
$test_line] \
@ -405,6 +486,10 @@ proc go-gc-tests { } {
} elseif { [string match "// \$G \$D/\$F.go" $test_line] \
|| [string match "// \$G \$D/\$F.go || echo BUG*" \
$test_line] \
|| [string match "// \$G \$D/\$F.go || echo \"Bug*" \
$test_line] \
|| [string match "// \$G \$D/\$F.go || echo \"Issue*" \
$test_line] \
|| [string match "// \$G \$F.go || echo BUG*" \
$test_line] \
|| [string match "// ! \$G \$D/\$F.go && echo BUG*" \
@ -452,13 +537,27 @@ proc go-gc-tests { } {
errchk $test ""
} elseif { [string match \
"// \$G \$D/\$F.dir/bug0.go && \$G \$D/\$F.dir/bug1.go || echo BUG*" \
$test_line] } {
$test_line] \
|| [string match \
"// \$G \$D/\$F.dir/one.go && \$G \$D/\$F.dir/two.go" \
$test_line] } {
if { [string match \
"// \$G \$D/\$F.dir/bug0.go && \$G \$D/\$F.dir/bug1.go || echo BUG*" \
$test_line] } {
set name1 "bug0.go"
set name2 "bug1.go"
} elseif { [string match \
"// \$G \$D/\$F.dir/one.go && \$G \$D/\$F.dir/two.go" \
$test_line] } {
set name1 "one.go"
set name2 "two.go"
}
set hold_runtests $runtests
set runtests "go-test.exp"
set dg-do-what-default "assemble"
regsub "\\.go$" $test ".dir/bug0.go" file1
regsub "\\.go$" $test ".dir/$name1" file1
dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
regsub "\\.go$" $test ".dir/bug1.go" file2
regsub "\\.go$" $test ".dir/$name2" file2
dg-test $file2 "-O" "-w $DEFAULT_GOCFLAGS"
file delete "[file rootname [file tail $file1]].o"
set runtests $hold_runtests
@ -650,14 +749,28 @@ proc go-gc-tests { } {
set runtests $hold_runtests
} elseif { [string match \
"// \$G \$D/\$F.dir/lib.go && \$G \$D/\$F.dir/main.go && \$L main.\$A && ./\$A.out || echo BUG*" \
$test_line ] } {
$test_line ] || \
[string match \
"// \$G \$D/\$F.dir/p.go && \$G \$D/\$F.dir/main.go && \$L main.\$A && ./\$A.out || echo BUG*" \
$test_line ] } {
if { [string match \
"// \$G \$D/\$F.dir/lib.go && \$G \$D/\$F.dir/main.go && \$L main.\$A && ./\$A.out || echo BUG*" \
$test_line ] } {
set name1 "lib.go"
set name2 "main.go"
} elseif { [string match \
"// \$G \$D/\$F.dir/p.go && \$G \$D/\$F.dir/main.go && \$L main.\$A && ./\$A.out || echo BUG*" \
$test_line ] } {
set name1 "p.go"
set name2 "main.go"
}
set hold_runtests $runtests
set runtests "go-test.exp"
set dg-do-what-default "assemble"
regsub "\\.go$" $test ".dir/lib.go" file1
regsub "\\.go$" $test ".dir/$name1" file1
dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
set ofile1 "[file rootname [file tail $file1]].o"
regsub "\\.go$" $test ".dir/main.go" file2
regsub "\\.go$" $test ".dir/$name2" file2
dg-test -keep-output $file2 "-O" "-w $DEFAULT_GOCFLAGS"
set ofile2 "[file rootname [file tail $file2]].o"
set dg-do-what-default "link"
@ -705,7 +818,7 @@ proc go-gc-tests { } {
errchk $file2 ""
file delete "[file rootname [file tail $file1]].o"
set runtests $hold_runtests
} elseif { [string match "// true*" $test_line] } {
} elseif { "$test_line" == "" || [string match "// true*" $test_line] } {
# Not a real test, just ignore.
} elseif { $test_line == "// \$G \$D/\$F.dir/bug0.go &&" \
&& $test_line2 == "// \$G \$D/\$F.dir/bug1.go &&" \
@ -886,7 +999,7 @@ proc go-gc-tests { } {
file delete $base-out.x
go-torture-execute "./$base-out.go"
}
# file delete $base-out.go
file delete $base-out.go
}
file delete $output_file
set runtests $hold_runtests
@ -894,23 +1007,96 @@ proc go-gc-tests { } {
regsub "\\.go$" $test ".dir/a.go" file1
regsub "\\.go$" $test ".dir/b.go" file2
errchk "$file1" "$file2"
} elseif { $test_line == "// \$G \$D/\$F.go \$D/z*.go && \$L \$F.\$A && ./\$A.out" } {
set dir [file dirname $test]
set go_compile_args [glob $dir/z*.go]
go-torture-execute $test
} elseif { $test_line == "// \$G -N -o slow.\$A \$D/bug369.dir/pkg.go &&" \
&& $test_line2 == "// \$G -o fast.\$A \$D/bug369.dir/pkg.go &&" \
&& $test_line3 == "// \$G \$D/\$F.go && \$L \$F.\$A && ./\$A.out" } {
set hold_runtests $runtests
set runtests "go-test.exp"
set dg-do-what-default "assemble"
regsub "\\.go$" $test ".dir/pkg.go" file1
dg-test -keep-output $file1 "" "-fgo-prefix=slow -w $DEFAULT_GOCFLAGS"
set ofile1 "[file rootname [file tail $file1]].o"
file rename -force $ofile1 slow.o
dg-test -keep-output $file1 "-O2" "-fgo-prefix=fast -w $DEFAULT_GOCFLAGS"
file rename -force $ofile1 fast.o
set ofile2 "[file rootname [file tail $test]].o"
dg-test -keep-output $test "-O" "-w $DEFAULT_GOCFLAGS"
set output_file "./[file rootname [file tail $test]].exe"
set comp_output [go_target_compile "$ofile2 slow.o fast.o" \
$output_file "executable" "$options"]
set comp_output [go-dg-prune $target_triplet $comp_output]
if [string match "" $comp_output] {
set result [go_load "$output_file" "" ""]
set status [lindex $result 0]
$status $name
} else {
verbose -log $comp_output
fail $name
}
file delete slow.o fast.o $ofile2 $output_file
set runtests $hold_runtests
} elseif { [string match \
"// \$G \$D/\$F.dir/pkg.go && \$G \$D/\$F.go || echo *" \
$test_line ] } {
set hold_runtests $runtests
set runtests "go-test.exp"
set dg-do-what-default "assemble"
regsub "\\.go$" $test ".dir/pkg.go" file1
dg-test -keep-output $file1 "-O" "-w $DEFAULT_GOCFLAGS"
dg-test $test "-O" "-w $DEFAULT_GOCFLAGS"
file delete "[file rootname [file tail $file1]].o"
set runtests $hold_runtests
} elseif { $test_line == "// \$G \$D/\$F.go && \$L \$F.\$A && ./\$A.out >tmp.go &&"
&& $test_line2 == "// \$G tmp.go && \$L tmp.\$A && ./\$A.out" } {
set go_execute_args ""
set hold_runtests $runtests
set runtests "go-test.exp"
set dg-do-what-default "link"
dg-test -keep-output $test "-O" "-w $DEFAULT_GOCFLAGS"
set output_file "./[file rootname [file tail $test]].exe"
set base "[file rootname [file tail $test]]"
if [isnative] {
if { [catch "exec $output_file >$base-out.go"] != 0 } {
fail "$name execution"
} else {
pass "$name execution"
file delete $base-out.x
go-torture-execute "./$base-out.go"
}
file delete $base-out.go
}
file delete $output_file
set runtests $hold_runtests
} elseif { $test_line == "// # generated by cmplxdivide.c" } {
# Ignore.
} elseif { $test_line == "// \$G \$D/bug302.dir/p.go && gopack grc pp.a p.\$A && \$G \$D/bug302.dir/main.go" \
|| $test_line == "// \$G \$D/empty.go && errchk \$G \$D/\$F.go" } {
# These tests import the same package under two different
# names, which gccgo does not support.
} elseif { $test_line == "// \$G -S \$D/\$F.go | egrep initdone >/dev/null && echo FAIL || true" } {
} elseif { $test_line == "// \$G -S \$D/\$F.go | egrep initdone >/dev/null && echo BUG sinit || true" } {
# This tests whether initializers are written out
# statically. gccgo does not provide a way to test that,
# as an initializer will be generated for any code which
# has global variables which need to be registered as GC
# roots.
} elseif { $test_line == "// errchk -0 \$G -m -l \$D/\$F.go" } {
# This tests debug output of the gc compiler, which is
# meaningless for gccgo.
} elseif { $test_line == "// \[ \$O == 6 \] || errchk \$G -e \$D/\$F.go" \
|| $test_line == "// \[ \$O != 6 \] || errchk \$G -e \$D/\$F.go" } {
# This tests specific handling of the gc compiler on types
# that are too large. It is target specific in a way I
# haven't bothered to check for here.
} else {
clone_output "$name: unrecognized test line: $test_line"
unsupported $name
}
set go_compile_args ""
set go_execute_args ""
}

View File

@ -0,0 +1,32 @@
// errchk $G -e $D/$F.go
// 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).
import (
"fmt"
"unicode/utf8"
)
func f(byte) {}
func g(uint8) {}
func main() {
var x float64
f(x) // ERROR "byte"
g(x) // ERROR "uint8"
// Test across imports.
var ff fmt.Formatter
var fs fmt.State
ff.Format(fs, x) // ERROR "rune"
utf8.RuneStart(x) // ERROR "byte"
}

View File

@ -0,0 +1,54 @@
// $G $D/$F.go && $L $F.$A && ./$A.out
// 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.
func main() {
var x interface{}
x = byte(1)
switch x.(type) {
case uint8:
// ok
default:
println("byte != uint8")
}
x = uint8(2)
switch x.(type) {
case byte:
// ok
default:
println("uint8 != byte")
}
rune32 := false
x = rune(3)
switch x.(type) {
case int:
// ok
case int32:
// must be new code
rune32 = true
default:
println("rune != int and rune != int32")
}
if rune32 {
x = int32(4)
} else {
x = int(5)
}
switch x.(type) {
case rune:
// ok
default:
println("int (or int32) != rune")
}
}

View File

@ -63,6 +63,11 @@ var tests = []struct {
{"byte i", append([]byte{0, 1, 2}, []byte{3}...), []byte{0, 1, 2, 3}},
{"byte j", append([]byte{0, 1, 2}, []byte{3, 4, 5}...), []byte{0, 1, 2, 3, 4, 5}},
{"bytestr a", append([]byte{}, "0"...), []byte("0")},
{"bytestr b", append([]byte{}, "0123"...), []byte("0123")},
{"bytestr c", append([]byte("012"), "3"...), []byte("0123")},
{"bytestr d", append([]byte("012"), "345"...), []byte("012345")},
{"int16 a", append([]int16{}), []int16{}},
{"int16 b", append([]int16{}, 0), []int16{0}},

View File

@ -2,23 +2,24 @@
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
include ../../src/Make.inc
include ../../../src/Make.inc
ALL=\
parser\
peano\
tree\
tree2\
all: $(addsuffix .out, $(ALL))
%.$O: %.go stats.go
$(GC) $*.go stats.go
$(GC) $(GCFLAGS) $(GCIMPORTS) $*.go stats.go
%.out: %.$O
$(LD) -o $@ $*.$O
%.bench: %.out
./$*.out
time ./$*.out
bench: $(addsuffix .bench, $(ALL))

View File

@ -12,27 +12,27 @@ import (
"go/ast"
"go/parser"
"go/token"
"log"
"net/http"
_ "net/http/pprof"
"os"
"path"
"runtime"
"strings"
"time"
"http"
_ "http/pprof"
"log"
)
var serve = flag.String("serve", "", "serve http on this address at end")
func isGoFile(dir *os.FileInfo) bool {
return dir.IsRegular() &&
!strings.HasPrefix(dir.Name, ".") && // ignore .files
path.Ext(dir.Name) == ".go"
func isGoFile(dir os.FileInfo) bool {
return !dir.IsDir() &&
!strings.HasPrefix(dir.Name(), ".") && // ignore .files
path.Ext(dir.Name()) == ".go"
}
func isPkgFile(dir *os.FileInfo) bool {
func isPkgFile(dir os.FileInfo) bool {
return isGoFile(dir) &&
!strings.HasSuffix(dir.Name, "_test.go") // ignore test files
!strings.HasSuffix(dir.Name(), "_test.go") // ignore test files
}
func pkgName(filename string) string {
@ -49,7 +49,7 @@ func parseDir(dirpath string) map[string]*ast.Package {
_, pkgname := path.Split(dirpath)
// filter function to select the desired .go files
filter := func(d *os.FileInfo) bool {
filter := func(d os.FileInfo) bool {
if isPkgFile(d) {
// Some directories contain main packages: Only accept
// files that belong to the expected package so that
@ -57,7 +57,7 @@ func parseDir(dirpath string) map[string]*ast.Package {
// found" errors.
// Additionally, accept the special package name
// fakePkgName if we are looking at cmd documentation.
name := pkgName(dirpath + "/" + d.Name)
name := pkgName(dirpath + "/" + d.Name())
return name == pkgname
}
return false
@ -66,17 +66,13 @@ func parseDir(dirpath string) map[string]*ast.Package {
// get package AST
pkgs, err := parser.ParseDir(token.NewFileSet(), dirpath, filter, parser.ParseComments)
if err != nil {
println("parse", dirpath, err.String())
println("parse", dirpath, err.Error())
panic("fail")
}
return pkgs
}
func main() {
runtime.GOMAXPROCS(4)
go func() {}()
go func() {}()
go func() {}()
st := &runtime.MemStats
packages = append(packages, packages...)
packages = append(packages, packages...)
@ -86,7 +82,7 @@ func main() {
flag.Parse()
var lastParsed []map[string]*ast.Package
var t0 int64
var t0 time.Time
pkgroot := runtime.GOROOT() + "/src/pkg/"
for pass := 0; pass < 2; pass++ {
// Once the heap is grown to full size, reset counters.
@ -95,7 +91,7 @@ func main() {
// the average look much better than it actually is.
st.NumGC = 0
st.PauseTotalNs = 0
t0 = time.Nanoseconds()
t0 = time.Now()
for i := 0; i < *n; i++ {
parsed := make([]map[string]*ast.Package, *p)
@ -109,7 +105,7 @@ func main() {
runtime.GC()
runtime.GC()
}
t1 := time.Nanoseconds()
t1 := time.Now()
fmt.Printf("Alloc=%d/%d Heap=%d Mallocs=%d PauseTime=%.3f/%d = %.3f\n",
st.Alloc, st.TotalAlloc,
@ -124,7 +120,7 @@ func main() {
}
*/
// Standard gotest benchmark output, collected by build dashboard.
gcstats("BenchmarkParser", *n, t1-t0)
gcstats("BenchmarkParser", *n, t1.Sub(t0))
if *serve != "" {
log.Fatal(http.ListenAndServe(*serve, nil))
@ -132,23 +128,20 @@ func main() {
}
}
var packages = []string{
"archive/tar",
"asn1",
"big",
"encoding/asn1",
"math/big",
"bufio",
"bytes",
"cmath",
"math/cmplx",
"compress/flate",
"compress/gzip",
"compress/zlib",
"container/heap",
"container/list",
"container/ring",
"container/vector",
"crypto/aes",
"crypto/block",
"crypto/blowfish",
"crypto/hmac",
"crypto/md4",
@ -167,20 +160,14 @@ var packages = []string{
"debug/macho",
"debug/elf",
"debug/gosym",
"debug/proc",
"ebnf",
"exp/ebnf",
"encoding/ascii85",
"encoding/base64",
"encoding/binary",
"encoding/git85",
"encoding/hex",
"encoding/pem",
"exec",
"exp/datafmt",
"exp/draw",
"exp/eval",
"exp/iterable",
"expvar",
"os/exec",
"flag",
"fmt",
"go/ast",
@ -189,18 +176,18 @@ var packages = []string{
"go/printer",
"go/scanner",
"go/token",
"gob",
"encoding/gob",
"hash",
"hash/adler32",
"hash/crc32",
"hash/crc64",
"http",
"net/http",
"image",
"image/jpeg",
"image/png",
"io",
"io/ioutil",
"json",
"encoding/json",
"log",
"math",
"mime",
@ -209,29 +196,29 @@ var packages = []string{
"os/signal",
"patch",
"path",
"rand",
"math/rand",
"reflect",
"regexp",
"rpc",
"net/rpc",
"runtime",
"scanner",
"text/scanner",
"sort",
"smtp",
"net/smtp",
"strconv",
"strings",
"sync",
"syscall",
"syslog",
"tabwriter",
"template",
"log/syslog",
"text/tabwriter",
"text/template",
"testing",
"testing/iotest",
"testing/quick",
"testing/script",
"time",
"unicode",
"utf8",
"utf16",
"unicode/utf8",
"unicode/utf16",
"websocket",
"xml",
"encoding/xml",
}

View File

@ -12,31 +12,25 @@ import (
"time"
)
type Number struct {
next *Number
}
// -------------------------------------
// Peano primitives
func zero() *Number { return nil }
func is_zero(x *Number) bool { return x == nil }
func add1(x *Number) *Number {
e := new(Number)
e.next = x
return e
}
func sub1(x *Number) *Number { return x.next }
func add(x, y *Number) *Number {
if is_zero(y) {
return x
@ -45,7 +39,6 @@ func add(x, y *Number) *Number {
return add(add1(x), sub1(y))
}
func mul(x, y *Number) *Number {
if is_zero(x) || is_zero(y) {
return zero()
@ -54,7 +47,6 @@ func mul(x, y *Number) *Number {
return add(mul(x, sub1(y)), x)
}
func fact(n *Number) *Number {
if is_zero(n) {
return add1(zero())
@ -63,7 +55,6 @@ func fact(n *Number) *Number {
return mul(fact(sub1(n)), n)
}
// -------------------------------------
// Helpers to generate/count Peano integers
@ -75,7 +66,6 @@ func gen(n int) *Number {
return zero()
}
func count(x *Number) int {
if is_zero(x) {
return 0
@ -84,7 +74,6 @@ func count(x *Number) int {
return count(sub1(x)) + 1
}
func check(x *Number, expected int) {
var c = count(x)
if c != expected {
@ -92,7 +81,6 @@ func check(x *Number, expected int) {
}
}
// -------------------------------------
// Test basic functionality
@ -117,19 +105,17 @@ func verify() {
check(fact(gen(5)), 120)
}
// -------------------------------------
// Factorial
func main() {
t0 := time.Nanoseconds()
t0 := time.Now()
verify()
for i := 0; i <= 9; i++ {
print(i, "! = ", count(fact(gen(i))), "\n")
}
runtime.GC()
t1 := time.Nanoseconds()
t1 := time.Now()
gcstats("BenchmarkPeano", 1, t1-t0)
gcstats("BenchmarkPeano", 1, t1.Sub(t0))
}

View File

@ -8,12 +8,13 @@ import (
"fmt"
"runtime"
"sort"
"time"
)
func gcstats(name string, n int, t int64) {
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/int64(n))
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))
nn := int(st.NumGC)
@ -22,13 +23,14 @@ func gcstats(name string, n int, t int64) {
}
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.%sScan: %v\n", name, st.ScanDist)
// fmt.Printf("garbage.%sScan: %v\n", name, st.ScanDist)
}
type T []uint64
func (t T) Len() int { return len(t) }
func (t T) Swap(i, j int) { t[i], t[j] = t[j], t[i] }
func (t T) Len() int { return len(t) }
func (t T) Swap(i, j int) { t[i], t[j] = t[j], t[i] }
func (t T) Less(i, j int) bool { return t[i] < t[j] }
func tukey5(raw []uint64) (lo, q1, q2, q3, hi uint64) {

View File

@ -68,7 +68,7 @@ const minDepth = 4
func main() {
flag.Parse()
t0 := time.Nanoseconds()
t0 := time.Now()
maxDepth := *n
if minDepth+2 > *n {
@ -93,8 +93,8 @@ func main() {
}
fmt.Printf("long lived tree of depth %d\t check: %d\n", maxDepth, longLivedTree.itemCheck())
t1 := time.Nanoseconds()
t1 := time.Now()
// Standard gotest benchmark output, collected by build dashboard.
gcstats("BenchmarkTree", *n, t1-t0)
gcstats("BenchmarkTree", *n, t1.Sub(t0))
}

View File

@ -0,0 +1,88 @@
// 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 main
import (
"flag"
"fmt"
"log"
"os"
"runtime"
"runtime/pprof"
"unsafe"
)
const BranchingFactor = 4
type Object struct {
child [BranchingFactor]*Object
}
var (
cpus = flag.Int("cpus", 1, "number of cpus to use")
heapsize = flag.Int64("heapsize", 100*1024*1024, "size of the heap in bytes")
cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
lastPauseNs uint64 = 0
lastFree uint64 = 0
heap *Object
calls [20]int
numobjects int64
)
func buildHeap() {
objsize := int64(unsafe.Sizeof(Object{}))
heap, _ = buildTree(float64(objsize), float64(*heapsize), 0)
fmt.Printf("*** built heap: %.0f MB; (%d objects * %d bytes)\n",
float64(*heapsize)/1048576, numobjects, objsize)
}
func buildTree(objsize, size float64, depth int) (*Object, float64) {
calls[depth]++
x := &Object{}
numobjects++
subtreeSize := (size - objsize) / BranchingFactor
alloc := objsize
for i := 0; i < BranchingFactor && alloc < size; i++ {
c, n := buildTree(objsize, subtreeSize, depth+1)
x.child[i] = c
alloc += n
}
return x, alloc
}
func gc() {
runtime.GC()
runtime.UpdateMemStats()
pause := runtime.MemStats.PauseTotalNs
inuse := runtime.MemStats.Alloc
free := runtime.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,
float64(inuse)/1048576)
lastPauseNs = pause
lastFree = free
}
func main() {
flag.Parse()
buildHeap()
runtime.GOMAXPROCS(*cpus)
runtime.UpdateMemStats()
lastPauseNs = runtime.MemStats.PauseTotalNs
lastFree = runtime.MemStats.TotalAlloc - runtime.MemStats.Alloc
if *cpuprofile != "" {
f, err := os.Create(*cpuprofile)
if err != nil {
log.Fatal(err)
}
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
}
for i := 0; i < 10; i++ {
gc()
}
}

View File

@ -0,0 +1,7 @@
include $(GOROOT)/src/Make.inc
TARG=go1
GOFILES=\
dummy.go\
include $(GOROOT)/src/Make.pkg

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,261 @@
go object linux amd64 weekly.2012-01-15 11312+ X:none
exports automatically generated from
_testmain.go in package "main"
$$ // exports
package main
import runtime "runtime"
import go1 "go1"
import testing "testing"
import regexp "regexp"
import time "time" // indirect
type @"time".zone struct { @"time".name string; @"time".offset int; @"time".isDST bool }
type @"time".zoneTrans struct { @"time".when int64; @"time".index uint8; @"time".isstd bool; @"time".isutc bool }
type @"time".Location struct { @"time".name string; @"time".zone []@"time".zone; @"time".tx []@"time".zoneTrans; @"time".cacheStart int64; @"time".cacheEnd int64; @"time".cacheZone *@"time".zone }
func (@"time".l *@"time".Location) String() (? string)
func (@"time".l *@"time".Location) @"time".get() (? *@"time".Location)
func (@"time".l *@"time".Location) @"time".lookup(@"time".sec int64) (@"time".name string, @"time".offset int, @"time".isDST bool, @"time".start int64, @"time".end int64)
func (@"time".l *@"time".Location) @"time".lookupName(@"time".name string "noescape") (@"time".offset int, @"time".isDST bool, @"time".ok bool)
func (@"time".l *@"time".Location) @"time".lookupOffset(@"time".offset int) (@"time".name string, @"time".isDST bool, @"time".ok bool)
type @"time".Duration int64
func (@"time".d @"time".Duration) Hours() (? float64)
func (@"time".d @"time".Duration) Minutes() (? float64)
func (@"time".d @"time".Duration) Nanoseconds() (? int64) { return int64(@"time".d) }
func (@"time".d @"time".Duration) Seconds() (? float64)
func (@"time".d @"time".Duration) String() (? string)
type @"time".Month int
func (@"time".m @"time".Month) String() (? string) { return @"time".months[@"time".m - @"time".Month(1)] }
type @"time".Weekday int
func (@"time".d @"time".Weekday) String() (? string) { return @"time".days[@"time".d] }
type @"time".Time struct { @"time".sec int64; @"time".nsec int32; @"time".loc *@"time".Location }
func (@"time".t @"time".Time) Add(@"time".d @"time".Duration) (? @"time".Time)
func (@"time".t @"time".Time) AddDate(@"time".years int, @"time".months int, @"time".days int) (? @"time".Time)
func (@"time".t @"time".Time "noescape") After(@"time".u @"time".Time "noescape") (? bool) { return @"time".t.@"time".sec > @"time".u.@"time".sec || @"time".t.@"time".sec == @"time".u.@"time".sec && @"time".t.@"time".nsec > @"time".u.@"time".nsec }
func (@"time".t @"time".Time "noescape") Before(@"time".u @"time".Time "noescape") (? bool) { return @"time".t.@"time".sec < @"time".u.@"time".sec || @"time".t.@"time".sec == @"time".u.@"time".sec && @"time".t.@"time".nsec < @"time".u.@"time".nsec }
func (@"time".t @"time".Time) Clock() (@"time".hour int, @"time".min int, @"time".sec int)
func (@"time".t @"time".Time) Date() (@"time".year int, @"time".month @"time".Month, @"time".day int)
func (@"time".t @"time".Time) Day() (? int)
func (@"time".t @"time".Time "noescape") Equal(@"time".u @"time".Time "noescape") (? bool) { return @"time".t.@"time".sec == @"time".u.@"time".sec && @"time".t.@"time".nsec == @"time".u.@"time".nsec }
func (@"time".t @"time".Time) Format(@"time".layout string) (? string)
func (@"time".t *@"time".Time "noescape") GobDecode(@"time".buf []byte "noescape") (? error)
func (@"time".t @"time".Time) GobEncode() (? []byte, ? error)
func (@"time".t @"time".Time) Hour() (? int)
func (@"time".t @"time".Time) ISOWeek() (@"time".year int, @"time".week int)
func (@"time".t @"time".Time) In(@"time".loc *@"time".Location) (? @"time".Time)
func (@"time".t @"time".Time "noescape") IsZero() (? bool) { return @"time".t.@"time".sec == 0 && @"time".t.@"time".nsec == 0 }
func (@"time".t @"time".Time) Local() (? @"time".Time)
func (@"time".t @"time".Time) Location() (? *@"time".Location)
func (@"time".t @"time".Time) MarshalJSON() (? []byte, ? error)
func (@"time".t @"time".Time) Minute() (? int)
func (@"time".t @"time".Time) Month() (? @"time".Month)
func (@"time".t @"time".Time "noescape") Nanosecond() (? int) { return int(@"time".t.@"time".nsec) }
func (@"time".t @"time".Time) Second() (? int)
func (@"time".t @"time".Time) String() (? string)
func (@"time".t @"time".Time "noescape") Sub(@"time".u @"time".Time "noescape") (? @"time".Duration) { return @"time".Duration(@"time".t.@"time".sec - @"time".u.@"time".sec) * @"time".Duration(1000000000) + @"time".Duration(@"time".t.@"time".nsec - @"time".u.@"time".nsec) }
func (@"time".t @"time".Time) UTC() (? @"time".Time)
func (@"time".t @"time".Time "noescape") Unix() (? int64) { return @"time".t.@"time".sec + -62135596800 }
func (@"time".t @"time".Time "noescape") UnixNano() (? int64) { return (@"time".t.@"time".sec + -62135596800) * 1000000000 + int64(@"time".t.@"time".nsec) }
func (@"time".t *@"time".Time "noescape") UnmarshalJSON(@"time".data []byte "noescape") (@"time".err error)
func (@"time".t @"time".Time) Weekday() (? @"time".Weekday)
func (@"time".t @"time".Time) Year() (? int)
func (@"time".t @"time".Time) Zone() (@"time".name string, @"time".offset int)
func (@"time".t @"time".Time) @"time".abs() (? uint64)
func (@"time".t @"time".Time) @"time".date(@"time".full bool) (@"time".year int, @"time".month @"time".Month, @"time".day int, @"time".yday int)
type @"testing".common struct { @"testing".output []byte; @"testing".failed bool; @"testing".start @"time".Time; @"testing".duration @"time".Duration; @"testing".self interface {}; @"testing".signal chan interface {} }
func (@"testing".c *@"testing".common "noescape") Error(@"testing".args ...interface {} "noescape")
func (@"testing".c *@"testing".common "noescape") Errorf(@"testing".format string "noescape", @"testing".args ...interface {} "noescape")
func (@"testing".c *@"testing".common "noescape") Fail() { @"testing".c.@"testing".failed = true }
func (@"testing".c *@"testing".common "noescape") FailNow()
func (@"testing".c *@"testing".common "noescape") Failed() (? bool) { return @"testing".c.@"testing".failed }
func (@"testing".c *@"testing".common "noescape") Fatal(@"testing".args ...interface {} "noescape")
func (@"testing".c *@"testing".common "noescape") Fatalf(@"testing".format string "noescape", @"testing".args ...interface {} "noescape")
func (@"testing".c *@"testing".common "noescape") Log(@"testing".args ...interface {} "noescape")
func (@"testing".c *@"testing".common "noescape") Logf(@"testing".format string "noescape", @"testing".args ...interface {} "noescape")
func (@"testing".c *@"testing".common "noescape") @"testing".log(@"testing".s string)
type @"testing".T struct { ? @"testing".common; @"testing".name string; @"testing".startParallel chan bool }
func (@"testing".t *@"testing".T "noescape") Parallel()
func (@"testing".t *@"testing".T "noescape") @"testing".report()
type @"testing".InternalTest struct { Name string; F func(? *@"testing".T) }
var @"".tests []@"testing".InternalTest
type @"testing".BenchmarkResult struct { N int; T @"time".Duration; Bytes int64 }
func (@"testing".r @"testing".BenchmarkResult) NsPerOp() (? int64)
func (@"testing".r @"testing".BenchmarkResult) String() (? string)
func (@"testing".r @"testing".BenchmarkResult) @"testing".mbPerSec() (? float64)
type @"testing".B struct { ? @"testing".common; N int; @"testing".benchmark @"testing".InternalBenchmark; @"testing".bytes int64; @"testing".timerOn bool; @"testing".result @"testing".BenchmarkResult }
func (@"testing".b *@"testing".B "noescape") ResetTimer()
func (@"testing".b *@"testing".B "noescape") SetBytes(@"testing".n int64) { @"testing".b.@"testing".bytes = @"testing".n }
func (@"testing".b *@"testing".B "noescape") StartTimer()
func (@"testing".b *@"testing".B "noescape") StopTimer()
func (@"testing".b *@"testing".B) @"testing".launch()
func (@"testing".b *@"testing".B "noescape") @"testing".nsPerOp() (? int64)
func (@"testing".b *@"testing".B) @"testing".run() (? @"testing".BenchmarkResult)
func (@"testing".b *@"testing".B) @"testing".runN(@"testing".n int)
func (@"testing".b *@"testing".B "noescape") @"testing".trimOutput()
type @"testing".InternalBenchmark struct { Name string; F func(@"testing".b *@"testing".B) }
var @"".benchmarks []@"testing".InternalBenchmark
type @"testing".InternalExample struct { Name string; F func(); Output string }
var @"".examples []@"testing".InternalExample
var @"".matchPat string
import syntax "regexp/syntax" // indirect
type @"regexp/syntax".InstOp uint8
type @"regexp/syntax".Inst struct { Op @"regexp/syntax".InstOp; Out uint32; Arg uint32; Rune []rune }
func (@"regexp/syntax".i *@"regexp/syntax".Inst "noescape") MatchEmptyWidth(@"regexp/syntax".before rune, @"regexp/syntax".after rune) (? bool)
func (@"regexp/syntax".i *@"regexp/syntax".Inst "noescape") MatchRune(@"regexp/syntax".r rune) (? bool)
func (@"regexp/syntax".i *@"regexp/syntax".Inst "noescape") String() (? string)
func (@"regexp/syntax".i *@"regexp/syntax".Inst "noescape") @"regexp/syntax".op() (? @"regexp/syntax".InstOp)
type @"regexp/syntax".EmptyOp uint8
type @"regexp/syntax".Prog struct { Inst []@"regexp/syntax".Inst; Start int; NumCap int }
func (@"regexp/syntax".p *@"regexp/syntax".Prog "noescape") Prefix() (@"regexp/syntax".prefix string, @"regexp/syntax".complete bool)
func (@"regexp/syntax".p *@"regexp/syntax".Prog "noescape") StartCond() (? @"regexp/syntax".EmptyOp)
func (@"regexp/syntax".p *@"regexp/syntax".Prog "noescape") String() (? string)
func (@"regexp/syntax".p *@"regexp/syntax".Prog "noescape") @"regexp/syntax".skipNop(@"regexp/syntax".pc uint32) (? *@"regexp/syntax".Inst)
import sync "sync" // indirect
type @"sync".Mutex struct { @"sync".state int32; @"sync".sema uint32 }
func (@"sync".m *@"sync".Mutex) Lock()
func (@"sync".m *@"sync".Mutex) Unlock()
type @"regexp".thread struct { @"regexp".inst *@"regexp/syntax".Inst; @"regexp".cap []int }
type @"regexp".entry struct { @"regexp".pc uint32; @"regexp".t *@"regexp".thread }
type @"regexp".queue struct { @"regexp".sparse []uint32; @"regexp".dense []@"regexp".entry }
type @"regexp".inputBytes struct { @"regexp".str []byte }
func (@"regexp".i *@"regexp".inputBytes "noescape") @"regexp".canCheckPrefix() (? bool) { return true }
func (@"regexp".i *@"regexp".inputBytes "noescape") @"regexp".context(@"regexp".pos int) (? @"regexp/syntax".EmptyOp)
func (@"regexp".i *@"regexp".inputBytes "noescape") @"regexp".hasPrefix(@"regexp".re *@"regexp".Regexp "noescape") (? bool)
func (@"regexp".i *@"regexp".inputBytes "noescape") @"regexp".index(@"regexp".re *@"regexp".Regexp "noescape", @"regexp".pos int) (? int)
func (@"regexp".i *@"regexp".inputBytes "noescape") @"regexp".step(@"regexp".pos int) (? rune, ? int)
type @"regexp".inputString struct { @"regexp".str string }
func (@"regexp".i *@"regexp".inputString "noescape") @"regexp".canCheckPrefix() (? bool) { return true }
func (@"regexp".i *@"regexp".inputString "noescape") @"regexp".context(@"regexp".pos int) (? @"regexp/syntax".EmptyOp)
func (@"regexp".i *@"regexp".inputString "noescape") @"regexp".hasPrefix(@"regexp".re *@"regexp".Regexp "noescape") (? bool)
func (@"regexp".i *@"regexp".inputString "noescape") @"regexp".index(@"regexp".re *@"regexp".Regexp "noescape", @"regexp".pos int) (? int)
func (@"regexp".i *@"regexp".inputString "noescape") @"regexp".step(@"regexp".pos int) (? rune, ? int)
import io "io" // indirect
type @"io".RuneReader interface { ReadRune() (@"io".r rune, @"io".size int, @"io".err error) }
type @"regexp".inputReader struct { @"regexp".r @"io".RuneReader; @"regexp".atEOT bool; @"regexp".pos int }
func (@"regexp".i *@"regexp".inputReader "noescape") @"regexp".canCheckPrefix() (? bool) { return false }
func (@"regexp".i *@"regexp".inputReader "noescape") @"regexp".context(@"regexp".pos int) (? @"regexp/syntax".EmptyOp) { return @"regexp/syntax".EmptyOp(0) }
func (@"regexp".i *@"regexp".inputReader "noescape") @"regexp".hasPrefix(@"regexp".re *@"regexp".Regexp "noescape") (? bool) { return false }
func (@"regexp".i *@"regexp".inputReader "noescape") @"regexp".index(@"regexp".re *@"regexp".Regexp "noescape", @"regexp".pos int) (? int) { return -1 }
func (@"regexp".i *@"regexp".inputReader "noescape") @"regexp".step(@"regexp".pos int) (? rune, ? int)
type @"regexp".input interface { @"regexp".step(@"regexp".pos int) (@"regexp".r rune, @"regexp".width int); @"regexp".canCheckPrefix() (? bool); @"regexp".hasPrefix(@"regexp".re *@"regexp".Regexp) (? bool); @"regexp".index(@"regexp".re *@"regexp".Regexp, @"regexp".pos int) (? int); @"regexp".context(@"regexp".pos int) (? @"regexp/syntax".EmptyOp) }
type @"regexp".machine struct { @"regexp".re *@"regexp".Regexp; @"regexp".p *@"regexp/syntax".Prog; @"regexp".q0 @"regexp".queue; @"regexp".q1 @"regexp".queue; @"regexp".pool []*@"regexp".thread; @"regexp".matched bool; @"regexp".matchcap []int; @"regexp".inputBytes @"regexp".inputBytes; @"regexp".inputString @"regexp".inputString; @"regexp".inputReader @"regexp".inputReader }
func (@"regexp".m *@"regexp".machine "noescape") @"regexp".add(@"regexp".q *@"regexp".queue "noescape", @"regexp".pc uint32, @"regexp".pos int, @"regexp".cap []int "noescape", @"regexp".cond @"regexp/syntax".EmptyOp, @"regexp".t *@"regexp".thread) (? *@"regexp".thread)
func (@"regexp".m *@"regexp".machine "noescape") @"regexp".alloc(@"regexp".i *@"regexp/syntax".Inst) (? *@"regexp".thread)
func (@"regexp".m *@"regexp".machine "noescape") @"regexp".clear(@"regexp".q *@"regexp".queue "noescape")
func (@"regexp".m *@"regexp".machine "noescape") @"regexp".free(@"regexp".t *@"regexp".thread)
func (@"regexp".m *@"regexp".machine "noescape") @"regexp".init(@"regexp".ncap int)
func (@"regexp".m *@"regexp".machine "noescape") @"regexp".match(@"regexp".i @"regexp".input, @"regexp".pos int) (? bool)
func (@"regexp".m *@"regexp".machine) @"regexp".newInputBytes(@"regexp".b []byte) (? @"regexp".input)
func (@"regexp".m *@"regexp".machine) @"regexp".newInputReader(@"regexp".r @"io".RuneReader) (? @"regexp".input)
func (@"regexp".m *@"regexp".machine) @"regexp".newInputString(@"regexp".s string) (? @"regexp".input)
func (@"regexp".m *@"regexp".machine "noescape") @"regexp".step(@"regexp".runq *@"regexp".queue "noescape", @"regexp".nextq *@"regexp".queue "noescape", @"regexp".pos int, @"regexp".nextPos int, @"regexp".c rune, @"regexp".nextCond @"regexp/syntax".EmptyOp)
type @"regexp".Regexp struct { @"regexp".expr string; @"regexp".prog *@"regexp/syntax".Prog; @"regexp".prefix string; @"regexp".prefixBytes []byte; @"regexp".prefixComplete bool; @"regexp".prefixRune rune; @"regexp".cond @"regexp/syntax".EmptyOp; @"regexp".numSubexp int; @"regexp".longest bool; @"regexp".mu @"sync".Mutex; @"regexp".machine []*@"regexp".machine }
func (@"regexp".re *@"regexp".Regexp) Find(@"regexp".b []byte) (? []byte)
func (@"regexp".re *@"regexp".Regexp) FindAll(@"regexp".b []byte, @"regexp".n int) (? [][]byte)
func (@"regexp".re *@"regexp".Regexp) FindAllIndex(@"regexp".b []byte, @"regexp".n int) (? [][]int)
func (@"regexp".re *@"regexp".Regexp) FindAllString(@"regexp".s string, @"regexp".n int) (? []string)
func (@"regexp".re *@"regexp".Regexp) FindAllStringIndex(@"regexp".s string, @"regexp".n int) (? [][]int)
func (@"regexp".re *@"regexp".Regexp) FindAllStringSubmatch(@"regexp".s string, @"regexp".n int) (? [][]string)
func (@"regexp".re *@"regexp".Regexp) FindAllStringSubmatchIndex(@"regexp".s string, @"regexp".n int) (? [][]int)
func (@"regexp".re *@"regexp".Regexp) FindAllSubmatch(@"regexp".b []byte, @"regexp".n int) (? [][][]byte)
func (@"regexp".re *@"regexp".Regexp) FindAllSubmatchIndex(@"regexp".b []byte, @"regexp".n int) (? [][]int)
func (@"regexp".re *@"regexp".Regexp) FindIndex(@"regexp".b []byte) (@"regexp".loc []int)
func (@"regexp".re *@"regexp".Regexp) FindReaderIndex(@"regexp".r @"io".RuneReader) (? []int)
func (@"regexp".re *@"regexp".Regexp) FindReaderSubmatchIndex(@"regexp".r @"io".RuneReader) (? []int)
func (@"regexp".re *@"regexp".Regexp) FindString(@"regexp".s string) (? string)
func (@"regexp".re *@"regexp".Regexp) FindStringIndex(@"regexp".s string) (? []int)
func (@"regexp".re *@"regexp".Regexp) FindStringSubmatch(@"regexp".s string) (? []string)
func (@"regexp".re *@"regexp".Regexp) FindStringSubmatchIndex(@"regexp".s string) (? []int)
func (@"regexp".re *@"regexp".Regexp) FindSubmatch(@"regexp".b []byte) (? [][]byte)
func (@"regexp".re *@"regexp".Regexp) FindSubmatchIndex(@"regexp".b []byte) (? []int)
func (@"regexp".re *@"regexp".Regexp "noescape") LiteralPrefix() (@"regexp".prefix string, @"regexp".complete bool) { return @"regexp".re.@"regexp".prefix, @"regexp".re.@"regexp".prefixComplete }
func (@"regexp".re *@"regexp".Regexp) Match(@"regexp".b []byte) (? bool)
func (@"regexp".re *@"regexp".Regexp) MatchReader(@"regexp".r @"io".RuneReader) (? bool)
func (@"regexp".re *@"regexp".Regexp) MatchString(@"regexp".s string) (? bool)
func (@"regexp".re *@"regexp".Regexp "noescape") NumSubexp() (? int) { return @"regexp".re.@"regexp".numSubexp }
func (@"regexp".re *@"regexp".Regexp) ReplaceAll(@"regexp".src []byte, @"regexp".repl []byte "noescape") (? []byte)
func (@"regexp".re *@"regexp".Regexp) ReplaceAllFunc(@"regexp".src []byte, @"regexp".repl func(? []byte) (? []byte) "noescape") (? []byte)
func (@"regexp".re *@"regexp".Regexp) ReplaceAllString(@"regexp".src string, @"regexp".repl string "noescape") (? string)
func (@"regexp".re *@"regexp".Regexp) ReplaceAllStringFunc(@"regexp".src string, @"regexp".repl func(? string) (? string) "noescape") (? string)
func (@"regexp".re *@"regexp".Regexp "noescape") String() (? string) { return @"regexp".re.@"regexp".expr }
func (@"regexp".re *@"regexp".Regexp) @"regexp".allMatches(@"regexp".s string, @"regexp".b []byte, @"regexp".n int, @"regexp".deliver func(? []int) "noescape")
func (@"regexp".re *@"regexp".Regexp) @"regexp".doExecute(@"regexp".r @"io".RuneReader, @"regexp".b []byte, @"regexp".s string, @"regexp".pos int, @"regexp".ncap int) (? []int)
func (@"regexp".re *@"regexp".Regexp) @"regexp".get() (? *@"regexp".machine)
func (@"regexp".re *@"regexp".Regexp "noescape") @"regexp".pad(@"regexp".a []int) (? []int)
func (@"regexp".re *@"regexp".Regexp) @"regexp".put(@"regexp".z *@"regexp".machine)
var @"".matchRe *@"regexp".Regexp
func @"".matchString(@"".pat string, @"".str string) (@"".result bool, @"".err error)
func @"".main()
var @"".statictmp_0001 [0]@"testing".InternalTest
var @"".statictmp_0002 [10]@"testing".InternalBenchmark
var @"".statictmp_0003 [0]@"testing".InternalExample
var @"".initdone· uint8
func @"".init()
var @"time".months [12]string
var @"time".days [7]string
$$ // local types
$$
!
y</y<homey<ianty<goy<testy<benchy<go1y<_testmain.go8y<go1.a8ÿÿÿÿu„y<testing.a8ÿÿÿÿu„y<regexp.a8ÿÿÿÿu8*q"".matchStringqtype.func(string, string) (bool, error)ãqE(8u„q"".matchPatqtype.stringrqt"".patrtt"".errqtype.error®u•(t®u•0tqtype.boolqu<>t "".resultq t„q
"".matchReq type.*regexp.Regexp®
q ®u¢Qp&Z<01>®q®<01>r<00>«<00>®t®<01>r<00>q runtime.cmpstringq type.func(string, string) int q rtr <00>&uZpY-t<00>regexp.expr«<0E>®q®ŽrqrŽ„qregexp.Compileqtype.func(string) (*regexp.Regexp, error)q®<00>®
q «<00>®Ž®•(t®Ž®•0t«•(t¢ŽuQ- ®#
q <00>regexp.re®#<11><00>regexp.s«#<12>t"".str®#t®#Žr#tr#Ž„qregexp.(*Regexp).MatchString#qq#<00>q#q#q# t®#u•(t®#u•0tª#q"".mainqtype.func()ã&q8'“qx<00>testing.matchString®'<17><00>testing.tests«'<18>q"".testsqtype.[]testing.InternalTest®'q®'Žr'qr'Žr' qr' Ž„<00>testing.benchmarks«'<1B>q"".benchmarksqtype.[]testing.InternalBenchmark®'q®'Žr'qr'Žr' qr' Ž„<00>testing.examples«'(<1E>q"".examplesq type.[]testing.InternalExample®'q ®'Žr'q r'Žr' q r' Ž„q!testing.Mainq"type.func(func(string, string) (bool, error), []testing.InternalTest, []testing.InternalBenchmark, []testing.InternalExample)'!q"ª(q#"".initã(#qu„q$"".initdone·q%type.uint8q($q%q(<00>%%(uQ(`pq(<00>%%(uZ(_(q&runtime.throwinit(&qq(u$q%„q'regexp.init('qq(testing.init((qq)go1.init()qq*go1.BenchmarkBinaryTree17q+type.func(*testing.B)®“q*x+q,"".statictmp_0002®,q„q-go1.BenchmarkFannkuch11®“q-x+®(,q„q.go1.BenchmarkGobDecode®“q.x+®@,q„q/go1.BenchmarkGobEncode®“q/x+®X,q„q0go1.BenchmarkGzip®“q0x+®p,q„q1go1.BenchmarkGunzip®“q1x+®ˆ,q„qgo1.BenchmarkJSONEncode®“qx+® ,q„qgo1.BenchmarkJSONDecode®“qx+®¸,q„qgo1.BenchmarkRevcomp25M®“qx+®Ð,q„qgo1.BenchmarkTemplate®“qx+®è,qq(u$q%ª(q"".statictmp_0001-“oqqx-—oqu-—o qu-“oqq,x-—oq
u-—o q
u„qgo.string."go1.BenchmarkBinaryTree17"-o,qq x-oqq x-oqu-o q go1.Benc-oq hmarkBin-oq aryTree1-o$q 7-o%qu6o
q(u-o,qu„qgo.string."go1.BenchmarkFannkuch11"-o,qq x-oqq x-oqu-o q go1.Benc-oq hmarkFan-oq nkuch11-o#qu6o
q(u-o ,qu„qgo.string."go1.BenchmarkGobDecode"-o0,qq x-oqq x-oqu-o q go1.Benc-oq hmarkGob-oq Decode-o"qu6o
q(u-o8,qu„q go.string."go1.BenchmarkGobEncode"-oH,qq x-o qq x-o qu-o q go1.Benc-o q hmarkGob-o q Encode-o" qu6o
q(u-oP,qu„q
go.string."go1.BenchmarkGzip"-o`,qq
x-o
qq
x-o
qu-o
q go1.Benc-o
q hmarkGzi-o
q p-o
qu6o
q u-oh,qu„q go.string."go1.BenchmarkGunzip"-ox,qq x-o qq x-o qu-o q go1.Benc-o q hmarkGun-o q zip-o qu6o
q u-o,qu„q go.string."go1.BenchmarkJSONEncode"-o<08>,qq x-o qq x-o qu-o q go1.Benc-o q hmarkJSO-o q NEncode-o# qu6o
q(u-o˜,qu„q go.string."go1.BenchmarkJSONDecode"-o¨,qq x-o qq x-o qu-o q go1.Benc-o q hmarkJSO-o q NDecode-o# qu6o
q(u-o°,qu„qgo.string."go1.BenchmarkRevcomp25M"-oÀ,qq x-oqq x-oqu-o q go1.Benc-oq hmarkRev-oq comp25M-o#qu6o
q(u-oÈ,qu„qgo.string."go1.BenchmarkTemplate"-oØ,qq x-oqq x-oqu-o q go1.Benc-oq hmarkTem-oq plate-o!qu6o
q(u-oà,qu„q"".statictmp_0003-“oq qx-—oq u-—o q u6qu6qu6q u„q"".matchPatqtype.string6qu„q"".matchReqtype.*regexp.Regexp6qu6qu6,qðu6qu6($q%u„qtype.func(string, string) (bool, error)qtype.*runtime.FuncType-(oqqx-(oqqx-(oqu-(oqB€7#u-(oqu-(oqu-(oqu-(oqu„qruntime.algarray-(o qq@x„qgo.string."func(string, string) (bool, error)"-(o(qqx-(oqq x-(oq"u-(o q func(str-(oq ing, str-(oq ing) (bo-(o$q ol, erro-(o,q r)-(o.qu6(o
q0u„qweak.type.*func(string, string) (bool, error)-(o8qqx-(o@qu-(oHqqhx-(oPqu-(oTqu-(oXqqxx-(o`qu-(odqu-(ohqqx-(opqqx„qtype.bool-(oxqqx„qtype.error-(oqqx6(o
qˆu„qtype.func(string, string) int-(oqqx-(oqqx-(oqu-(oqE6Ìu-(oqu-(oqu-(oqu-(oqu-(o qq@x„qgo.string."func(string, string) int"-(o(qqx-(oqq x-(oqu-(o q func(str-(oq ing, str-(oq ing) int-(o$qu6(o
q(u„qweak.type.*func(string, string) int-(o8qqx-(o@qu-(oHqqhx-(oPqu-(oTqu-(oXqqxx-(o`qu-(odqu-(ohqqx-(opqqx„qtype.int-(oxqqx6(o
qu„q type.func(string) (*regexp.Regexp, error)-(o qqx-(o qq x-(o qu-(o qEN4Béu-(o qu-(o qu-(o qu-(o qu-(o qq@x„q!go.string."func(string) (*regexp.Regexp, error)"-(o( qq!x-(o!qq !x-(o!q$u-(o !q func(str-(o!q ing) (*r-(o!q egexp.Re-(o$!q gexp, er-(o,!q ror)-(o0!qu6(o
!q8u„q"weak.type.*func(string) (*regexp.Regexp, error)-(o8 qq"x-(o@ qu-(oH qqh x-(oP qu-(oT qu-(oX qqp x-(o` qu-(od qu-(oh qqx-(op qqx-(ox qqx6(o
qu„q#type.func()-(o#qqx-(o#qq#x-(o#qu-(o#qEö¼öu-(o#qu-(o#qu-(o#qu-(o#qu-(o #qq@x„q$go.string."func()"-(o(#qq$x-(o$qq $x-(o$qu-(o $q func()-(o$qu6(o
$qu„q%weak.type.*func()-(o8#qq%x-(o@#qu-(oH#qqh#x-(oP#qu-(oT#qu-(oX#qqh#x-(o`#qu-(od#qu6(o
#qhu„q&type.[]testing.InternalTestq'type.*runtime.SliceType-(o&qq'x-(o&qq&x-(o&qu-(o&q…ÑXu-(o&qu-(o&qu-(o&qu-(o&qu-(o &qqàx„q(go.string."[]testing.InternalTest"-(o(&qq(x-(o(qq (x-(o(qu-(o (q []testin-(o(q g.Intern-(o(q alTest-(o"(qu6(o
(q(u„q)weak.type.*[]testing.InternalTest-(o8&qq)x„q*type.testing.InternalTest-(o@&qq*x6(o
&qHu„q+type.[]testing.InternalBenchmark-(o+qq'x-(o+qq+x-(o+qu-(o+q'À(Vu-(o+qu-(o+qu-(o+qu-(o+qu-(o +qqàx„q,go.string."[]testing.InternalBenchmark"-(o(+qq,x-(o,qq ,x-(o,qu-(o ,q []testin-(o,q g.Intern-(o,q alBenchm-(o$,q ark-(o',qu6(o
,q(u„q-weak.type.*[]testing.InternalBenchmark-(o8+qq-x„q.type.testing.InternalBenchmark-(o@+qq.x6(o
+qHu„q/type.[]testing.InternalExample-(o/qq'x-(o/qq/x-(o/qu-(o/qoÁ£Ju-(o/qu-(o/qu-(o/qu-(o/qu-(o /qqàx„q0go.string."[]testing.InternalExample"-(o(/qq0x-(o0qq 0x-(o0qu-(o 0q []testin-(o0q g.Intern-(o0q alExampl-(o$0q e-(o%0qu6(o
0q(u„q1weak.type.*[]testing.InternalExample-(o8/qq1x„qtype.testing.InternalExample-(o@/qqx6(o
/qHu„qtype.func(func(string, string) (bool, error), []testing.InternalTest, []testing.InternalBenchmark, []testing.InternalExample)-(oqqx-(oqqx-(oqu-(oqEÍŒu-(oqu-(oqu-(oqu-(oqu-(o qq@x„q""..gostring.1-(o(qqx-(oqq x-(oqxu-(o q func(fun-(oq c(string-(oq , string-(o$q ) (bool,-(o,q error),-(o4q []testi-(o<q ng.Inter-(oDq nalTest,-(oLq []testi-(oTq ng.Inter-(o\q nalBench-(odq mark, []-(olq testing.-(otq Internal-(o|q Example)-(oqu6(o
qˆu„qweak.type.*func(func(string, string) (bool, error), []testing.InternalTest, []testing.InternalBenchmark, []testing.InternalExample)-(o8qqx-(o@qu-(oHqqhx-(oPqu-(oTqu-(oXqqˆx-(o`qu-(odqu-(ohqqx-(opqq&x-(oxqq+x-(oqq/x6(o
qˆu„qtype.func(*testing.B)-(oqqx-(oqqx-(oqu-(oqEúrÀu-(oqu-(oqu-(oqu-(oqu-(o qqÀx„qgo.string."func(*testing.B)"-(o(qqx-(oqq x-(oqu-(o q func(*te-(oq sting.B)-(oqu6(o
q u„qweak.type.*func(*testing.B)-(o8qqx-(o@qu-(oHqqhx-(oPqu-(oTqu-(oXqqpx-(o`qu-(odqu„qtype.*testing.B-(ohqqx6(o
qpu„q go.importpath.runtime.q
go.string."runtime"-(o qq
x-(o
qq
x-(o
qu-(o
q runtime-(o
qu6(o
qu-(o qu6(o
qu„q go.importpath.go1.q go.string."go1"-(o qq x-(o qq x-(o qu-(o q go1-(o qu6(o
qu-(o qu6(o
qu„q go.importpath.testing.qgo.string."testing"-(o qq x-(oqq x-(oqu-(o q testing-(oqu6(o
qu-(o qu6(o
qu„qgo.importpath.regexp.qgo.string."regexp"-(oqq x-(oqq x-(oqu-(o q regexp-(oqu6(o
qu-(oqu6(o
quP

View File

@ -0,0 +1,40 @@
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)
}

View File

@ -0,0 +1,63 @@
// 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.
// This benchmark, taken from the shootout, tests garbage collector
// performance by generating and discarding large binary trees.
package go1
import "testing"
type binaryNode struct {
item int
left, right *binaryNode
}
func bottomUpTree(item, depth int) *binaryNode {
if depth <= 0 {
return &binaryNode{item: item}
}
return &binaryNode{item, bottomUpTree(2*item-1, depth-1), bottomUpTree(2*item, depth-1)}
}
func (n *binaryNode) itemCheck() int {
if n.left == nil {
return n.item
}
return n.item + n.left.itemCheck() - n.right.itemCheck()
}
const minDepth = 4
func binarytree(n int) {
maxDepth := n
if minDepth+2 > n {
maxDepth = minDepth + 2
}
stretchDepth := maxDepth + 1
check := bottomUpTree(0, stretchDepth).itemCheck()
//fmt.Printf("stretch tree of depth %d\t check: %d\n", stretchDepth, check)
longLivedTree := bottomUpTree(0, maxDepth)
for depth := minDepth; depth <= maxDepth; depth += 2 {
iterations := 1 << uint(maxDepth-depth+minDepth)
check = 0
for i := 1; i <= iterations; i++ {
check += bottomUpTree(i, depth).itemCheck()
check += bottomUpTree(-i, depth).itemCheck()
}
//fmt.Printf("%d\t trees of depth %d\t check: %d\n", iterations*2, depth, check)
}
longLivedTree.itemCheck()
//fmt.Printf("long lived tree of depth %d\t check: %d\n", maxDepth, longLivedTree.itemCheck())
}
func BenchmarkBinaryTree17(b *testing.B) {
for i := 0; i < b.N; i++ {
binarytree(17)
}
}

View File

@ -0,0 +1,3 @@
package go1
// Nothing to see here: everything is in the _test files.

View File

@ -0,0 +1,84 @@
// 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.
// This benchmark, taken from the shootout, tests array indexing
// and array bounds elimination performance.
package go1
import "testing"
func fannkuch(n int) int {
if n < 1 {
return 0
}
n1 := n - 1
perm := make([]int, n)
perm1 := make([]int, n)
count := make([]int, n)
for i := 0; i < n; i++ {
perm1[i] = i // initial (trivial) permutation
}
r := n
didpr := 0
flipsMax := 0
for {
if didpr < 30 {
didpr++
}
for ; r != 1; r-- {
count[r-1] = r
}
if perm1[0] != 0 && perm1[n1] != n1 {
flips := 0
for i := 1; i < n; i++ { // perm = perm1
perm[i] = perm1[i]
}
k := perm1[0] // cache perm[0] in k
for { // k!=0 ==> k>0
for i, j := 1, k-1; i < j; i, j = i+1, j-1 {
perm[i], perm[j] = perm[j], perm[i]
}
flips++
// Now exchange k (caching perm[0]) and perm[k]... with care!
j := perm[k]
perm[k] = k
k = j
if k == 0 {
break
}
}
if flipsMax < flips {
flipsMax = flips
}
}
for ; r < n; r++ {
// rotate down perm[0..r] by one
perm0 := perm1[0]
for i := 0; i < r; i++ {
perm1[i] = perm1[i+1]
}
perm1[r] = perm0
count[r]--
if count[r] > 0 {
break
}
}
if r == n {
return flipsMax
}
}
return 0
}
func BenchmarkFannkuch11(b *testing.B) {
for i := 0; i < b.N; i++ {
fannkuch(11)
}
}

View File

@ -0,0 +1,164 @@
// 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 go1
// Not a benchmark; input for revcomp.
var fasta25m = fasta(25e6)
func fasta(n int) []byte {
out := make(fastaBuffer, 0, 11*n)
iub := []fastaAcid{
{prob: 0.27, sym: 'a'},
{prob: 0.12, sym: 'c'},
{prob: 0.12, sym: 'g'},
{prob: 0.27, sym: 't'},
{prob: 0.02, sym: 'B'},
{prob: 0.02, sym: 'D'},
{prob: 0.02, sym: 'H'},
{prob: 0.02, sym: 'K'},
{prob: 0.02, sym: 'M'},
{prob: 0.02, sym: 'N'},
{prob: 0.02, sym: 'R'},
{prob: 0.02, sym: 'S'},
{prob: 0.02, sym: 'V'},
{prob: 0.02, sym: 'W'},
{prob: 0.02, sym: 'Y'},
}
homosapiens := []fastaAcid{
{prob: 0.3029549426680, sym: 'a'},
{prob: 0.1979883004921, sym: 'c'},
{prob: 0.1975473066391, sym: 'g'},
{prob: 0.3015094502008, sym: 't'},
}
alu := []byte(
"GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG" +
"GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA" +
"CCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAAT" +
"ACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAATCCCA" +
"GCTACTCGGGAGGCTGAGGCAGGAGAATCGCTTGAACCCGGG" +
"AGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTGCACTCC" +
"AGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA")
out.WriteString(">ONE Homo sapiens alu\n")
fastaRepeat(&out, alu, 2*n)
out.WriteString(">TWO IUB ambiguity codes\n")
fastaRandom(&out, iub, 3*n)
out.WriteString(">THREE Homo sapiens frequency\n")
fastaRandom(&out, homosapiens, 5*n)
return out
}
type fastaBuffer []byte
func (b *fastaBuffer) Flush() {
panic("flush")
}
func (b *fastaBuffer) WriteString(s string) {
p := b.NextWrite(len(s))
copy(p, s)
}
func (b *fastaBuffer) NextWrite(n int) []byte {
p := *b
if len(p)+n > cap(p) {
b.Flush()
p = *b
}
out := p[len(p) : len(p)+n]
*b = p[:len(p)+n]
return out
}
const fastaLine = 60
func fastaRepeat(out *fastaBuffer, alu []byte, n int) {
buf := append(alu, alu...)
off := 0
for n > 0 {
m := n
if m > fastaLine {
m = fastaLine
}
buf1 := out.NextWrite(m + 1)
copy(buf1, buf[off:])
buf1[m] = '\n'
if off += m; off >= len(alu) {
off -= len(alu)
}
n -= m
}
}
const (
fastaLookupSize = 4096
fastaLookupScale float64 = fastaLookupSize - 1
)
var fastaRand uint32 = 42
type fastaAcid struct {
sym byte
prob float64
cprob float64
next *fastaAcid
}
func fastaComputeLookup(acid []fastaAcid) *[fastaLookupSize]*fastaAcid {
var lookup [fastaLookupSize]*fastaAcid
var p float64
for i := range acid {
p += acid[i].prob
acid[i].cprob = p * fastaLookupScale
if i > 0 {
acid[i-1].next = &acid[i]
}
}
acid[len(acid)-1].cprob = 1.0 * fastaLookupScale
j := 0
for i := range lookup {
for acid[j].cprob < float64(i) {
j++
}
lookup[i] = &acid[j]
}
return &lookup
}
func fastaRandom(out *fastaBuffer, acid []fastaAcid, n int) {
const (
IM = 139968
IA = 3877
IC = 29573
)
lookup := fastaComputeLookup(acid)
for n > 0 {
m := n
if m > fastaLine {
m = fastaLine
}
buf := out.NextWrite(m + 1)
f := fastaLookupScale / IM
myrand := fastaRand
for i := 0; i < m; i++ {
myrand = (myrand*IA + IC) % IM
r := float64(int(myrand)) * f
a := lookup[int(r)]
for a.cprob < r {
a = a.next
}
buf[i] = a.sym
}
fastaRand = myrand
buf[m] = '\n'
n -= m
}
}

View File

@ -0,0 +1,95 @@
// 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.
// This benchmark tests gob encoding and decoding performance.
package go1
import (
"bytes"
"encoding/gob"
"encoding/json"
"io/ioutil"
"log"
"reflect"
"testing"
)
var (
gobbytes []byte
gobdata *JSONResponse
)
func gobinit() {
// gobinit is called after json's init,
// because it uses jsondata.
gobdata = gobResponse(&jsondata)
var buf bytes.Buffer
if err := gob.NewEncoder(&buf).Encode(gobdata); err != nil {
panic(err)
}
gobbytes = buf.Bytes()
var r JSONResponse
if err := gob.NewDecoder(bytes.NewBuffer(gobbytes)).Decode(&r); err != nil {
panic(err)
}
if !reflect.DeepEqual(gobdata, &r) {
log.Printf("%v\n%v", jsondata, r)
b, _ := json.Marshal(&jsondata)
br, _ := json.Marshal(&r)
log.Printf("%s\n%s\n", b, br)
panic("gob: encode+decode lost data")
}
}
// gob turns [] into null, so make a copy of the data structure like that
func gobResponse(r *JSONResponse) *JSONResponse {
return &JSONResponse{gobNode(r.Tree), r.Username}
}
func gobNode(n *JSONNode) *JSONNode {
n1 := new(JSONNode)
*n1 = *n
if len(n1.Kids) == 0 {
n1.Kids = nil
} else {
for i, k := range n1.Kids {
n1.Kids[i] = gobNode(k)
}
}
return n1
}
func gobdec() {
if gobbytes == nil {
panic("gobdata not initialized")
}
var r JSONResponse
if err := gob.NewDecoder(bytes.NewBuffer(gobbytes)).Decode(&r); err != nil {
panic(err)
}
_ = r
}
func gobenc() {
if err := gob.NewEncoder(ioutil.Discard).Encode(&gobdata); err != nil {
panic(err)
}
}
func BenchmarkGobDecode(b *testing.B) {
b.SetBytes(int64(len(gobbytes)))
for i := 0; i < b.N; i++ {
gobdec()
}
}
func BenchmarkGobEncode(b *testing.B) {
b.SetBytes(int64(len(gobbytes)))
for i := 0; i < b.N; i++ {
gobenc()
}
}

View File

@ -0,0 +1,69 @@
// 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.
// This benchmark tests gzip and gunzip performance.
package go1
import (
"bytes"
gz "compress/gzip"
"io"
"io/ioutil"
"testing"
)
var (
jsongunz = bytes.Repeat(jsonbytes, 10)
jsongz []byte
)
func init() {
var buf bytes.Buffer
c, err := gz.NewWriter(&buf)
if err != nil {
panic(err)
}
c.Write(jsongunz)
c.Close()
jsongz = buf.Bytes()
}
func gzip() {
c, err := gz.NewWriter(ioutil.Discard)
if err != nil {
panic(err)
}
if _, err := c.Write(jsongunz); err != nil {
panic(err)
}
if err := c.Close(); err != nil {
panic(err)
}
}
func gunzip() {
r, err := gz.NewReader(bytes.NewBuffer(jsongz))
if err != nil {
panic(err)
}
if _, err := io.Copy(ioutil.Discard, r); err != nil {
panic(err)
}
r.Close()
}
func BenchmarkGzip(b *testing.B) {
b.SetBytes(int64(len(jsongunz)))
for i := 0; i < b.N; i++ {
gzip()
}
}
func BenchmarkGunzip(b *testing.B) {
b.SetBytes(int64(len(jsongunz)))
for i := 0; i < b.N; i++ {
gunzip()
}
}

View File

@ -0,0 +1,84 @@
// 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.
// This benchmark tests JSON encoding and decoding performance.
package go1
import (
"compress/bzip2"
"encoding/base64"
"encoding/json"
"io"
"io/ioutil"
"strings"
"testing"
)
var (
jsonbytes []byte
jsondata JSONResponse
)
func init() {
var r io.Reader
r = strings.NewReader(jsonbz2_base64)
r = base64.NewDecoder(base64.StdEncoding, r)
r = bzip2.NewReader(r)
b, err := ioutil.ReadAll(r)
if err != nil {
panic(err)
}
jsonbytes = b
if err := json.Unmarshal(jsonbytes, &jsondata); err != nil {
panic(err)
}
gobinit()
}
type JSONResponse struct {
Tree *JSONNode `json:"tree"`
Username string `json:"username"`
}
type JSONNode struct {
Name string `json:"name"`
Kids []*JSONNode `json:"kids"`
CLWeight float64 `json:"cl_weight"`
Touches int `json:"touches"`
MinT int64 `json:"min_t"`
MaxT int64 `json:"max_t"`
MeanT int64 `json:"mean_t"`
}
func jsondec() {
var r JSONResponse
if err := json.Unmarshal(jsonbytes, &r); err != nil {
panic(err)
}
_ = r
}
func jsonenc() {
buf, err := json.Marshal(&jsondata)
if err != nil {
panic(err)
}
_ = buf
}
func BenchmarkJSONEncode(b *testing.B) {
b.SetBytes(int64(len(jsonbytes)))
for i := 0; i < b.N; i++ {
jsonenc()
}
}
func BenchmarkJSONDecode(b *testing.B) {
b.SetBytes(int64(len(jsonbytes)))
for i := 0; i < b.N; i++ {
jsondec()
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,85 @@
// 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.
// This benchmark, taken from the shootout, tests array indexing
// and array bounds elimination performance.
package go1
import (
"bufio"
"bytes"
"io/ioutil"
"testing"
)
var revCompTable = [256]uint8{
'A': 'T', 'a': 'T',
'C': 'G', 'c': 'G',
'G': 'C', 'g': 'C',
'T': 'A', 't': 'A',
'U': 'A', 'u': 'A',
'M': 'K', 'm': 'K',
'R': 'Y', 'r': 'Y',
'W': 'W', 'w': 'W',
'S': 'S', 's': 'S',
'Y': 'R', 'y': 'R',
'K': 'M', 'k': 'M',
'V': 'B', 'v': 'B',
'H': 'D', 'h': 'D',
'D': 'H', 'd': 'H',
'B': 'V', 'b': 'V',
'N': 'N', 'n': 'N',
}
func revcomp(data []byte) {
in := bufio.NewReader(bytes.NewBuffer(data))
out := ioutil.Discard
buf := make([]byte, 1024*1024)
line, err := in.ReadSlice('\n')
for err == nil {
out.Write(line)
// Accumulate reversed complement in buf[w:]
nchar := 0
w := len(buf)
for {
line, err = in.ReadSlice('\n')
if err != nil || line[0] == '>' {
break
}
line = line[0 : len(line)-1]
nchar += len(line)
if len(line)+nchar/60+128 >= w {
nbuf := make([]byte, len(buf)*5)
copy(nbuf[len(nbuf)-len(buf):], buf)
w += len(nbuf) - len(buf)
buf = nbuf
}
// This loop is the bottleneck.
for _, c := range line {
w--
buf[w] = revCompTable[c]
}
}
// Copy down to beginning of buffer, inserting newlines.
// The loop left room for the newlines and 128 bytes of padding.
i := 0
for j := w; j < len(buf); j += 60 {
n := copy(buf[i:i+60], buf[j:])
buf[i+n] = '\n'
i += n + 1
}
out.Write(buf[0:i])
}
}
func BenchmarkRevcomp25M(b *testing.B) {
b.SetBytes(int64(len(fasta25m)))
for i := 0; i < b.N; i++ {
revcomp(fasta25m)
}
}

View File

@ -0,0 +1,76 @@
// 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.
// This benchmark tests text/template throughput,
// converting a large data structure with a simple template.
package go1
import (
"bytes"
"io/ioutil"
"strings"
"testing"
"text/template"
)
// After removing \t and \n this generates identical output to
// json.Marshal, making it easy to test for correctness.
const tmplText = `
{
"tree":{{template "node" .Tree}},
"username":"{{.Username}}"
}
{{define "node"}}
{
"name":"{{.Name}}",
"kids":[
{{range $i, $k := .Kids}}
{{if $i}}
,
{{end}}
{{template "node" $k}}
{{end}}
],
"cl_weight":{{.CLWeight}},
"touches":{{.Touches}},
"min_t":{{.MinT}},
"max_t":{{.MaxT}},
"mean_t":{{.MeanT}}
}
{{end}}
`
func stripTabNL(r rune) rune {
if r == '\t' || r == '\n' {
return -1
}
return r
}
var tmpl = template.Must(template.New("main").Parse(strings.Map(stripTabNL, tmplText)))
func init() {
var buf bytes.Buffer
if err := tmpl.Execute(&buf, &jsondata); err != nil {
panic(err)
}
if !bytes.Equal(buf.Bytes(), jsonbytes) {
println(buf.Len(), len(jsonbytes))
panic("wrong output")
}
}
func tmplexec() {
if err := tmpl.Execute(ioutil.Discard, &jsondata); err != nil {
panic(err)
}
}
func BenchmarkTemplate(b *testing.B) {
b.SetBytes(int64(len(jsonbytes)))
for i := 0; i < b.N; i++ {
tmplexec()
}
}

View File

@ -2,7 +2,7 @@
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
include ../../src/Make.inc
include ../../../src/Make.inc
all:
@echo "make clean or timing"

View File

@ -49,20 +49,20 @@ const (
)
var complement = [...]int{
red | red<<2: red,
red | yellow<<2: blue,
red | blue<<2: yellow,
yellow | red<<2: blue,
red | red<<2: red,
red | yellow<<2: blue,
red | blue<<2: yellow,
yellow | red<<2: blue,
yellow | yellow<<2: yellow,
yellow | blue<<2: red,
blue | red<<2: yellow,
blue | yellow<<2: red,
blue | blue<<2: blue,
yellow | blue<<2: red,
blue | red<<2: yellow,
blue | yellow<<2: red,
blue | blue<<2: blue,
}
var colname = [...]string{
blue: "blue",
red: "red",
blue: "blue",
red: "red",
yellow: "yellow",
}

View File

@ -70,7 +70,7 @@ const (
IA = 3877
IC = 29573
LookupSize = 4096
LookupSize = 4096
LookupScale float64 = LookupSize - 1
)
@ -178,7 +178,6 @@ func main() {
Random(homosapiens, 5**n)
}
type buffer []byte
func (b *buffer) Flush() {

View File

@ -43,7 +43,6 @@ import (
var max_solutions = flag.Int("n", 2100, "maximum number of solutions")
func boolInt(b bool) int8 {
if b {
return 1
@ -115,7 +114,6 @@ var piece_def = [10][4]int8{
[4]int8{E, E, E, SW},
}
/* To minimize the amount of work done in the recursive solve function below,
* I'm going to allocate enough space for all legal rotations of each piece
* at each position on the board. That's 10 pieces x 50 board positions x
@ -138,7 +136,6 @@ func rotate(dir int8) int8 { return (dir + 2) % PIVOT }
/* Returns the direction flipped on the horizontal axis */
func flip(dir int8) int8 { return (PIVOT - dir) % PIVOT }
/* Returns the new cell index from the specified cell in the
* specified direction. The index is only valid if the
* starting cell and direction have been checked by the
@ -322,7 +319,6 @@ func record_piece(piece int, minimum int8, first_empty int8, piece_mask uint64)
piece_counts[piece][minimum]++
}
/* Fill the entire board going cell by cell. If any cells are "trapped"
* they will be left alone.
*/
@ -351,7 +347,6 @@ func fill_contiguous_space(board []int8, index int8) {
}
}
/* To thin the number of pieces, I calculate if any of them trap any empty
* cells at the edges. There are only a handful of exceptions where the
* the board can be solved with the trapped cells. For example: piece 8 can
@ -382,7 +377,6 @@ func has_island(cell []int8, piece int) bool {
return true
}
/* Calculate all six rotations of the specified piece at the specified index.
* We calculate only half of piece 3's rotations. This is because any solution
* found has an identical solution rotated 180 degrees. Thus we can reduce the
@ -417,7 +411,6 @@ func calc_pieces() {
}
}
/* Calculate all 32 possible states for a 5-bit row and all rows that will
* create islands that follow any of the 32 possible rows. These pre-
* calculated 5-bit rows will be used to find islands in a partially solved
@ -530,7 +523,6 @@ func calc_rows() {
}
}
/* Calculate islands while solving the board.
*/
func boardHasIslands(cell int8) int8 {
@ -545,7 +537,6 @@ func boardHasIslands(cell int8) int8 {
return bad_even_triple[current_triple]
}
/* The recursive solve algorithm. Try to place each permutation in the upper-
* leftmost empty cell. Mark off available pieces as it goes along.
* Because the board is a bit mask, the piece number and bit mask must be saved

View File

@ -125,39 +125,39 @@ func (sys System) advance(dt float64) {
var (
jupiter = Body{
x: 4.84143144246472090e+00,
y: -1.16032004402742839e+00,
z: -1.03622044471123109e-01,
vx: 1.66007664274403694e-03 * daysPerYear,
vy: 7.69901118419740425e-03 * daysPerYear,
vz: -6.90460016972063023e-05 * daysPerYear,
x: 4.84143144246472090e+00,
y: -1.16032004402742839e+00,
z: -1.03622044471123109e-01,
vx: 1.66007664274403694e-03 * daysPerYear,
vy: 7.69901118419740425e-03 * daysPerYear,
vz: -6.90460016972063023e-05 * daysPerYear,
mass: 9.54791938424326609e-04 * solarMass,
}
saturn = Body{
x: 8.34336671824457987e+00,
y: 4.12479856412430479e+00,
z: -4.03523417114321381e-01,
vx: -2.76742510726862411e-03 * daysPerYear,
vy: 4.99852801234917238e-03 * daysPerYear,
vz: 2.30417297573763929e-05 * daysPerYear,
x: 8.34336671824457987e+00,
y: 4.12479856412430479e+00,
z: -4.03523417114321381e-01,
vx: -2.76742510726862411e-03 * daysPerYear,
vy: 4.99852801234917238e-03 * daysPerYear,
vz: 2.30417297573763929e-05 * daysPerYear,
mass: 2.85885980666130812e-04 * solarMass,
}
uranus = Body{
x: 1.28943695621391310e+01,
y: -1.51111514016986312e+01,
z: -2.23307578892655734e-01,
vx: 2.96460137564761618e-03 * daysPerYear,
vy: 2.37847173959480950e-03 * daysPerYear,
vz: -2.96589568540237556e-05 * daysPerYear,
x: 1.28943695621391310e+01,
y: -1.51111514016986312e+01,
z: -2.23307578892655734e-01,
vx: 2.96460137564761618e-03 * daysPerYear,
vy: 2.37847173959480950e-03 * daysPerYear,
vz: -2.96589568540237556e-05 * daysPerYear,
mass: 4.36624404335156298e-05 * solarMass,
}
neptune = Body{
x: 1.53796971148509165e+01,
y: -2.59193146099879641e+01,
z: 1.79258772950371181e-01,
vx: 2.68067772490389322e-03 * daysPerYear,
vy: 1.62824170038242295e-03 * daysPerYear,
vz: -9.51592254519715870e-05 * daysPerYear,
x: 1.53796971148509165e+01,
y: -2.59193146099879641e+01,
z: 1.79258772950371181e-01,
vx: 2.68067772490389322e-03 * daysPerYear,
vy: 1.62824170038242295e-03 * daysPerYear,
vz: -9.51592254519715870e-05 * daysPerYear,
mass: 5.15138902046611451e-05 * solarMass,
}
sun = Body{

View File

@ -38,9 +38,9 @@ POSSIBILITY OF SUCH DAMAGE.
package main
import (
"big"
"flag"
"fmt"
"math/big"
)
var n = flag.Int("n", 27, "number of digits")

View File

@ -39,8 +39,8 @@ import (
"fmt"
"io/ioutil"
"os"
"runtime"
"regexp"
"runtime"
)
var variants = []string{

View File

@ -52,7 +52,7 @@ func f(i int, in <-chan int, out chan<- int) {
fmt.Printf("%d\n", i)
os.Exit(0)
}
out <- n-1
out <- n - 1
}
}

View File

@ -5,7 +5,7 @@
set -e
eval $(gomake --no-print-directory -f ../../src/Make.inc go-env)
eval $(gomake --no-print-directory -f ../../../src/Make.inc go-env)
PATH=.:$PATH
havegccgo=false

View File

@ -101,6 +101,46 @@ func main() {
}
h(a, b)
m()
}
type I interface {
M(_ int, y int)
}
type TI struct{}
func (TI) M(x int, y int) {
if x != y {
println("invalid M call:", x, y)
panic("bad M")
}
}
var fp = func(_ int, y int) {}
func init() {
fp = fp1
}
func fp1(x, y int) {
if x != y {
println("invalid fp1 call:", x, y)
panic("bad fp1")
}
}
func m() {
var i I
i = TI{}
i.M(1, 1)
i.M(2, 2)
fp(1, 1)
fp(2, 2)
}
// useless but legal
@ -120,3 +160,4 @@ func _() {
func ff() {
var _ int = 1
}

View File

@ -0,0 +1,22 @@
// echo bug395 is broken # takes 90+ seconds to break
// # $G $D/$F.go || echo bug395
// 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 1909
// Would OOM due to exponential recursion on Foo's expanded methodset in nodefmt
package test
type Foo interface {
Bar() interface {
Foo
}
Baz() interface {
Foo
}
Bug() interface {
Foo
}
}

View File

@ -82,5 +82,4 @@ func main() {
// However, the result of the bug linked to at the top is that we'll
// end up panicking with: "throw: bad g->status in ready".
recver(cmux)
print("PASS\n")
}

View File

@ -279,5 +279,4 @@ func main() {
<-sync
}
}
print("PASS\n")
}

View File

@ -48,4 +48,11 @@ func main() {
case x := <-cs: // ERROR "receive"
_ = x
}
for _ = range cs {// ERROR "receive"
}
close(c)
close(cs)
close(cr) // ERROR "receive"
}

View File

@ -0,0 +1,68 @@
// $G $D/$F.go && $L $F.$A && ./$A.out
// 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 select when discarding a value.
package main
import "runtime"
func recv1(c <-chan int) {
<-c
}
func recv2(c <-chan int) {
select {
case <-c:
}
}
func recv3(c <-chan int) {
c2 := make(chan int)
select {
case <-c:
case <-c2:
}
}
func send1(recv func(<-chan int)) {
c := make(chan int)
go recv(c)
runtime.Gosched()
c <- 1
}
func send2(recv func(<-chan int)) {
c := make(chan int)
go recv(c)
runtime.Gosched()
select {
case c <- 1:
}
}
func send3(recv func(<-chan int)) {
c := make(chan int)
go recv(c)
runtime.Gosched()
c2 := make(chan int)
select {
case c <- 1:
case c2 <- 1:
}
}
func main() {
send1(recv1)
send2(recv1)
send3(recv1)
send1(recv2)
send2(recv2)
send3(recv2)
send1(recv3)
send2(recv3)
send3(recv3)
}

View File

@ -6,6 +6,8 @@
package main
import "runtime"
var c = make(chan int)
func check(a []int) {
@ -77,6 +79,8 @@ func h() {
func newfunc() func(int) int { return func(x int) int { return x } }
func main() {
var fail bool
go f()
check([]int{1, 4, 5, 4})
@ -88,13 +92,26 @@ func main() {
go h()
check([]int{100, 200, 101, 201, 500, 101, 201, 500})
runtime.UpdateMemStats()
n0 := runtime.MemStats.Mallocs
x, y := newfunc(), newfunc()
if x(1) != 1 || y(2) != 2 {
println("newfunc returned broken funcs")
panic("fail")
fail = true
}
runtime.UpdateMemStats()
if n0 != runtime.MemStats.Mallocs {
println("newfunc allocated unexpectedly")
fail = true
}
ff(1)
if fail {
panic("fail")
}
}
func ff(x int) {

View File

@ -0,0 +1,400 @@
// $G $D/$F.go && $L $F.$A && ./$A.out
// 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.
package main
import "unsafe"
var global bool
func use(b bool) { global = b }
func stringptr(s string) uintptr { return *(*uintptr)(unsafe.Pointer(&s)) }
func isfalse(b bool) {
if b {
// stack will explain where
panic("wanted false, got true")
}
}
func istrue(b bool) {
if !b {
// stack will explain where
panic("wanted true, got false")
}
}
type T *int
func main() {
var a []int
var b map[string]int
var c string = "hello"
var d string = "hel" // try to get different pointer
d = d + "lo"
if stringptr(c) == stringptr(d) {
panic("compiler too smart -- got same string")
}
var e = make(chan int)
var ia interface{} = a
var ib interface{} = b
var ic interface{} = c
var id interface{} = d
var ie interface{} = e
// these comparisons are okay because
// string compare is okay and the others
// are comparisons where the types differ.
isfalse(ia == ib)
isfalse(ia == ic)
isfalse(ia == id)
isfalse(ib == ic)
isfalse(ib == id)
istrue(ic == id)
istrue(ie == ie)
istrue(ia != ib)
istrue(ia != ic)
istrue(ia != id)
istrue(ib != ic)
istrue(ib != id)
isfalse(ic != id)
isfalse(ie != ie)
// these are not okay, because there is no comparison on slices or maps.
//isfalse(a == ib)
//isfalse(a == ic)
//isfalse(a == id)
//isfalse(b == ic)
//isfalse(b == id)
istrue(c == id)
istrue(e == ie)
//isfalse(ia == b)
isfalse(ia == c)
isfalse(ia == d)
isfalse(ib == c)
isfalse(ib == d)
istrue(ic == d)
istrue(ie == e)
//istrue(a != ib)
//istrue(a != ic)
//istrue(a != id)
//istrue(b != ic)
//istrue(b != id)
isfalse(c != id)
isfalse(e != ie)
//istrue(ia != b)
istrue(ia != c)
istrue(ia != d)
istrue(ib != c)
istrue(ib != d)
isfalse(ic != d)
isfalse(ie != e)
// 6g used to let this go through as true.
var g uint64 = 123
var h int64 = 123
var ig interface{} = g
var ih interface{} = h
isfalse(ig == ih)
istrue(ig != ih)
// map of interface should use == on interface values,
// not memory.
var m = make(map[interface{}]int)
m[ic] = 1
m[id] = 2
if m[c] != 2 {
println("m[c] = ", m[c])
panic("bad m[c]")
}
// non-interface comparisons
{
c := make(chan int)
c1 := (<-chan int)(c)
c2 := (chan<- int)(c)
istrue(c == c1)
istrue(c == c2)
istrue(c1 == c)
istrue(c2 == c)
isfalse(c != c1)
isfalse(c != c2)
isfalse(c1 != c)
isfalse(c2 != c)
d := make(chan int)
isfalse(c == d)
isfalse(d == c)
isfalse(d == c1)
isfalse(d == c2)
isfalse(c1 == d)
isfalse(c2 == d)
istrue(c != d)
istrue(d != c)
istrue(d != c1)
istrue(d != c2)
istrue(c1 != d)
istrue(c2 != d)
}
// named types vs not
{
var x = new(int)
var y T
var z T = x
isfalse(x == y)
istrue(x == z)
isfalse(y == z)
isfalse(y == x)
istrue(z == x)
isfalse(z == y)
istrue(x != y)
isfalse(x != z)
istrue(y != z)
istrue(y != x)
isfalse(z != x)
istrue(z != y)
}
// structs
{
var x = struct {
x int
y string
}{1, "hi"}
var y = struct {
x int
y string
}{2, "bye"}
var z = struct {
x int
y string
}{1, "hi"}
isfalse(x == y)
isfalse(y == x)
isfalse(y == z)
isfalse(z == y)
istrue(x == z)
istrue(z == x)
istrue(x != y)
istrue(y != x)
istrue(y != z)
istrue(z != y)
isfalse(x != z)
isfalse(z != x)
var m = make(map[struct {
x int
y string
}]int)
m[x] = 10
m[y] = 20
m[z] = 30
istrue(m[x] == 30)
istrue(m[y] == 20)
istrue(m[z] == 30)
istrue(m[x] != 10)
isfalse(m[x] != 30)
isfalse(m[y] != 20)
isfalse(m[z] != 30)
isfalse(m[x] == 10)
var m1 = make(map[struct {
x int
y string
}]struct {
x int
y string
})
m1[x] = x
m1[y] = y
m1[z] = z
istrue(m1[x] == z)
istrue(m1[y] == y)
istrue(m1[z] == z)
istrue(m1[x] == x)
isfalse(m1[x] != z)
isfalse(m1[y] != y)
isfalse(m1[z] != z)
isfalse(m1[x] != x)
var ix, iy, iz interface{} = x, y, z
isfalse(ix == iy)
isfalse(iy == ix)
isfalse(iy == iz)
isfalse(iz == iy)
istrue(ix == iz)
istrue(iz == ix)
isfalse(x == iy)
isfalse(y == ix)
isfalse(y == iz)
isfalse(z == iy)
istrue(x == iz)
istrue(z == ix)
isfalse(ix == y)
isfalse(iy == x)
isfalse(iy == z)
isfalse(iz == y)
istrue(ix == z)
istrue(iz == x)
istrue(ix != iy)
istrue(iy != ix)
istrue(iy != iz)
istrue(iz != iy)
isfalse(ix != iz)
isfalse(iz != ix)
istrue(x != iy)
istrue(y != ix)
istrue(y != iz)
istrue(z != iy)
isfalse(x != iz)
isfalse(z != ix)
istrue(ix != y)
istrue(iy != x)
istrue(iy != z)
istrue(iz != y)
isfalse(ix != z)
isfalse(iz != x)
}
// arrays
{
var x = [2]string{"1", "hi"}
var y = [2]string{"2", "bye"}
var z = [2]string{"1", "hi"}
isfalse(x == y)
isfalse(y == x)
isfalse(y == z)
isfalse(z == y)
istrue(x == z)
istrue(z == x)
istrue(x != y)
istrue(y != x)
istrue(y != z)
istrue(z != y)
isfalse(x != z)
isfalse(z != x)
var m = make(map[[2]string]int)
m[x] = 10
m[y] = 20
m[z] = 30
istrue(m[x] == 30)
istrue(m[y] == 20)
istrue(m[z] == 30)
isfalse(m[x] != 30)
isfalse(m[y] != 20)
isfalse(m[z] != 30)
var ix, iy, iz interface{} = x, y, z
isfalse(ix == iy)
isfalse(iy == ix)
isfalse(iy == iz)
isfalse(iz == iy)
istrue(ix == iz)
istrue(iz == ix)
isfalse(x == iy)
isfalse(y == ix)
isfalse(y == iz)
isfalse(z == iy)
istrue(x == iz)
istrue(z == ix)
isfalse(ix == y)
isfalse(iy == x)
isfalse(iy == z)
isfalse(iz == y)
istrue(ix == z)
istrue(iz == x)
istrue(ix != iy)
istrue(iy != ix)
istrue(iy != iz)
istrue(iz != iy)
isfalse(ix != iz)
isfalse(iz != ix)
istrue(x != iy)
istrue(y != ix)
istrue(y != iz)
istrue(z != iy)
isfalse(x != iz)
isfalse(z != ix)
istrue(ix != y)
istrue(iy != x)
istrue(iy != z)
istrue(iz != y)
isfalse(ix != z)
isfalse(iz != x)
}
shouldPanic(p1)
shouldPanic(p2)
shouldPanic(p3)
shouldPanic(p4)
}
func p1() {
var a []int
var ia interface{} = a
use(ia == ia)
}
func p2() {
var b []int
var ib interface{} = b
use(ib == ib)
}
func p3() {
var a []int
var ia interface{} = a
var m = make(map[interface{}]int)
m[ia] = 1
}
func p4() {
var b []int
var ib interface{} = b
var m = make(map[interface{}]int)
m[ib] = 1
}
func shouldPanic(f func()) {
defer func() {
if recover() == nil {
panic("function should panic")
}
}()
f()
}

View File

@ -1,15 +0,0 @@
// $G $D/$F.go && $L $F.$A && ! ./$A.out
// 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.
package main
func use(bool) { }
func main() {
var a []int
var ia interface{} = a
use(ia == ia)
}

View File

@ -1,15 +0,0 @@
// $G $D/$F.go && $L $F.$A && ! ./$A.out
// 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.
package main
func use(bool) { }
func main() {
var b []int
var ib interface{} = b
use(ib == ib)
}

View File

@ -1,14 +0,0 @@
// $G $D/$F.go && $L $F.$A && ! ./$A.out
// 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.
package main
func main() {
var a []int
var ia interface{} = a
var m = make(map[interface{}] int)
m[ia] = 1
}

View File

@ -31,6 +31,18 @@ func eq(a []*R) {
}
}
func teq(t *T, n int) {
for i := 0; i < n; i++ {
if t == nil || t.i != i {
panic("bad")
}
t = t.next
}
if t != nil {
panic("bad")
}
}
type P struct {
a, b int
}
@ -46,6 +58,9 @@ func main() {
var tp *T
tp = &T{0, 7.2, "hi", &t}
tl := &T{i: 0, next: &T{i: 1, next: &T{i: 2, next: &T{i: 3, next: &T{i: 4}}}}}
teq(tl, 5)
a1 := []int{1, 2, 3}
if len(a1) != 3 {
panic("a1")
@ -93,6 +108,7 @@ func main() {
}
eq([]*R{itor(0), itor(1), itor(2), itor(3), itor(4), itor(5)})
eq([]*R{{0}, {1}, {2}, {3}, {4}, {5}})
p1 := NewP(1, 2)
p2 := NewP(1, 2)

View File

@ -0,0 +1,39 @@
// errchk $G -e $D/$F.go
// 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
var m map[int][3]int
func f() [3]int
func fp() *[3]int
var mp map[int]*[3]int
var (
_ = [3]int{1, 2, 3}[:] // ERROR "slice of unaddressable value"
_ = m[0][:] // ERROR "slice of unaddressable value"
_ = f()[:] // ERROR "slice of unaddressable value"
// these are okay because they are slicing a pointer to an array
_ = (&[3]int{1, 2, 3})[:]
_ = mp[0][:]
_ = fp()[:]
)
type T struct {
i int
f float64
s string
next *T
}
var (
_ = &T{0, 0, "", nil} // ok
_ = &T{i: 0, f: 0, s: "", next: {}} // ERROR "missing type in composite literal|omit types within composite literal"
_ = &T{0, 0, "", {}} // ERROR "missing type in composite literal|omit types within composite literal"
)

View File

@ -0,0 +1,96 @@
// errchk $G -e $D/$F.go
// 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
type Tbyte []byte
type Trune []rune
type Tint64 []int64
type Tstring string
func main() {
s := "hello"
sb := []byte("hello")
sr := []rune("hello")
si := []int64{'h', 'e', 'l', 'l', 'o'}
ts := Tstring(s)
tsb := Tbyte(sb)
tsr := Trune(sr)
tsi := Tint64(si)
_ = string(s)
_ = []byte(s)
_ = []rune(s)
_ = []int64(s) // ERROR "cannot convert.*\[\]int64|invalid type conversion"
_ = Tstring(s)
_ = Tbyte(s)
_ = Trune(s)
_ = Tint64(s) // ERROR "cannot convert.*Tint64|invalid type conversion"
_ = string(sb)
_ = []byte(sb)
_ = []rune(sb) // ERROR "cannot convert.*\[\]rune|invalid type conversion"
_ = []int64(sb) // ERROR "cannot convert.*\[\]int64|invalid type conversion"
_ = Tstring(sb)
_ = Tbyte(sb)
_ = Trune(sb) // ERROR "cannot convert.*Trune|invalid type conversion"
_ = Tint64(sb) // ERROR "cannot convert.*Tint64|invalid type conversion"
_ = string(sr)
_ = []byte(sr) // ERROR "cannot convert.*\[\]byte|invalid type conversion"
_ = []rune(sr)
_ = []int64(sr) // ERROR "cannot convert.*\[\]int64|invalid type conversion"
_ = Tstring(sr)
_ = Tbyte(sr) // ERROR "cannot convert.*Tbyte|invalid type conversion"
_ = Trune(sr)
_ = Tint64(sr) // ERROR "cannot convert.*Tint64|invalid type conversion"
_ = string(si) // ERROR "cannot convert.* string|invalid type conversion"
_ = []byte(si) // ERROR "cannot convert.*\[\]byte|invalid type conversion"
_ = []rune(si) // ERROR "cannot convert.*\[\]rune|invalid type conversion"
_ = []int64(si)
_ = Tstring(si) // ERROR "cannot convert.*Tstring|invalid type conversion"
_ = Tbyte(si) // ERROR "cannot convert.*Tbyte|invalid type conversion"
_ = Trune(si) // ERROR "cannot convert.*Trune|invalid type conversion"
_ = Tint64(si)
_ = string(ts)
_ = []byte(ts)
_ = []rune(ts)
_ = []int64(ts) // ERROR "cannot convert.*\[\]int64|invalid type conversion"
_ = Tstring(ts)
_ = Tbyte(ts)
_ = Trune(ts)
_ = Tint64(ts) // ERROR "cannot convert.*Tint64|invalid type conversion"
_ = string(tsb)
_ = []byte(tsb)
_ = []rune(tsb) // ERROR "cannot convert.*\[\]rune|invalid type conversion"
_ = []int64(tsb) // ERROR "cannot convert.*\[\]int64|invalid type conversion"
_ = Tstring(tsb)
_ = Tbyte(tsb)
_ = Trune(tsb) // ERROR "cannot convert.*Trune|invalid type conversion"
_ = Tint64(tsb) // ERROR "cannot convert.*Tint64|invalid type conversion"
_ = string(tsr)
_ = []byte(tsr) // ERROR "cannot convert.*\[\]byte|invalid type conversion"
_ = []rune(tsr)
_ = []int64(tsr) // ERROR "cannot convert.*\[\]int64|invalid type conversion"
_ = Tstring(tsr)
_ = Tbyte(tsr) // ERROR "cannot convert.*Tbyte|invalid type conversion"
_ = Trune(tsr)
_ = Tint64(tsr) // ERROR "cannot convert.*Tint64|invalid type conversion"
_ = string(tsi) // ERROR "cannot convert.* string|invalid type conversion"
_ = []byte(tsi) // ERROR "cannot convert.*\[\]byte|invalid type conversion"
_ = []rune(tsi) // ERROR "cannot convert.*\[\]rune|invalid type conversion"
_ = []int64(tsi)
_ = Tstring(tsi) // ERROR "cannot convert.*Tstring|invalid type conversion"
_ = Tbyte(tsi) // ERROR "cannot convert.*Tbyte|invalid type conversion"
_ = Trune(tsi) // ERROR "cannot convert.*Trune|invalid type conversion"
_ = Tint64(tsi)
}

View File

@ -0,0 +1,52 @@
// $G $D/$F.go && $L $F.$A && ./$A.out >tmp.go &&
// $G tmp.go && $L tmp.$A && ./$A.out
// rm -f tmp.go
// 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 files and strings containing \r and \r\n.
package main
import (
"fmt"
"strings"
)
func main() {
prog = strings.Replace(prog, "BQ", "`", -1)
prog = strings.Replace(prog, "CR", "\r", -1)
fmt.Print(prog)
}
var prog = `
package main
CR
import "fmt"
var CR s = "hello\n" + CR
" world"CR
var t = BQhelloCR
worldBQ
var u = BQhCReCRlCRlCRoCR
worldBQ
var golden = "hello\n world"
func main() {
if s != golden {
fmt.Printf("s=%q, want %q", s, golden)
}
if t != golden {
fmt.Printf("t=%q, want %q", t, golden)
}
if u != golden {
fmt.Printf("u=%q, want %q", u, golden)
}
}
`

View File

@ -15,8 +15,8 @@ var (
_ = sum()
_ = sum(1.0, 2.0)
_ = sum(1.5) // ERROR "integer"
_ = sum("hello") // ERROR "string.*as type int|incompatible"
_ = sum([]int{1}) // ERROR "slice literal.*as type int|incompatible"
_ = sum("hello") // ERROR ".hello. .type string. as type int|incompatible"
_ = sum([]int{1}) // ERROR "\[\]int literal.*as type int|incompatible"
)
type T []T

View File

@ -1,4 +1,4 @@
// $G $D/$F.go && $L $F.$A && ./$A.out
// $G $D/$F.go && $L $F.$A && ./$A.out 2>&1 | cmp - $D/$F.out
// Copyright 2010 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style

View File

@ -0,0 +1,2 @@
printing: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
42 true false true +1.500000e+000 world 0x0 [0/0]0x0 0x0 0x0 255

View File

@ -0,0 +1,83 @@
// $G $D/$F.go && $L $F.$A && ./$A.out
// 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.
//line foo/bar.y:4
package main
//line foo/bar.y:60
func main() {
//line foo/bar.y:297
f, l := 0, 0
//line yacctab:1
f, l = 1, 1
//line yaccpar:1
f, l = 2, 1
//line foo/bar.y:82
f, l = 3, 82
//line foo/bar.y:90
f, l = 3, 90
//line foo/bar.y:92
f, l = 3, 92
//line foo/bar.y:100
f, l = 3, 100
//line foo/bar.y:104
l = 104
//line foo/bar.y:112
l = 112
//line foo/bar.y:117
l = 117
//line foo/bar.y:121
l = 121
//line foo/bar.y:125
l = 125
//line foo/bar.y:133
l = 133
//line foo/bar.y:146
l = 146
//line foo/bar.y:148
//line foo/bar.y:153
//line foo/bar.y:155
l = 155
//line foo/bar.y:160
//line foo/bar.y:164
//line foo/bar.y:173
//line foo/bar.y:178
//line foo/bar.y:180
//line foo/bar.y:185
//line foo/bar.y:195
//line foo/bar.y:197
//line foo/bar.y:202
//line foo/bar.y:204
//line foo/bar.y:208
//line foo/bar.y:211
//line foo/bar.y:213
//line foo/bar.y:215
//line foo/bar.y:217
//line foo/bar.y:221
//line foo/bar.y:229
//line foo/bar.y:236
//line foo/bar.y:238
//line foo/bar.y:240
//line foo/bar.y:244
//line foo/bar.y:249
//line foo/bar.y:253
//line foo/bar.y:257
//line foo/bar.y:262
//line foo/bar.y:267
//line foo/bar.y:272
if l == f {
//line foo/bar.y:277
panic("aie!")
//line foo/bar.y:281
}
//line foo/bar.y:285
return
//line foo/bar.y:288
//line foo/bar.y:290
}
//line foo/bar.y:293
//line foo/bar.y:295

View File

@ -1,14 +1,29 @@
// $G $D/$F.go && $L $F.$A && ! ./$A.out
// $G $D/$F.go $D/z*.go && $L $F.$A && ./$A.out
// 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.
package main
func main() {
var b []int
var ib interface{} = b
var m = make(map[interface{}] int)
m[ib] = 1
F1()
F2()
F3()
F4()
F5()
F6()
F7()
F8()
F9()
F10()
F11()
F12()
F13()
F14()
F15()
F16()
F17()
F18()
F19()
F20()
}

View File

@ -0,0 +1,5 @@
//line x1.go:4
package main
func F1() {}

View File

@ -0,0 +1,6 @@
//line x10.go:4
package main
func F10() {}

View File

@ -0,0 +1,4 @@
//line x11.go:4
package main
func F11() {}

Some files were not shown because too many files have changed in this diff Show More