gdm.scm 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2022⁠–⁠2023 Bruno Victal <mirai@makinata.eu>.
  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 gdm)
  19. #:use-module (gnu tests)
  20. #:use-module (gnu packages freedesktop)
  21. #:use-module (gnu services)
  22. #:use-module (gnu services desktop)
  23. #:use-module (gnu services xorg)
  24. #:use-module (gnu system)
  25. #:use-module (gnu system vm)
  26. #:use-module (guix gexp)
  27. #:use-module (ice-9 format)
  28. #:export (%test-gdm-x11
  29. %test-gdm-wayland))
  30. (define* (make-os #:key wayland?)
  31. (operating-system
  32. (inherit %simple-os)
  33. (services
  34. (modify-services %desktop-services
  35. (gdm-service-type config => (gdm-configuration
  36. (inherit config)
  37. (wayland? wayland?)))))))
  38. (define* (run-gdm-test #:key wayland?)
  39. "Run tests in a vm which has gdm running."
  40. (define os
  41. (marionette-operating-system
  42. (make-os #:wayland? wayland?)
  43. #:imported-modules '((gnu services herd))))
  44. (define vm
  45. (virtual-machine
  46. (operating-system os)
  47. (memory-size 1024)))
  48. (define name (format #f "gdm-~:[x11~;wayland~]" wayland?))
  49. (define test
  50. (with-imported-modules '((gnu build marionette))
  51. #~(begin
  52. (use-modules (gnu build marionette)
  53. (ice-9 format)
  54. (srfi srfi-64))
  55. (let ((marionette (make-marionette (list #$vm)))
  56. (expected-session-type #$(if wayland? "wayland" "x11")))
  57. (test-runner-current (system-test-runner #$output))
  58. (test-begin #$name)
  59. ;; service for gdm is called xorg-server
  60. (test-assert "service is running"
  61. (marionette-eval
  62. '(begin
  63. (use-modules (gnu services herd))
  64. (start-service 'xorg-server))
  65. marionette))
  66. (test-assert "gdm ready"
  67. (wait-for-file "/var/run/gdm/gdm.pid" marionette))
  68. ;; waiting for gdm.pid is not enough, tests may still sporadically fail.
  69. (sleep 1)
  70. (test-equal (string-append "session-type is " expected-session-type)
  71. expected-session-type
  72. (marionette-eval
  73. '(begin
  74. (use-modules (ice-9 popen)
  75. (ice-9 rdelim))
  76. (let* ((loginctl #$(file-append elogind "/bin/loginctl"))
  77. (get-session-cmd (string-join `(,loginctl "show-user" "gdm"
  78. "--property Display" "--value")))
  79. (session (call-with-port (open-input-pipe get-session-cmd) read-line))
  80. (get-type-cmd (string-join `(,loginctl "show-session" ,session
  81. "--property Type" "--value")))
  82. (type (call-with-port (open-input-pipe get-type-cmd) read-line)))
  83. type))
  84. marionette))
  85. (test-end)))))
  86. (gexp->derivation (string-append name "-test") test))
  87. (define %test-gdm-x11
  88. (system-test
  89. (name "gdm-x11")
  90. (description "Basic tests for the GDM service. (X11)")
  91. (value (run-gdm-test))))
  92. (define %test-gdm-wayland
  93. (system-test
  94. (name "gdm-wayland")
  95. (description "Basic tests for the GDM service. (Wayland)")
  96. (value (run-gdm-test #:wayland? #t))))