helpers

package
v0.0.0-...-fc88c08 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddToDags

func AddToDags(unit gomel.Preunit, rss []gomel.RandomSource, dags []gomel.Dag) (gomel.Unit, error)

AddToDags is a helper function that adds a given unit to all provided dags.

func AddToDagsIngoringErrors

func AddToDagsIngoringErrors(unit gomel.Preunit, dags []gomel.Dag) gomel.Unit

AddToDagsIngoringErrors adds a unit to all dags ignoring all errors while doing it. It returns, if possible, a Unit added the owning dag (assuming that order of 'dags' lists corresponds with their ids).

func AddUnitsToDagsInRandomOrder

func AddUnitsToDagsInRandomOrder(units []gomel.Unit, dags []gomel.Dag) error

AddUnitsToDagsInRandomOrder adds a set of units in random order (per each dag) to all provided dags.

func ComputeLevel

func ComputeLevel(dag gomel.Dag, parents []gomel.Unit) int

ComputeLevel computes value of the level attribute for a given preunit.

func GenerateKeys

func GenerateKeys(nProcesses int) ([]gomel.PublicKey, []gomel.PrivateKey)

GenerateKeys is a helper function that creates a list of pairs of public-private keys.

func MakeStandardDag

func MakeStandardDag(nProc uint16) gomel.Dag

MakeStandardDag returns a daag with standard checks.

func NewDefaultConfigurations

func NewDefaultConfigurations(nProcesses uint16) []config.Config

NewDefaultConfigurations creates a slice of a given size containing default configurations.

func NewDefaultDataContent

func NewDefaultDataContent() []byte

NewDefaultDataContent creates an instance of []byte equal to [1, 2, 3, 4]. It is not intended to be a valid payload for a unit.

func NewDefaultVerifier

func NewDefaultVerifier() func([]gomel.Dag, []gomel.PrivateKey) DagVerifier

NewDefaultVerifier returns a DagVerifier composed from VerifyAllDagsContainSameMaximalUnits, VerifyTimingUnits and VerifyOrdering verifiers.

func SimpleCoin

func SimpleCoin(pid uint16, level int) bool

SimpleCoin returns a pseudo-random bit that is only dependent on the value of the level parameter.

func Test

func Test(
	pubKeys []gomel.PublicKey,
	privKeys []gomel.PrivateKey,
	configurations []config.Config,
	testingRoutine *TestingRoutine,
) error

Test is a helper function that performs a single test using provided TestingRoutineFactory and the FixedCoin as RandomSource.

func TestUsingRandomSourceProvider

func TestUsingRandomSourceProvider(
	pubKeys []gomel.PublicKey,
	privKeys []gomel.PrivateKey,
	configurations []config.Config,
	rssProvider func(pid uint16, dag gomel.Dag) (gomel.RandomSource, gomel.Dag),
	testingRoutine *TestingRoutine,
) error

TestUsingRandomSourceProvider is a helper function that performs a single test using provided TestingRoutineFactory.

func TestUsingTestRandomSource

func TestUsingTestRandomSource(
	pubKeys []gomel.PublicKey,
	privKeys []gomel.PrivateKey,
	configurations []config.Config,
	testingRoutine *TestingRoutine,
) error

TestUsingTestRandomSource is a helper function that performs a single test using provided TestingRoutineFactory and testRandomSource as RandomSource.

Types

type AddingHandler

type AddingHandler func(dags []gomel.Dag, rss []gomel.RandomSource, preunit gomel.Unit) error

AddingHandler is a type of a function that given a list of dags and a unit handles adding of that unit with accordance to used strategy.

func ComposeAdders

func ComposeAdders(adders ...AddingHandler) AddingHandler

ComposeAdders composes provided 'adders' into a single 'adder'. Created 'adder' fails immediately after it discovers a failure of one of its 'adders'.

func NewDefaultAdder

func NewDefaultAdder() AddingHandler

NewDefaultAdder creates an instance of AddingHandler that ads a given unit to all dags under test.

func NewNoOpAdder

func NewNoOpAdder() AddingHandler

NewNoOpAdder return an instance of 'AddingHandler' type that performs no operation.

type Creator

type Creator func(dag gomel.Dag, creator uint16, privKey gomel.PrivateKey, rs gomel.RandomSource) (gomel.Unit, error)

Creator is a type of a function that given a dag and some 'creator' attempts to build a valid unit.

func NewDefaultCreator

func NewDefaultCreator(maxParents int32) Creator

NewDefaultCreator creates an instance of Creator that when called attempts to create a unit using default data.

type DagVerifier

type DagVerifier func([]gomel.Dag, []uint16, []config.Config, []gomel.RandomSource) error

DagVerifier is a type of a function that is responsible for verifying if a given list of dags is in valid state.

func ComposeVerifiers

func ComposeVerifiers(verifiers ...DagVerifier) DagVerifier

ComposeVerifiers composes provided verifiers into a single verifier. Created verifier fails immediately after it discovers a failure of one of its verifiers.

func NewNoOpVerifier

func NewNoOpVerifier() DagVerifier

NewNoOpVerifier returns a DagVerifier that does not check provided dags and immediately answers that they are correct.

func VerifyAllDagsContainSameMaximalUnits

func VerifyAllDagsContainSameMaximalUnits() DagVerifier

VerifyAllDagsContainSameMaximalUnits returns a DagVerifier that checks if all dags provide same set of maximal units.

func VerifyOrdering

func VerifyOrdering() DagVerifier

VerifyOrdering returns a DagVerifier that compares if all dags orders their underlying units in the same way.

func VerifyTimingUnits

func VerifyTimingUnits() DagVerifier

VerifyTimingUnits returns a dag verifier that checks if all dags returns same set of timing units.

type TestingRoutine

type TestingRoutine struct {
	// contains filtered or unexported fields
}

TestingRoutine describes a strategy for performing a test on a given set of dags.

func NewDefaultTestingRoutine

func NewDefaultTestingRoutine(
	creator func(dags []gomel.Dag, privKeys []gomel.PrivateKey) UnitCreator,
	adder func(dags []gomel.Dag, privKeys []gomel.PrivateKey, rss []gomel.RandomSource) AddingHandler,
	verifier func(dags []gomel.Dag, privKeys []gomel.PrivateKey) DagVerifier,
) *TestingRoutine

NewDefaultTestingRoutine creates an instance of TestingRoutine.

func NewTestingRoutineWithStopCondition

func NewTestingRoutineWithStopCondition(
	creator func(dags []gomel.Dag, privKeys []gomel.PrivateKey) UnitCreator,
	adder func(dags []gomel.Dag, privKeys []gomel.PrivateKey, rss []gomel.RandomSource) AddingHandler,
	verifier func(dags []gomel.Dag, privKeys []gomel.PrivateKey) DagVerifier,
	stopCondition func([]gomel.Dag) bool,
) *TestingRoutine

NewTestingRoutineWithStopCondition creates an instance of TestingRoutine.

func (*TestingRoutine) CreateAddingHandler

func (test *TestingRoutine) CreateAddingHandler(dags []gomel.Dag, privKeys []gomel.PrivateKey, rss []gomel.RandomSource) AddingHandler

CreateAddingHandler creates an instance of AddingHandler.

func (*TestingRoutine) CreateDagVerifier

func (test *TestingRoutine) CreateDagVerifier(dags []gomel.Dag, privKeys []gomel.PrivateKey) DagVerifier

CreateDagVerifier creates an instance of DagVerifier.

func (*TestingRoutine) CreateUnitCreator

func (test *TestingRoutine) CreateUnitCreator(dags []gomel.Dag, privKeys []gomel.PrivateKey) UnitCreator

CreateUnitCreator create an instance of UnitCreator.

func (*TestingRoutine) StopCondition

func (test *TestingRoutine) StopCondition() func(dags []gomel.Dag) bool

StopCondition creates an instance of a function that decides when a testing routine should be stopped.

type UnitCreator

type UnitCreator func([]gomel.Dag, []gomel.PrivateKey, []gomel.RandomSource) (gomel.Unit, error)

UnitCreator is a type of a function that given a list of dags attempts to create a new unit or returns an error otherwise.

func NewDefaultUnitCreator

func NewDefaultUnitCreator(unitFactory Creator) UnitCreator

NewDefaultUnitCreator returns an implementation of the UnitCreator type that tries to build a unit using a randomly selected dag.

func NewEachInSequenceUnitCreator

func NewEachInSequenceUnitCreator(unitFactory Creator) UnitCreator

NewEachInSequenceUnitCreator returns an instance of type UnitCreator that on every call attempts to create a new unit using a creator which is a direct successor of the previous one (i.e. 0, 1, 2...).

Jump to

Keyboard shortcuts

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