98 lines
2.6 KiB
Go
98 lines
2.6 KiB
Go
// Fenrir console screen reader.
|
|
// Copyright (c) 2026 Storm Dragon
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify it
|
|
// under the terms of the GNU General Public License as published by the Free
|
|
// Software Foundation, either version 3 of the License, or (at your option)
|
|
// any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
// more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License along with
|
|
// this program. If not, see <https://www.gnu.org/licenses/gpl-3.0.html>.
|
|
|
|
//go:build linux && cgo
|
|
|
|
package console
|
|
|
|
import (
|
|
"net"
|
|
"syscall"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// TCP urgent data exercises the same kernel POLLPRI/acknowledge/rearm contract
|
|
// as VCSA without requiring a real console, privileges or physical input.
|
|
func TestPriorityReadinessAcknowledgementAndRearm(t *testing.T) {
|
|
listener, err := net.ListenTCP("tcp", &net.TCPAddr{IP: net.IPv4(127, 0, 0, 1)})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer listener.Close()
|
|
writer, err := net.DialTCP("tcp", nil, listener.Addr().(*net.TCPAddr))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer writer.Close()
|
|
reader, err := listener.AcceptTCP()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer reader.Close()
|
|
readControl, err := reader.SyscallConn()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
writeControl, err := writer.SyscallConn()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
watcher, err := newReadinessWatcher(syscall.EPOLLPRI)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer watcher.close()
|
|
var operationErr error
|
|
if err := readControl.Control(func(fd uintptr) { operationErr = watcher.add(int(fd)) }); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if operationErr != nil {
|
|
t.Fatal(operationErr)
|
|
}
|
|
for range 2 {
|
|
if err := writeControl.Control(func(fd uintptr) {
|
|
operationErr = syscall.Sendto(int(fd), []byte{1}, syscall.MSG_OOB, nil)
|
|
}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if operationErr != nil {
|
|
t.Fatal(operationErr)
|
|
}
|
|
select {
|
|
case err := <-watcher.events:
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
case <-time.After(time.Second):
|
|
t.Fatal("priority data did not wake the watcher")
|
|
}
|
|
if err := readControl.Control(func(fd uintptr) {
|
|
var data [1]byte
|
|
_, _, operationErr = syscall.Recvfrom(int(fd), data[:], syscall.MSG_OOB)
|
|
if operationErr == nil {
|
|
operationErr = watcher.arm(int(fd))
|
|
}
|
|
}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if operationErr != nil {
|
|
t.Fatal(operationErr)
|
|
}
|
|
}
|
|
}
|