vnc.scm 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2022 Maxim Cournoyer <maxim.cournoyer@gmail.com>.
  3. ;;; Copyright © 2023 Bruno Victal <mirai@makinata.eu>
  4. ;;;
  5. ;;; This file is part of GNU Guix.
  6. ;;;
  7. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  8. ;;; under the terms of the GNU General Public License as published by
  9. ;;; the Free Software Foundation; either version 3 of the License, or (at
  10. ;;; your option) any later version.
  11. ;;;
  12. ;;; GNU Guix is distributed in the hope that it will be useful, but
  13. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;;; GNU General Public License for more details.
  16. ;;;
  17. ;;; You should have received a copy of the GNU General Public License
  18. ;;; 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))
  44. (define %xvnc-os
  45. (operating-system
  46. ;; Usual boilerplate.
  47. (host-name "komputilo")
  48. (timezone "Europe/Berlin")
  49. (locale "en_US.UTF-8")
  50. (bootloader (bootloader-configuration
  51. (bootloader grub-bootloader)
  52. (targets '("/dev/sdX"))))
  53. (file-systems (cons (file-system
  54. (device (file-system-label "my-root"))
  55. (mount-point "/")
  56. (type "ext4"))
  57. %base-file-systems))
  58. (users (cons (user-account
  59. (name "dummy")
  60. (group "users")
  61. (supplementary-groups '("wheel" "netdev"
  62. "audio" "video")))
  63. %base-user-accounts))
  64. (packages (cons* dbus ;for dbus-run-session
  65. dconf
  66. `(,glib "bin")
  67. glib
  68. gnome-settings-daemon ;for schemas
  69. ratpoison
  70. tigervnc-client
  71. xterm
  72. %base-packages))
  73. (services (cons*
  74. (service openssh-service-type (openssh-configuration
  75. (permit-root-login #t)
  76. (allow-empty-passwords? #t)))
  77. (service xvnc-service-type (xvnc-configuration
  78. (display-number 5)
  79. (security-types (list "None"))
  80. (log-level 100)
  81. (localhost? #f)
  82. (xdmcp? #t)
  83. (inetd? #t)))
  84. (modify-services %desktop-services
  85. (gdm-service-type config => (gdm-configuration
  86. (inherit config)
  87. (auto-login? #t)
  88. (auto-suspend? #f)
  89. (default-user "root")
  90. (debug? #t)
  91. (xdmcp? #t))))))))
  92. (define (run-xvnc-test)
  93. "Run tests in %XVNC-OS."
  94. (define os (marionette-operating-system
  95. %xvnc-os
  96. #:imported-modules (source-module-closure
  97. '((gnu services herd)))))
  98. (define vm (virtual-machine
  99. (operating-system os)
  100. (memory-size 1024)))
  101. (define ocr (file-append ocrad "/bin/ocrad"))
  102. (define test
  103. (with-imported-modules (source-module-closure
  104. '((gnu build marionette)
  105. (guix build utils)))
  106. #~(begin
  107. (use-modules (gnu build marionette)
  108. (srfi srfi-26)
  109. (srfi srfi-64))
  110. (let ((marionette (make-marionette (list #$vm))))
  111. (test-runner-current (system-test-runner #$output))
  112. (test-begin "xvnc")
  113. (test-assert "service running"
  114. (marionette-eval
  115. '(begin
  116. (use-modules (gnu services herd))
  117. (start-service 'xvnc))
  118. marionette))
  119. (test-assert "wait for port 5905, IPv4"
  120. (wait-for-tcp-port 5905 marionette))
  121. (test-assert "wait for port 5905, IPv6"
  122. (wait-for-tcp-port 5905 marionette
  123. #:address
  124. '(make-socket-address
  125. AF_INET6 (inet-pton AF_INET6 "::1") 5905)))
  126. (test-assert "gdm auto-suspend is disabled"
  127. ;; More a GDM than a Xvnc test, but since it's a cross-cutting
  128. ;; concern and we have everything set up here, we might as well
  129. ;; check it here.
  130. (marionette-eval
  131. '(begin
  132. (use-modules (guix build utils))
  133. ;; Check that DCONF_PROFILE is set...
  134. (invoke "/bin/sh" "-lc" "\
  135. pgrep gdm | head -n1 | xargs -I{} grep -Fq DCONF_PROFILE /proc/{}/environ")
  136. ;; ... and that 'sleep-inactive-ac-type' is unset.
  137. (invoke "/bin/sh" "-lc" "\
  138. sudo -E -u gdm env DCONF_PROFILE=/etc/dconf/profile/gdm dbus-run-session \
  139. gsettings get org.gnome.settings-daemon.plugins.power sleep-inactive-ac-type \
  140. | grep -Fq nothing"))
  141. marionette))
  142. (test-group "vnc lands on the gdm login screen"
  143. ;; This test runs vncviewer on the local VM and verifies that it
  144. ;; manages to access the GDM login screen (via XDMCP).
  145. (define (ratpoison-abort)
  146. (marionette-control "sendkey ctrl-g" marionette))
  147. (define (ratpoison-help)
  148. (marionette-control "sendkey ctrl-t" marionette)
  149. (marionette-type "?" marionette)
  150. (sleep 1)) ;wait for help screen to appear
  151. (define (ratpoison-exec command)
  152. (marionette-control "sendkey ctrl-t" marionette)
  153. (marionette-type "!" marionette)
  154. (marionette-type (string-append command "\n") marionette))
  155. ;; Wait until the ratpoison help screen can be displayed; this
  156. ;; means the window manager is ready.
  157. ;; XXX: The letters are half of the height preferred by
  158. ;; GNU Ocrad, scale it by 2.
  159. (test-assert "window manager is ready"
  160. (wait-for-screen-text marionette
  161. (cut string-contains <> "key bindings")
  162. #:ocr #$ocr
  163. #:ocr-arguments '("--scale=2")
  164. #:pre-action ratpoison-help
  165. #:post-action ratpoison-abort))
  166. ;; Run vncviewer and expect the GDM login screen (accessed via
  167. ;; XDMCP). This can take a while to appear on slower machines.
  168. (ratpoison-exec "vncviewer localhost:5905")
  169. (test-assert "GDM login screen ready"
  170. ;; XXX: The '--invert' argument as the sole option to GNU
  171. ;; Ocrad is required for it to recognize "Guix" from the
  172. ;; background image. 'Username' from the UI would be a better
  173. ;; choice but is not recognized at all.
  174. (wait-for-screen-text marionette
  175. (cut string-contains <> "Guix")
  176. #:ocr #$ocr
  177. #:ocr-arguments '("--invert")
  178. #:timeout 120))) ;for slow systems
  179. (test-end)))))
  180. (gexp->derivation "xvnc-test" test))
  181. (define %test-xvnc
  182. (system-test
  183. (name "xvnc")
  184. (description "Basic tests for the Xvnc service. One of the tests validate
  185. that XDMCP works with GDM, and is therefore heavy in terms of disk and memory
  186. requirements.")
  187. (value (run-xvnc-test))))