c4f

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

Documentation

Overview

Package c4f contains wrappers for the external c4f programs.

Index

Examples

Constants

View Source
const BinC4fC = "c4f-c"

BinC4fC is the name of the c4f C services binary.

View Source
const BinC4fFuzz = "c4f"

BinC4fFuzz is the name of the c4f fuzzer binary.

Variables

View Source
var ErrNoBaseRunner = errors.New("no base runner supplied")

ErrNoBaseRunner occurs if we try to use a Runner that has no Runner.Base set.

View Source
var ErrStatsetParse = errors.New("statistic parse error")

ErrStatsetParse occurs when there is a parse error reading a statset.

Functions

func MakeFuzzConfFile

func MakeFuzzConfFile(j fuzzer.Job) (string, error)

MakeFuzzConfFile creates a temporary file, then outputs WriteFuzzConf of j to it and returns the filepath. It is the caller's responsibility to delete the file.

func ParseStats

func ParseStats(s *litmus.Statset, r io.Reader) error

ParseStats parses a statistics set from r into statistics set s. Each statistic should be in the form "name value\n".

func WriteFuzzConf

func WriteFuzzConf(w io.Writer, j fuzzer.Job) error

WriteFuzzConf writes a fuzzer configuration based on j to w.

Example (Empty)

ExampleWriteFuzzConf_empty is a testable example for WriteFuzzConf, showing an empty config.

package main

import (
	"fmt"
	"os"

	"github.com/c4-project/c4t/internal/model/service/fuzzer"

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

func main() {
	if err := c4f.WriteFuzzConf(os.Stdout, (fuzzer.Job{})); err != nil {
		fmt.Println("ERROR:", err)
	}

}
Output:

# AUTOGENERATED BY TESTER
fuzz {
}
Example (Machine)

ExampleWriteFuzzConf_machine is a testable example for WriteFuzzConf, showing the effect of adding a machine.

package main

import (
	"fmt"
	"os"

	"github.com/c4-project/c4t/internal/model/service/fuzzer"

	"github.com/c4-project/c4t/internal/c4f"
	"github.com/c4-project/c4t/internal/machine"
)

func main() {
	f := fuzzer.Job{Machine: &machine.Machine{Cores: 4}}
	if err := c4f.WriteFuzzConf(os.Stdout, f); err != nil {
		fmt.Println("ERROR:", err)
	}

}
Output:

# AUTOGENERATED BY TESTER
fuzz {
## MACHINE SPECIFIC OVERRIDES ##
  # Set to number of cores in machine to prevent thrashing.
  set param cap.threads to 4
}
Example (Params)

ExampleWriteFuzzConf_params is a testable example for WriteFuzzConf, showing the effect of adding parameters.

package main

import (
	"fmt"
	"os"

	"github.com/c4-project/c4t/internal/model/service/fuzzer"

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

func main() {
	// These will be output in ascending alphabetical order of keys.
	f := fuzzer.Job{Config: &fuzzer.Config{Params: map[string]string{
		"int.action.cap.upper":          "1000",
		"int.this.will.not.parse":       "six",
		"bool.mem.unsafe-weaken-orders": "true",
		"bool.action.enable":            "2:1",
		"bool.action.pick-extra":        "false",
		"bool.this.will.not.parse":      ":",
		"action.var.make":               "10",
		"action.var.nope":               "ten",
		"nonsuch":                       "thing",
		"":                              "nope",
	}}}
	if err := c4f.WriteFuzzConf(os.Stdout, f); err != nil {
		fmt.Println("ERROR:", err)
	}

}
Output:

# AUTOGENERATED BY TESTER
fuzz {
## CONFIGURATION OVERRIDES ##
  # unsupported param "": "nope"
  action var.make weight 10
  # unsupported param "action.var.nope": "ten"
  set flag action.enable to ratio 2:1
  set flag action.pick-extra to false
  set flag mem.unsafe-weaken-orders to true
  # unsupported param "bool.this.will.not.parse": ":"
  set param action.cap.upper to 1000
  # unsupported param "int.this.will.not.parse": "six"
  # unsupported param "nonsuch": "thing"
}

Types

type CmdSpec

type CmdSpec struct {
	// Cmd is the name of the c4f command (binary) to run.
	Cmd string
	// Subcmd is the name of the c4f subcommand to run.
	Subcmd string
	// Args is the argument vector to supply to the c4f subcommand.
	Args []string
	// Stdout, if given, redirects the command's stdout to this writer.
	Stdout io.Writer
}

CmdSpec holds all information about the invocation of an c4f command.

func (CmdSpec) FullArgv

func (c CmdSpec) FullArgv() []string

FullArgv gets the full argument vector for the command, including the subcommand.

type DelitmusJob

type DelitmusJob struct {
	// InLitmus is the filepath of the input litmus file.
	InLitmus string
	// OutAux is the filepath to which the delitmusifier should write the auxiliary file.
	OutAux string
	// OutC is the filepath to which the delitmusifier should write the output file.
	OutC string
}

DelitmusJob holds information about a single delitmus run.

func (DelitmusJob) Args

func (d DelitmusJob) Args() []string

Args gets the argument vector for DelitmusJob.

type Header struct {
	// Name is the name of the Litmus test.
	Name string `json:"name"`

	// Locations is the list of locations present in the Litmus test.
	Locations []string `json:"locations"`

	// Init is the initialiser block for the Litmus test.
	Init map[string]int `json:"init"`

	// Postcondition is the Litmus postcondition.
	Postcondition string `json:"postcondition"`
}

Header represents a Litmus test header in the form that c4f-c accepts and dumps.

func (*Header) Read

func (h *Header) Read(r io.Reader) error

ReadHeader tries to read a Metadata from JSON in r.

type Runner

type Runner struct {
	// DuneExec toggles whether c4f should be run through dune.
	DuneExec bool

	// Base is the basic service runner the c4f runner is using to run binaries.
	Base service.Runner
}

Runner stores information about how to run the core c4f binaries.

func (*Runner) CVersion

func (a *Runner) CVersion(ctx context.Context) (string, error)

CVersion gets the version of the c4f-c tool.

func (*Runner) Delitmus

func (a *Runner) Delitmus(ctx context.Context, d DelitmusJob) error

Delitmus runs c4f-c delitmus as directed by d.

func (*Runner) DumpHeader

func (a *Runner) DumpHeader(ctx context.Context, h *Header, path string) error

DumpHeader runs c4f-c dump-header on the subject at path, writing the results to h.

func (*Runner) DumpStats

func (a *Runner) DumpStats(ctx context.Context, s *litmus.Statset, path string) error

DumpStats runs c4f-c dump-stats on the subject at path, writing the stats to s.

func (*Runner) Fuzz

func (a *Runner) Fuzz(ctx context.Context, j fuzzer.Job) error

Fuzz wraps the c4f one-file fuzzer, supplying the given seed.

func (*Runner) ProbeSubject

func (a *Runner) ProbeSubject(ctx context.Context, path string) (*subject.Named, error)

ProbeSubject probes the litmus test at path, returning a named subject record.

func (*Runner) Run

func (a *Runner) Run(ctx context.Context, s CmdSpec) error

Jump to

Keyboard shortcuts

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