Skip to content

Commit 2c2e081

Browse files
runtime: remove -tags=threadprof in tests
Use an enviroment variable rather than a build tag to control starting a busy loop thread when testprogcgo starts. This lets us skip another build that invokes the C compiler and linker, which should avoid timeouts running the runtime tests. Fixes #44422 Change-Id: I516668d71a373da311d844990236566ff63e6d72 Reviewed-on: https://go-review.googlesource.com/c/go/+/379294 Trust: Ian Lance Taylor <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> Reviewed-by: Bryan Mills <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Austin Clements <[email protected]>
1 parent 65535bf commit 2c2e081

File tree

2 files changed

+16
-31
lines changed

2 files changed

+16
-31
lines changed

src/runtime/crash_cgo_test.go

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
package runtime_test
88

99
import (
10-
"bytes"
1110
"fmt"
1211
"internal/testenv"
1312
"os"
@@ -95,17 +94,8 @@ func TestCgoExternalThreadSIGPROF(t *testing.T) {
9594
t.Skipf("no pthreads on %s", runtime.GOOS)
9695
}
9796

98-
exe, err := buildTestProg(t, "testprogcgo", "-tags=threadprof")
99-
if err != nil {
100-
t.Fatal(err)
101-
}
102-
103-
got, err := testenv.CleanCmdEnv(exec.Command(exe, "CgoExternalThreadSIGPROF")).CombinedOutput()
104-
if err != nil {
105-
t.Fatalf("exit status: %v\n%s", err, got)
106-
}
107-
108-
if want := "OK\n"; string(got) != want {
97+
got := runTestProg(t, "testprogcgo", "CgoExternalThreadSIGPROF", "GO_START_SIGPROF_THREAD=1")
98+
if want := "OK\n"; got != want {
10999
t.Fatalf("expected %q, but got:\n%s", want, got)
110100
}
111101
}
@@ -118,18 +108,8 @@ func TestCgoExternalThreadSignal(t *testing.T) {
118108
t.Skipf("no pthreads on %s", runtime.GOOS)
119109
}
120110

121-
exe, err := buildTestProg(t, "testprogcgo", "-tags=threadprof")
122-
if err != nil {
123-
t.Fatal(err)
124-
}
125-
126-
got, err := testenv.CleanCmdEnv(exec.Command(exe, "CgoExternalThreadSignal")).CombinedOutput()
127-
if err != nil {
128-
t.Fatalf("exit status: %v\n%s", err, got)
129-
}
130-
131-
want := []byte("OK\n")
132-
if !bytes.Equal(got, want) {
111+
got := runTestProg(t, "testprogcgo", "CgoExternalThreadSignal")
112+
if want := "OK\n"; got != want {
133113
t.Fatalf("expected %q, but got:\n%s", want, got)
134114
}
135115
}

src/runtime/testdata/testprogcgo/threadprof.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,22 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
// We only build this file with the tag "threadprof", since it starts
6-
// a thread running a busy loop at constructor time.
7-
8-
//go:build !plan9 && !windows && threadprof
9-
// +build !plan9,!windows,threadprof
5+
//go:build !plan9 && !windows
6+
// +build !plan9,!windows
107

118
package main
129

1310
/*
1411
#include <stdint.h>
12+
#include <stdlib.h>
1513
#include <signal.h>
1614
#include <pthread.h>
1715
1816
volatile int32_t spinlock;
1917
18+
// Note that this thread is only started if GO_START_SIGPROF_THREAD
19+
// is set in the environment, which is only done when running the
20+
// CgoExternalThreadSIGPROF test.
2021
static void *thread1(void *p) {
2122
(void)p;
2223
while (spinlock == 0)
@@ -26,9 +27,13 @@ static void *thread1(void *p) {
2627
return NULL;
2728
}
2829
30+
// This constructor function is run when the program starts.
31+
// It is used for the CgoExternalThreadSIGPROF test.
2932
__attribute__((constructor)) void issue9456() {
30-
pthread_t tid;
31-
pthread_create(&tid, 0, thread1, NULL);
33+
if (getenv("GO_START_SIGPROF_THREAD") != NULL) {
34+
pthread_t tid;
35+
pthread_create(&tid, 0, thread1, NULL);
36+
}
3237
}
3338
3439
void **nullptr;

0 commit comments

Comments
 (0)