From c8f6135d4fd0be14bfc63c2bbb911cc9647e00a6 Mon Sep 17 00:00:00 2001 From: Alberto Donizetti Date: Fri, 16 Oct 2020 17:48:29 +0200 Subject: [PATCH] test: add regression test from #41474 This issue was fixed with multiple individual compiler optimizations, each of which had their own respective test cases. This CL just adds the capstone test case to demonstrate that the issue has been fixed and doesn't regress again. Updates #41474. Change-Id: Iae752d4b0e7b83ee356b946843340a4fbc254058 Reviewed-on: https://go-review.googlesource.com/c/go/+/263097 Trust: Alberto Donizetti Trust: Ian Lance Taylor Run-TryBot: Alberto Donizetti TryBot-Result: Go Bot Reviewed-by: Matthew Dempsky Reviewed-by: Ian Lance Taylor --- src/os/os_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/os/os_test.go b/src/os/os_test.go index 865dfcc0def..50160eac385 100644 --- a/src/os/os_test.go +++ b/src/os/os_test.go @@ -9,6 +9,7 @@ import ( "errors" "flag" "fmt" + "internal/race" "internal/testenv" "io" "io/ioutil" @@ -2579,3 +2580,20 @@ func TestOpenFileKeepsPermissions(t *testing.T) { t.Errorf("Stat after OpenFile is %v, should be writable", fi.Mode()) } } + +// Issue 41474. +func TestStdoutWriteDoesNotHeapAllocate(t *testing.T) { + if runtime.GOOS == "js" || runtime.GOOS == "windows" { + t.Skip("Still heap allocates on js/wasm and windows, but it used to too") + } + if race.Enabled { + t.Skip("Heap allocates in race mode") + } + + n := testing.AllocsPerRun(10, func() { + Stdout.Write([]byte{'h', 'e', 'l', 'l', 'o', '\n'}) + }) + if n != 0 { + t.Errorf("AllocsPerRun = %v, want 0", n) + } +}