Documentation ¶
Overview ¶
Package litmus contains model structs and associated functions for Litmus test entries.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
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") )
var ( // ErrStatDumperNil occurs when we try to use a nil stat dumper with PopulateStatsFrom. ErrStatDumperNil = errors.New("stat dumper is nil") )
Functions ¶
func ArchOfFile ¶
ArchOfFile tries to divine the architecture ID of a Litmus test by reading its first line from file fpath.
func ArchOfLitmus ¶
ArchOfLitmus tries to look up the C4 identifier of a Litmus architecture.
Example ¶
ExampleArchOfLitmus gives a few testable examples of ArchOfLitmus.
package main import ( "fmt" "github.com/c4-project/c4t/internal/model/litmus" ) func main() { a1, _ := litmus.ArchOfLitmus("AArch64") fmt.Println(a1) a2, _ := litmus.ArchOfLitmus("PPC") fmt.Println(a2) a3, _ := litmus.ArchOfLitmus("X86_64") fmt.Println(a3) a4, _ := litmus.ArchOfLitmus("C") fmt.Println(a4) }
Output: aarch64 ppc x86.64 c
func ArchToLitmus ¶
ArchToLitmus tries to look up the Litmus name of a C4 architecture ID.
Example ¶
ExampleArchToLitmus gives a few testable examples of ArchToLitmus.
package main import ( "fmt" "github.com/c4-project/c4t/internal/model/litmus" "github.com/c4-project/c4t/internal/id" ) func main() { a1, _ := litmus.ArchToLitmus(id.ArchAArch64) fmt.Println(a1) a2, _ := litmus.ArchToLitmus(id.ArchPPCPOWER9) fmt.Println(a2) a3, _ := litmus.ArchToLitmus(id.ArchX8664) fmt.Println(a3) a4, _ := litmus.ArchToLitmus(id.ArchC) fmt.Println(a4) }
Output: AArch64 PPC X86_64 C
Types ¶
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.
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 ¶
New constructs a litmus record for slashpath path and options os.
Remember to call filepath.FromSlash if needed.
func (*Litmus) IsC ¶
IsC checks whether a litmus test targets the C language.
Example ¶
ExampleLitmus_IsC is a testable example for Litmus.IsC.
package main import ( "fmt" "github.com/c4-project/c4t/internal/id" "github.com/c4-project/c4t/internal/model/litmus" ) 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()) }
Output: C: true C11: true Arm: false
func (*Litmus) PopulateArchFromFile ¶
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 ¶
Option is the type of options to the litmus-test record constructor.
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 WithThreads ¶
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`.