mirror of https://github.com/golang/go.git
misc/cgo/errors: limit number of parallel executions
Fixes #32328 Change-Id: Iee71ecb247f2c439804c2ff03a6ed7b7f5a8b562 Reviewed-on: https://go-review.googlesource.com/c/go/+/179603 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
9e2299207a
commit
d53f380e62
|
|
@ -553,18 +553,23 @@ func main() {
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
|
var csem = make(chan bool, 16)
|
||||||
|
|
||||||
func testOne(t *testing.T, pt ptrTest, exe string) {
|
func testOne(t *testing.T, pt ptrTest, exe string) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
newcmd := func(cgocheck string) *exec.Cmd {
|
// Run the tests in parallel, but don't run too many
|
||||||
|
// executions in parallel, to avoid overloading the system.
|
||||||
|
runcmd := func(cgocheck string) ([]byte, error) {
|
||||||
|
csem <- true
|
||||||
|
defer func() { <-csem }()
|
||||||
cmd := exec.Command(exe, pt.name)
|
cmd := exec.Command(exe, pt.name)
|
||||||
cmd.Env = append(os.Environ(), "GODEBUG=cgocheck="+cgocheck)
|
cmd.Env = append(os.Environ(), "GODEBUG=cgocheck="+cgocheck)
|
||||||
return cmd
|
return cmd.CombinedOutput()
|
||||||
}
|
}
|
||||||
|
|
||||||
if pt.expensive {
|
if pt.expensive {
|
||||||
cmd := newcmd("1")
|
buf, err := runcmd("1")
|
||||||
buf, err := cmd.CombinedOutput()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Logf("%s", buf)
|
t.Logf("%s", buf)
|
||||||
if pt.fail {
|
if pt.fail {
|
||||||
|
|
@ -576,12 +581,12 @@ func testOne(t *testing.T, pt ptrTest, exe string) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := newcmd("")
|
cgocheck := ""
|
||||||
if pt.expensive {
|
if pt.expensive {
|
||||||
cmd = newcmd("2")
|
cgocheck = "2"
|
||||||
}
|
}
|
||||||
|
|
||||||
buf, err := cmd.CombinedOutput()
|
buf, err := runcmd(cgocheck)
|
||||||
if pt.fail {
|
if pt.fail {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Logf("%s", buf)
|
t.Logf("%s", buf)
|
||||||
|
|
@ -598,8 +603,7 @@ func testOne(t *testing.T, pt ptrTest, exe string) {
|
||||||
|
|
||||||
if !pt.expensive {
|
if !pt.expensive {
|
||||||
// Make sure it passes with the expensive checks.
|
// Make sure it passes with the expensive checks.
|
||||||
cmd := newcmd("2")
|
buf, err := runcmd("2")
|
||||||
buf, err := cmd.CombinedOutput()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Logf("%s", buf)
|
t.Logf("%s", buf)
|
||||||
t.Fatalf("failed unexpectedly with expensive checks: %v", err)
|
t.Fatalf("failed unexpectedly with expensive checks: %v", err)
|
||||||
|
|
@ -608,8 +612,7 @@ func testOne(t *testing.T, pt ptrTest, exe string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if pt.fail {
|
if pt.fail {
|
||||||
cmd := newcmd("0")
|
buf, err := runcmd("0")
|
||||||
buf, err := cmd.CombinedOutput()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Logf("%s", buf)
|
t.Logf("%s", buf)
|
||||||
t.Fatalf("failed unexpectedly with GODEBUG=cgocheck=0: %v", err)
|
t.Fatalf("failed unexpectedly with GODEBUG=cgocheck=0: %v", err)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue