feat: add bounded display_diag journal diagnostics for the OSD (#3)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package display
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
@@ -498,6 +499,121 @@ func TestCreateWindowValuesOmitCursorWhenUnavailable(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// scriptedQueries scripts the one-time query bundle: fixed answers for
|
||||
// shape extents, geometry, parent and stacking position, with an optional
|
||||
// shape query error.
|
||||
type scriptedQueries struct {
|
||||
shape string
|
||||
geom string
|
||||
parent string
|
||||
pos string
|
||||
of string
|
||||
shapeErr error
|
||||
}
|
||||
|
||||
func (q *scriptedQueries) ShapeExtents(xproto.Window) (string, error) {
|
||||
return q.shape, q.shapeErr
|
||||
}
|
||||
|
||||
func (q *scriptedQueries) Geometry(xproto.Window) (string, error) {
|
||||
return q.geom, nil
|
||||
}
|
||||
|
||||
func (q *scriptedQueries) Parent(xproto.Window) (string, error) {
|
||||
return q.parent, nil
|
||||
}
|
||||
|
||||
func (q *scriptedQueries) StackPosition(xproto.Window) (string, string, error) {
|
||||
return q.pos, q.of, nil
|
||||
}
|
||||
|
||||
func TestRecordFlushEmitsFirstRedrawAndQueryBundleOnce(t *testing.T) {
|
||||
var buf bytes.Buffer
|
||||
presence := NewVideoPresence()
|
||||
session := &x11Session{
|
||||
role: RoleAbove,
|
||||
diag: NewDiag(&buf),
|
||||
video: presence,
|
||||
width: 1920,
|
||||
height: 1080,
|
||||
lastTrigger: "initial",
|
||||
queries: &scriptedQueries{
|
||||
shape: "196x106+28+15", geom: "1920x1080+0+26",
|
||||
parent: "0x1a00001", pos: "1", of: "3",
|
||||
},
|
||||
}
|
||||
session.drawn = []xproto.Rectangle{
|
||||
{X: 30, Y: 19, Width: 58, Height: 18},
|
||||
{X: 30, Y: 51, Width: 196, Height: 18},
|
||||
{X: 30, Y: 83, Width: 120, Height: 18},
|
||||
}
|
||||
|
||||
session.recordFlush(nil)
|
||||
session.recordFlush(nil) // the bundle and the first-redraw record are once-only
|
||||
|
||||
lines := strings.Split(strings.TrimSpace(buf.String()), "\n")
|
||||
if len(lines) != 2 {
|
||||
t.Fatalf("lines=%v want exactly the first_redraw and query records", lines)
|
||||
}
|
||||
wantFirst := "display_diag kind=first_redraw role=osd trigger=initial ops=0 regions=3 bounds=196x82+30+19 snap=none video=off stack=top ok"
|
||||
if lines[0] != wantFirst {
|
||||
t.Fatalf("first_redraw=%q want %q", lines[0], wantFirst)
|
||||
}
|
||||
wantQuery := "display_diag kind=query role=osd shape=196x106+28+15 geom=1920x1080+0+26 parent=0x1a00001 stack=1/3"
|
||||
if lines[1] != wantQuery {
|
||||
t.Fatalf("query=%q want %q", lines[1], wantQuery)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRecordFlushReportsShapeErrorsWithoutBlockingTheLayer(t *testing.T) {
|
||||
var buf bytes.Buffer
|
||||
session := &x11Session{
|
||||
role: RoleAbove,
|
||||
diag: NewDiag(&buf),
|
||||
video: NewVideoPresence(),
|
||||
lastTrigger: "refresh",
|
||||
queries: &scriptedQueries{shapeErr: errors.New("BadWindow")},
|
||||
}
|
||||
|
||||
// The shape error arrives with the first flush: it must be carried by
|
||||
// the first_redraw record and the query bundle reports its own query
|
||||
// failure alongside.
|
||||
session.recordFlush(errors.New("bounding shape: BadWindow"))
|
||||
session.recordFlush(nil)
|
||||
|
||||
lines := strings.Split(strings.TrimSpace(buf.String()), "\n")
|
||||
if len(lines) != 2 {
|
||||
t.Fatalf("lines=%v want the first_redraw error record and the query error record", lines)
|
||||
}
|
||||
if !strings.Contains(lines[0], "ok=no") || !strings.Contains(lines[0], "err=bounding shape: BadWindow") {
|
||||
t.Fatalf("first_redraw=%q must carry the shape error", lines[0])
|
||||
}
|
||||
if !strings.Contains(lines[1], "err=") {
|
||||
t.Fatalf("query=%q must carry the query error", lines[1])
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetDiagSnapshotEmitsTransitionsOnly(t *testing.T) {
|
||||
var buf bytes.Buffer
|
||||
session := &x11Session{role: RoleAbove, diag: NewDiag(&buf)}
|
||||
|
||||
session.SetDiagSnapshot("none")
|
||||
session.SetDiagSnapshot("none")
|
||||
session.SetDiagSnapshot("fresh")
|
||||
session.SetDiagSnapshot("fresh")
|
||||
session.SetDiagSnapshot("stale")
|
||||
|
||||
lines := strings.Split(strings.TrimSpace(buf.String()), "\n")
|
||||
if len(lines) != 3 {
|
||||
t.Fatalf("lines=%v want none, fresh and stale transitions only", lines)
|
||||
}
|
||||
for i, want := range []string{"none", "fresh", "stale"} {
|
||||
if !strings.Contains(lines[i], "kind=snap") || !strings.Contains(lines[i], "state="+want) {
|
||||
t.Fatalf("line %d=%q want the %s transition", i, lines[i], want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestTransparentShapesEmptyInputAndOutput(t *testing.T) {
|
||||
var input, output bool
|
||||
for _, kind := range transparentShapeKinds() {
|
||||
|
||||
Reference in New Issue
Block a user