]> git.feebdaed.xyz Git - 0xmirror/go.git/commitdiff
runtime: only run TestNotInGoMetricCallback when building with cgo
authorMichael Anthony Knyszek <mknyszek@google.com>
Mon, 8 Dec 2025 16:17:15 +0000 (16:17 +0000)
committerGopher Robot <gobot@golang.org>
Mon, 8 Dec 2025 16:36:30 +0000 (08:36 -0800)
It seems like some platforms don't build with cgo at all, like
linux/ppc64.

Change-Id: Ibe5306e79899822e77d42cb3018f9f0c9ca2604c
Reviewed-on: https://go-review.googlesource.com/c/go/+/728140
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Auto-Submit: Michael Knyszek <mknyszek@google.com>

src/runtime/metrics_cgo_test.go [new file with mode: 0644]
src/runtime/metrics_test.go

diff --git a/src/runtime/metrics_cgo_test.go b/src/runtime/metrics_cgo_test.go
new file mode 100644 (file)
index 0000000..6cc9d23
--- /dev/null
@@ -0,0 +1,32 @@
+// Copyright 2025 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.
+
+//go:build cgo
+
+package runtime_test
+
+import (
+       "internal/race"
+       "runtime"
+       "testing"
+)
+
+func TestNotInGoMetricCallback(t *testing.T) {
+       switch runtime.GOOS {
+       case "windows", "plan9":
+               t.Skip("unsupported on Windows and Plan9")
+       case "freebsd":
+               if race.Enabled {
+                       t.Skipf("race + cgo freebsd not supported. See https://go.dev/issue/73788.")
+               }
+       }
+
+       // This test is run in a subprocess to prevent other tests from polluting the metrics
+       // and because we need to make some cgo callbacks.
+       output := runTestProg(t, "testprogcgo", "NotInGoMetricCallback")
+       want := "OK\n"
+       if output != want {
+               t.Fatalf("output:\n%s\n\nwanted:\n%s", output, want)
+       }
+}
index 278efdc69f8345ed79001c3bc414934b71d5d1e4..92cec75465ce4cc2c93ccfaf699c092e05982026 100644 (file)
@@ -9,7 +9,6 @@ import (
        "internal/abi"
        "internal/goexperiment"
        "internal/profile"
-       "internal/race"
        "internal/testenv"
        "os"
        "reflect"
@@ -1585,22 +1584,3 @@ func TestReadMetricsSched(t *testing.T) {
                t.Fatalf("output:\n%s\n\nwanted:\n%s", output, want)
        }
 }
-
-func TestNotInGoMetricCallback(t *testing.T) {
-       switch runtime.GOOS {
-       case "windows", "plan9":
-               t.Skip("unsupported on Windows and Plan9")
-       case "freebsd":
-               if race.Enabled {
-                       t.Skipf("race + cgo freebsd not supported. See https://go.dev/issue/73788.")
-               }
-       }
-
-       // This test is run in a subprocess to prevent other tests from polluting the metrics
-       // and because we need to make some cgo callbacks.
-       output := runTestProg(t, "testprogcgo", "NotInGoMetricCallback")
-       want := "OK\n"
-       if output != want {
-               t.Fatalf("output:\n%s\n\nwanted:\n%s", output, want)
-       }
-}