testbackend

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 30, 2019 License: MIT Imports: 9 Imported by: 2

README

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 {

Documentation

Overview

Package testbackend provides a set of testing helper functions that test backend interface implementations. The tests are extracted and converted from the onnx test set

Example
package main

import (
	"testing"

	"github.com/owulveryck/onnx-go/backend"
	"github.com/owulveryck/onnx-go/backend/testbackend"
)

func main() {
	// The backend you want to test
	var backend backend.ComputationBackend
	// Replace this line in your code by:
	// func TestConv(t i*testing.T) {
	testConv := func(t *testing.T) {
		for _, tc := range testbackend.GetOpTypeTests("Conv") {
			tc := tc // capture range variable
			t.Run(tc().GetInfo(), tc().RunTest(backend, false))
		}
	}
	_ = testConv
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindAllTestsMatching

func FindAllTestsMatching(re *regexp.Regexp) []func() *TestCase

FindAllTestsMatching tests matching the regexp

func GetAllRegisteredTests

func GetAllRegisteredTests() []func() *TestCase

GetAllRegisteredTests ...

func GetOpTypeTests

func GetOpTypeTests(optype string) []func() *TestCase

GetOpTypeTests returns all the tests of the OpType passed as argument

func Register

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

Register a test

Types

type TestCase

type TestCase struct {
	OpType         string
	Title          string
	ModelB         []byte
	Input          []tensor.Tensor
	ExpectedOutput []tensor.Tensor
	Tested         bool // true if the test has be executed
	Skipped        bool // true if the test has been executed and skipped
	Failed         bool // true if the test failed
}

TestCase describes an integration test

func (*TestCase) Dump

func (tc *TestCase) Dump(w io.Writer) error

Dump a raw version of the onnx data decoded in the protobuf structure. Useful for debugging

func (*TestCase) GetInfo

func (tc *TestCase) GetInfo() string

GetInfo ...

func (*TestCase) RunTest

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

RunTest Returns a function to be executed against the ComputationBackend. The return function should be executed via a call to testing.Run(...) If parallel is true, a t.Parallel() is added at the beginning of the test

Directories

Path Synopsis
Package onnxtest contains an export of the onnx test files
Package onnxtest contains an export of the onnx test files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL