Skip to content

Latest commit

 

History

History
68 lines (50 loc) · 1.96 KB

README.md

File metadata and controls

68 lines (50 loc) · 1.96 KB

GoDoc

About

This package contains utilities for testing a backend.

Test cases are described thanks to this structure

type TestCase struct {
	Title          string
	ModelB         []byte
	Input          []tensor.Tensor
	ExpectedOutput []tensor.Tensor
}

The structure own a method that genererate a test function suitable to run through T.Run()

func (tc *TestCase) RunTest(b backend.ComputationBackend, parallel bool) func(t *testing.T) {

A test for a certain OpType can be registered with the following command:

func Register(optype, testTitle string, constructor func() *TestCase)

Usage in your backend implementation

Here is an example of a test for the Convolution Operator.

Register the tests from ONNX:

_ "github.com/owulveryck/onnx-go/backend/testbackend/onnx"
func(t *testing.T) {
		for _, tc := range testbackend.GetOpTypeTests("Conv") {
			tc := tc // capture range variable
			t.Run(tc().GetInfo(), tc().RunTest(backend, false))
		}
	}

Tests from ONNX

Test files have been autogenerated from the ONNX tests data and are exposed via a seperate package.

A void import of the package register all the tests that are accessible through a call to the function GetOpTypeTests

_ "github.com/owulveryck/onnx-go/backend/testbackend/onnx"
func GetOpTypeTests(optype string) []func() *TestCase {