Source file src/runtime/metrics_cgo_test.go

     1  // Copyright 2025 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build cgo
     6  
     7  package runtime_test
     8  
     9  import (
    10  	"internal/race"
    11  	"runtime"
    12  	"testing"
    13  )
    14  
    15  func TestNotInGoMetric(t *testing.T) {
    16  	switch runtime.GOOS {
    17  	case "windows", "plan9":
    18  		t.Skip("unsupported on Windows and Plan9")
    19  	case "freebsd":
    20  		if race.Enabled {
    21  			t.Skipf("race + cgo freebsd not supported. See https://go.dev/issue/73788.")
    22  		}
    23  	}
    24  
    25  	run := func(t *testing.T, name string) {
    26  		// This test is run in a subprocess to prevent other tests from polluting the metrics
    27  		// and because we need to make some cgo callbacks.
    28  		output := runTestProg(t, "testprogcgo", name)
    29  		want := "OK\n"
    30  		if output != want {
    31  			t.Fatalf("output:\n%s\n\nwanted:\n%s", output, want)
    32  		}
    33  	}
    34  	t.Run("CgoCall", func(t *testing.T) {
    35  		run(t, "NotInGoMetricCgoCall")
    36  	})
    37  	t.Run("CgoCallback", func(t *testing.T) {
    38  		run(t, "NotInGoMetricCgoCallback")
    39  	})
    40  	t.Run("CgoCallAndCallback", func(t *testing.T) {
    41  		run(t, "NotInGoMetricCgoCallAndCallback")
    42  	})
    43  }
    44  

View as plain text