1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2017 Thomas Danckaert <post@thomasdanckaert.be>
4 ;;; This file is part of GNU Guix.
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.
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.
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/>.
19 (define-module (gnu tests networking)
20 #:use-module (gnu tests)
21 #:use-module (gnu system)
22 #:use-module (gnu system vm)
23 #:use-module (gnu services)
24 #:use-module (gnu services networking)
25 #:use-module (guix gexp)
26 #:use-module (guix store)
27 #:use-module (guix monads)
28 #:use-module (gnu packages bash)
29 #:export (%test-inetd))
32 ;; Operating system with 2 inetd services.
33 (simple-operating-system
35 (service inetd-service-type
50 (program (file-append bash
53 (list "bash" (plain-file "my-dict.sh" "\
56 if [[ $line =~ ^DEFINE\\ (.*)$ ]]
58 case ${BASH_REMATCH[1]} in
60 echo GNU Guix is a package management tool for the GNU system.
63 echo Like an S-expression but with a G.
66 echo NO DEFINITION FOUND
74 (define* (run-inetd-test)
75 "Run tests in %INETD-OS, where the inetd service provides an echo service on
76 port 7, and a dict service on port 2628."
78 (marionette-operating-system %inetd-os))
83 (port-forwardings `((8007 . 7)
87 (with-imported-modules '((gnu build marionette))
89 (use-modules (ice-9 rdelim)
91 (gnu build marionette))
93 (make-marionette (list #$vm)))
100 ;; Make sure the PID file is created.
101 (test-assert "PID file"
103 '(file-exists? "/var/run/inetd.pid")
106 ;; Test the echo service.
107 (test-equal "echo response"
109 (let ((echo (socket PF_INET SOCK_STREAM 0))
110 (addr (make-socket-address AF_INET INADDR_LOOPBACK 8007)))
112 (display "Hello, Guix!\n" echo)
113 (let ((response (read-line echo)))
117 ;; Test the dict service
118 (test-equal "dict response"
119 "GNU Guix is a package management tool for the GNU system."
120 (let ((dict (socket PF_INET SOCK_STREAM 0))
121 (addr (make-socket-address AF_INET INADDR_LOOPBACK 8628)))
123 (display "DEFINE Guix\n" dict)
124 (let ((response (read-line dict)))
129 (exit (= (test-runner-fail-count (test-runner-current)) 0)))))
131 (gexp->derivation "inetd-test" test))
136 (description "Connect to a host with an INETD server.")
137 (value (run-inetd-test))))