1
0
mirror of https://github.com/golang/go synced 2024-11-18 14:54:40 -07:00

go.tools/ssa/interp: add several standard library packages to test suite.

- Add math.{Log,Ldexp} to externals
- Test now uses FromArgs
- Scan all initial packages for tests, don't assume Created[0] exists.
  (It doesn't if we import a package that has only in-package tests.)

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/62010044
This commit is contained in:
Alan Donovan 2014-02-11 20:35:18 -05:00
parent b2557286bb
commit d10dca34ca
3 changed files with 48 additions and 18 deletions

View File

@ -74,6 +74,8 @@ func init() {
"math.Float32frombits": ext۰math۰Float32frombits,
"math.Float64bits": ext۰math۰Float64bits,
"math.Float64frombits": ext۰math۰Float64frombits,
"math.Ldexp": ext۰math۰Ldexp,
"math.Log": ext۰math۰Log,
"math.Min": ext۰math۰Min,
"reflect.New": ext۰reflect۰New,
"reflect.TypeOf": ext۰reflect۰TypeOf,
@ -199,6 +201,14 @@ func ext۰math۰Min(fr *frame, args []value) value {
return math.Min(args[0].(float64), args[1].(float64))
}
func ext۰math۰Ldexp(fr *frame, args []value) value {
return math.Ldexp(args[0].(float64), args[1].(int))
}
func ext۰math۰Log(fr *frame, args []value) value {
return math.Log(args[0].(float64))
}
func ext۰runtime۰Breakpoint(fr *frame, args []value) value {
runtime.Breakpoint()
return nil

View File

@ -146,15 +146,26 @@ var testdataTests = []string{
"callstack.go",
}
// These are files in $GOROOT/src/pkg/.
// These tests exercise the "testing" package.
// These are files and packages in $GOROOT/src/pkg/.
var gorootSrcPkgTests = []string{
"unicode/script_test.go",
"unicode/digit_test.go",
"hash/crc32/crc32.go hash/crc32/crc32_generic.go hash/crc32/crc32_test.go",
"path/path.go path/path_test.go",
// TODO(adonovan): figure out the package loading error here:
// "strings.go strings/search.go strings/search_test.go",
"encoding/ascii85",
"encoding/csv",
"encoding/hex",
"encoding/pem",
"hash/crc32",
"testing",
"text/scanner",
"unicode",
// Too slow:
// "container/ring",
// "hash/adler32",
// TODO(adonovan): packages with Examples require os.Pipe (unimplemented):
// "unicode/utf8",
// "log",
// "path",
// "flag",
}
type successPredicate func(exitcode int, output string) error
@ -166,14 +177,15 @@ func run(t *testing.T, dir, input string, success successPredicate) bool {
var inputs []string
for _, i := range strings.Split(input, " ") {
inputs = append(inputs, dir+i)
if strings.HasSuffix(i, ".go") {
i = dir + i
}
inputs = append(inputs, i)
}
conf := loader.Config{SourceImports: true}
// TODO(adonovan): add the following packages' tests, which pass:
// "flag", "unicode", "unicode/utf8", "testing", "log", "path".
if err := conf.CreateFromFilenames("", inputs...); err != nil {
t.Errorf("CreateFromFilenames(%s) failed: %s", inputs, err)
if _, err := conf.FromArgs(inputs, true); err != nil {
t.Errorf("FromArgs(%s) failed: %s", inputs, err)
return false
}
@ -203,9 +215,17 @@ func run(t *testing.T, dir, input string, success successPredicate) bool {
prog := ssa.Create(iprog, ssa.SanityCheckFunctions)
prog.BuildAll()
mainPkg := prog.Package(iprog.Created[0].Pkg)
if mainPkg.Func("main") == nil {
testmainPkg := prog.CreateTestMainPackage(mainPkg)
var mainPkg *ssa.Package
var initialPkgs []*ssa.Package
for _, info := range iprog.InitialPackages() {
p := prog.Package(info.Pkg)
initialPkgs = append(initialPkgs, p)
if mainPkg == nil && p.Func("main") != nil {
mainPkg = p
}
}
if mainPkg == nil {
testmainPkg := prog.CreateTestMainPackage(initialPkgs...)
if testmainPkg == nil {
t.Errorf("CreateTestMainPackage(%s) returned nil", mainPkg)
return false

View File

@ -81,7 +81,7 @@ func ext۰reflect۰rtype۰Bits(fr *frame, args []value) value {
if !ok {
panic(fmt.Sprintf("reflect.Type.Bits(%T): non-basic type", rt))
}
return fr.i.sizes.Sizeof(basic) * 8
return int(fr.i.sizes.Sizeof(basic)) * 8
}
func ext۰reflect۰rtype۰Elem(fr *frame, args []value) value {
@ -135,7 +135,7 @@ func ext۰reflect۰rtype۰Out(fr *frame, args []value) value {
func ext۰reflect۰rtype۰Size(fr *frame, args []value) value {
// Signature: func (t reflect.rtype) uintptr
return uint64(fr.i.sizes.Sizeof(args[0].(rtype).t))
return uintptr(fr.i.sizes.Sizeof(args[0].(rtype).t))
}
func ext۰reflect۰rtype۰String(fr *frame, args []value) value {