1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2022 Maxim Cournoyer <maxim.cournoyer@gmail.com>.
4 ;;; This file is part of GNU Guix.
6 ;;; GNU Guix is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or (at
9 ;;; your option) any later version.
11 ;;; GNU Guix is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19 (define-module (gnu tests vnc)
20 #:use-module (gnu bootloader)
21 #:use-module (gnu bootloader grub)
22 #:use-module (gnu packages)
23 #:use-module (gnu packages ocr)
24 #:use-module (gnu packages glib)
25 #:use-module (gnu packages gnome)
26 #:use-module (gnu packages ratpoison)
27 #:use-module (gnu packages vnc)
28 #:use-module (gnu packages xorg)
29 #:use-module (gnu services)
30 #:use-module (gnu services dbus)
31 #:use-module (gnu services desktop)
32 #:use-module (gnu services networking)
33 #:use-module (gnu services ssh)
34 #:use-module (gnu services vnc)
35 #:use-module (gnu services xorg)
36 #:use-module (gnu system)
37 #:use-module (gnu system file-systems)
38 #:use-module (gnu system shadow)
39 #:use-module (gnu system vm)
40 #:use-module (gnu tests)
41 #:use-module (guix gexp)
42 #:use-module (guix modules)
43 #:export (%test-xvnc))
48 (host-name "komputilo")
49 (timezone "Europe/Berlin")
50 (locale "en_US.UTF-8")
51 (bootloader (bootloader-configuration
52 (bootloader grub-bootloader)
53 (targets '("/dev/sdX"))))
54 (file-systems (cons (file-system
55 (device (file-system-label "my-root"))
60 (users (cons (user-account
63 (supplementary-groups '("wheel" "netdev"
66 (packages (cons* dbus ;for dbus-run-session
70 gnome-settings-daemon ;for schemas
76 (service openssh-service-type (openssh-configuration
77 (permit-root-login #t)
78 (allow-empty-passwords? #t)))
79 (service xvnc-service-type (xvnc-configuration
81 (security-types (list "None"))
86 (modify-services %desktop-services
87 (gdm-service-type config => (gdm-configuration
95 (define (run-xvnc-test)
96 "Run tests in %XVNC-OS."
98 (define os (marionette-operating-system
100 #:imported-modules (source-module-closure
101 '((gnu services herd)))))
103 (define vm (virtual-machine
104 (operating-system os)
108 (with-imported-modules (source-module-closure
109 '((gnu build marionette)
112 (use-modules (gnu build marionette)
117 (let ((marionette (make-marionette (list #$vm))))
119 (test-runner-current (system-test-runner #$output))
122 (test-assert "service running"
125 (use-modules (gnu services herd))
126 (start-service 'xvnc))
129 (test-assert "wait for port 5905, IPv4"
130 (wait-for-tcp-port 5905 marionette))
132 (test-assert "wait for port 5905, IPv6"
133 (wait-for-tcp-port 5905 marionette
135 '(make-socket-address
136 AF_INET6 (inet-pton AF_INET6 "::1") 5905)))
138 (test-assert "gdm auto-suspend is disabled"
139 ;; More a GDM than a Xvnc test, but since it's a cross-cutting
140 ;; concern and we have everything set up here, we might as well
144 ;; Check that DCONF_PROFILE is set...
145 (invoke "/bin/sh" "-lc" "\
146 pgrep gdm | head -n1 | xargs -I{} grep -Fq DCONF_PROFILE /proc/{}/environ")
149 (invoke "/bin/sh" "-lc" "\
150 sudo -E -u gdm env DCONF_PROFILE=/etc/dconf/profile/gdm dbus-run-session \
151 gsettings get org.gnome.settings-daemon.plugins.power sleep-inactive-ac-type \
152 | grep -Fq nothing"))
155 (test-assert "vnc lands on the gdm login screen"
156 ;; This test runs vncviewer on the local VM and verifies that it
157 ;; manages to access the GDM login screen (via XDMCP).
159 (define (ratpoison-abort)
160 (marionette-control "sendkey ctrl-g" marionette))
162 (define (ratpoison-help)
163 (marionette-control "sendkey ctrl-t" marionette)
164 (marionette-type "?" marionette)
165 (sleep 1)) ;wait for help screen to appear
167 (define (ratpoison-exec command)
168 (marionette-control "sendkey ctrl-t" marionette)
169 (marionette-type "!" marionette)
170 (marionette-type (string-append command "\n") marionette))
172 ;; Wait until the ratpoison help screen can be displayed; this
173 ;; means the window manager is ready.
174 (wait-for-screen-text marionette
175 (cut string-contains <> "key bindings")
176 #:ocr #$(file-append tesseract-ocr
178 #:pre-action ratpoison-help
179 #:post-action ratpoison-abort)
181 ;; Run vncviewer and expect the GDM login screen (accessed via
182 ;; XDMCP). This can take a while to appear on slower machines.
183 (ratpoison-exec "vncviewer localhost:5905")
184 ;; XXX: tesseract narrowly recognizes "Guix" as "uix" from the
185 ;; background image; ocrad fares worst. Sadly, 'Username' is
186 ;; not recognized at all.
187 (wait-for-screen-text marionette
188 (cut string-contains <> "uix")
189 #:ocr #$(file-append tesseract-ocr
195 (gexp->derivation "xvnc-test" test))
200 (description "Basic tests for the Xvnc service. One of the tests validate
201 that XDMCP works with GDM, and is therefore heavy in terms of disk and memory
203 (value (run-xvnc-test))))