@@ -33,7 +33,7 @@ import (
3333 "unicode"
3434)
3535
36- var globalSkip = func (t * testing.T ) {}
36+ var globalSkip = func (t testing.TB ) {}
3737
3838// Program to run.
3939var bin []string
@@ -59,12 +59,12 @@ func TestMain(m *testing.M) {
5959
6060func testMain (m * testing.M ) int {
6161 if testing .Short () && os .Getenv ("GO_BUILDER_NAME" ) == "" {
62- globalSkip = func (t * testing.T ) { t .Skip ("short mode and $GO_BUILDER_NAME not set" ) }
62+ globalSkip = func (t testing.TB ) { t .Skip ("short mode and $GO_BUILDER_NAME not set" ) }
6363 return m .Run ()
6464 }
6565 if runtime .GOOS == "linux" {
6666 if _ , err := os .Stat ("/etc/alpine-release" ); err == nil {
67- globalSkip = func (t * testing.T ) { t .Skip ("skipping failing test on alpine - go.dev/issue/19938" ) }
67+ globalSkip = func (t testing.TB ) { t .Skip ("skipping failing test on alpine - go.dev/issue/19938" ) }
6868 return m .Run ()
6969 }
7070 }
@@ -1291,8 +1291,8 @@ func TestPreemption(t *testing.T) {
12911291 }
12921292}
12931293
1294- // Issue 59294. Test calling Go function from C after using some
1295- // stack space.
1294+ // Issue 59294 and 68285 . Test calling Go function from C after with
1295+ // various stack space.
12961296func TestDeepStack (t * testing.T ) {
12971297 globalSkip (t )
12981298 testenv .MustHaveGoBuild (t )
@@ -1350,6 +1350,53 @@ func TestDeepStack(t *testing.T) {
13501350 }
13511351}
13521352
1353+ func BenchmarkCgoCallbackMainThread (b * testing.B ) {
1354+ // Benchmark for calling into Go fron C main thread.
1355+ // See issue #68587.
1356+ //
1357+ // It uses a subprocess, which is a C binary that calls
1358+ // Go on the main thread b.N times. There is some overhead
1359+ // for launching the subprocess. It is probably fine when
1360+ // b.N is large.
1361+
1362+ globalSkip (b )
1363+ testenv .MustHaveGoBuild (b )
1364+ testenv .MustHaveCGO (b )
1365+ testenv .MustHaveBuildMode (b , "c-archive" )
1366+
1367+ if ! testWork {
1368+ defer func () {
1369+ os .Remove ("testp10" + exeSuffix )
1370+ os .Remove ("libgo10.a" )
1371+ os .Remove ("libgo10.h" )
1372+ }()
1373+ }
1374+
1375+ cmd := exec .Command ("go" , "build" , "-buildmode=c-archive" , "-o" , "libgo10.a" , "./libgo10" )
1376+ out , err := cmd .CombinedOutput ()
1377+ b .Logf ("%v\n %s" , cmd .Args , out )
1378+ if err != nil {
1379+ b .Fatal (err )
1380+ }
1381+
1382+ ccArgs := append (cc , "-o" , "testp10" + exeSuffix , "main10.c" , "libgo10.a" )
1383+ out , err = exec .Command (ccArgs [0 ], ccArgs [1 :]... ).CombinedOutput ()
1384+ b .Logf ("%v\n %s" , ccArgs , out )
1385+ if err != nil {
1386+ b .Fatal (err )
1387+ }
1388+
1389+ argv := cmdToRun ("./testp10" )
1390+ argv = append (argv , fmt .Sprint (b .N ))
1391+ cmd = exec .Command (argv [0 ], argv [1 :]... )
1392+
1393+ b .ResetTimer ()
1394+ err = cmd .Run ()
1395+ if err != nil {
1396+ b .Fatal (err )
1397+ }
1398+ }
1399+
13531400func TestSharedObject (t * testing.T ) {
13541401 // Test that we can put a Go c-archive into a C shared object.
13551402 globalSkip (t )
0 commit comments