v0.3.0 96f3aeb

format_table_test.go RawHistoryFolder

1//go:build linux
2
3package protocol_test
4
5import (
6	"errors"
7	"github.com/bnema/wlturbo"
8	"github.com/bnema/wlturbo/protocol/linuxdmabuf"
9	"golang.org/x/sys/unix"
10	"io"
11	"os"
12	"testing"
13)
14
15// Exercise format_table through generated event dispatch so the received FD
16// has real transport ownership; verify closing by inspecting the taken FD.
17func TestMalformedFormatTables(t *testing.T) {
18	for _, tc := range []struct {
19		name     string
20		contents []byte
21		size     uint32
22		wantErr  bool
23	}{
24		{"unaligned", make([]byte, 16), 17, true},
25		{"truncated", make([]byte, 16), 32, true},
26		{"zero", nil, 0, false},
27		{"oversize", nil, (16 << 20) + 16, true},
28	} {
29		t.Run(tc.name, func(t *testing.T) {
30			c, p := pair(t)
31			d, e := wlturbo.ConnectFromConn(c)
32			noerr(t, e)
33			defer d.Close()
34			request(t, p)
35			fb := linuxdmabuf.NewLinuxDmabufFeedback(d.Context())
36			fb.SetID(d.AllocateID())
37			d.Context().Register(fb)
38			file, e := os.CreateTemp(t.TempDir(), "table")
39			noerr(t, e)
40			defer file.Close()
41			_, e = file.Write(tc.contents)
42			noerr(t, e)
43			called := false
44			fb.OnFormatTable(func(fd *wlturbo.OwnedFD, size uint32) {
45				called = true
46				entries, err := linuxdmabuf.ReadFormatTable(fd, size)
47				if (err != nil) != tc.wantErr {
48					t.Fatalf("size=%d entries=%v err=%v", size, entries, err)
49				}
50				if tc.name == "truncated" && !errors.Is(err, io.ErrUnexpectedEOF) {
51					t.Fatalf("short read: %v", err)
52				}
53				// Take/Close must be idempotent, including after a failed size check.
54				if _, err = fd.Take(); err == nil {
55					t.Fatal("already consumed fd still takeable")
56				}
57				noerr(t, fd.Close())
58				noerr(t, fd.Close())
59			})
60			send(t, p, msg(fb.ID(), 1, tc.size), int(file.Fd()))
61			noerr(t, d.Dispatch())
62			if !called {
63				t.Fatal("no callback")
64			}
65			// The transport FD was a duplicate: caller's descriptor is still open.
66			if _, e = unix.FcntlInt(file.Fd(), unix.F_GETFD, 0); e != nil {
67				t.Fatalf("sender fd closed: %v", e)
68			}
69		})
70	}
71}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 8

↑↓ moveenter openesc close