diff --git a/src/pkg/runtime/export_test.go b/src/pkg/runtime/export_test.go --- a/src/pkg/runtime/export_test.go +++ b/src/pkg/runtime/export_test.go @@ -68,12 +68,14 @@ var TestSchedLocalQueue1 = testSchedLocalQueue var TestSchedLocalQueueSteal1 = testSchedLocalQueueSteal +func analizeStack(t uintptr, fn func(uintptr)) func haveGoodHash() bool func stringHash(s string, seed uintptr) uintptr func bytesHash(b []byte, seed uintptr) uintptr func int32Hash(i uint32, seed uintptr) uintptr func int64Hash(i uint64, seed uintptr) uintptr +var AnalizeStack = analizeStack var HaveGoodHash = haveGoodHash var StringHash = stringHash var BytesHash = bytesHash diff --git a/src/pkg/runtime/goroot_test.c b/src/pkg/runtime/goroot_test.c new file mode 100644 --- /dev/null +++ b/src/pkg/runtime/goroot_test.c @@ -0,0 +1,14 @@ +// Copyright 2013 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. + +#include "runtime.h" +#include "arch_GOARCH.h" + +// For testing from Go +// func analizeStack(uintptr t, fn func(uintptr)) +void +runtime·analizeStack(uintptr t, void *fn) +{ + (*(void(**)(uintptr))fn)(t); +} diff --git a/src/pkg/runtime/goroot_test.go b/src/pkg/runtime/goroot_test.go new file mode 100644 --- /dev/null +++ b/src/pkg/runtime/goroot_test.go @@ -0,0 +1,81 @@ +// Copyright 2013 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 runtime_test + +import ( + "flag" + "os" + "os/exec" + "path/filepath" + "runtime" + "strings" + "testing" + "unsafe" +) + +var sympathprefix = flag.String("sympathprefix", "", "param for TestSymPathPrefix") + +// TODO: only checks .go and .c files (need also verify .s files) +func testSymPathPrefix(p uintptr) { + t := (*testing.T)(unsafe.Pointer(p)) + todir := func(pkg string) string { + d := filepath.Join(*sympathprefix, "src", "pkg", pkg) + return filepath.ToSlash(d) + } + rdir := todir("runtime") + tdir := todir("testing") + for i := 0; ; i++ { + _, file, _, ok := runtime.Caller(i) + if !ok { + break + } + switch filepath.ToSlash(filepath.Dir(file)) { + case rdir, tdir: + continue + } + t.Errorf("wrong dir in %v (%v or %v expected)", file, rdir, tdir) + } +} + +func TestSymPathPrefix(t *testing.T) { + runtime.AnalizeStack(uintptr(unsafe.Pointer(t)), testSymPathPrefix) +} + +func setEnv(env []string, name, value string) []string { + for i, e := range env { + if strings.HasPrefix(e, name+"=") { + env[i] = name + "=" + value + return env + } + } + return append(env, name+"="+value) +} + +func testALEX(t *testing.T, sympathprefix string, env []string) { + obj := filepath.Join(runtime.GOROOT(), "pkg", runtime.GOOS+"_"+runtime.GOARCH, "runtime.a") + os.Remove(obj) + cmd := exec.Command("go", "install", "runtime") + cmd.Env = env + out, err := cmd.CombinedOutput() + if err != nil { + t.Fatalf("go install failed: err=%v output=%s", err, out) + } + defer os.Remove(obj) + cmd = exec.Command("go", "test", "-v", "-sympathprefix="+sympathprefix, "-run=TestSymPathPrefix", "runtime") + cmd.Env = env + out, err = cmd.CombinedOutput() + if err != nil { + t.Fatalf("go test failed: err=%v output=%s", err, out) + } +} + +func TestALEX(t *testing.T) { + final := "/final" + if runtime.GOOS == "windows" { + final = `c:\final` + } + testALEX(t, final, setEnv(os.Environ(), "GOROOT_FINAL", final)) + testALEX(t, runtime.GOROOT(), os.Environ()) +}