Browse Source

transform: move tests to transform_test package

This allows for adding more advanced tests, for example tests that use
the compiler package so that test sources can be written in Go instead
of LLVM IR.
pull/1833/head
Ayke van Laethem 4 years ago
committed by Ron Evans
parent
commit
404b65941a
  1. 6
      transform/allocs_test.go
  2. 6
      transform/func-lowering_test.go
  3. 7
      transform/gc_test.go
  4. 5
      transform/globals_test.go
  5. 6
      transform/goroutine_test.go
  6. 5
      transform/interface-lowering_test.go
  7. 5
      transform/interrupt_test.go
  8. 5
      transform/maps_test.go
  9. 6
      transform/panic_test.go
  10. 9
      transform/rtcalls_test.go
  11. 5
      transform/stacksize_test.go
  12. 2
      transform/transform_test.go
  13. 5
      transform/wasm-abi_test.go

6
transform/allocs_test.go

@ -1,10 +1,12 @@
package transform package transform_test
import ( import (
"testing" "testing"
"github.com/tinygo-org/tinygo/transform"
) )
func TestAllocs(t *testing.T) { func TestAllocs(t *testing.T) {
t.Parallel() t.Parallel()
testTransform(t, "testdata/allocs", OptimizeAllocs) testTransform(t, "testdata/allocs", transform.OptimizeAllocs)
} }

6
transform/func-lowering_test.go

@ -1,10 +1,12 @@
package transform package transform_test
import ( import (
"testing" "testing"
"github.com/tinygo-org/tinygo/transform"
) )
func TestFuncLowering(t *testing.T) { func TestFuncLowering(t *testing.T) {
t.Parallel() t.Parallel()
testTransform(t, "testdata/func-lowering", LowerFuncValues) testTransform(t, "testdata/func-lowering", transform.LowerFuncValues)
} }

7
transform/gc_test.go

@ -1,21 +1,22 @@
package transform package transform_test
import ( import (
"testing" "testing"
"github.com/tinygo-org/tinygo/transform"
"tinygo.org/x/go-llvm" "tinygo.org/x/go-llvm"
) )
func TestAddGlobalsBitmap(t *testing.T) { func TestAddGlobalsBitmap(t *testing.T) {
t.Parallel() t.Parallel()
testTransform(t, "testdata/gc-globals", func(mod llvm.Module) { testTransform(t, "testdata/gc-globals", func(mod llvm.Module) {
AddGlobalsBitmap(mod) transform.AddGlobalsBitmap(mod)
}) })
} }
func TestMakeGCStackSlots(t *testing.T) { func TestMakeGCStackSlots(t *testing.T) {
t.Parallel() t.Parallel()
testTransform(t, "testdata/gc-stackslots", func(mod llvm.Module) { testTransform(t, "testdata/gc-stackslots", func(mod llvm.Module) {
MakeGCStackSlots(mod) transform.MakeGCStackSlots(mod)
}) })
} }

5
transform/globals_test.go

@ -1,14 +1,15 @@
package transform package transform_test
import ( import (
"testing" "testing"
"github.com/tinygo-org/tinygo/transform"
"tinygo.org/x/go-llvm" "tinygo.org/x/go-llvm"
) )
func TestApplyFunctionSections(t *testing.T) { func TestApplyFunctionSections(t *testing.T) {
t.Parallel() t.Parallel()
testTransform(t, "testdata/globals-function-sections", func(mod llvm.Module) { testTransform(t, "testdata/globals-function-sections", func(mod llvm.Module) {
ApplyFunctionSections(mod) transform.ApplyFunctionSections(mod)
}) })
} }

6
transform/goroutine_test.go

@ -1,14 +1,16 @@
package transform package transform_test
import ( import (
"testing" "testing"
"github.com/tinygo-org/tinygo/transform"
"tinygo.org/x/go-llvm" "tinygo.org/x/go-llvm"
) )
func TestGoroutineLowering(t *testing.T) { func TestGoroutineLowering(t *testing.T) {
t.Parallel() t.Parallel()
testTransform(t, "testdata/coroutines", func(mod llvm.Module) { testTransform(t, "testdata/coroutines", func(mod llvm.Module) {
err := LowerCoroutines(mod, false) err := transform.LowerCoroutines(mod, false)
if err != nil { if err != nil {
panic(err) panic(err)
} }

5
transform/interface-lowering_test.go

@ -1,15 +1,16 @@
package transform package transform_test
import ( import (
"testing" "testing"
"github.com/tinygo-org/tinygo/transform"
"tinygo.org/x/go-llvm" "tinygo.org/x/go-llvm"
) )
func TestInterfaceLowering(t *testing.T) { func TestInterfaceLowering(t *testing.T) {
t.Parallel() t.Parallel()
testTransform(t, "testdata/interface", func(mod llvm.Module) { testTransform(t, "testdata/interface", func(mod llvm.Module) {
err := LowerInterfaces(mod, 0) err := transform.LowerInterfaces(mod, 0)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }

5
transform/interrupt_test.go

@ -1,8 +1,9 @@
package transform package transform_test
import ( import (
"testing" "testing"
"github.com/tinygo-org/tinygo/transform"
"tinygo.org/x/go-llvm" "tinygo.org/x/go-llvm"
) )
@ -11,7 +12,7 @@ func TestInterruptLowering(t *testing.T) {
for _, subtest := range []string{"avr", "cortexm"} { for _, subtest := range []string{"avr", "cortexm"} {
t.Run(subtest, func(t *testing.T) { t.Run(subtest, func(t *testing.T) {
testTransform(t, "testdata/interrupt-"+subtest, func(mod llvm.Module) { testTransform(t, "testdata/interrupt-"+subtest, func(mod llvm.Module) {
errs := LowerInterrupts(mod, 0) errs := transform.LowerInterrupts(mod, 0)
if len(errs) != 0 { if len(errs) != 0 {
t.Fail() t.Fail()
for _, err := range errs { for _, err := range errs {

5
transform/maps_test.go

@ -1,8 +1,9 @@
package transform package transform_test
import ( import (
"testing" "testing"
"github.com/tinygo-org/tinygo/transform"
"tinygo.org/x/go-llvm" "tinygo.org/x/go-llvm"
) )
@ -10,7 +11,7 @@ func TestOptimizeMaps(t *testing.T) {
t.Parallel() t.Parallel()
testTransform(t, "testdata/maps", func(mod llvm.Module) { testTransform(t, "testdata/maps", func(mod llvm.Module) {
// Run optimization pass. // Run optimization pass.
OptimizeMaps(mod) transform.OptimizeMaps(mod)
// Run an optimization pass, to clean up the result. // Run an optimization pass, to clean up the result.
// This shows that all code related to the map is really eliminated. // This shows that all code related to the map is really eliminated.

6
transform/panic_test.go

@ -1,10 +1,12 @@
package transform package transform_test
import ( import (
"testing" "testing"
"github.com/tinygo-org/tinygo/transform"
) )
func TestReplacePanicsWithTrap(t *testing.T) { func TestReplacePanicsWithTrap(t *testing.T) {
t.Parallel() t.Parallel()
testTransform(t, "testdata/panic", ReplacePanicsWithTrap) testTransform(t, "testdata/panic", transform.ReplacePanicsWithTrap)
} }

9
transform/rtcalls_test.go

@ -1,8 +1,9 @@
package transform package transform_test
import ( import (
"testing" "testing"
"github.com/tinygo-org/tinygo/transform"
"tinygo.org/x/go-llvm" "tinygo.org/x/go-llvm"
) )
@ -10,7 +11,7 @@ func TestOptimizeStringToBytes(t *testing.T) {
t.Parallel() t.Parallel()
testTransform(t, "testdata/stringtobytes", func(mod llvm.Module) { testTransform(t, "testdata/stringtobytes", func(mod llvm.Module) {
// Run optimization pass. // Run optimization pass.
OptimizeStringToBytes(mod) transform.OptimizeStringToBytes(mod)
}) })
} }
@ -18,7 +19,7 @@ func TestOptimizeStringEqual(t *testing.T) {
t.Parallel() t.Parallel()
testTransform(t, "testdata/stringequal", func(mod llvm.Module) { testTransform(t, "testdata/stringequal", func(mod llvm.Module) {
// Run optimization pass. // Run optimization pass.
OptimizeStringEqual(mod) transform.OptimizeStringEqual(mod)
}) })
} }
@ -26,6 +27,6 @@ func TestOptimizeReflectImplements(t *testing.T) {
t.Parallel() t.Parallel()
testTransform(t, "testdata/reflect-implements", func(mod llvm.Module) { testTransform(t, "testdata/reflect-implements", func(mod llvm.Module) {
// Run optimization pass. // Run optimization pass.
OptimizeReflectImplements(mod) transform.OptimizeReflectImplements(mod)
}) })
} }

5
transform/stacksize_test.go

@ -1,9 +1,10 @@
package transform package transform_test
import ( import (
"testing" "testing"
"github.com/tinygo-org/tinygo/compileopts" "github.com/tinygo-org/tinygo/compileopts"
"github.com/tinygo-org/tinygo/transform"
"tinygo.org/x/go-llvm" "tinygo.org/x/go-llvm"
) )
@ -11,7 +12,7 @@ func TestCreateStackSizeLoads(t *testing.T) {
t.Parallel() t.Parallel()
testTransform(t, "testdata/stacksize", func(mod llvm.Module) { testTransform(t, "testdata/stacksize", func(mod llvm.Module) {
// Run optimization pass. // Run optimization pass.
CreateStackSizeLoads(mod, &compileopts.Config{ transform.CreateStackSizeLoads(mod, &compileopts.Config{
Target: &compileopts.TargetSpec{ Target: &compileopts.TargetSpec{
DefaultStackSize: 1024, DefaultStackSize: 1024,
}, },

2
transform/transform_test.go

@ -1,4 +1,4 @@
package transform package transform_test
// This file defines some helper functions for testing transforms. // This file defines some helper functions for testing transforms.

5
transform/wasm-abi_test.go

@ -1,8 +1,9 @@
package transform package transform_test
import ( import (
"testing" "testing"
"github.com/tinygo-org/tinygo/transform"
"tinygo.org/x/go-llvm" "tinygo.org/x/go-llvm"
) )
@ -10,7 +11,7 @@ func TestWasmABI(t *testing.T) {
t.Parallel() t.Parallel()
testTransform(t, "testdata/wasm-abi", func(mod llvm.Module) { testTransform(t, "testdata/wasm-abi", func(mod llvm.Module) {
// Run ABI change pass. // Run ABI change pass.
err := ExternalInt64AsPtr(mod) err := transform.ExternalInt64AsPtr(mod)
if err != nil { if err != nil {
t.Errorf("failed to change wasm ABI: %v", err) t.Errorf("failed to change wasm ABI: %v", err)
} }

Loading…
Cancel
Save