projects/guix·blob master · refs

108 lines · 4.0 KiB

1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2025 Maxim Cournoyer <[email protected]>
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 games)
20 #:use-module (gnu packages luanti)
21 #:use-module (gnu tests)
22 #:use-module (gnu services)
23 #:use-module (gnu services games)
24 #:use-module (gnu system)
25 #:use-module (gnu system vm)
26 #:use-module (guix gexp)
27 #:use-module (guix modules)
28 #:export (%test-luanti))
29
30(define (run-luanti-test name config)
31 "Run a test of an OS running LUANTI-SERVICE."
32 (define os
33 (marionette-operating-system
34 (simple-operating-system
35 (service luanti-service-type config))
36 #:imported-modules '((gnu build dbus-service)
37 (gnu services herd))))
38
39 (define vm (virtual-machine
40 (operating-system os)
41 (memory-size 1024)))
42
43 (define test
44 (with-imported-modules (source-module-closure
45 '((gnu build marionette)))
46 #~(begin
47 (use-modules (gnu build marionette)
48 (srfi srfi-64))
49
50 (define marionette
51 (make-marionette (list #$vm)))
52
53 (test-runner-current (system-test-runner #$output))
54 (test-begin "luanti")
55
56 (test-assert "luanti service can be stopped"
57 (marionette-eval
58 '(begin
59 (use-modules (gnu services herd))
60 (stop-service 'luanti))
61 marionette))
62
63 (test-assert "luanti service can be started"
64 (marionette-eval
65 '(begin
66 (use-modules (gnu services herd))
67 (start-service 'luanti))
68 marionette))
69
70 (test-assert "luanti server is responding on configured port"
71 ;; This is based on the Python script example in doc/protocol.txt.
72 (marionette-eval
73 `(begin
74 (use-modules ((gnu build dbus-service) #:select (with-retries))
75 (gnu services herd)
76 (ice-9 match)
77 (rnrs bytevectors)
78 (rnrs bytevectors gnu))
79
80 (define sock (socket PF_INET SOCK_DGRAM 0))
81 (define addr (make-socket-address AF_INET INADDR_LOOPBACK
82 ,#$(luanti-configuration-port
83 config)))
84 (define probe #vu8(#x4f #x45 #x74 #x03 #x00 #x00 #x00 #x01))
85 (define buf (make-bytevector 1000))
86
87 (with-retries 25 1
88 (sendto sock probe addr)
89 (match (select (list sock) '() '() 2) ;limit time to block
90 (((sock) _ _)
91 (match (recvfrom! sock buf)
92 ((byte-count . _)
93 (and (>= (pk 'byte-count byte-count) 14)
94 (pk 'peer-id (bytevector-slice buf 12 2)))))))))
95 marionette))
96
97 (test-end))))
98
99 (gexp->derivation name test))
100
101(define %test-luanti
102 (system-test
103 (name "luanti")
104 (description "Connect to a running Luanti server.")
105 (value (run-luanti-test name (luanti-configuration
106 (game luanti-mineclonia)
107 ;; To test some extra code paths.
108 (mods (list luanti-whitelist)))))))