headlesstest

package
v0.2.21 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 22 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Compositor drivers for the harness: the suite itself is compositor-agnostic; the pieces that differ - how to close a client window through the compositor's own control channel, where the boot recipe records the pid, what it named the config and log - live behind this interface. LYS_UI_TEST_COMPOSITOR picks the driver ("sway" default, "hyprland"), so the same test run works against either the sway gate (just headless) or the Hyprland VM gate (tests/hyprland-vm.nix).

Package headlesstest is lys-ui's compositor-in-the-loop test harness: it attaches to a private headless compositor session (booted by the justfile's test-env recipe: sway on the wlroots headless backend with the pixman renderer, or Hyprland on its own DRM node inside the tests/hyprland-vm.nix VM - LYS_UI_TEST_COMPOSITOR picks the driver), launches a lys-ui client under test inside it, drives a synthetic seat through zwlr_virtual_pointer_v1 and zwp_virtual_keyboard_v1, and asserts on the client's observable behavior through its LYS_DEBUG trace log.

The package has two kinds of users. The unit-testable pieces (trace parsing, keymap table, compositor drivers) are plain exported functions and run everywhere. The compositor-in-the-loop tests live in this package's _test files and are gated by the LYS_TEST_HEADLESS environment variable:

  • LYS_TEST_HEADLESS unset or empty: the integration tests skip, so a plain `go test ./...` on a machine with no compositor passes.
  • LYS_TEST_HEADLESS set (CI, or `just headless`): the tests are required. The harness attaches to the running compositor via WAYLAND_DISPLAY/XDG_RUNTIME_DIR; if the env is not there, the run fails - a skip under LYS_TEST_HEADLESS would be a silent hole.

The session is isolated from the developer's desktop: the compositor runs against its own runtime dir, and the recipe's teardown removes it after the run.

The Hyprland driver for the VM gate (tests/hyprland-vm.nix): compositor-side actions go through Hyprland's own control socket - a plain request/reply channel at $XDG_RUNTIME_DIR/hypr/<instance>/.socket.sock - so the same kill by compositor command the sway tests use works here too.

sway IPC access for the compositor-in-the-loop tests: some scenarios need the COMPOSITOR to act on a client - a close request delivered while the window is fullscreen, say - and the synthetic seat cannot express that. The recipe boots sway with its IPC socket in the session's private runtime dir; this file speaks the small i3/sway wire protocol (magic, length, type, payload) so tests run swaymsg commands against the live compositor.

Index

Constants

View Source
const (
	BTNLeft  = 0x110
	BTNRight = 0x111
)

Pointer button codes (linux/input-event-codes.h), the values wl_pointer.button carries.

View Source
const (
	KeyEscape = 1
	KeyTab    = 15
	KeyEnter  = 28
	KeyA      = 30
	KeyD      = 32
	KeyC      = 46
	KeyV      = 47
	KeySpace  = 57
	KeyHome   = 102
	KeyLeft   = 105
	KeyRight  = 106
	KeyEnd    = 107
	KeyDown   = 108
	KeyUp     = 103
)

evdev key codes the suite drives (linux/input-event-codes.h). The compositor maps them through the seat's keymap when it has one; the client under test decodes keycodes with its built-in US fallback regardless, so codes behave as they would from a physical US keyboard.

View Source
const (
	ModShift uint32 = 1 << 0
	ModCtrl  uint32 = 1 << 2
)

xkb modifier masks, the values wl_keyboard.modifiers and zwp_virtual_keyboard_v1.modifiers exchange (Shift, Lock, Control, Alt from bit 0).

View Source
const AppID = "dev.stubbe.lys.ui.hello"

AppID is the Wayland app_id of the showcase client under test. The test-env recipe's sway config pins it to a floating 640x470 window at the output's origin so widget coordinates traced by the client are compositor coordinates.

View Source
const MultilistAppID = "dev.stubbe.lys.ui.multilist"

MultilistAppID is the Wayland app_id of the multi-select list client (cmd/lys-ui-multilist). The recipe's sway rule pins it to a floating window beside the showcase, so the row centers the client traces are compositor coordinates.

View Source
const StatesAppID = "dev.stubbe.lys.ui.states"

StatesAppID is the Wayland app_id of the window-state client (cmd/lys-ui-states). The recipe's sway rule pins it to a floating 420x280 window, so the confirmed maximize/fullscreen configure sizes are deterministic: the 1280x800 output mode for the state-sized configure, the pinned 420x280 for the restored one.

Variables

This section is empty.

Functions

func BuildClient

func BuildClient(dir, pkg, bin string) (string, error)

BuildClient compiles one lys-ui command package with the lysdebug tag (trace calls are compiled out otherwise) into dir/bin and returns the binary path.

func BuildShowcase

func BuildShowcase(dir string) (string, error)

BuildShowcase compiles the widget showcase with the lysdebug tag (its trace calls are compiled out otherwise) into dir/lys-ui-hello and returns the binary path.

func KeyFor

func KeyFor(r rune) (code uint32, shift bool, err error)

KeyFor maps a rune to the evdev key code that produces it under the US layout the test keymap carries, plus whether shift must be held. The table covers exactly what the suite types; an unmapped rune is a harness bug and errors instead of silently typing the wrong key.

func ModuleDir

func ModuleDir() (string, error)

ModuleDir locates the lys-ui module root by walking up from the current directory (the tests run inside the module tree), so the harness can build cmd targets without assuming a working directory.

func WireServer

func WireServer(t *testing.T, display string) <-chan WireFrame

WireServer listens on a LoopbackDisplay and drains every request the first client sends into the returned channel, so a test pins the bytes a binding actually writes. The wayland connection is endianness-native, so the decoder is too. The listener closes at cleanup.

Types

type Client

type Client struct {
	Name    string
	LogPath string
	// contains filtered or unexported fields
}

Client is one run of the client under test inside an Env, with its stderr and stdout going to a log file a LogWatcher can follow.

func (*Client) Exited

func (c *Client) Exited() <-chan struct{}

Exited returns a channel that closes once the client process has exited and been reaped. Tests arm it to assert the client SURVIVED an event (a tooltip, a grab) - a dead client passes every trace wait that already matched, so survival needs its own assertion.

func (*Client) Stop

func (c *Client) Stop()

Stop kills the client if it is still running and reaps it. Safe in any order relative to Wait and any number of times.

func (*Client) Wait

func (c *Client) Wait() error

Wait blocks until the client process exits (e.g. after the Escape key closed the window) and reports whether it exited cleanly. A nonzero exit or signal death comes back as the error.

func (*Client) Watch

func (c *Client) Watch() (*LogWatcher, error)

Watch attaches a LogWatcher to this client's log.

type Compositor

type Compositor interface {
	// Name is the driver's LYS_UI_TEST_COMPOSITOR value, also the
	// substring the failure diagnostics grep procfs for.
	Name() string
	// ConfigName is the compositor config file the recipe writes into
	// the session dir ("sway.cfg"). The path survives daemonizing, so
	// it is the reliable kill pattern.
	ConfigName() string
	// PIDName is the file the recipe records the compositor pid into
	// ("sway.pid").
	PIDName() string
	// LogName is the file the recipe redirects compositor output to
	// ("sway.log").
	LogName() string
	// CloseWindow asks the compositor, through its own control
	// channel, to close the client window carrying this app_id - the
	// real xdg_toplevel.close delivery the synthetic seat cannot
	// express. dir is the session's private runtime dir.
	CloseWindow(dir, appID string) error
	// CanRestart reports whether Restart is supported - asked before a
	// test kills the compositor it could not bring back.
	CanRestart() bool
	// Restart boots the compositor again in dir after a kill, on the
	// same display socket name - the reconnect scenario.
	Restart(dir string) error
}

Compositor is the compositor-specific slice of the harness. Every method names an artifact the boot recipe owns: the recipe writes the config the kill pattern points at, records the pid, and redirects the compositor's own output to the log, so the driver only carries the names and the control protocol.

type Env

type Env struct {
	// Dir is the session's private XDG_RUNTIME_DIR (mode 0700). The
	// recipe logs the compositor to its driver's LogName inside it;
	// client logs and the built showcase binary land here too.
	Dir string
	// Display is the WAYLAND_DISPLAY socket name (e.g. "wayland-1").
	Display string
	// contains filtered or unexported fields
}

Env is the private headless compositor session the tests run against: the runtime dir the justfile's test-env recipe booted sway into, and the WAYLAND_DISPLAY socket name inside it. The harness never starts the compositor itself - booting it is the recipe's job (the proven path: sway on wlroots' headless backend with the pixman renderer inside a private XDG_RUNTIME_DIR, socket polled until it appears) - so the test binary carries no boot knowledge and the env outlives it, shared by every test in the run. Which compositor is attached is the driver's business: LYS_UI_TEST_COMPOSITOR names it ("sway" default, "hyprland" for the VM gate).

func Attach

func Attach() (*Env, error)

Attach connects the harness to the compositor the caller booted: the process environment carries WAYLAND_DISPLAY and XDG_RUNTIME_DIR (exported by the just headless recipe, or by hand after just test-env). An error names what is missing, so a mis-wired run fails with the fix in the message instead of a connection timeout deep inside the first test.

func (*Env) CanRestartCompositor

func (e *Env) CanRestartCompositor() bool

CanRestartCompositor reports whether RestartCompositor works here.

func (*Env) CloseWindow

func (e *Env) CloseWindow(appID string) error

CloseWindow asks the compositor to close the client window with the given app_id (the real xdg_toplevel.close delivery).

func (*Env) Compositor

func (e *Env) Compositor() Compositor

Compositor is the driver for the attached session; tests reach the compositor-specific names and actions through it.

func (*Env) KillCompositor

func (e *Env) KillCompositor()

KillCompositor SIGKILLs the compositor serving this session, by the config path recorded in its cmdline - the only trace a daemonizing compositor leaves behind.

func (*Env) LogPath

func (e *Env) LogPath() string

LogPath is the file the boot recipe redirects the compositor's own output to - the first place a failed assertion points at.

func (*Env) PIDPath

func (e *Env) PIDPath() string

PIDPath is the file the boot recipe records the compositor pid in.

func (*Env) RestartCompositor

func (e *Env) RestartCompositor() error

RestartCompositor boots the compositor again after KillCompositor, on the same display.

func (*Env) StartClient

func (e *Env) StartClient(bin, name, categories string, args ...string) (*Client, error)

StartClient runs a built client binary inside the env with the given LYS_DEBUG categories and extra arguments, its stdout and stderr going to a log file a LogWatcher can follow. The caller must Stop it (or Wait it after a close request).

func (*Env) StartClientEnv

func (e *Env) StartClientEnv(bin, name, categories string, env []string, args ...string) (*Client, error)

StartClientEnv is StartClient with extra environment entries (KEY=value), for knobs such as LYS_UI_NO_CURSOR_SHAPE.

func (*Env) StartShowcase

func (e *Env) StartShowcase(bin, name string) (*Client, error)

StartShowcase runs the showcase binary inside the env with input, frame, seat, wire and demo tracing on, and returns the handle. The caller must Stop it (or Wait it after a close request).

type LogWatcher

type LogWatcher struct {
	// contains filtered or unexported fields
}

LogWatcher follows one client log from its current end, handing out only traces that arrived after the previous Wait: consecutive Waits assert order without re-matching older lines. Lines read but not yet matched stay pending, so a burst written between two polls is delivered one Wait at a time instead of being swallowed by whichever Wait ran first. It is safe for one goroutine at a time (the tests are sequential).

func Watch

func Watch(path string) (*LogWatcher, error)

Watch starts following the log at path from its current size, so a watcher only sees what happens after it was attached.

func (*LogWatcher) CountSince

func (w *LogWatcher) CountSince(mark int, category, substr string) int

CountSince counts the traces in category containing substr that arrived after mark, without consuming anything.

func (*LogWatcher) Mark

func (w *LogWatcher) Mark() int

Mark is a position in the watcher's history, for SeenSince and WaitSince.

func (*LogWatcher) MaxGapSince

func (w *LogWatcher) MaxGapSince(mark int, category, substr string) float64

MaxGapSince returns the largest pause in seconds between consecutive traces in category containing substr after mark, counting the wait for the first such trace from mark itself and the silence after the last one up to the newest trace of any kind. Software renderers under suite load present slowly but steadily; a pacing bug stops outright, and this is the signal that tells them apart from a low frame count.

func (*LogWatcher) SeenSince

func (w *LogWatcher) SeenSince(mark int, category, substr string) bool

SeenSince reports whether a trace in category containing substr arrived after mark, without consuming anything.

func (*LogWatcher) Since

func (w *LogWatcher) Since(mark int) []Trace

Since returns the traces that arrived after mark, oldest first, without consuming anything.

func (*LogWatcher) Tail

func (w *LogWatcher) Tail(n int) []Trace

Tail returns up to n most recent traces seen so far, oldest first, for failure messages.

func (*LogWatcher) Wait

func (w *LogWatcher) Wait(category, substr string, timeout time.Duration) (Trace, error)

Wait polls the log until a trace in category containing substr arrives, and returns it. category "" matches any line (including non-trace output). On timeout the error carries the tail of what did arrive, which is the failure evidence for the suite.

func (*LogWatcher) WaitAll

func (w *LogWatcher) WaitAll(category string, timeout time.Duration, substrs ...string) error

WaitAll is Wait for a set: it waits until each substr has arrived (one trace per substr, in ANY order) since this call began. State transitions produce two racing traces - the confirmed-state line and the relayout draw - and a sequential Wait would consume whichever came first, starving the other. Unconsumed traces left over from earlier waits are discarded at the start, so a phase can only be satisfied by its own window.

func (*LogWatcher) WaitEver

func (w *LogWatcher) WaitEver(category, substr string, timeout time.Duration) error

WaitEver waits until a trace in category containing substr has arrived at any point since the watcher attached - lines earlier Waits already passed included - and consumes nothing: for state that holds once reached (a window's keyboard focus) rather than an event in a sequence.

func (*LogWatcher) WaitSince

func (w *LogWatcher) WaitSince(mark int, category, substr string, timeout time.Duration) error

WaitSince waits until a trace in category containing substr has arrived after mark, consuming nothing: an event the caller marked the start of, whether or not a Wait already read past it.

type Trace

type Trace struct {
	Secs     float64
	Category string
	Message  string
}

Trace is one line of the client's LYS_DEBUG output: "<secs>s <category>: <message>" (see internal/debug). Lines that do not parse as traces (plain log.Fatal output, Go panics) keep Category empty and carry the whole line as Message, so the watcher can also wait for them.

func ParseTraces

func ParseTraces(data []byte) []Trace

ParseTraces extracts the trace lines from a log snapshot.

func (Trace) String

func (t Trace) String() string

type VirtualInput

type VirtualInput struct {
	// contains filtered or unexported fields
}

VirtualInput is a connected synthetic-seat client over a vinput.Device. One instance per test keeps focus, grab and keymap state from bleeding between tests.

func Dial

func Dial(display string) (*VirtualInput, error)

Dial connects to the compositor socket named by WAYLAND_DISPLAY in the process's XDG_RUNTIME_DIR, binds the seat and the virtual-input managers, and creates a pointer and a keyboard. If the seat offers a keymap it is relayed to the virtual keyboard; when it does not (a virtual-only seat may never have compiled one), keys are injected raw and modifiers are pushed explicitly through zwp_virtual_keyboard_v1.modifiers - the client under test decodes keycodes with its own US fallback either way.

func DialKeymap

func DialKeymap(display, keymap string) (*VirtualInput, error)

DialKeymap connects with a keyboard that uploads keymap, the way wtype and other virtual keyboards number keys their own way.

func DialPointerOnly

func DialPointerOnly(display string) (*VirtualInput, error)

DialPointerOnly connects with a virtual pointer and no keyboard: the shape of a seat whose input devices are pointers only. Widgets that open surfaces on hover (tooltips, popups) must survive and behave there exactly as with a keyboard present.

func (*VirtualInput) ClickAt

func (v *VirtualInput) ClickAt(x, y int, button uint32) error

ClickAt presses and releases button at (x, y), arriving there with motion (MoveOnto).

func (*VirtualInput) Close

func (v *VirtualInput) Close()

Close destroys the virtual devices and disconnects.

func (*VirtualInput) Combo

func (v *VirtualInput) Combo(code uint32) error

Combo holds the ctrl modifier, taps key, releases it: ctrl+c and friends.

func (*VirtualInput) DoubleClickAt

func (v *VirtualInput) DoubleClickAt(x, y int, button uint32) error

DoubleClickAt clicks button twice at (x, y) as one burst: one move (MoveOnto), then both press/release pairs back to back with a single roundtrip, so the pair stays inside any double-click interval however slow the compositor's roundtrips are.

func (*VirtualInput) DragTo

func (v *VirtualInput) DragTo(x0, y0, x1, y1 int, steps int) error

DragTo presses at (x0, y0), moves in steps to (x1, y1), and releases there: the gesture drag-driven widgets need (a plain click neither moves a slider nor drags a scrollbar).

func (*VirtualInput) FingerScrollAt

func (v *VirtualInput) FingerScrollAt(x, y int, dy float64) error

FingerScrollAt scrolls by dy at (x, y) as a touchpad does: finger frames carrying dy, then the frame that lifts the fingers.

func (*VirtualInput) MoveOnto

func (v *VirtualInput) MoveOnto(x, y int) error

MoveOnto moves the pointer onto (x, y) so the compositor always sees motion arriving there, from a pixel off: a window can map under a pointer that already rests on the spot (the client traces its layout before its first frame lands), or a retry can aim at the spot the last attempt left the pointer on - and a compositor that sends no enter for a surface appearing under a resting cursor (Hyprland) then leaves the press with no surface at all.

func (*VirtualInput) MoveTo

func (v *VirtualInput) MoveTo(x, y int) error

MoveTo moves the pointer to compositor coordinates (x, y).

func (*VirtualInput) ScrollAt

func (v *VirtualInput) ScrollAt(x, y int, dy float64) error

ScrollAt sends a wheel tick at (x, y); dy is in wayland axis units, positive down.

func (*VirtualInput) Tap

func (v *VirtualInput) Tap(code uint32) error

Tap presses and releases one key.

func (*VirtualInput) TypeText

func (v *VirtualInput) TypeText(s string) error

TypeText types s: lowercase letters, digits and spaces. Anything else is a harness bug (a test asking for a key the table does not know), so it errors instead of guessing.

type WireFrame

type WireFrame struct {
	Obj    uint32
	Opcode uint32
	Body   []byte
}

WireFrame is one request as it hit a WireServer: object id, opcode, and the payload words.

func WaitForFrame

func WaitForFrame(t *testing.T, frames <-chan WireFrame, name string, match func(WireFrame) bool) WireFrame

WaitForFrame consumes frames until one matches, failing the test after two seconds; the buffered noise passes through.

func (WireFrame) Word

func (f WireFrame) Word(i int) int32

Word reads payload word i as int32.

Directories

Path Synopsis
Package inproc runs lys-ui applications inside a test process against the headless compositor and inspects the output through screencopy: the in-process half of the compositor-in-the-loop suite, for tests that drive the app API directly instead of a demo client.
Package inproc runs lys-ui applications inside a test process against the headless compositor and inspects the output through screencopy: the in-process half of the compositor-in-the-loop suite, for tests that drive the app API directly instead of a demo client.

Jump to

Keyboard shortcuts

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