re PR target/61662 (Incorrect value calculated for _lrotl on LLP64 systems)
[official-gcc.git] / libgo / go / runtime / runtime_test.go
blob1702298aed1a40c757bb71b5ad334965830b4e74
1 // Copyright 2012 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 package runtime_test
7 import (
8 "io"
9 // "io/ioutil"
10 // "os"
11 // "os/exec"
12 // . "runtime"
13 // "strconv"
14 // "strings"
15 "testing"
18 var errf error
20 func errfn() error {
21 return errf
24 func errfn1() error {
25 return io.EOF
28 func BenchmarkIfaceCmp100(b *testing.B) {
29 for i := 0; i < b.N; i++ {
30 for j := 0; j < 100; j++ {
31 if errfn() == io.EOF {
32 b.Fatal("bad comparison")
38 func BenchmarkIfaceCmpNil100(b *testing.B) {
39 for i := 0; i < b.N; i++ {
40 for j := 0; j < 100; j++ {
41 if errfn1() == nil {
42 b.Fatal("bad comparison")
48 func BenchmarkDefer(b *testing.B) {
49 for i := 0; i < b.N; i++ {
50 defer1()
54 func defer1() {
55 defer func(x, y, z int) {
56 if recover() != nil || x != 1 || y != 2 || z != 3 {
57 panic("bad recover")
59 }(1, 2, 3)
60 return
63 func BenchmarkDefer10(b *testing.B) {
64 for i := 0; i < b.N/10; i++ {
65 defer2()
69 func defer2() {
70 for i := 0; i < 10; i++ {
71 defer func(x, y, z int) {
72 if recover() != nil || x != 1 || y != 2 || z != 3 {
73 panic("bad recover")
75 }(1, 2, 3)
79 func BenchmarkDeferMany(b *testing.B) {
80 for i := 0; i < b.N; i++ {
81 defer func(x, y, z int) {
82 if recover() != nil || x != 1 || y != 2 || z != 3 {
83 panic("bad recover")
85 }(1, 2, 3)
89 /* The go tool is not present in gccgo.
91 // The profiling signal handler needs to know whether it is executing runtime.gogo.
92 // The constant RuntimeGogoBytes in arch_*.h gives the size of the function;
93 // we don't have a way to obtain it from the linker (perhaps someday).
94 // Test that the constant matches the size determined by 'go tool nm -S'.
95 // The value reported will include the padding between runtime.gogo and the
96 // next function in memory. That's fine.
97 func TestRuntimeGogoBytes(t *testing.T) {
98 // TODO(brainman): delete when issue 6973 is fixed.
99 if GOOS == "windows" {
100 t.Skip("skipping broken test on windows")
102 dir, err := ioutil.TempDir("", "go-build")
103 if err != nil {
104 t.Fatalf("failed to create temp directory: %v", err)
106 defer os.RemoveAll(dir)
108 out, err := exec.Command("go", "build", "-o", dir+"/hello", "../../../test/helloworld.go").CombinedOutput()
109 if err != nil {
110 t.Fatalf("building hello world: %v\n%s", err, out)
113 out, err = exec.Command("go", "tool", "nm", "-size", dir+"/hello").CombinedOutput()
114 if err != nil {
115 t.Fatalf("go tool nm: %v\n%s", err, out)
118 for _, line := range strings.Split(string(out), "\n") {
119 f := strings.Fields(line)
120 if len(f) == 4 && f[3] == "runtime.gogo" {
121 size, _ := strconv.Atoi(f[1])
122 if GogoBytes() != int32(size) {
123 t.Fatalf("RuntimeGogoBytes = %d, should be %d", GogoBytes(), size)
125 return
129 t.Fatalf("go tool nm did not report size for runtime.gogo")
133 // golang.org/issue/7063
134 func TestStopCPUProfilingWithProfilerOff(t *testing.T) {
135 SetCPUProfileRate(0)