Version: v0.0.0-...-0d16973 Latest Latest

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

Go to latest
Published: Aug 10, 2021 License: MIT Imports: 10 Imported by: 0



Package litmus contains model structs and associated functions for Litmus test entries.




This section is empty.


View Source
var (
	// ErrEmptyArch occurs when the arch ID sent to the Litmus backend is empty.
	ErrEmptyArch = errors.New("arch empty")
	// ErrBadArch occurs when the arch ID sent to the Litmus backend doesn't match any of the ones known to it.
	ErrBadArch = errors.New("arch family unknown")
View Source
var (
	// ErrStatDumperNil occurs when we try to use a nil stat dumper with PopulateStatsFrom.
	ErrStatDumperNil = errors.New("stat dumper is nil")


func ArchOfFile

func ArchOfFile(fpath string) (id.ID, error)

ArchOfFile tries to divine the architecture ID of a Litmus test by reading its first line from file fpath.

func ArchOfLitmus

func ArchOfLitmus(arch string) (id.ID, error)

ArchOfLitmus tries to look up the C4 identifier of a Litmus architecture.


ExampleArchOfLitmus gives a few testable examples of ArchOfLitmus.

package main

import (


func main() {
	a1, _ := litmus.ArchOfLitmus("AArch64")

	a2, _ := litmus.ArchOfLitmus("PPC")

	a3, _ := litmus.ArchOfLitmus("X86_64")

	a4, _ := litmus.ArchOfLitmus("C")



func ArchToLitmus

func ArchToLitmus(arch id.ID) (string, error)

ArchToLitmus tries to look up the Litmus name of a C4 architecture ID.


ExampleArchToLitmus gives a few testable examples of ArchToLitmus.

package main

import (



func main() {
	a1, _ := litmus.ArchToLitmus(id.ArchAArch64)

	a2, _ := litmus.ArchToLitmus(id.ArchPPCPOWER9)

	a3, _ := litmus.ArchToLitmus(id.ArchX8664)

	a4, _ := litmus.ArchToLitmus(id.ArchC)




type AtomicStatset

type AtomicStatset struct {
	// Types gives the types of atomic, categorised by type.
	Types map[id.ID]int `toml:"types,omitzero,omitempty" json:"types,omitempty"`
	// MemOrders gives the types of memory order, categorised by type.
	MemOrders map[id.ID]int `toml:"mem_orders,omitzero,omitempty" json:"mem_orders,omitempty"`

AtomicStatset contains a set of statistics about atomics (expressions or statements).

func (*AtomicStatset) AddMemOrder

func (s *AtomicStatset) AddMemOrder(mo id.ID, k int)

AddMemOrder adds k to the memory order with ID mo.

func (*AtomicStatset) AddType

func (s *AtomicStatset) AddType(ty id.ID, k int)

AddType adds k to the type with ID ty.

type Litmus

type Litmus struct {
	// Path contains the slashpath to the file.
	Path string `json:"path"`

	// Arch contains the architecture of the Litmus test, if it is not a C test.
	Arch id.ID `json:"arch,omitempty"`

	// Stats contains, if available, the statistics set for this litmus test.
	Stats *Statset `json:"stats,omitempty"`

Litmus contains information about a single litmus test file.

func New

func New(path string, os ...Option) (*Litmus, error)

New constructs a litmus record for slashpath path and options os.

Remember to call filepath.FromSlash if needed.

func NewOrPanic

func NewOrPanic(path string, os ...Option) *Litmus

NewOrPanic is like New, but panics if there's an error.

Use in tests only.

func (*Litmus) Filepath

func (l *Litmus) Filepath() string

Filepath gets the OS path for this litmus file.

func (*Litmus) HasPath

func (l *Litmus) HasPath() bool

HasPath checks if this litmus file actually has a path given.

func (*Litmus) IsC

func (l *Litmus) IsC() bool

IsC checks whether a litmus test targets the C language.


ExampleLitmus_IsC is a testable example for Litmus.IsC.

package main

import (


func main() {
	foo := litmus.NewOrPanic("foo.litmus", litmus.WithArch(id.ArchC))
	fmt.Println("C:  ", foo.IsC())

	bar := litmus.NewOrPanic("bar.litmus", litmus.WithArch(id.ArchC.Join(id.FromString("11"))))
	fmt.Println("C11:", bar.IsC())

	baz := litmus.NewOrPanic("baz.litmus", litmus.WithArch(id.ArchArm))
	fmt.Println("Arm:", baz.IsC())


C:   true
C11: true
Arm: false

func (*Litmus) PopulateArchFromFile

func (l *Litmus) PopulateArchFromFile() error

PopulateArchFromFile sets this litmus test's architecture to that from calling ArchOfFile over its defined Filepath.

func (*Litmus) PopulateStats

func (l *Litmus) PopulateStats(ctx context.Context, s StatDumper) error

PopulateStats uses s to populate the statistics for this litmus file,

type Option

type Option func(*Litmus) error

Option is the type of options to the litmus-test record constructor.

func Options

func Options(os ...Option) Option

Options bundles the options in os into one option.

func PopulateStatsFrom

func PopulateStatsFrom(ctx context.Context, s StatDumper) Option

PopulateStatsFrom is an option that causes the litmus test to populate its statistics set using s and ctx.

func ReadArchFromFile

func ReadArchFromFile() Option

ReadArchFromFile is an option that causes the litmus test to populate its architecture from its given file.

func WithArch

func WithArch(id id.ID) Option

WithArch is an option that forces the litmus test's architecture to be id.

func WithThreads

func WithThreads(threads int) Option

WithThreads is an option that sets the test's thread count to threads.

type StatDumper

type StatDumper interface {
	// DumpStats populates s with statistics gleaned from the Litmus file at filepath path.
	DumpStats(ctx context.Context, s *Statset, path string) error

StatDumper is the interface of things that can dump statistics for a litmus test.

type Statset

type Statset struct {
	// Threads is the number of threads.
	Threads int `json:"threads,omitempty"`

	// Returns is the number of return statements.
	Returns int `json:"returns,omitempty"`

	// LiteralBools is the number of Boolean literals (true, false, etc).
	LiteralBools int `json:"literal_bools,omitempty"`

	// AtomicExpressions gives information about atomic statements.
	AtomicExpressions AtomicStatset `json:"atomic_expressions,omitempty"`

	// AtomicStatements gives information about atomic statements.
	AtomicStatements AtomicStatset `json:"atomic_statements,omitempty"`

Statset contains a set of statistics acquired from `c4f-c dump-stats`.


Path Synopsis

Jump to

Keyboard shortcuts

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