~ruther/guix-local

ref: cfc5ec77a72d4e4d04d4e93aa8dee8462baa2cf7 guix-local/gnu/tests/games.scm -rw-r--r-- 4.0 KiB
cfc5ec77 — Hugo Buddelmeijer gnu: guile-2.2.4: Fix build by using libxcrypt-without-failure-tokens. a month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2025 Maxim Cournoyer <maxim@guixotic.coop>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (gnu tests games)
  #:use-module (gnu packages luanti)
  #:use-module (gnu tests)
  #:use-module (gnu services)
  #:use-module (gnu services games)
  #:use-module (gnu system)
  #:use-module (gnu system vm)
  #:use-module (guix gexp)
  #:use-module (guix modules)
  #:export (%test-luanti))

(define (run-luanti-test name config)
  "Run a test of an OS running LUANTI-SERVICE."
  (define os
    (marionette-operating-system
     (simple-operating-system
      (service luanti-service-type config))
     #:imported-modules '((gnu build dbus-service)
                          (gnu services herd))))

  (define vm (virtual-machine
               (operating-system os)
               (memory-size 1024)))

  (define test
    (with-imported-modules (source-module-closure
                            '((gnu build marionette)))
      #~(begin
          (use-modules (gnu build marionette)
                       (srfi srfi-64))

          (define marionette
            (make-marionette (list #$vm)))

          (test-runner-current (system-test-runner #$output))
          (test-begin "luanti")

          (test-assert "luanti service can be stopped"
            (marionette-eval
             '(begin
                (use-modules (gnu services herd))
                (stop-service 'luanti))
             marionette))

          (test-assert "luanti service can be started"
            (marionette-eval
             '(begin
                (use-modules (gnu services herd))
                (start-service 'luanti))
             marionette))

          (test-assert "luanti server is responding on configured port"
            ;; This is based on the Python script example in doc/protocol.txt.
            (marionette-eval
             `(begin
                (use-modules ((gnu build dbus-service) #:select (with-retries))
                             (gnu services herd)
                             (ice-9 match)
                             (rnrs bytevectors)
                             (rnrs bytevectors gnu))

                (define sock (socket PF_INET SOCK_DGRAM 0))
                (define addr (make-socket-address AF_INET INADDR_LOOPBACK
                                                  ,#$(luanti-configuration-port
                                                      config)))
                (define probe #vu8(#x4f #x45 #x74 #x03 #x00 #x00 #x00 #x01))
                (define buf (make-bytevector 1000))

                (with-retries 25 1
                  (sendto sock probe addr)
                  (match (select (list sock) '() '() 2) ;limit time to block
                    (((sock) _ _)
                     (match (recvfrom! sock buf)
                       ((byte-count . _)
                        (and (>= (pk 'byte-count byte-count) 14)
                             (pk 'peer-id (bytevector-slice buf 12 2)))))))))
             marionette))

          (test-end))))

  (gexp->derivation name test))

(define %test-luanti
  (system-test
   (name "luanti")
   (description "Connect to a running Luanti server.")
   (value (run-luanti-test name (luanti-configuration
                                 (game luanti-mineclonia)
                                 ;; To test some extra code paths.
                                 (mods (list luanti-whitelist)))))))