]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: make TestAssembly resilient to output ordering
authorJosh Bleecher Snyder <josharian@gmail.com>
Thu, 6 Apr 2017 22:30:53 +0000 (15:30 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Thu, 13 Apr 2017 02:30:29 +0000 (02:30 +0000)
To preserve reproducible builds, the text entries
during compilation will be sorted before being printed.
TestAssembly currently assumes that function init
comes after all user-defined functions.
Remove that assumption.
Instead of looking for "TEXT" to tell you where
a function ends--which may now yield lots of
non-function-code junk--look for a line beginning
with non-whitespace.

Updates #15756

Change-Id: Ibc82dba6143d769ef4c391afc360e523b1a51348
Reviewed-on: https://go-review.googlesource.com/39853
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/gc/asm_test.go

index b340d079420def524c080b24cf9f900c78bbff61..a36287865bcf8d6e45fedf1414c7010792b85785 100644 (file)
@@ -42,23 +42,32 @@ func TestAssembly(t *testing.T) {
                                asm := ats.compileToAsm(tt, dir)
 
                                for _, at := range ats.tests {
-                                       funcName := nameRegexp.FindString(at.function)[5:]
-                                       fa := funcAsm(asm, funcName)
-                                       at.verifyAsm(tt, fa)
+                                       funcName := nameRegexp.FindString(at.function)[len("func "):]
+                                       fa := funcAsm(tt, asm, funcName)
+                                       if fa != "" {
+                                               at.verifyAsm(tt, fa)
+                                       }
                                }
                        })
                }
        })
 }
 
+var nextTextRegexp = regexp.MustCompile(`\n\S`)
+
 // funcAsm returns the assembly listing for the given function name.
-func funcAsm(asm string, funcName string) string {
+func funcAsm(t *testing.T, asm string, funcName string) string {
        if i := strings.Index(asm, fmt.Sprintf("TEXT\t\"\".%s(SB)", funcName)); i >= 0 {
                asm = asm[i:]
+       } else {
+               t.Errorf("could not find assembly for function %v", funcName)
+               return ""
        }
 
-       if i := strings.Index(asm[1:], "TEXT\t\"\"."); i >= 0 {
-               asm = asm[:i+1]
+       // Find the next line that doesn't begin with whitespace.
+       loc := nextTextRegexp.FindStringIndex(asm)
+       if loc != nil {
+               asm = asm[:loc[0]]
        }
 
        return asm
@@ -130,12 +139,6 @@ func (ats *asmTests) compileToAsm(t *testing.T, dir string) string {
 
        // Now, compile the individual file for which we want to see the generated assembly.
        asm := ats.runGo(t, "tool", "compile", "-I", testDir, "-S", "-o", filepath.Join(testDir, "out.o"), src)
-
-       // Get rid of code for "".init. Also gets rid of type algorithms & other junk.
-       if i := strings.Index(asm, "\n\"\".init "); i >= 0 {
-               asm = asm[:i+1]
-       }
-
        return asm
 }