Update to go1.23.4
This commit is contained in:
@@ -33,7 +33,7 @@ import (
|
||||
"unicode"
|
||||
)
|
||||
|
||||
var globalSkip = func(t *testing.T) {}
|
||||
var globalSkip = func(t testing.TB) {}
|
||||
|
||||
// Program to run.
|
||||
var bin []string
|
||||
@@ -59,12 +59,12 @@ func TestMain(m *testing.M) {
|
||||
|
||||
func testMain(m *testing.M) int {
|
||||
if testing.Short() && os.Getenv("GO_BUILDER_NAME") == "" {
|
||||
globalSkip = func(t *testing.T) { t.Skip("short mode and $GO_BUILDER_NAME not set") }
|
||||
globalSkip = func(t testing.TB) { t.Skip("short mode and $GO_BUILDER_NAME not set") }
|
||||
return m.Run()
|
||||
}
|
||||
if runtime.GOOS == "linux" {
|
||||
if _, err := os.Stat("/etc/alpine-release"); err == nil {
|
||||
globalSkip = func(t *testing.T) { t.Skip("skipping failing test on alpine - go.dev/issue/19938") }
|
||||
globalSkip = func(t testing.TB) { t.Skip("skipping failing test on alpine - go.dev/issue/19938") }
|
||||
return m.Run()
|
||||
}
|
||||
}
|
||||
@@ -1291,8 +1291,8 @@ func TestPreemption(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Issue 59294. Test calling Go function from C after using some
|
||||
// stack space.
|
||||
// Issue 59294 and 68285. Test calling Go function from C after with
|
||||
// various stack space.
|
||||
func TestDeepStack(t *testing.T) {
|
||||
globalSkip(t)
|
||||
testenv.MustHaveGoBuild(t)
|
||||
@@ -1350,6 +1350,53 @@ func TestDeepStack(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCgoCallbackMainThread(b *testing.B) {
|
||||
// Benchmark for calling into Go fron C main thread.
|
||||
// See issue #68587.
|
||||
//
|
||||
// It uses a subprocess, which is a C binary that calls
|
||||
// Go on the main thread b.N times. There is some overhead
|
||||
// for launching the subprocess. It is probably fine when
|
||||
// b.N is large.
|
||||
|
||||
globalSkip(b)
|
||||
testenv.MustHaveGoBuild(b)
|
||||
testenv.MustHaveCGO(b)
|
||||
testenv.MustHaveBuildMode(b, "c-archive")
|
||||
|
||||
if !testWork {
|
||||
defer func() {
|
||||
os.Remove("testp10" + exeSuffix)
|
||||
os.Remove("libgo10.a")
|
||||
os.Remove("libgo10.h")
|
||||
}()
|
||||
}
|
||||
|
||||
cmd := exec.Command("go", "build", "-buildmode=c-archive", "-o", "libgo10.a", "./libgo10")
|
||||
out, err := cmd.CombinedOutput()
|
||||
b.Logf("%v\n%s", cmd.Args, out)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
|
||||
ccArgs := append(cc, "-o", "testp10"+exeSuffix, "main10.c", "libgo10.a")
|
||||
out, err = exec.Command(ccArgs[0], ccArgs[1:]...).CombinedOutput()
|
||||
b.Logf("%v\n%s", ccArgs, out)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
|
||||
argv := cmdToRun("./testp10")
|
||||
argv = append(argv, fmt.Sprint(b.N))
|
||||
cmd = exec.Command(argv[0], argv[1:]...)
|
||||
|
||||
b.ResetTimer()
|
||||
err = cmd.Run()
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSharedObject(t *testing.T) {
|
||||
// Test that we can put a Go c-archive into a C shared object.
|
||||
globalSkip(t)
|
||||
|
||||
12
src/cmd/cgo/internal/testcarchive/testdata/libgo10/a.go
vendored
Normal file
12
src/cmd/cgo/internal/testcarchive/testdata/libgo10/a.go
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
// Copyright 2024 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.
|
||||
|
||||
package main
|
||||
|
||||
import "C"
|
||||
|
||||
//export GoF
|
||||
func GoF() {}
|
||||
|
||||
func main() {}
|
||||
@@ -6,9 +6,29 @@ package main
|
||||
|
||||
import "runtime"
|
||||
|
||||
// extern void callGoWithVariousStack(int);
|
||||
import "C"
|
||||
|
||||
func main() {}
|
||||
|
||||
//export GoF
|
||||
func GoF() { runtime.GC() }
|
||||
func GoF(p int32) {
|
||||
runtime.GC()
|
||||
if p != 0 {
|
||||
panic("panic")
|
||||
}
|
||||
}
|
||||
|
||||
//export callGoWithVariousStackAndGoFrame
|
||||
func callGoWithVariousStackAndGoFrame(p int32) {
|
||||
if p != 0 {
|
||||
defer func() {
|
||||
e := recover()
|
||||
if e == nil {
|
||||
panic("did not panic")
|
||||
}
|
||||
runtime.GC()
|
||||
}()
|
||||
}
|
||||
C.callGoWithVariousStack(C.int(p));
|
||||
}
|
||||
|
||||
22
src/cmd/cgo/internal/testcarchive/testdata/main10.c
vendored
Normal file
22
src/cmd/cgo/internal/testcarchive/testdata/main10.c
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
// Copyright 2024 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.
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "libgo10.h"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int n, i;
|
||||
|
||||
if (argc != 2) {
|
||||
perror("wrong arg");
|
||||
return 2;
|
||||
}
|
||||
n = atoi(argv[1]);
|
||||
for (i = 0; i < n; i++)
|
||||
GoF();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -6,19 +6,27 @@
|
||||
|
||||
void use(int *x) { (*x)++; }
|
||||
|
||||
void callGoFWithDeepStack() {
|
||||
void callGoFWithDeepStack(int p) {
|
||||
int x[10000];
|
||||
|
||||
use(&x[0]);
|
||||
use(&x[9999]);
|
||||
|
||||
GoF();
|
||||
GoF(p);
|
||||
|
||||
use(&x[0]);
|
||||
use(&x[9999]);
|
||||
}
|
||||
|
||||
int main() {
|
||||
GoF(); // call GoF without using much stack
|
||||
callGoFWithDeepStack(); // call GoF with a deep stack
|
||||
void callGoWithVariousStack(int p) {
|
||||
GoF(0); // call GoF without using much stack
|
||||
callGoFWithDeepStack(p); // call GoF with a deep stack
|
||||
GoF(0); // again on a shallow stack
|
||||
}
|
||||
|
||||
int main() {
|
||||
callGoWithVariousStack(0);
|
||||
|
||||
callGoWithVariousStackAndGoFrame(0); // normal execution
|
||||
callGoWithVariousStackAndGoFrame(1); // panic and recover
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user