Documentation
¶
Overview ¶
Package kerneljudge makes the Linux kernel, and the filesystem's own native tools, the judge of a go-filesystems driver that has no independent oracle.
A driver's test calls Run (and RunPerf) behind FS_KERNEL_JUDGE=1. The test binary is built for linux/arm64 and run as root inside a Tart VM by the kerneljudge command (see cmd/kerneljudge); on any other machine, or without the variable, the judge skips and says why.
The truth is never the driver: it is a deterministic Corpus. Every image, whoever wrote it, is checked against the Corpus, so a driver that is wrong in the same way on both sides of its own round trip is still caught.
Index ¶
- Constants
- func ComparePerf(a, b []PerfLine, tol float64, allowMixed bool) (string, error)
- func Diff(want, got []Node, c Compare) []string
- func Enabled(t *testing.T)
- func PopulateDir(root string, es []Entry) error
- func PopulateFS(f filesystem.Filesystem, es []Entry) error
- func RegimeText(rs Regimes) string
- func Run(t *testing.T, d Driver)
- func RunExternal(t *testing.T, x External)
- func SameRegime(a, b, tol float64) bool
- type Builder
- type Calibration
- type Caps
- type Compare
- type Driver
- type Entry
- type External
- type Kind
- type Known
- type Native
- type Node
- type Options
- type PerfLine
- type PerfOptions
- type Pool
- type Regime
- type Regimes
- type Result
- type Variant
Constants ¶
const DefaultRegimeTolerance = 0.10
DefaultRegimeTolerance is how far two calibrations may differ (relative to the larger) and still be the same regime. Measured on fsjudge-vm at 4 CPUs: an idle host repeats within 5 %, a busy one reads a third of that.
const EnvExtra = "FS_KERNEL_JUDGE_EXTRA"
EnvExtra names a directory (in the VM) of existing files the external judge also compares, reader against oracle. They are copied in for the run and removed after it; the judge never writes them anywhere else.
const EnvJudge = "FS_KERNEL_JUDGE"
EnvJudge enables the judge. The kerneljudge command sets it in the VM.
const EnvKeep = "FS_KERNEL_JUDGE_KEEP"
EnvKeep names a directory (in the VM) that receives a copy of every image the judge examines, so a mismatch can be reproduced by hand.
const EnvPerf = "FS_KERNEL_JUDGE_PERF"
EnvPerf turns the performance run on (it needs a quiet VM and host).
const EnvRegimeRetries = "FS_KERNEL_JUDGE_REGIME_RETRIES"
EnvRegimeRetries is how many times a round that ran in another regime than the first is measured again (default 2, 0 = never).
Variables ¶
This section is empty.
Functions ¶
func ComparePerf ¶ added in v0.4.0
ComparePerf compares two runs measurement by measurement and returns a report. It returns an error, after the report, when any compared pair does not share one regime: a line with no recorded regime, a series whose rounds were mixed, or two series whose calibrations differ by more than tol. allowMixed turns the error into a "NOT COMPARABLE" flag on the line.
func Diff ¶
Diff lists every difference between want and got, one line each, with the exact path and the two values. An empty result is equality.
func Enabled ¶
Enabled reports whether the judge is on, and skips t with the reason when it is not. The judge needs Linux, root and the native tools.
func PopulateDir ¶
PopulateDir writes a corpus through the host's own filesystem calls, which on a mounted image means the kernel's driver. Xattrs are written only where the platform has them (Linux).
func PopulateFS ¶
func PopulateFS(f filesystem.Filesystem, es []Entry) error
PopulateFS writes a corpus through a driver's own API.
func RegimeText ¶ added in v0.4.0
RegimeText is the regime of a series as printed in the PERF line: its median calibration figure, whether every round shared it, and the rounds' labels. ParsePerf reads it back.
func Run ¶
Run is the correctness judge. In one run, per driver:
- write: our writer makes the image; the native fsck, the kernel's mount and our own reader each compare it with the corpus;
- reverse: the kernel (mkfs and a read-write mount) or the native tool writes the image; the same three comparisons.
func RunExternal ¶ added in v0.3.0
RunExternal judges a driver against an independent reader and writer:
- write: our writer makes the image; the oracle and our own reader each compare it with the corpus;
- reverse: each native writer makes the image from the same corpus; the oracle and our reader compare it;
- extra: every file of FS_KERNEL_JUDGE_EXTRA is read by both and the two trees must be equal (no expectation of content: these are foreign files).
func SameRegime ¶ added in v0.4.0
SameRegime reports whether two calibration readings (Mops/s) are within tol of each other, relative to the larger.
Types ¶
type Builder ¶
Builder is a writer of ours that makes an image from a directory (squashfs has no read-write API: it builds).
type Calibration ¶ added in v0.4.0
type Calibration struct {
Workers int
// Mops is the aggregate speed over all workers, in millions of loop
// iterations per second (the median of the repeats).
Mops float64
// Min and Max are the slowest and fastest single worker of that repeat: a
// wide gap is a vCPU on a different kind of core; a uniformly low figure is
// every vCPU time-sliced by a busy host.
Min, Max float64
}
Calibration is one reading of the machine's speed: the fixed loop run on Workers threads at once, repeated, the median kept.
func Calibrate ¶ added in v0.4.0
func Calibrate(workers int) Calibration
Calibrate times the fixed loop on workers threads (0 = every CPU) three times and returns the median reading. It takes about half a second.
func (Calibration) String ¶ added in v0.4.0
func (c Calibration) String() string
type Caps ¶
type Caps struct {
Symlinks bool
Sparse bool // Truncate can grow a file into a hole
Mtime bool // Chtimes
Xattrs bool
}
Caps says which optional parts of a corpus a writer can honour.
func CapsOf ¶
func CapsOf(f filesystem.Filesystem) Caps
CapsOf reads off a driver's filesystem which optional parts of a corpus it can write: what it offers is judged, what it does not is not invented.
type Compare ¶
type Compare struct {
Mtime bool
MtimeTolerance time.Duration // default 2 s
Xattrs bool
Perm bool
FoldCase bool // compare names case-insensitively, without an ISO ";1" suffix
}
Compare selects what Diff holds two snapshots to.
type Driver ¶
type Driver struct {
Name string // "btrfs"
FSType string // the kernel's name for it: "btrfs", "exfat", "squashfs"
ImageSize int64 // default 256 MiB
// Our reader.
Open func(img string) (filesystem.Filesystem, error)
// Our writer: Format (read-write drivers) and/or Builders (squashfs).
Format func(img string, size int64) (filesystem.Filesystem, error)
Builders []Builder
// BuilderCaps is what a Builder is asked to carry (default: all of it).
BuilderCaps *Caps
// The kernel side. Mkfs makes an empty image for the kernel to write into
// (read-write filesystems); Natives make an image from a directory.
Mkfs []string
Natives []Native
MountOpts string
// FSCaps is what the on-disk format can hold at all (exFAT has no symlinks,
// no xattrs and no permissions). Default: everything.
FSCaps *Caps
// Fsck commands, each with {img}; every one must exit 0.
Fsck [][]string
// Compare says which metadata is held to the corpus.
Compare Compare
// Mtime reads a file's modification time when the driver has its own
// accessor and not filesystem.TimesReader.
Mtime func(f filesystem.Filesystem, path string) (time.Time, error)
Known []Known
// Pool makes the "mount" a zpool import (read-only) or create (read-write)
// of the image file instead of a loop mount: OpenZFS.
Pool *Pool
// Map changes every run's corpus (for a format with its own name rules,
// e.g. ISO 9660 level 1: 8.3 upper-case names). It must treat a directory
// and its children alike.
Map func(Entry) (Entry, bool)
// Variants add "write-<name>" runs of our writer on a changed corpus, to
// look behind a defect that hides the rest of an image.
Variants []Variant
}
Driver describes one driver to the judge.
type Entry ¶
type Entry struct {
Path string
Kind Kind
Perm fs.FileMode // permission bits; files and directories
Size int64 // logical size of a file
Head int // bytes of seeded data at the start of a file; the rest is a hole. 0 = the whole file is data
Seed uint64
Target string // symlink target
Mtime time.Time
Xattrs map[string]string
}
Entry is one object of a corpus. Path is absolute inside the filesystem.
type External ¶ added in v0.3.0
type External struct {
Name string
// Write makes an image from a corpus with our writer.
Write func(img string, es []Entry) error
// Read describes every path of an image as our reader sees it.
Read func(img string) ([]Node, error)
// Oracle describes an image as the independent reader sees it
// (OleOracle by default).
Oracle func(img string) ([]Node, error)
// Natives write an image from a directory (Args with {img}, {src}).
Natives []Native
// Map renames or drops corpus entries (names the format cannot hold).
Map func(Entry) (Entry, bool)
// ExtraSuffix selects the files of EnvExtra to compare.
ExtraSuffix string
Known []Known
}
External describes a driver whose format has no kernel filesystem (CFB). The judge is an independent reader (olefile) and an independent writer (gsf).
type Known ¶
Known is a defect already filed: a difference whose line ("<step>: <line>") matches the regular expression Match, in a test whose name matches Test (all tests when empty), is logged as known with its issue instead of failing the run. Remove the entry when the issue is fixed.
type Native ¶
Native is a writer that is not ours: a program that makes an image from a directory. Args hold {img} and {src}.
type Node ¶
type Node struct {
Path string
Kind Kind
Perm fs.FileMode
Size int64
SHA256 [32]byte // files
Target string // symlinks
Mtime time.Time
Xattrs map[string]string
}
Node is what one side says a path is.
func OleOracle ¶ added in v0.3.0
OleOracle reads a CFB file with Python's olefile (python3 -I, so no module is loaded from the current directory). The script is passed with -c and never written to disk: a fixed name in the shared temporary directory let another local user pre-create it as a symlink (clobbering a file of ours) or swap its contents between the write and python3 reading it (running their code as us).
func SnapshotDir ¶
SnapshotDir walks a directory (a kernel mount, or the source of a build) and describes every path under it.
func SnapshotFS ¶
func SnapshotFS(f filesystem.Filesystem, mtime func(f filesystem.Filesystem, path string) (time.Time, error)) ([]Node, []string)
SnapshotFS describes every path of a driver's filesystem as the driver reads it back. A read error is part of the snapshot's report, not a stop: the failing path is returned with the other errors so one defect does not hide the rest.
mtime, when not nil, reads a file's modification time for a driver that has its own accessor instead of filesystem.TimesReader.
type Options ¶
type Options struct {
LargeBytes int64 // the large file; default 32 MiB
SparseBytes int64 // logical size of the sparse file; default 16 MiB
SmallFiles int // extra small files spread over directories, for the metadata walk
Map func(Entry) (Entry, bool) // applied to every entry last (rename or drop)
SizeAlign int64 // round every non-empty file size up to a multiple of this (0 = exact sizes)
Caps Caps
}
Options sizes a corpus.
type PerfLine ¶ added in v0.4.0
type PerfLine struct {
Driver, Op, Impl string
Median float64
Unit string
// Regime is the median calibration figure (Mops/s) and Mixed is true when
// the rounds did not all share it. Known is false for a line written
// before regimes were recorded.
Regime float64
Mixed bool
Known bool
}
PerfLine is one parsed "PERF" line of a --perf run.
type PerfOptions ¶
type PerfOptions struct {
LargeBytes int64 // default 256 MiB
SmallFiles int // default 4000
Rounds int // default 5, or FS_KERNEL_JUDGE_ROUNDS
}
PerfOptions sizes the performance image.
type Pool ¶ added in v0.3.0
type Pool struct {
// Name is the pool name inside the image: our Format is given it, and the
// native writer creates it.
Name string
// CreateArgs are extra arguments for zpool create (e.g. "-o", "ashift=12").
CreateArgs []string
}
Pool describes an OpenZFS pool in an image file. The judge imports it read-only with the kernel's zfs module (zpool import -d <dir> -o readonly=on -R <mnt> <Name>) and exports it afterwards; a read-write run creates the pool (zpool create -f -O mountpoint=/ -R <mnt>), so the root dataset's files appear at <mnt>.
type Regime ¶ added in v0.4.0
Regime is the machine's speed class during one measurement round: the calibration taken before the round and the one taken after it.
func (Regime) Label ¶ added in v0.4.0
Label is the regime as printed next to a measurement: the calibration figure rounded to 50 Mops/s (so that readings of one regime print alike), with a "~" when the machine changed speed during the round.
type Regimes ¶ added in v0.4.0
type Regimes []Regime
Regimes is the list of the rounds' regimes of one measurement series.
type Result ¶
type Result struct {
Op, Impl string
Rate []float64 // MiB/s for "seq read", files/s for "walk"
Unit string
Note string
// Regimes holds, for every round, the machine's speed class measured by a
// calibration before and after it (see Calibrate).
Regimes Regimes
}
Result is one measurement series.
func RunPerf ¶
func RunPerf(t *testing.T, d Driver, o PerfOptions) []Result
RunPerf measures the kernel (mounted image) and our driver on one image written by the native tools, in the same VM, rounds interleaved, caches dropped before every measurement. Each measurement includes the mount (or Open) it needs, so the two sides pay for their own metadata.
type Variant ¶
type Variant struct {
Name string
// Opts changes the corpus options (sizes, capabilities).
Opts func(*Options)
// Map changes or drops an entry (return false to drop it). It must treat a
// directory and its children alike, or the corpus is not a tree.
Map func(Entry) (Entry, bool)
}
Variant changes the corpus of a write run.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
kerneljudge
command
Command kerneljudge runs a go-filesystems driver's judge test as root inside a Tart Linux VM, where the Linux kernel and the filesystem's native tools (btrfs check, fsck.exfat, unsquashfs, mkfs, mksquashfs) are the judges.
|
Command kerneljudge runs a go-filesystems driver's judge test as root inside a Tart Linux VM, where the Linux kernel and the filesystem's native tools (btrfs check, fsck.exfat, unsquashfs, mkfs, mksquashfs) are the judges. |