aboutsummaryrefslogtreecommitdiff
path: root/src/internal
diff options
context:
space:
mode:
authorCherry Mui <cherryyz@google.com>2025-06-10 14:57:15 -0400
committerCherry Mui <cherryyz@google.com>2025-06-10 14:57:15 -0400
commitb2e8ddba3ca4dd7ba8241cf6716b06e042185f71 (patch)
treedcfda1b821732c62930102fa8558fa8403fd6766 /src/internal
parent884f646966efdc1b2ee6dc7728bade7ceef33ace (diff)
parent773701a853a3105696c59c2b92b2eff35e0e055b (diff)
downloadgo-b2e8ddba3ca4dd7ba8241cf6716b06e042185f71.tar.xz
[dev.simd] all: merge master (773701a) into dev.simd
Merge List: + 2025-06-10 773701a853 internal/trace: pass GOTRACEBACK=crash to testprogs + 2025-06-10 fb0c27c514 os: do not follow dangling symlinks in Root when O_CREATE|O_EXCL on AIX + 2025-06-10 1cafdfb63b net/http: make the zero value of CrossOriginProtection work + 2025-06-10 a35701b352 cmd/dist: only install necessary tools when doing local test + 2025-06-10 a189516d3a runtime: don't do a direct G handoff in semrelease on systemstack + 2025-06-10 f18d046568 all.{bash,rc}: use "../bin/go tool dist" instead of "%GOTOOLDIR%/dist" print build info + 2025-06-09 ee7bfbdbcc cmd/compile/internal/ssa: fix PPC64 merging of (AND (S[RL]Dconst ...) + 2025-06-09 985d600f3a runtime: use small struct TestSynctest to ensure cleanups run + 2025-06-09 848a768ba7 runtime: clarify stack traces for bubbled goroutines + 2025-06-09 049a5e6036 runtime: return a different bubble deadlock error when main goroutine is done + 2025-06-09 ac1686752b cmd/internal/doc: increase version of pkgsite doc command that's run + 2025-06-09 da0e8c4517 cmd/compile: relax reshaping condition + 2025-06-09 7800f4f0ad log/slog: fix level doc on handlers + 2025-06-07 d184f8dc02 runtime: check for gsignal in racecall on loong64 + 2025-06-06 0ccfbc834a os/signal: doc link to syscall.EPIPE + 2025-06-06 78eadf5b3d all: update vendored dependencies [generated] + 2025-06-05 4d1c255f15 net/http: strip sensitive proxy headers from redirect requests + 2025-06-04 3432c68467 runtime: make bubbled timers more consistent with unbubbled + 2025-06-04 1aa3362093 Revert "cmd/compile: Enable inlining of tail calls" + 2025-06-04 f537061e1b cmd/trace: handle Sync event at the beginning of the trace + 2025-06-04 d4bf716793 runtime: reduce per-P memory footprint when greenteagc is disabled + 2025-06-04 1f2a4d192d test: add another regression test for issue 73309 + 2025-06-04 5b748eed9c cmd/compile: better error message when import embed package + 2025-06-03 cfb4e9bc4a cmd/dist: don't install tools that won't be shipped in distribution + 2025-06-03 94764d0938 cmd/doc: build cmd/doc directly into the go command + 2025-06-03 74b70eead7 go/token: remove unreachable code + 2025-06-03 0c0094c893 go/token: tweak comment + 2025-06-03 792548a483 cmd/go/internal/cfg: fix GOROOT setting when forcing host config + 2025-06-02 49f6304724 runtime: additional memmove benchmarks + 2025-06-02 eebae283b6 go/token: FileSet: hold Files in a balanced tree + 2025-06-02 3bd0eab96f runtime: randomize order of timers at the same instant in bubbles + 2025-06-02 a379698521 go/{ast,parser,types}: add signpost to golang.org/x/tools/go/packages + 2025-06-02 497cb7c0c3 cmd/compile/internal/noder: document quirk of string elements + 2025-06-02 cc119ee391 cmd/compile/internal/noder: stub type section and adjust others + 2025-06-02 25ca686a0b cmd/compile/internal/noder: begin filling in SectionObj + 2025-06-02 11660d537b cmd/compile/internal/noder: fill in SectionName Change-Id: I7c0a7c56105f1a6912f4ed122d615d12b1ea7877
Diffstat (limited to 'src/internal')
-rw-r--r--src/internal/synctest/synctest_test.go115
-rw-r--r--src/internal/trace/trace_test.go4
2 files changed, 117 insertions, 2 deletions
diff --git a/src/internal/synctest/synctest_test.go b/src/internal/synctest/synctest_test.go
index 2e1393591f..fe6eb63702 100644
--- a/src/internal/synctest/synctest_test.go
+++ b/src/internal/synctest/synctest_test.go
@@ -16,6 +16,7 @@ import (
"strconv"
"strings"
"sync"
+ "sync/atomic"
"testing"
"time"
"weak"
@@ -218,6 +219,116 @@ func TestTimerFromOutsideBubble(t *testing.T) {
}
}
+// TestTimerNondeterminism verifies that timers firing at the same instant
+// don't always fire in exactly the same order.
+func TestTimerNondeterminism(t *testing.T) {
+ synctest.Run(func() {
+ const iterations = 1000
+ var seen1, seen2 bool
+ for range iterations {
+ tm1 := time.NewTimer(1)
+ tm2 := time.NewTimer(1)
+ select {
+ case <-tm1.C:
+ seen1 = true
+ case <-tm2.C:
+ seen2 = true
+ }
+ if seen1 && seen2 {
+ return
+ }
+ synctest.Wait()
+ }
+ t.Errorf("after %v iterations, seen timer1:%v, timer2:%v; want both", iterations, seen1, seen2)
+ })
+}
+
+// TestSleepNondeterminism verifies that goroutines sleeping to the same instant
+// don't always schedule in exactly the same order.
+func TestSleepNondeterminism(t *testing.T) {
+ synctest.Run(func() {
+ const iterations = 1000
+ var seen1, seen2 bool
+ for range iterations {
+ var first atomic.Int32
+ go func() {
+ time.Sleep(1)
+ first.CompareAndSwap(0, 1)
+ }()
+ go func() {
+ time.Sleep(1)
+ first.CompareAndSwap(0, 2)
+ }()
+ time.Sleep(1)
+ synctest.Wait()
+ switch v := first.Load(); v {
+ case 1:
+ seen1 = true
+ case 2:
+ seen2 = true
+ default:
+ t.Fatalf("first = %v, want 1 or 2", v)
+ }
+ if seen1 && seen2 {
+ return
+ }
+ synctest.Wait()
+ }
+ t.Errorf("after %v iterations, seen goroutine 1:%v, 2:%v; want both", iterations, seen1, seen2)
+ })
+}
+
+// TestTimerRunsImmediately verifies that a 0-duration timer sends on its channel
+// without waiting for the bubble to block.
+func TestTimerRunsImmediately(t *testing.T) {
+ synctest.Run(func() {
+ start := time.Now()
+ tm := time.NewTimer(0)
+ select {
+ case got := <-tm.C:
+ if !got.Equal(start) {
+ t.Errorf("<-tm.C = %v, want %v", got, start)
+ }
+ default:
+ t.Errorf("0-duration timer channel is not readable; want it to be")
+ }
+ })
+}
+
+// TestTimerRunsLater verifies that reading from a timer's channel receives the
+// timer fired, even when that time is in reading from a timer's channel receives the
+// time the timer fired, even when that time is in the past.
+func TestTimerRanInPast(t *testing.T) {
+ synctest.Run(func() {
+ delay := 1 * time.Second
+ want := time.Now().Add(delay)
+ tm := time.NewTimer(delay)
+ time.Sleep(2 * delay)
+ select {
+ case got := <-tm.C:
+ if !got.Equal(want) {
+ t.Errorf("<-tm.C = %v, want %v", got, want)
+ }
+ default:
+ t.Errorf("0-duration timer channel is not readable; want it to be")
+ }
+ })
+}
+
+// TestAfterFuncRunsImmediately verifies that a 0-duration AfterFunc is scheduled
+// without waiting for the bubble to block.
+func TestAfterFuncRunsImmediately(t *testing.T) {
+ synctest.Run(func() {
+ var b atomic.Bool
+ time.AfterFunc(0, func() {
+ b.Store(true)
+ })
+ for !b.Load() {
+ runtime.Gosched()
+ }
+ })
+}
+
func TestChannelFromOutsideBubble(t *testing.T) {
choutside := make(chan struct{})
for _, test := range []struct {
@@ -377,7 +488,7 @@ func TestDeadlockRoot(t *testing.T) {
}
func TestDeadlockChild(t *testing.T) {
- defer wantPanic(t, "deadlock: all goroutines in bubble are blocked")
+ defer wantPanic(t, "deadlock: main bubble goroutine has exited but blocked goroutines remain")
synctest.Run(func() {
go func() {
select {}
@@ -386,7 +497,7 @@ func TestDeadlockChild(t *testing.T) {
}
func TestDeadlockTicker(t *testing.T) {
- defer wantPanic(t, "deadlock: all goroutines in bubble are blocked")
+ defer wantPanic(t, "deadlock: main bubble goroutine has exited but blocked goroutines remain")
synctest.Run(func() {
go func() {
for range time.Tick(1 * time.Second) {
diff --git a/src/internal/trace/trace_test.go b/src/internal/trace/trace_test.go
index 0aa297d762..7eb50d0f4e 100644
--- a/src/internal/trace/trace_test.go
+++ b/src/internal/trace/trace_test.go
@@ -600,6 +600,10 @@ func testTraceProg(t *testing.T, progName string, extra func(t *testing.T, trace
godebug += "," + extraGODEBUG
}
cmd.Env = append(cmd.Env, "GODEBUG="+godebug)
+ if _, ok := os.LookupEnv("GOTRACEBACK"); !ok {
+ // Unless overriden, set GOTRACEBACK=crash.
+ cmd.Env = append(cmd.Env, "GOTRACEBACK=crash")
+ }
// Capture stdout and stderr.
//