]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: add a test for reproducible build with anonymous interfaces
authorCherry Zhang <cherryyz@google.com>
Fri, 17 Aug 2018 15:12:43 +0000 (11:12 -0400)
committerCherry Zhang <cherryyz@google.com>
Tue, 28 Aug 2018 19:23:26 +0000 (19:23 +0000)
Duplicated anonymous interfaces caused nondeterministic build.
The fix is CL 129515. This CL adds a test.

Updates #27013.

Change-Id: I6b7e1bbfc943c22e8e6f32c145f7aebb567cef15
Reviewed-on: https://go-review.googlesource.com/129680
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/cmd/compile/internal/gc/reproduciblebuilds_test.go
src/cmd/compile/internal/gc/testdata/reproducible/issue27013.go [new file with mode: 0644]

index b5f318e7618f6f303d8f79d05d6af6d2d2e596b5..9173f80ee313322ca0b405d31cbba4395344caff 100644 (file)
@@ -15,34 +15,45 @@ import (
 )
 
 func TestReproducibleBuilds(t *testing.T) {
+       tests := []string{
+               "issue20272.go",
+               "issue27013.go",
+       }
+
        testenv.MustHaveGoBuild(t)
        iters := 10
        if testing.Short() {
                iters = 4
        }
        t.Parallel()
-       var want []byte
-       tmp, err := ioutil.TempFile("", "")
-       if err != nil {
-               t.Fatalf("temp file creation failed: %v", err)
-       }
-       defer os.Remove(tmp.Name())
-       defer tmp.Close()
-       for i := 0; i < iters; i++ {
-               out, err := exec.Command(testenv.GoToolPath(t), "tool", "compile", "-o", tmp.Name(), filepath.Join("testdata", "reproducible", "issue20272.go")).CombinedOutput()
-               if err != nil {
-                       t.Fatalf("failed to compile: %v\n%s", err, out)
-               }
-               obj, err := ioutil.ReadFile(tmp.Name())
-               if err != nil {
-                       t.Fatalf("failed to read object file: %v", err)
-               }
-               if i == 0 {
-                       want = obj
-               } else {
-                       if !bytes.Equal(want, obj) {
-                               t.Fatalf("builds produced different output after %d iters (%d bytes vs %d bytes)", i, len(want), len(obj))
+       for _, test := range tests {
+               test := test
+               t.Run(test, func(t *testing.T) {
+                       t.Parallel()
+                       var want []byte
+                       tmp, err := ioutil.TempFile("", "")
+                       if err != nil {
+                               t.Fatalf("temp file creation failed: %v", err)
+                       }
+                       defer os.Remove(tmp.Name())
+                       defer tmp.Close()
+                       for i := 0; i < iters; i++ {
+                               out, err := exec.Command(testenv.GoToolPath(t), "tool", "compile", "-o", tmp.Name(), filepath.Join("testdata", "reproducible", test)).CombinedOutput()
+                               if err != nil {
+                                       t.Fatalf("failed to compile: %v\n%s", err, out)
+                               }
+                               obj, err := ioutil.ReadFile(tmp.Name())
+                               if err != nil {
+                                       t.Fatalf("failed to read object file: %v", err)
+                               }
+                               if i == 0 {
+                                       want = obj
+                               } else {
+                                       if !bytes.Equal(want, obj) {
+                                               t.Fatalf("builds produced different output after %d iters (%d bytes vs %d bytes)", i, len(want), len(obj))
+                                       }
+                               }
                        }
-               }
+               })
        }
 }
diff --git a/src/cmd/compile/internal/gc/testdata/reproducible/issue27013.go b/src/cmd/compile/internal/gc/testdata/reproducible/issue27013.go
new file mode 100644 (file)
index 0000000..817f4a6
--- /dev/null
@@ -0,0 +1,15 @@
+// Copyright 2018 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 p
+
+func A(arg interface{}) {
+       _ = arg.(interface{ Func() int32 })
+       _ = arg.(interface{ Func() int32 })
+       _ = arg.(interface{ Func() int32 })
+       _ = arg.(interface{ Func() int32 })
+       _ = arg.(interface{ Func() int32 })
+       _ = arg.(interface{ Func() int32 })
+       _ = arg.(interface{ Func() int32 })
+}