]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: remove -tags=threadprof in tests
authorIan Lance Taylor <iant@golang.org>
Wed, 19 Jan 2022 02:46:00 +0000 (18:46 -0800)
committerIan Lance Taylor <iant@golang.org>
Thu, 20 Jan 2022 19:24:26 +0000 (19:24 +0000)
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 <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
src/runtime/crash_cgo_test.go
src/runtime/testdata/testprogcgo/threadprof.go

index 6f1265c0149795959714e4dca6933c9b18f0f33a..9444554d3700e1e3574d5f6c77dd103571e27a63 100644 (file)
@@ -7,7 +7,6 @@
 package runtime_test
 
 import (
-       "bytes"
        "fmt"
        "internal/testenv"
        "os"
@@ -95,17 +94,8 @@ func TestCgoExternalThreadSIGPROF(t *testing.T) {
                t.Skipf("no pthreads on %s", runtime.GOOS)
        }
 
-       exe, err := buildTestProg(t, "testprogcgo", "-tags=threadprof")
-       if err != nil {
-               t.Fatal(err)
-       }
-
-       got, err := testenv.CleanCmdEnv(exec.Command(exe, "CgoExternalThreadSIGPROF")).CombinedOutput()
-       if err != nil {
-               t.Fatalf("exit status: %v\n%s", err, got)
-       }
-
-       if want := "OK\n"; string(got) != want {
+       got := runTestProg(t, "testprogcgo", "CgoExternalThreadSIGPROF", "GO_START_SIGPROF_THREAD=1")
+       if want := "OK\n"; got != want {
                t.Fatalf("expected %q, but got:\n%s", want, got)
        }
 }
@@ -118,18 +108,8 @@ func TestCgoExternalThreadSignal(t *testing.T) {
                t.Skipf("no pthreads on %s", runtime.GOOS)
        }
 
-       exe, err := buildTestProg(t, "testprogcgo", "-tags=threadprof")
-       if err != nil {
-               t.Fatal(err)
-       }
-
-       got, err := testenv.CleanCmdEnv(exec.Command(exe, "CgoExternalThreadSignal")).CombinedOutput()
-       if err != nil {
-               t.Fatalf("exit status: %v\n%s", err, got)
-       }
-
-       want := []byte("OK\n")
-       if !bytes.Equal(got, want) {
+       got := runTestProg(t, "testprogcgo", "CgoExternalThreadSignal")
+       if want := "OK\n"; got != want {
                t.Fatalf("expected %q, but got:\n%s", want, got)
        }
 }
index 8081173c0f45e24cba315e93fb5bc2d1135aa7a9..d62d4b4be839f7cb2bc9bb495c6d636dd3746d1a 100644 (file)
@@ -2,21 +2,22 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// We only build this file with the tag "threadprof", since it starts
-// a thread running a busy loop at constructor time.
-
-//go:build !plan9 && !windows && threadprof
-// +build !plan9,!windows,threadprof
+//go:build !plan9 && !windows
+// +build !plan9,!windows
 
 package main
 
 /*
 #include <stdint.h>
+#include <stdlib.h>
 #include <signal.h>
 #include <pthread.h>
 
 volatile int32_t spinlock;
 
+// Note that this thread is only started if GO_START_SIGPROF_THREAD
+// is set in the environment, which is only done when running the
+// CgoExternalThreadSIGPROF test.
 static void *thread1(void *p) {
        (void)p;
        while (spinlock == 0)
@@ -26,9 +27,13 @@ static void *thread1(void *p) {
        return NULL;
 }
 
+// This constructor function is run when the program starts.
+// It is used for the CgoExternalThreadSIGPROF test.
 __attribute__((constructor)) void issue9456() {
-       pthread_t tid;
-       pthread_create(&tid, 0, thread1, NULL);
+       if (getenv("GO_START_SIGPROF_THREAD") != NULL) {
+               pthread_t tid;
+               pthread_create(&tid, 0, thread1, NULL);
+       }
 }
 
 void **nullptr;