Skip to content

Commit

Permalink
Cleanup (#64)
Browse files Browse the repository at this point in the history
* chore: new coverage generation

* fix: remove old files because tests were registered twice

* chore: fix some tests and test the tests

* wip: temporary comment this test

* chore: coverage

* feat: only cover the main package
  • Loading branch information
owulveryck authored May 22, 2019
1 parent 7f952f6 commit c917fc1
Show file tree
Hide file tree
Showing 577 changed files with 11,488 additions and 994 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ before_install:

script:
- go test ./...
- $GOPATH/bin/goveralls -service=travis-ci
- $GOPATH/bin/goveralls -service=travis-ci -package github.com/owulveryck/onnx-go
37 changes: 33 additions & 4 deletions backend/testbackend/onnx/gen_cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,19 @@ func processFile(file os.FileInfo) (string, string, error) {
if err != nil {
return "", "", err
}
data := fmt.Sprintf("%#v", t.Data())
shape := fmt.Sprintf("%#v", t.Shape())
if len(t.Shape()) == 1 && t.Shape()[0] == 1 {
data = fmt.Sprintf("[]float32{%v}", t.Data())
}
if len(t.Shape()) == 0 {
data = fmt.Sprintf("[]float32{%v}", t.Data())
shape = "(1)"
}
tv.Input[i] = iO{
Shape: fmt.Sprintf("%#v", t.Shape()),
Data: fmt.Sprintf("%#v", t.Data()),
Shape: shape,
//Data: fmt.Sprintf("%#v", t.Data()),
Data: data,
}
}
mv.Output = make([]valueInfoProto, len(model.Graph.Output))
Expand Down Expand Up @@ -174,9 +184,18 @@ func processFile(file os.FileInfo) (string, string, error) {
if err != nil {
return "", "", err
}
shape := fmt.Sprintf("%#v", t.Shape())
data := fmt.Sprintf("%#v", t.Data())
if len(t.Shape()) == 1 && t.Shape()[0] == 1 {
data = fmt.Sprintf("[]float32{%v}", t.Data())
}
if len(t.Shape()) == 0 {
data = fmt.Sprintf("[]float32{%v}", t.Data())
shape = "(1)"
}
tv.ExpectedOutput[i] = iO{
Shape: fmt.Sprintf("%#v", t.Shape()),
Data: fmt.Sprintf("%#v", t.Data()),
Shape: shape,
Data: data,
}
}
mv.ValueInfo = make([]valueInfoProto, len(model.Graph.ValueInfo))
Expand All @@ -194,18 +213,28 @@ func processFile(file os.FileInfo) (string, string, error) {

// TestTemplate
output := os.Stdout
outputTest := os.Stdout
if *outputdir != "" {
output, err = os.Create(filepath.Join(*outputdir, "onnx_"+file.Name()+".go"))
if err != nil {
return "", "", err
}
defer output.Close()
outputTest, err = os.Create(filepath.Join(*outputdir, "onnx_"+file.Name()+"_test.go"))
if err != nil {
return "", "", err
}
defer outputTest.Close()
}
tv.ModelValue = mv
err = processTemplate(testTemplate, tv, output)
if err != nil {
return "", "", err
}
err = processTemplate(testTestTemplate, tv, outputTest)
if err != nil {
return "", "", err
}
/*
err = processTemplate(modelTemplate, mv, output)
if err != nil {
Expand Down
45 changes: 30 additions & 15 deletions backend/testbackend/onnx/gen_cmd/test_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ package main
import "text/template"

var testTemplate = template.Must(template.New("testCase").Parse(testTmpl))
var testCasesTemplate = template.Must(template.New("testCase").Parse(testCasesTmpl))

//var modelTemplate = template.Must(template.New("modelCase").Parse(modelTmpl))
var testTestTemplate = template.Must(template.New("testTestCase").Parse(testTestTmpl))

type testValue struct {
OpType string
Expand Down Expand Up @@ -58,6 +56,35 @@ type attribute struct {
Strings string
}

const testTestTmpl = `
package onnxtest
import (
"testing"
"github.com/gogo/protobuf/proto"
"github.com/owulveryck/onnx-go/internal/pb-onnx"
)
func TestNew{{ .TestName }}(t *testing.T) {
mytest := New{{ .TestName }}()
var model pb.ModelProto
err := proto.Unmarshal(mytest.ModelB, &model)
if err != nil {
t.Fatal(err)
}
if model.Graph == nil {
t.Fatal("graph is nil")
}
if len(model.Graph.Input) != len(mytest.Input) {
t.Fatalf("invalid test: model has %v input, but test only provide %v", len(model.Graph.Input), len(mytest.Input))
}
if len(model.Graph.Output) != len(mytest.ExpectedOutput) {
t.Fatalf("invalid test: model has %v input, but test only provide %v", len(model.Graph.Output), len(mytest.ExpectedOutput))
}
}
`

//Model: {{ template "modelCase" .ModelValue }},

const testTmpl = `
Expand Down Expand Up @@ -251,15 +278,3 @@ type testCases struct {
Title string
Constructor string
}

const testCasesTmpl = `
package onnxtest
import "github.com/owulveryck/onnx-go/backend/testbackend"
func init() {
// Register all the test cases
{{ if . }} {{ range . }}
{{ if .OpType }} testbackend.Register({{ .OpType }},"{{ .Title }}",New{{ .Title }}) {{end}} {{ end }} {{end}}
}
`
331 changes: 0 additions & 331 deletions backend/testbackend/onnx/onnx_register_testcases.go

This file was deleted.

26 changes: 26 additions & 0 deletions backend/testbackend/onnx/onnx_test_abs_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package onnxtest

import (
"testing"

"github.com/gogo/protobuf/proto"
"github.com/owulveryck/onnx-go/internal/pb-onnx"
)

func TestNewTestAbs(t *testing.T) {
mytest := NewTestAbs()
var model pb.ModelProto
err := proto.Unmarshal(mytest.ModelB, &model)
if err != nil {
t.Fatal(err)
}
if model.Graph == nil {
t.Fatal("graph is nil")
}
if len(model.Graph.Input) != len(mytest.Input) {
t.Fatalf("invalid test: model has %v input, but test only provide %v", len(model.Graph.Input), len(mytest.Input))
}
if len(model.Graph.Output) != len(mytest.ExpectedOutput) {
t.Fatalf("invalid test: model has %v input, but test only provide %v", len(model.Graph.Output), len(mytest.ExpectedOutput))
}
}
26 changes: 26 additions & 0 deletions backend/testbackend/onnx/onnx_test_acos_example_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package onnxtest

import (
"testing"

"github.com/gogo/protobuf/proto"
"github.com/owulveryck/onnx-go/internal/pb-onnx"
)

func TestNewTestAcosExample(t *testing.T) {
mytest := NewTestAcosExample()
var model pb.ModelProto
err := proto.Unmarshal(mytest.ModelB, &model)
if err != nil {
t.Fatal(err)
}
if model.Graph == nil {
t.Fatal("graph is nil")
}
if len(model.Graph.Input) != len(mytest.Input) {
t.Fatalf("invalid test: model has %v input, but test only provide %v", len(model.Graph.Input), len(mytest.Input))
}
if len(model.Graph.Output) != len(mytest.ExpectedOutput) {
t.Fatalf("invalid test: model has %v input, but test only provide %v", len(model.Graph.Output), len(mytest.ExpectedOutput))
}
}
26 changes: 26 additions & 0 deletions backend/testbackend/onnx/onnx_test_acos_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package onnxtest

import (
"testing"

"github.com/gogo/protobuf/proto"
"github.com/owulveryck/onnx-go/internal/pb-onnx"
)

func TestNewTestAcos(t *testing.T) {
mytest := NewTestAcos()
var model pb.ModelProto
err := proto.Unmarshal(mytest.ModelB, &model)
if err != nil {
t.Fatal(err)
}
if model.Graph == nil {
t.Fatal("graph is nil")
}
if len(model.Graph.Input) != len(mytest.Input) {
t.Fatalf("invalid test: model has %v input, but test only provide %v", len(model.Graph.Input), len(mytest.Input))
}
if len(model.Graph.Output) != len(mytest.ExpectedOutput) {
t.Fatalf("invalid test: model has %v input, but test only provide %v", len(model.Graph.Output), len(mytest.ExpectedOutput))
}
}
26 changes: 26 additions & 0 deletions backend/testbackend/onnx/onnx_test_acosh_example_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package onnxtest

import (
"testing"

"github.com/gogo/protobuf/proto"
"github.com/owulveryck/onnx-go/internal/pb-onnx"
)

func TestNewTestAcoshExample(t *testing.T) {
mytest := NewTestAcoshExample()
var model pb.ModelProto
err := proto.Unmarshal(mytest.ModelB, &model)
if err != nil {
t.Fatal(err)
}
if model.Graph == nil {
t.Fatal("graph is nil")
}
if len(model.Graph.Input) != len(mytest.Input) {
t.Fatalf("invalid test: model has %v input, but test only provide %v", len(model.Graph.Input), len(mytest.Input))
}
if len(model.Graph.Output) != len(mytest.ExpectedOutput) {
t.Fatalf("invalid test: model has %v input, but test only provide %v", len(model.Graph.Output), len(mytest.ExpectedOutput))
}
}
26 changes: 26 additions & 0 deletions backend/testbackend/onnx/onnx_test_acosh_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package onnxtest

import (
"testing"

"github.com/gogo/protobuf/proto"
"github.com/owulveryck/onnx-go/internal/pb-onnx"
)

func TestNewTestAcosh(t *testing.T) {
mytest := NewTestAcosh()
var model pb.ModelProto
err := proto.Unmarshal(mytest.ModelB, &model)
if err != nil {
t.Fatal(err)
}
if model.Graph == nil {
t.Fatal("graph is nil")
}
if len(model.Graph.Input) != len(mytest.Input) {
t.Fatalf("invalid test: model has %v input, but test only provide %v", len(model.Graph.Input), len(mytest.Input))
}
if len(model.Graph.Output) != len(mytest.ExpectedOutput) {
t.Fatalf("invalid test: model has %v input, but test only provide %v", len(model.Graph.Output), len(mytest.ExpectedOutput))
}
}
26 changes: 26 additions & 0 deletions backend/testbackend/onnx/onnx_test_add_bcast_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package onnxtest

import (
"testing"

"github.com/gogo/protobuf/proto"
"github.com/owulveryck/onnx-go/internal/pb-onnx"
)

func TestNewTestAddBcast(t *testing.T) {
mytest := NewTestAddBcast()
var model pb.ModelProto
err := proto.Unmarshal(mytest.ModelB, &model)
if err != nil {
t.Fatal(err)
}
if model.Graph == nil {
t.Fatal("graph is nil")
}
if len(model.Graph.Input) != len(mytest.Input) {
t.Fatalf("invalid test: model has %v input, but test only provide %v", len(model.Graph.Input), len(mytest.Input))
}
if len(model.Graph.Output) != len(mytest.ExpectedOutput) {
t.Fatalf("invalid test: model has %v input, but test only provide %v", len(model.Graph.Output), len(mytest.ExpectedOutput))
}
}
26 changes: 26 additions & 0 deletions backend/testbackend/onnx/onnx_test_add_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package onnxtest

import (
"testing"

"github.com/gogo/protobuf/proto"
"github.com/owulveryck/onnx-go/internal/pb-onnx"
)

func TestNewTestAdd(t *testing.T) {
mytest := NewTestAdd()
var model pb.ModelProto
err := proto.Unmarshal(mytest.ModelB, &model)
if err != nil {
t.Fatal(err)
}
if model.Graph == nil {
t.Fatal("graph is nil")
}
if len(model.Graph.Input) != len(mytest.Input) {
t.Fatalf("invalid test: model has %v input, but test only provide %v", len(model.Graph.Input), len(mytest.Input))
}
if len(model.Graph.Output) != len(mytest.ExpectedOutput) {
t.Fatalf("invalid test: model has %v input, but test only provide %v", len(model.Graph.Output), len(mytest.ExpectedOutput))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func NewTestArgmaxDefaultAxisExample() *testbackend.TestCase {
Name: "",
OpType: "ArgMax",
Attributes: ([]*pb.AttributeProto) (len=1 cap=1) {
(*pb.AttributeProto)(0xc00013d000)(name:"keepdims" type:INT i:1 )
(*pb.AttributeProto)(0xc000126800)(name:"keepdims" type:INT i:1 )
}
,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package onnxtest

import (
"testing"

"github.com/gogo/protobuf/proto"
"github.com/owulveryck/onnx-go/internal/pb-onnx"
)

func TestNewTestArgmaxDefaultAxisExample(t *testing.T) {
mytest := NewTestArgmaxDefaultAxisExample()
var model pb.ModelProto
err := proto.Unmarshal(mytest.ModelB, &model)
if err != nil {
t.Fatal(err)
}
if model.Graph == nil {
t.Fatal("graph is nil")
}
if len(model.Graph.Input) != len(mytest.Input) {
t.Fatalf("invalid test: model has %v input, but test only provide %v", len(model.Graph.Input), len(mytest.Input))
}
if len(model.Graph.Output) != len(mytest.ExpectedOutput) {
t.Fatalf("invalid test: model has %v input, but test only provide %v", len(model.Graph.Output), len(mytest.ExpectedOutput))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func NewTestArgmaxDefaultAxisRandom() *testbackend.TestCase {
Name: "",
OpType: "ArgMax",
Attributes: ([]*pb.AttributeProto) (len=1 cap=1) {
(*pb.AttributeProto)(0xc00013d100)(name:"keepdims" type:INT i:1 )
(*pb.AttributeProto)(0xc000350300)(name:"keepdims" type:INT i:1 )
}
,
},
Expand Down
Loading

0 comments on commit c917fc1

Please sign in to comment.