From 8d5ff2e182c52c4fa6af18e536dcef6e12ad8cb2 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Mon, 21 Dec 2015 10:29:21 -0500 Subject: runtime: move test programs out of source code, coalesce MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now there are just three programs to compile instead of many, and repeated tests can reuse the compilation result instead of rebuilding it. Combined, these changes reduce the time spent testing runtime during all.bash on my laptop from about 60 to about 30 seconds. (All.bash itself runs in 5½ minutes.) For #10571. Change-Id: Ie2c1798b847f1a635a860d11dcdab14375319ae9 Reviewed-on: https://go-review.googlesource.com/18085 Reviewed-by: Austin Clements Run-TryBot: Austin Clements --- src/runtime/testdata/testprognet/main.go | 35 ++++++++++++++++++++++++++++++++ src/runtime/testdata/testprognet/net.go | 29 ++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 src/runtime/testdata/testprognet/main.go create mode 100644 src/runtime/testdata/testprognet/net.go (limited to 'src/runtime/testdata/testprognet') diff --git a/src/runtime/testdata/testprognet/main.go b/src/runtime/testdata/testprognet/main.go new file mode 100644 index 0000000000..5784865ea2 --- /dev/null +++ b/src/runtime/testdata/testprognet/main.go @@ -0,0 +1,35 @@ +// Copyright 2015 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 "os" + +var cmds = map[string]func(){} + +func register(name string, f func()) { + if cmds[name] != nil { + panic("duplicate registration: " + name) + } + cmds[name] = f +} + +func registerInit(name string, f func()) { + if len(os.Args) >= 2 && os.Args[1] == name { + f() + } +} + +func main() { + if len(os.Args) < 2 { + println("usage: "+os.Args[0]+" name-of-test") + return + } + f := cmds[os.Args[1]] + if f == nil { + println("unknown function: " + os.Args[1]) + return + } + f() +} diff --git a/src/runtime/testdata/testprognet/net.go b/src/runtime/testdata/testprognet/net.go new file mode 100644 index 0000000000..c1a7f3f132 --- /dev/null +++ b/src/runtime/testdata/testprognet/net.go @@ -0,0 +1,29 @@ +// Copyright 2015 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 ( + "fmt" + "net" +) + +func init() { + registerInit("NetpollDeadlock", NetpollDeadlockInit) + register("NetpollDeadlock", NetpollDeadlock) +} + +func NetpollDeadlockInit() { + fmt.Println("dialing") + c, err := net.Dial("tcp", "localhost:14356") + if err == nil { + c.Close() + } else { + fmt.Println("error: ", err) + } +} + +func NetpollDeadlock() { + fmt.Println("done") +} -- cgit v1.3