quantity

package
v0.0.0-...-1dd1f65 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package quantity contains the quantity sets for various parts of the tester.

These sets appear grouped into this package primarily for reasons of dependency cycle breaking; various bits of the tester at various different levels need access to them.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenericOverride

func GenericOverride(old, new interface{})

GenericOverride substitutes any quantities in new that are non-zero for those in *old (which must be a pointer).

func LogWorkers

func LogWorkers(l *log.Logger, nworkers int)

LogWorkers dumps the number of workers configured by nworkers to the logger l.

Types

type BatchSet

type BatchSet struct {
	// Timeout is the timeout for each runner.
	// Non-positive values disable the timeout.
	Timeout Timeout `toml:"timeout,omitzero" json:"timeout,omitempty"`

	// NWorkers is the number of parallel run workers that should be spawned.
	// Anything less than or equal to 1 will sequentialise the run.
	NWorkers int `toml:"workers,omitzero" json:"workers,omitempty"`
}

BatchSet contains the tunable quantities for either a batch compiler or a batch runner.

func (*BatchSet) Log

func (q *BatchSet) Log(l *log.Logger)

Log logs this quantity set to l.

func (*BatchSet) Override

func (q *BatchSet) Override(new BatchSet)

Override substitutes any non-zero quantities in new for those in this quantity set, in-place.

type FuzzSet

type FuzzSet struct {
	// CorpusSize is the sampling size for the corpus after fuzzing.
	// It has a similar effect to CorpusSize in planner.Planner.
	CorpusSize int `toml:"corpus_size,omitzero" json:"corpus_size,omitempty"`

	// SubjectCycles is the number of times to fuzz each file.
	SubjectCycles int `toml:"subject_cycles,omitzero" json:"subject_cycles,omitempty"`

	// NWorkers is the number of workers to use when fuzzing.
	NWorkers int `toml:"workers,omitzero" json:"num_workers,omitempty"`
}

FuzzSet represents the part of a configuration that holds various tunable parameters for the fuzzer.

func (*FuzzSet) Log

func (q *FuzzSet) Log(l *log.Logger)

Log logs q to l.

func (*FuzzSet) Override

func (q *FuzzSet) Override(new FuzzSet)

Override substitutes any quantities in new that are non-zero for those in this set.

Example

ExampleFuzzSet_Override is a runnable example for FuzzSet.Override.

package main

import (
	"fmt"

	"github.com/c4-project/c4t/internal/quantity"
)

func main() {
	q1 := quantity.FuzzSet{
		CorpusSize:    27,
		SubjectCycles: 53,
	}
	q2 := quantity.FuzzSet{
		SubjectCycles: 42,
	}
	q1.Override(q2)

	fmt.Println("corpus size:   ", q1.CorpusSize)
	fmt.Println("subject cycles:", q1.SubjectCycles)

}
Output:

corpus size:    27
subject cycles: 42

type MachNodeSet

type MachNodeSet struct {
	// Compiler is the quantity set for the compiler.
	Compiler BatchSet `toml:"compiler,omitzero" json:"compiler,omitempty"`
	// Runner is the quantity set for the runner.
	Runner BatchSet `toml:"runner,omitzero" json:"runner,omitempty"`
}

MachNodeSet contains the tunable quantities for both batch-compiler and batch-runner.

func (*MachNodeSet) Log

func (q *MachNodeSet) Log(l *log.Logger)

Log logs q to l.

Example

ExampleMachNodeSet_Log is a testable example for MachNodeSet.Log.

package main

import (
	"log"
	"os"
	"time"

	"github.com/c4-project/c4t/internal/quantity"
)

func main() {
	qs := quantity.MachNodeSet{
		Compiler: quantity.BatchSet{
			Timeout:  quantity.Timeout(1 * time.Minute),
			NWorkers: 2,
		},
		Runner: quantity.BatchSet{
			Timeout:  quantity.Timeout(2 * time.Minute),
			NWorkers: 1,
		},
	}

	l := log.New(os.Stdout, "", 0)
	qs.Log(l)

}
Output:

[Compiler]
running across 2 workers
timeout at 1m0s
[Runner]
running across 1 worker
timeout at 2m0s

func (*MachNodeSet) Override

func (q *MachNodeSet) Override(new MachNodeSet)

Override overrides the quantities in this set with any new quantities supplied in new.

type MachineSet

type MachineSet struct {
	// Fuzz is the quantity set for the fuzz stage.
	Fuzz FuzzSet `toml:"fuzz,omitzero" json:"fuzz,omitempty"`
	// Mach is the quantity set for the machine-local stage, as well as any machine-local stages run remotely.
	Mach MachNodeSet `toml:"mach,omitzero" json:"mach,omitempty"`
	// Perturb is the quantity set for the planner stage.
	Perturb PerturbSet `toml:"perturb,omitzero" json:"perturb,omitempty"`
}

MachineSet contains overridable quantities for each stage operating on a particular machine. Often, but not always, these quantities will be shared between machines.

func (*MachineSet) Log

func (q *MachineSet) Log(l *log.Logger)

Log logs q to l.

func (*MachineSet) Override

func (q *MachineSet) Override(new MachineSet)

Override substitutes any quantities in new that are non-zero for those in this set.

type PerturbSet

type PerturbSet struct {
	// CorpusSize is the requested size of the test corpus.
	// If zero, no corpus sampling is done, but the perturber will still error if the final corpus size is 0.
	// If nonzero, the corpus will be sampled if larger than the size, and an error occurs if the final size is below
	// that requested.
	CorpusSize int `toml:"corpus_size,omitzero" json:"corpus_size,omitempty"`
}

PerturbSet contains configurable quantities for the perturber.

func (*PerturbSet) Log

func (q *PerturbSet) Log(l *log.Logger)

Log logs q to l.

func (*PerturbSet) Override

func (q *PerturbSet) Override(new PerturbSet)

Override substitutes any quantities in new that are non-zero for those in this set.

type PlanSet

type PlanSet struct {
	// NWorkers is the number of workers to use when probing the corpus.
	NWorkers int `toml:"workers,omitzero"`
}

PlanSet contains configurable quantities for the planner.

func (*PlanSet) Log

func (q *PlanSet) Log(l *log.Logger)

Log logs q to l.

func (*PlanSet) Override

func (q *PlanSet) Override(new PlanSet)

Override substitutes any quantities in new that are non-zero for those in this set.

type RootSet

type RootSet struct {
	// GlobalTimeout is the top-level timeout for the director.
	GlobalTimeout Timeout `toml:"global_timeout,omitzero"`

	// Plan is the quantity set for the planner stage.
	Plan PlanSet `toml:"plan,omitempty"`

	// This part of the quantity set is effectively a default for all machines that don't have overrides.
	MachineSet
}

RootSet is the top-level set of tunable quantities for a director.

func (*RootSet) Log

func (q *RootSet) Log(l *log.Logger)

Log logs q to l.

Example

ExampleRootSet_Log is a runnable example for RootSet.Log.

package main

import (
	"log"
	"os"
	"time"

	"github.com/c4-project/c4t/internal/quantity"
)

func main() {
	qs := quantity.RootSet{
		MachineSet: quantity.MachineSet{
			Fuzz: quantity.FuzzSet{
				CorpusSize:    10,
				SubjectCycles: 5,
				NWorkers:      4,
			},
			Mach: quantity.MachNodeSet{
				Compiler: quantity.BatchSet{
					Timeout:  quantity.Timeout(3 * time.Minute),
					NWorkers: 6,
				},
				Runner: quantity.BatchSet{
					Timeout:  quantity.Timeout(2 * time.Minute),
					NWorkers: 7,
				},
			},
			Perturb: quantity.PerturbSet{
				CorpusSize: 80,
			},
		},
		Plan: quantity.PlanSet{
			NWorkers: 9,
		},
	}

	qs.Log(log.New(os.Stdout, "", 0))

}
Output:

[Plan]
running across 9 workers
[Perturb]
target corpus size: 80 subjects
[Fuzz]
running across 4 workers
fuzzing each subject 5 times
target corpus size: 10 subjects
[Mach]
[Compiler]
running across 6 workers
timeout at 3m0s
[Runner]
running across 7 workers
timeout at 2m0s

func (*RootSet) Override

func (q *RootSet) Override(new RootSet)

Override substitutes any quantities in new that are non-zero for those in this set.

type Timeout

type Timeout time.Duration

Timeout is a Duration with the semantics of non-positive values being an absence of timeout.

func (Timeout) IsActive

func (t Timeout) IsActive() bool

IsActive checks whether t represents a valid, active timeout.

func (Timeout) Log

func (t Timeout) Log(l *log.Logger)

Log dumps this timeout to the logger l, if it is active.

func (Timeout) MarshalText

func (t Timeout) MarshalText() (text []byte, err error)

MarshalText marshals a timeout by stringifying it.

func (Timeout) OnContext

func (t Timeout) OnContext(parent context.Context) (context.Context, context.CancelFunc)

OnContext lifts this timeout to a context with the given parent. If this timeout is active, the semantics are as context.WithTimeout; else, context.WithCancel.

func (*Timeout) Override

func (t *Timeout) Override(new Timeout)

Override overrides this timeout with new if new is active.

func (Timeout) String

func (t Timeout) String() string

String forwards the usual duration stringification for timeouts.

func (*Timeout) UnmarshalText

func (t *Timeout) UnmarshalText(in []byte) error

UnmarshalText unmarshals a timeout by using ParseDuration.

Jump to

Keyboard shortcuts

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