gnu: ardour: Update to 7.0
[jackhill/guix/guix.git] / gnu / tests / lightdm.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2022 Maxim Cournoyer <maxim.cournoyer@gmail.com>.
3 ;;;
4 ;;; This file is part of GNU Guix.
5 ;;;
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.
10 ;;;
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.
15 ;;;
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/>.
18
19 (define-module (gnu tests lightdm)
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 ratpoison)
25 #:use-module (gnu packages vnc)
26 #:use-module (gnu packages xorg)
27 #:use-module (gnu services)
28 #:use-module (gnu services base)
29 #:use-module (gnu services dbus)
30 #:use-module (gnu services desktop)
31 #:use-module (gnu services networking)
32 #:use-module (gnu services lightdm)
33 #:use-module (gnu services ssh)
34 #:use-module (gnu services xorg)
35 #:use-module (gnu system)
36 #:use-module (gnu system file-systems)
37 #:use-module (gnu system shadow)
38 #:use-module (gnu system vm)
39 #:use-module (gnu tests)
40 #:use-module (guix gexp)
41 #:use-module (guix modules)
42 #:use-module (srfi srfi-1)
43 #:export (%test-lightdm))
44
45 (define minimal-desktop-services
46 (list polkit-wheel-service
47 (service upower-service-type)
48 (accountsservice-service)
49 (service polkit-service-type)
50 (elogind-service)
51 (dbus-service)
52 x11-socket-directory-service))
53
54 (define %lightdm-os
55 (operating-system
56 (inherit %simple-os)
57 (packages (cons* ocrad ratpoison xterm %base-packages))
58 (services
59 (cons* (service lightdm-service-type
60 (lightdm-configuration
61 (allow-empty-passwords? #t)
62 (debug? #t)
63 (xdmcp? #t)
64 (vnc-server? #t)
65 (vnc-server-command
66 (file-append tigervnc-server "/bin/Xvnc"
67 " -SecurityTypes None"))
68 (greeters (list (lightdm-gtk-greeter-configuration
69 (allow-debugging? #t))))
70 (seats (list (lightdm-seat-configuration
71 (name "*")
72 (user-session "ratpoison"))))))
73
74 ;; For debugging.
75 (service dhcp-client-service-type)
76 (service openssh-service-type
77 (openssh-configuration
78 (permit-root-login #t)
79 (allow-empty-passwords? #t)))
80 (append minimal-desktop-services
81 (remove (lambda (service)
82 (eq? (service-kind service) guix-service-type))
83 %base-services))))))
84
85 (define (run-lightdm-test)
86 "Run tests in %LIGHTDM-OS."
87
88 (define os (marionette-operating-system
89 %lightdm-os
90 #:imported-modules (source-module-closure
91 '((gnu services herd)))))
92
93 (define vm (virtual-machine os))
94
95 (define test
96 (with-imported-modules (source-module-closure
97 '((gnu build marionette)))
98 #~(begin
99 (use-modules (gnu build marionette)
100 (srfi srfi-26)
101 (srfi srfi-64))
102
103 (let ((marionette (make-marionette (list #$vm))))
104
105 (test-runner-current (system-test-runner #$output))
106 (test-begin "lightdm")
107
108 (test-assert "service is running"
109 (marionette-eval
110 '(begin
111 (use-modules (gnu services herd))
112 (start-service 'lightdm))
113 marionette))
114
115 (test-assert "service can be stopped"
116 (marionette-eval
117 '(begin
118 (use-modules (gnu services herd))
119 (stop-service 'lightdm))
120 marionette))
121
122 (test-assert "service can be restarted"
123 (marionette-eval
124 '(begin
125 (use-modules (gnu services herd))
126 (restart-service 'lightdm))
127 marionette))
128
129 (test-assert "login screen is displayed"
130 ;; GNU Ocrad fails to recognize the "Log In" button text, so use
131 ;; Tesseract.
132 (wait-for-screen-text marionette
133 (cut string-contains <> "Log In")
134 #:ocr #$(file-append tesseract-ocr
135 "/bin/tesseract")))
136
137 (test-assert "can connect to TCP port 5900 on IPv4"
138 (wait-for-tcp-port 5900 marionette))
139
140 ;; The VNC server fails to listen to IPv6 due to "Error binding to
141 ;; address [::]:5900: Address already in use" (see:
142 ;; https://github.com/canonical/lightdm/issues/266).
143 (test-expect-fail 1)
144 (test-assert "can connect to TCP port 5900 on IPv6"
145 (wait-for-tcp-port 5900 marionette
146 #:address
147 `(make-socket-address
148 AF_INET6
149 (inet-pton AF_INET6 "::1")
150 5900)))
151
152 (test-end)))))
153
154 (gexp->derivation "lightdm-test" test))
155
156 (define %test-lightdm
157 (system-test
158 (name "lightdm")
159 (description "Basic tests for the LightDM service.")
160 (value (run-lightdm-test))))