vnc.scm 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. (define-module (gnu tests vnc)
  19. #:use-module (gnu bootloader)
  20. #:use-module (gnu bootloader grub)
  21. #:use-module (gnu packages)
  22. #:use-module (gnu packages ocr)
  23. #:use-module (gnu packages glib)
  24. #:use-module (gnu packages gnome)
  25. #:use-module (gnu packages ratpoison)
  26. #:use-module (gnu packages vnc)
  27. #:use-module (gnu packages xorg)
  28. #:use-module (gnu services)
  29. #:use-module (gnu services dbus)
  30. #:use-module (gnu services desktop)
  31. #:use-module (gnu services networking)
  32. #:use-module (gnu services ssh)
  33. #:use-module (gnu services vnc)
  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. #:export (%test-xvnc))
  43. (define %xvnc-os
  44. (operating-system
  45. ;; Usual boilerplate.
  46. (host-name "komputilo")
  47. (timezone "Europe/Berlin")
  48. (locale "en_US.UTF-8")
  49. (bootloader (bootloader-configuration
  50. (bootloader grub-bootloader)
  51. (targets '("/dev/sdX"))))
  52. (file-systems (cons (file-system
  53. (device (file-system-label "my-root"))
  54. (mount-point "/")
  55. (type "ext4"))
  56. %base-file-systems))
  57. (users (cons (user-account
  58. (name "dummy")
  59. (group "users")
  60. (supplementary-groups '("wheel" "netdev"
  61. "audio" "video")))
  62. %base-user-accounts))
  63. (packages (cons* dbus ;for dbus-run-session
  64. dconf
  65. `(,glib "bin")
  66. glib
  67. gnome-settings-daemon ;for schemas
  68. ratpoison
  69. tigervnc-client
  70. xterm
  71. %base-packages))
  72. (services (cons*
  73. (service openssh-service-type (openssh-configuration
  74. (permit-root-login #t)
  75. (allow-empty-passwords? #t)))
  76. (service xvnc-service-type (xvnc-configuration
  77. (display-number 5)
  78. (security-types (list "None"))
  79. (log-level 100)
  80. (localhost? #f)
  81. (xdmcp? #t)
  82. (inetd? #t)))
  83. (modify-services %desktop-services
  84. (gdm-service-type config => (gdm-configuration
  85. (inherit config)
  86. (auto-login? #t)
  87. (auto-suspend? #f)
  88. (default-user "root")
  89. (debug? #t)
  90. (xdmcp? #t))))))))
  91. (define (run-xvnc-test)
  92. "Run tests in %XVNC-OS."
  93. (define os (marionette-operating-system
  94. %xvnc-os
  95. #:imported-modules (source-module-closure
  96. '((gnu services herd)))))
  97. (define vm (virtual-machine
  98. (operating-system os)
  99. (memory-size 1024)))
  100. (define test
  101. (with-imported-modules (source-module-closure
  102. '((gnu build marionette)
  103. (guix build utils)))
  104. #~(begin
  105. (use-modules (gnu build marionette)
  106. (guix build utils)
  107. (srfi srfi-26)
  108. (srfi srfi-64))
  109. (let ((marionette (make-marionette (list #$vm))))
  110. (test-runner-current (system-test-runner #$output))
  111. (test-begin "xvnc")
  112. (test-assert "service running"
  113. (marionette-eval
  114. '(begin
  115. (use-modules (gnu services herd))
  116. (start-service 'xvnc))
  117. marionette))
  118. (test-assert "wait for port 5905, IPv4"
  119. (wait-for-tcp-port 5905 marionette))
  120. (test-assert "wait for port 5905, IPv6"
  121. (wait-for-tcp-port 5905 marionette
  122. #:address
  123. '(make-socket-address
  124. AF_INET6 (inet-pton AF_INET6 "::1") 5905)))
  125. (test-assert "gdm auto-suspend is disabled"
  126. ;; More a GDM than a Xvnc test, but since it's a cross-cutting
  127. ;; concern and we have everything set up here, we might as well
  128. ;; check it here.
  129. (marionette-eval
  130. '(begin
  131. ;; Check that DCONF_PROFILE is set...
  132. (invoke "/bin/sh" "-lc" "\
  133. pgrep gdm | head -n1 | xargs -I{} grep -Fq DCONF_PROFILE /proc/{}/environ")
  134. ;; ... and that
  135. (invoke "/bin/sh" "-lc" "\
  136. sudo -E -u gdm env DCONF_PROFILE=/etc/dconf/profile/gdm dbus-run-session \
  137. gsettings get org.gnome.settings-daemon.plugins.power sleep-inactive-ac-type \
  138. | grep -Fq nothing"))
  139. marionette))
  140. (test-assert "vnc lands on the gdm login screen"
  141. ;; This test runs vncviewer on the local VM and verifies that it
  142. ;; manages to access the GDM login screen (via XDMCP).
  143. (begin
  144. (define (ratpoison-abort)
  145. (marionette-control "sendkey ctrl-g" marionette))
  146. (define (ratpoison-help)
  147. (marionette-control "sendkey ctrl-t" marionette)
  148. (marionette-type "?" marionette)
  149. (sleep 1)) ;wait for help screen to appear
  150. (define (ratpoison-exec command)
  151. (marionette-control "sendkey ctrl-t" marionette)
  152. (marionette-type "!" marionette)
  153. (marionette-type (string-append command "\n") marionette))
  154. ;; Wait until the ratpoison help screen can be displayed; this
  155. ;; means the window manager is ready.
  156. (wait-for-screen-text marionette
  157. (cut string-contains <> "key bindings")
  158. #:ocr #$(file-append tesseract-ocr
  159. "/bin/tesseract")
  160. #:pre-action ratpoison-help
  161. #:post-action ratpoison-abort)
  162. ;; Run vncviewer and expect the GDM login screen (accessed via
  163. ;; XDMCP). This can take a while to appear on slower machines.
  164. (ratpoison-exec "vncviewer localhost:5905")
  165. ;; XXX: tesseract narrowly recognizes "Guix" as "uix" from the
  166. ;; background image; ocrad fares worst. Sadly, 'Username' is
  167. ;; not recognized at all.
  168. (wait-for-screen-text marionette
  169. (cut string-contains <> "uix")
  170. #:ocr #$(file-append tesseract-ocr
  171. "/bin/tesseract")
  172. #:timeout 120)))
  173. (test-end)))))
  174. (gexp->derivation "xvnc-test" test))
  175. (define %test-xvnc
  176. (system-test
  177. (name "xvnc")
  178. (description "Basic tests for the Xvnc service. One of the tests validate
  179. that XDMCP works with GDM, and is therefore heavy in terms of disk and memory
  180. requirements.")
  181. (value (run-xvnc-test))))