subject

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: 7 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// ErrMissingCompilation occurs on requests for compile results for a compiler that do not have them.
	ErrMissingCompilation = errors.New("no such compilation")

	// ErrDuplicateCompile occurs when one tries to insert a compile result that already exists.
	ErrDuplicateCompile = errors.New("duplicate compile result")

	// ErrDuplicateRecipe occurs when one tries to insert a recipe that already exists.
	ErrDuplicateRecipe = errors.New("duplicate recipe")

	// ErrDuplicateRun occurs when one tries to insert a run that already exists.
	ErrDuplicateRun = errors.New("duplicate run")

	// ErrMissingCompile occurs on requests for compile results for a compiler that do not have them.
	ErrMissingCompile = errors.New("no such compile result")

	// ErrMissingRecipe occurs on requests for recipe paths for an arch that do not have them.
	ErrMissingRecipe = errors.New("no such recipe")

	// ErrMissingRun occurs on requests for runs for a compiler that do not have them.
	ErrMissingRun = errors.New("no such run")

	// ErrNoBestLitmus occurs when asking for a BestLitmus() on a test with no valid Litmus file paths.
	ErrNoBestLitmus = errors.New("no valid litmus file for this subject")
)

Functions

This section is empty.

Types

type Fuzz

type Fuzz struct {
	// Duration is the length of time it took to fuzz this file.
	Duration time.Duration `toml:"duration,omitzero" json:"duration,omitempty"`

	// Litmus holds information about this subject's fuzzed Litmus file.
	Litmus litmus.Litmus `toml:"litmus,omitempty" json:"litmus,omitempty"`

	// Trace is the slashpath to this subject's fuzzer trace file.
	Trace string `toml:"trace,omitempty" json:"trace,omitempty"`
}

Fuzz is the set of file paths, and other metadata, associated with a fuzzer output.

type Named

type Named struct {
	// Name is the name of the subject.
	Name string

	// Normalise embeds the subject itself.
	Subject
}

Named wraps a Subject with its name.

type Option

type Option func(*Subject) error

Option is the type of (functional) options to the New constructor.

func Options

func Options(os ...Option) Option

Options combines the options os into a single option.

func WithCompile

func WithCompile(cid id.ID, c compilation.CompileResult) Option

WithCompile is an option that tries to preload a compile result for compiler ID cid onto a subject.

func WithFuzz

func WithFuzz(fz *Fuzz) Option

WithFuzz is an option that sets the incoming subject's fuzzer record to fz.

func WithRecipe

func WithRecipe(arch id.ID, r recipe.Recipe) Option

WithRecipe is an option that tries to preload a recipe for architecture ID arch onto a subject.

func WithRun

func WithRun(cid id.ID, r compilation.RunResult) Option

WithRun is an option that tries to preload a run for compiler ID cid onto a subject.

type Subject

type Subject struct {
	// Fuzz is the fuzzer output for this subject, if it has been fuzzed.
	Fuzz *Fuzz `toml:"fuzz,omitempty" json:"fuzz,omitempty"`

	// Source refers to the original litmus test for this subject.
	Source litmus.Litmus `toml:"source,omitempty" json:"source,omitempty"`

	// Compilations contains information about this subject's compilations, organised by compiler ID.
	// If nil, this subject hasn't had any compilations.
	Compilations compilation.Map `toml:"compilations,omitempty" json:"compilations,omitempty"`

	// Recipes contains information about this subject's lifted test recipes.
	// If nil, this subject hasn't had any recipes generated.
	Recipes recipe.Map `toml:"recipes,omitempty" json:"recipes,omitempty"`
}

Subject represents a single test subject in a corpus.

func New

func New(origLitmus *litmus.Litmus, opt ...Option) (*Subject, error)

New is a convenience constructor for subjects.

func NewOrPanic

func NewOrPanic(origLitmus *litmus.Litmus, opt ...Option) *Subject

NewOrPanic is like New, but panics if there is an error. Use in tests only.

func (*Subject) AddCompileResult

func (s *Subject) AddCompileResult(cid id.ID, c compilation.CompileResult) error

AddCompileResult sets the compilation information for compiler ID cid to c in this subject. It fails if there already _is_ a compilation.

func (*Subject) AddName

func (s *Subject) AddName(name string) *Named

AddName copies this subject into a new Named with the given name.

func (*Subject) AddRecipe

func (s *Subject) AddRecipe(arch id.ID, r recipe.Recipe) error

AddRecipe sets the recipe information for arch to r in this subject. It fails if there already _is_ a recipe for arch.

func (*Subject) AddRun

func (s *Subject) AddRun(cid id.ID, r compilation.RunResult) error

AddRun sets the run information for cid to r in this subject. It fails if there already _is_ a run for cid.

func (*Subject) BestLitmus

func (s *Subject) BestLitmus() (*litmus.Litmus, error)

BestLitmus tries to get the 'best' litmus test for further development.

When there is a fuzzing record for this subject, the fuzz output is the best path. Otherwise, if there is a non-empty Litmus file for this subject, that file is the best path. Else, BestLitmus returns an error.

Example

ExampleSubject_BestLitmus is a testable example for BestLitmus.

package main

import (
	"fmt"

	"github.com/c4-project/c4t/internal/model/litmus"

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

func main() {
	l, _ := litmus.New("foo.litmus")

	s1, _ := subject.New(l)
	b1, _ := s1.BestLitmus()

	// This subject has a fuzzed litmus file, which takes priority.
	f, _ := litmus.New("bar.litmus")
	s2, _ := subject.New(l, subject.WithFuzz(&subject.Fuzz{Litmus: *f}))
	b2, _ := s2.BestLitmus()

	fmt.Println("s1:", b1.Path)
	fmt.Println("s2:", b2.Path)

}
Output:

s1: foo.litmus
s2: bar.litmus

func (*Subject) Compilation

func (s *Subject) Compilation(cid id.ID) (compilation.Compilation, error)

Compilation gets the compilation information for the compiler ID cid.

func (*Subject) CompileResult

func (s *Subject) CompileResult(cid id.ID) (*compilation.CompileResult, error)

CompileResult gets the compilation result for the compiler ID cid.

Example

ExampleSubject_CompileResult is a testable example for CompileResult.

package main

import (
	"fmt"

	"github.com/c4-project/c4t/internal/subject/compilation"

	"github.com/c4-project/c4t/internal/subject/status"

	"github.com/c4-project/c4t/internal/id"

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

func main() {
	s := subject.Subject{Compilations: compilation.Map{
		id.FromString("gcc"): {
			Compile: &compilation.CompileResult{
				Result: compilation.Result{Status: status.Ok}, Files: compilation.CompileFileset{Bin: "a.out", Log: "gcc.log"},
			}},
		id.FromString("clang"): {
			Compile: &compilation.CompileResult{
				Result: compilation.Result{Status: status.CompileFail}, Files: compilation.CompileFileset{Bin: "a.out", Log: "clang.log"},
			}},
	}}
	gr, _ := s.CompileResult(id.FromString("gcc"))
	cr, _ := s.CompileResult(id.FromString("clang"))

	fmt.Println("gcc:", gr.Status, gr.Files.Bin, gr.Files.Log)
	fmt.Println("clang:", cr.Status, cr.Files.Bin, cr.Files.Log)

}
Output:

gcc: Ok a.out gcc.log
clang: CompileFail a.out clang.log

func (*Subject) HasFuzzFile

func (s *Subject) HasFuzzFile() bool

HasFuzzFile gets whether this subject has a fuzzed testcase file.

func (*Subject) Recipe

func (s *Subject) Recipe(arch id.ID) (id.ID, recipe.Recipe, error)

Recipe gets the recipe for the architecture with id arch. It returns the ID of the recipe as well as the recipe contents.

Example

ExampleSubject_Recipe is a testable example for Recipe.

package main

import (
	"fmt"

	"github.com/c4-project/c4t/internal/model/recipe"

	"github.com/c4-project/c4t/internal/id"

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

func main() {
	s := subject.Subject{Recipes: recipe.Map{
		id.ArchX8664: {Dir: "foo", Files: []string{"bar", "baz"}},
		id.ArchArm:   {Dir: "foobar", Files: []string{"barbaz"}},
	}}
	xsn, xs, _ := s.Recipe(id.ArchX8664)
	asn, as, _ := s.Recipe(id.ArchArm)

	fmt.Println("#", xsn)
	for _, r := range xs.Files {
		fmt.Println(r)
	}
	fmt.Println("#", asn)
	for _, r := range as.Files {
		fmt.Println(r)
	}

}
Output:

# x86.64
bar
baz
# arm
barbaz

func (*Subject) RunResult

func (s *Subject) RunResult(cid id.ID) (*compilation.RunResult, error)

RunResult gets the run result for the compiler with id cid.

Example

ExampleSubject_RunResult is a testable example for Subject.RunResult.

package main

import (
	"fmt"

	"github.com/c4-project/c4t/internal/subject/compilation"

	"github.com/c4-project/c4t/internal/subject/status"

	"github.com/c4-project/c4t/internal/id"

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

func main() {
	s := subject.Subject{Compilations: compilation.Map{
		id.FromString("gcc"): {
			Run: &compilation.RunResult{
				Result: compilation.Result{Status: status.Ok},
			}},
		id.FromString("clang"): {
			Run: &compilation.RunResult{
				Result: compilation.Result{Status: status.RunTimeout},
			}},
	}}
	gr, _ := s.RunResult(id.FromString("gcc"))
	cr, _ := s.RunResult(id.FromString("clang"))

	fmt.Println("gcc:", gr.Status)
	fmt.Println("clang:", cr.Status)

}
Output:

gcc: Ok
clang: RunTimeout

Directories

Path Synopsis
Package compilation contains types and functions for dealing with 'compilations': subject/compiler products.
Package compilation contains types and functions for dealing with 'compilations': subject/compiler products.
Package corpus concerns test corpora (collections of named subjects).
Package corpus concerns test corpora (collections of named subjects).
builder
Package builder describes a set of types and methods for building corpora asynchronously.
Package builder describes a set of types and methods for building corpora asynchronously.
Package normaliser provides utilities for archiving and transferring plans, corpora, and subjects.
Package normaliser provides utilities for archiving and transferring plans, corpora, and subjects.
Package normpath contains various 'normalised path' fragments, and functions for constructing them.
Package normpath contains various 'normalised path' fragments, and functions for constructing them.
Package obs concerns 'observations': the end result of running a test on a particular machine.
Package obs concerns 'observations': the end result of running a test on a particular machine.

Jump to

Keyboard shortcuts

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