| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 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 | |
| 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) |
| 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 | |
| 108 | (mods (list luanti-whitelist)))))))
|