]> Cypherpunks.ru repositories - gostls13.git/blobdiff - test/copy.go
cmd/compile/internal/inline: score call sites exposed by inlines
[gostls13.git] / test / copy.go
index 037d3f41fe623d6e95a800e71209cbd2029cc50e..e6108d905d199b62398eedf0f29ab5fd004eccc8 100644 (file)
@@ -1,10 +1,10 @@
-// $G $F.go && $L $F.$A && ./$A.out
+// run
 
 // Copyright 2009 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.
 
-// Semi-exhaustive test for copy()
+// Semi-exhaustive test for the copy predeclared function.
 
 package main
 
@@ -23,6 +23,15 @@ var input32 = make([]uint32, N)
 var output32 = make([]uint32, N)
 var input64 = make([]uint64, N)
 var output64 = make([]uint64, N)
+var inputS string
+var outputS = make([]uint8, N)
+
+type my8 []uint8
+type my16 []uint16
+type my32 []uint32
+type my32b []uint32
+type my64 []uint64
+type myS string
 
 func u8(i int) uint8 {
        i = 'a' + i%26
@@ -64,6 +73,7 @@ func reset() {
        for i := range input8 {
                input8[i] = u8(in)
                output8[i] = u8(out)
+               outputS[i] = u8(out)
                input16[i] = u16(in)
                output16[i] = u16(out)
                input32[i] = u32(in)
@@ -73,6 +83,7 @@ func reset() {
                in++
                out++
        }
+       inputS = string(input8)
 }
 
 func clamp(n int) int {
@@ -95,13 +106,15 @@ func ncopied(length, in, out int) int {
 
 func doAllSlices(length, in, out int) {
        reset()
-       n := copy(output8[out:clamp(out+length)], input8[in:clamp(in+length)])
+       n := copy(my8(output8[out:clamp(out+length)]), input8[in:clamp(in+length)])
        verify8(length, in, out, n)
-       n = copy(output16[out:clamp(out+length)], input16[in:clamp(in+length)])
+       n = copy(my8(outputS[out:clamp(out+length)]), myS(inputS[in:clamp(in+length)]))
+       verifyS(length, in, out, n)
+       n = copy(my16(output16[out:clamp(out+length)]), input16[in:clamp(in+length)])
        verify16(length, in, out, n)
-       n = copy(output32[out:clamp(out+length)], input32[in:clamp(in+length)])
+       n = copy(my32(output32[out:clamp(out+length)]), my32b(input32[in:clamp(in+length)]))
        verify32(length, in, out, n)
-       n = copy(output64[out:clamp(out+length)], input64[in:clamp(in+length)])
+       n = copy(my64(output64[out:clamp(out+length)]), input64[in:clamp(in+length)])
        verify64(length, in, out, n)
 }
 
@@ -119,6 +132,7 @@ func verify8(length, in, out, m int) {
        n := ncopied(length, in, out)
        if m != n {
                fmt.Printf("count bad(%d %d %d): %d not %d\n", length, in, out, m, n)
+               os.Exit(1)
                return
        }
        // before
@@ -145,6 +159,47 @@ func verify8(length, in, out, m int) {
        }
 }
 
+func badS(state string, i, length, in, out int) {
+       fmt.Printf("%s bad(%d %d %d): %c not %c:\n\t%s\n\t%s\n",
+               state,
+               length, in, out,
+               outputS[i],
+               uint8(i+13),
+               inputS, outputS)
+       os.Exit(1)
+}
+
+func verifyS(length, in, out, m int) {
+       n := ncopied(length, in, out)
+       if m != n {
+               fmt.Printf("count bad(%d %d %d): %d not %d\n", length, in, out, m, n)
+               os.Exit(1)
+               return
+       }
+       // before
+       var i int
+       for i = 0; i < out; i++ {
+               if outputS[i] != u8(i+13) {
+                       badS("beforeS", i, length, in, out)
+                       return
+               }
+       }
+       // copied part
+       for ; i < out+n; i++ {
+               if outputS[i] != u8(i+in-out) {
+                       badS("copiedS", i, length, in, out)
+                       return
+               }
+       }
+       // after
+       for ; i < len(outputS); i++ {
+               if outputS[i] != u8(i+13) {
+                       badS("afterS", i, length, in, out)
+                       return
+               }
+       }
+}
+
 func bad16(state string, i, length, in, out int) {
        fmt.Printf("%s bad(%d %d %d): %x not %x:\n\t%v\n\t%v\n",
                state,
@@ -159,6 +214,7 @@ func verify16(length, in, out, m int) {
        n := ncopied(length, in, out)
        if m != n {
                fmt.Printf("count bad(%d %d %d): %d not %d\n", length, in, out, m, n)
+               os.Exit(1)
                return
        }
        // before
@@ -199,6 +255,7 @@ func verify32(length, in, out, m int) {
        n := ncopied(length, in, out)
        if m != n {
                fmt.Printf("count bad(%d %d %d): %d not %d\n", length, in, out, m, n)
+               os.Exit(1)
                return
        }
        // before
@@ -239,6 +296,7 @@ func verify64(length, in, out, m int) {
        n := ncopied(length, in, out)
        if m != n {
                fmt.Printf("count bad(%d %d %d): %d not %d\n", length, in, out, m, n)
+               os.Exit(1)
                return
        }
        // before