// 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 . //go:build linux && cgo package console import ( "encoding/binary" "errors" "fmt" "os" "path/filepath" "strings" "testing" ) func TestSourceWaitsForConsoleOwner(t *testing.T) { for _, terminal := range []int{2, 15} { t.Run(fmt.Sprint(terminal), func(t *testing.T) { root := t.TempDir() activePath := filepath.Join(root, "sys/devices/virtual/tty/tty0/active") if err := os.MkdirAll(filepath.Dir(activePath), 0700); err != nil { t.Fatal(err) } if err := os.WriteFile(activePath, fmt.Appendf(nil, "tty%d\n", terminal), 0600); err != nil { t.Fatal(err) } // Other occupied consoles (including tty1) must not make this one // appear occupied. There are deliberately no target device files yet. mask := uint16(3) stateCalls := 0 source := &Source{ root: root, usage: func(path string) (uint16, error) { if path != filepath.Join(root, "dev/tty1") { t.Fatalf("usage query opened target or foreground alias: %s", path) } return mask, nil }, state: func(path string) (bool, bool, bool, error) { stateCalls++ if mask&(uint16(1)<