"internal/testenv"
"io"
"io/ioutil"
+ "runtime"
"sort"
"strings"
"testing"
// Zip64 is required if the total size of the records is uint32max.
func TestZip64LargeDirectory(t *testing.T) {
+ if runtime.GOARCH == "wasm" {
+ t.Skip("too slow on wasm")
+ }
if testing.Short() {
t.Skip("skipping in short mode")
}
func init() {
switch runtime.GOOS {
- case "android", "nacl":
+ case "android", "js", "nacl":
canRun = false
case "darwin":
switch runtime.GOARCH {
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris
+// +build darwin dragonfly freebsd js linux nacl netbsd openbsd solaris
package base
}
func TestHttpsInsecure(t *testing.T) {
- if runtime.GOOS == "nacl" {
+ if runtime.GOOS == "nacl" || runtime.GOOS == "js" {
t.Skip("test assumes tcp available")
}
saveHome := os.Getenv(homeEnv())
}
func TestGetHostAndPort(t *testing.T) {
- if runtime.GOOS == "nacl" {
+ if runtime.GOOS == "nacl" || runtime.GOOS == "js" {
t.Skip("test assumes tcp available")
}
func TestNoSectionOverlaps(t *testing.T) {
// Ensure cmd/link outputs sections without overlaps.
switch runtime.GOOS {
- case "android", "darwin", "nacl", "plan9", "windows":
+ case "android", "darwin", "js", "nacl", "plan9", "windows":
t.Skipf("cmd/link doesn't produce ELF binaries on %s", runtime.GOOS)
}
_ = net.ResolveIPAddr // force dynamic linkage
"fmt"
"io/ioutil"
"reflect"
+ "runtime"
"strings"
"testing"
)
// TestHugeWriteFails tests that enormous messages trigger an error.
func TestHugeWriteFails(t *testing.T) {
+ if runtime.GOARCH == "wasm" {
+ t.Skip("out of memory on wasm")
+ }
if testing.Short() {
// Requires allocating a monster, so don't do this from all.bash.
t.Skip("skipping huge allocation in short mode")
return false
}
switch runtime.GOOS {
- case "android", "nacl":
+ case "android", "nacl", "js":
return false
case "darwin":
if strings.HasPrefix(runtime.GOARCH, "arm") {
// using os.StartProcess or (more commonly) exec.Command.
func HasExec() bool {
switch runtime.GOOS {
- case "nacl":
+ case "nacl", "js":
return false
case "darwin":
if strings.HasPrefix(runtime.GOARCH, "arm") {
// HasExternalNetwork reports whether the current system can use
// external (non-localhost) networks.
func HasExternalNetwork() bool {
- return !testing.Short()
+ return !testing.Short() && runtime.GOOS != "nacl" && runtime.GOOS != "js"
}
// MustHaveExternalNetwork checks that the current system can use
// external (non-localhost) networks.
// If not, MustHaveExternalNetwork calls t.Skip with an explanation.
func MustHaveExternalNetwork(t testing.TB) {
+ if runtime.GOOS == "nacl" || runtime.GOOS == "js" {
+ t.Skipf("skipping test: no external network on %s", runtime.GOOS)
+ }
if testing.Short() {
t.Skipf("skipping test: no external network in -short mode")
}
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build !windows,!nacl,!plan9
+// +build !windows,!nacl,!plan9,!js
package syslog
var globalMu sync.Mutex
outer := 100
inner := 100000
- if testing.Short() {
+ if testing.Short() || runtime.GOARCH == "wasm" {
outer = 10
inner = 1000
}
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build windows plan9 nacl
+// +build windows plan9 nacl js,wasm
package runtime_test
}
func TestPeriodicGC(t *testing.T) {
+ if runtime.GOARCH == "wasm" {
+ t.Skip("no sysmon on wasm yet")
+ }
+
// Make sure we're not in the middle of a GC.
runtime.GC()
// Strings with up to two nonzero bytes all have distinct hashes.
func TestSmhasherTwoNonzero(t *testing.T) {
+ if GOARCH == "wasm" {
+ t.Skip("Too slow on wasm")
+ }
if testing.Short() {
t.Skip("Skipping in short mode")
}
// Test strings with only a few bits set
func TestSmhasherSparse(t *testing.T) {
+ if GOARCH == "wasm" {
+ t.Skip("Too slow on wasm")
+ }
if testing.Short() {
t.Skip("Skipping in short mode")
}
// Test all possible combinations of n blocks from the set s.
// "permutation" is a bad name here, but it is what Smhasher uses.
func TestSmhasherPermutation(t *testing.T) {
+ if GOARCH == "wasm" {
+ t.Skip("Too slow on wasm")
+ }
if testing.Short() {
t.Skip("Skipping in short mode")
}
// Flipping a single bit of a key should flip each output bit with 50% probability.
func TestSmhasherAvalanche(t *testing.T) {
+ if GOARCH == "wasm" {
+ t.Skip("Too slow on wasm")
+ }
if testing.Short() {
t.Skip("Skipping in short mode")
}
windowed(t, &BytesKey{make([]byte, 128)})
}
func windowed(t *testing.T, k Key) {
+ if GOARCH == "wasm" {
+ t.Skip("Too slow on wasm")
+ }
if testing.Short() {
t.Skip("Skipping in short mode")
}
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build !nacl
+// +build !nacl,!js
package pprof
}
func TestStopTheWorldDeadlock(t *testing.T) {
+ if runtime.GOARCH == "wasm" {
+ t.Skip("no preemption on wasm yet")
+ }
if testing.Short() {
t.Skip("skipping during short test")
}
}
func TestTimerFairness(t *testing.T) {
+ if runtime.GOARCH == "wasm" {
+ t.Skip("no preemption on wasm yet")
+ }
+
done := make(chan bool)
c := make(chan bool)
for i := 0; i < 2; i++ {
}
func TestTimerFairness2(t *testing.T) {
+ if runtime.GOARCH == "wasm" {
+ t.Skip("no preemption on wasm yet")
+ }
+
done := make(chan bool)
c := make(chan bool)
for i := 0; i < 2; i++ {
}
func TestPreemption(t *testing.T) {
+ if runtime.GOARCH == "wasm" {
+ t.Skip("no preemption on wasm yet")
+ }
+
// Test that goroutines are preempted at function calls.
N := 5
if testing.Short() {
}
func TestPreemptionGC(t *testing.T) {
+ if runtime.GOARCH == "wasm" {
+ t.Skip("no preemption on wasm yet")
+ }
+
// Test that pending GC preempts running goroutines.
P := 5
N := 10
}
func TestPingPongHog(t *testing.T) {
+ if runtime.GOARCH == "wasm" {
+ t.Skip("no preemption on wasm yet")
+ }
if testing.Short() {
t.Skip("skipping in -short mode")
}
}
func TestLockOSThreadNesting(t *testing.T) {
+ if runtime.GOARCH == "wasm" {
+ t.Skip("no threads on wasm yet")
+ }
+
go func() {
e, i := runtime.LockOSCounts()
if e != 0 || i != 0 {
if GOOS == "nacl" {
t.Skip("nacl doesn't seem to fault on high addresses")
}
+ if GOOS == "js" {
+ t.Skip("js does not support catching faults")
+ }
defer func() {
if err := recover(); err != nil {
}
func TestBadOpen(t *testing.T) {
- if GOOS == "windows" || GOOS == "nacl" {
+ if GOOS == "windows" || GOOS == "nacl" || GOOS == "js" {
t.Skip("skipping OS that doesn't have open/read/write/close")
}
// make sure we get the correct error code if open fails. Same for
}
func TestParallelRWMutexReaders(t *testing.T) {
+ if GOARCH == "wasm" {
+ t.Skip("wasm has no threads yet")
+ }
defer GOMAXPROCS(GOMAXPROCS(-1))
// If runtime triggers a forced GC during this test then it will deadlock,
// since the goroutines can't be stopped/preempted.
// Test stack growing in different contexts.
func TestStackGrowth(t *testing.T) {
+ if GOARCH == "wasm" {
+ t.Skip("fails on wasm (too slow?)")
+ }
+
// Don't make this test parallel as this makes the 20 second
// timeout unreliable on slow builders. (See issue #19381.)
}
func TestGettimeofday(t *testing.T) {
- if runtime.GOOS == "nacl" {
- t.Skip("not implemented on nacl")
+ if runtime.GOOS == "nacl" || runtime.GOOS == "js" {
+ t.Skip("not implemented on " + runtime.GOOS)
}
tv := &syscall.Timeval{}
if err := syscall.Gettimeofday(tv); err != nil {
// templates. This limit is only practically reached by accidentally
// recursive template invocations. This limit allows us to return
// an error instead of triggering a stack overflow.
-const maxExecDepth = 100000
+var maxExecDepth = initMaxExecDepth()
+
+func initMaxExecDepth() int {
+ if runtime.GOARCH == "wasm" {
+ return 1000
+ }
+ return 100000
+}
// state represents the state of an execution. It's not part of the
// template so that multiple executions of the same template
-// +build !nacl,!plan9,!windows
+// +build !nacl,!js,!plan9,!windows
// run
// Copyright 2009 The Go Authors. All rights reserved.
-// +build !nacl
+// +build !nacl,!js
// run
// Copyright 2010 The Go Authors. All rights reserved.
-// +build !nacl,!plan9,!windows
+// +build !nacl,!js,!plan9,!windows
// run
// Copyright 2011 The Go Authors. All rights reserved.
-// +build !nacl,!windows
+// +build !nacl,!js,!windows
// run
// Copyright 2011 The Go Authors. All rights reserved.
-// +build !nacl
+// +build !nacl,!js
// run
// Copyright 2014 The Go Authors. All rights reserved.
-// +build !nacl,disabled_see_issue_18589
+// +build !nacl,!js,disabled_see_issue_18589
// buildrun -t 10 -gcflags=-d=ssa/insert_resched_checks/on,ssa/check/on
// Copyright 2016 The Go Authors. All rights reserved.
// doesn't go into the Go runtime.
// +build !windows
+// wasm does not work, because the linear memory is not executable.
+// +build !wasm
+
package main
import (
-// +build !nacl
+// +build !nacl,!js
// run
// Copyright 2015 The Go Authors. All rights reserved.
-// +build !nacl,!android,!darwin darwin,!arm
+// +build !nacl,!js,!android,!darwin darwin,!arm
// run
// Copyright 2016 The Go Authors. All rights reserved.
-// +build !nacl,!android
+// +build !nacl,!js,!android
// run
// Copyright 2016 The Go Authors. All rights reserved.
// run
-// +build !nacl
+// +build !nacl,!js
// Copyright 2016 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// run
+// +build !js
// Copyright 2017 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
-// +build !nacl
+// +build !nacl,!js
// run
// Copyright 2017 The Go Authors. All rights reserved.
)
func main() {
- if runtime.Compiler != "gc" || runtime.GOOS == "nacl" {
+ if runtime.Compiler != "gc" || runtime.GOOS == "nacl" || runtime.GOOS == "js" {
return
}
)
func main() {
- if runtime.GOOS == "nacl" {
+ if runtime.GOOS == "nacl" || runtime.GOOS == "js" {
return // no file system available on builders
}
}
func main() {
- if runtime.GOOS == "nacl" {
- return // no file system available on builders
+ if runtime.GOOS == "nacl" || runtime.GOOS == "js" {
+ return // can not exec go tool
}
f, err := ioutil.TempFile("", "issue22662b.go")
)
func main() {
- if runtime.Compiler != "gc" || runtime.GOOS == "nacl" {
+ if runtime.Compiler != "gc" || runtime.GOOS == "nacl" || runtime.GOOS == "js" {
return
}
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
+// terribly slow on wasm
+// +build !wasm
+
package main
import (
-// +build !nacl
+// +build !nacl,!js
// run
// Copyright 2015 The Go Authors. All rights reserved.
-// +build !nacl
+// +build !nacl,!js
// run
// Copyright 2011 The Go Authors. All rights reserved.
-// +build !nacl
+// +build !nacl,!js
// run
// Copyright 2014 The Go Authors. All rights reserved.
-// +build !nacl
+// +build !nacl,!js
// run
// Copyright 2016 The Go Authors. All rights reserved.
-// +build !nacl
+// +build !nacl,!js
// run
// Copyright 2014 The Go Authors. All rights reserved.
// errorcheck -0 -m -live
-// +build !windows
+// +build !windows,!js
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// errorcheck -0 -d=nil
+// +build !wasm
+
// Copyright 2013 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.
--- /dev/null
+// errorcheck -0 -d=nil
+
+// +build wasm
+
+// Copyright 2013 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 nil checks are removed.
+// Optimization is enabled.
+
+package p
+
+type Struct struct {
+ X int
+ Y float64
+}
+
+type BigStruct struct {
+ X int
+ Y float64
+ A [1 << 20]int
+ Z string
+}
+
+type Empty struct {
+}
+
+type Empty1 struct {
+ Empty
+}
+
+var (
+ intp *int
+ arrayp *[10]int
+ array0p *[0]int
+ bigarrayp *[1 << 26]int
+ structp *Struct
+ bigstructp *BigStruct
+ emptyp *Empty
+ empty1p *Empty1
+)
+
+func f1() {
+ _ = *intp // ERROR "generated nil check"
+
+ // This one should be removed but the block copy needs
+ // to be turned into its own pseudo-op in order to see
+ // the indirect.
+ _ = *arrayp // ERROR "generated nil check"
+
+ // 0-byte indirect doesn't suffice.
+ // we don't registerize globals, so there are no removed.* nil checks.
+ _ = *array0p // ERROR "generated nil check"
+ _ = *array0p // ERROR "removed nil check"
+
+ _ = *intp // ERROR "removed nil check"
+ _ = *arrayp // ERROR "removed nil check"
+ _ = *structp // ERROR "generated nil check"
+ _ = *emptyp // ERROR "generated nil check"
+ _ = *arrayp // ERROR "removed nil check"
+}
+
+func f2() {
+ var (
+ intp *int
+ arrayp *[10]int
+ array0p *[0]int
+ bigarrayp *[1 << 20]int
+ structp *Struct
+ bigstructp *BigStruct
+ emptyp *Empty
+ empty1p *Empty1
+ )
+
+ _ = *intp // ERROR "generated nil check"
+ _ = *arrayp // ERROR "generated nil check"
+ _ = *array0p // ERROR "generated nil check"
+ _ = *array0p // ERROR "removed.* nil check"
+ _ = *intp // ERROR "removed.* nil check"
+ _ = *arrayp // ERROR "removed.* nil check"
+ _ = *structp // ERROR "generated nil check"
+ _ = *emptyp // ERROR "generated nil check"
+ _ = *arrayp // ERROR "removed.* nil check"
+ _ = *bigarrayp // ERROR "generated nil check" ARM removed nil check before indirect!!
+ _ = *bigstructp // ERROR "generated nil check"
+ _ = *empty1p // ERROR "generated nil check"
+}
+
+func fx10k() *[10000]int
+
+var b bool
+
+func f3(x *[10000]int) {
+ // Using a huge type and huge offsets so the compiler
+ // does not expect the memory hardware to fault.
+ _ = x[9999] // ERROR "generated nil check"
+
+ for {
+ if x[9999] != 0 { // ERROR "removed nil check"
+ break
+ }
+ }
+
+ x = fx10k()
+ _ = x[9999] // ERROR "generated nil check"
+ if b {
+ _ = x[9999] // ERROR "removed.* nil check"
+ } else {
+ _ = x[9999] // ERROR "removed.* nil check"
+ }
+ _ = x[9999] // ERROR "removed nil check"
+
+ x = fx10k()
+ if b {
+ _ = x[9999] // ERROR "generated nil check"
+ } else {
+ _ = x[9999] // ERROR "generated nil check"
+ }
+ _ = x[9999] // ERROR "generated nil check"
+
+ fx10k()
+ // This one is a bit redundant, if we figured out that
+ // x wasn't going to change across the function call.
+ // But it's a little complex to do and in practice doesn't
+ // matter enough.
+ _ = x[9999] // ERROR "removed nil check"
+}
+
+func f3a() {
+ x := fx10k()
+ y := fx10k()
+ z := fx10k()
+ _ = &x[9] // ERROR "generated nil check"
+ y = z
+ _ = &x[9] // ERROR "removed.* nil check"
+ x = y
+ _ = &x[9] // ERROR "generated nil check"
+}
+
+func f3b() {
+ x := fx10k()
+ y := fx10k()
+ _ = &x[9] // ERROR "generated nil check"
+ y = x
+ _ = &x[9] // ERROR "removed.* nil check"
+ x = y
+ _ = &x[9] // ERROR "removed.* nil check"
+}
+
+func fx10() *[10]int
+
+func f4(x *[10]int) {
+ // Most of these have no checks because a real memory reference follows,
+ // and the offset is small enough that if x is nil, the address will still be
+ // in the first unmapped page of memory.
+
+ _ = x[9] // ERROR "generated nil check" // bug: would like to remove this check (but nilcheck and load are in different blocks)
+
+ for {
+ if x[9] != 0 { // ERROR "removed nil check"
+ break
+ }
+ }
+
+ x = fx10()
+ _ = x[9] // ERROR "generated nil check" // bug would like to remove before indirect
+ if b {
+ _ = x[9] // ERROR "removed nil check"
+ } else {
+ _ = x[9] // ERROR "removed nil check"
+ }
+ _ = x[9] // ERROR "removed nil check"
+
+ x = fx10()
+ if b {
+ _ = x[9] // ERROR "generated nil check" // bug would like to remove before indirect
+ } else {
+ _ = &x[9] // ERROR "generated nil check"
+ }
+ _ = x[9] // ERROR "generated nil check" // bug would like to remove before indirect
+
+ fx10()
+ _ = x[9] // ERROR "removed nil check"
+
+ x = fx10()
+ y := fx10()
+ _ = &x[9] // ERROR "generated nil check"
+ y = x
+ _ = &x[9] // ERROR "removed[a-z ]* nil check"
+ x = y
+ _ = &x[9] // ERROR "removed[a-z ]* nil check"
+}
+
+func f5(p *float32, q *float64, r *float32, s *float64) float64 {
+ x := float64(*p) // ERROR "generated nil check"
+ y := *q // ERROR "generated nil check"
+ *r = 7 // ERROR "generated nil check"
+ *s = 9 // ERROR "generated nil check"
+ return x + y
+}
+
+type T [29]byte
+
+func f6(p, q *T) {
+ x := *p // ERROR "generated nil check"
+ *q = x // ERROR "generated nil check"
+}
+
+func m1(m map[int][80]byte) byte {
+ v := m[3] // ERROR "removed nil check"
+ return v[5]
+}
+func m2(m map[int][800]byte) byte {
+ v := m[3] // ERROR "removed nil check"
+ return v[5]
+}
+func m3(m map[int][80]byte) (byte, bool) {
+ v, ok := m[3] // ERROR "removed nil check"
+ return v[5], ok
+}
+func m4(m map[int][800]byte) (byte, bool) {
+ v, ok := m[3] // ERROR "removed nil check"
+ return v[5], ok
+}
+func p1() byte {
+ p := new([100]byte)
+ return p[5] // ERROR "removed nil check"
+}
+
+// make sure not to do nil check for access of PAUTOHEAP
+//go:noinline
+func (p *Struct) m() {}
+func c1() {
+ var x Struct
+ func() { x.m() }() // ERROR "removed nil check"
+}
+
+type SS struct {
+ x byte
+}
+
+type TT struct {
+ SS
+}
+
+func f(t *TT) *byte {
+ // See issue 17242.
+ s := &t.SS // ERROR "removed nil check"
+ return &s.x // ERROR "generated nil check"
+}
+
+// make sure not to do nil check for newobject
+func f7() (*Struct, float64) {
+ t := new(Struct)
+ p := &t.Y // ERROR "removed nil check"
+ return t, *p // ERROR "removed nil check"
+}
+
+// make sure to remove nil check for memory move (issue #18003)
+func f8(t *[8]int) [8]int {
+ return *t // ERROR "generated nil check"
+}
+
+func f9() []int {
+ x := new([1]int)
+ x[0] = 1 // ERROR "removed nil check"
+ y := x[:] // ERROR "removed nil check"
+ return y
+}
-// +build !nacl
+// +build !nacl,!js
// run
// Copyright 2014 The Go Authors. All rights reserved.
package main
+import "runtime"
+
type Number *Number
// -------------------------------------
}
func main() {
- for i := 0; i <= 9; i++ {
+ max := 9
+ if runtime.GOARCH == "wasm" {
+ max = 7 // stack size is limited
+ }
+ for i := 0; i <= max; i++ {
if f := count(fact(gen(i))); f != results[i] {
println("FAIL:", i, "!:", f, "!=", results[i])
panic(0)
-// +build !nacl
+// +build !nacl,!js
// run
// Copyright 2014 The Go Authors. All rights reserved.