From: Bruno Victal <mirai@makinata.eu>
To: 60788@debbugs.gnu.org
Cc: ludo@gnu.org, Bruno Victal <mirai@makinata.eu>,
maxim.cournoyer@gmail.com
Subject: [bug#60788] [PATCH v10 3/3] tests: Add vnstat tests.
Date: Fri, 5 May 2023 01:18:39 +0100 [thread overview]
Message-ID: <2b1c8fa1c767cb2bcdec87109402fc42be17753d.1683245610.git.mirai@makinata.eu> (raw)
In-Reply-To: <95b646eb6b23dec213cba43b6e4e7ddc4a601d0f.1673640404.git.mirai@makinata.eu>
* gnu/tests/vnstat.scm: New file.
* gnu/local.mk: Register it.
---
gnu/local.mk | 1 +
gnu/tests/vnstat.scm | 159 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 160 insertions(+)
create mode 100644 gnu/tests/vnstat.scm
diff --git a/gnu/local.mk b/gnu/local.mk
index 5f5de953d7..c462c41b9d 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -795,6 +795,7 @@ GNU_SYSTEM_MODULES = \
%D%/tests/version-control.scm \
%D%/tests/virtualization.scm \
%D%/tests/vnc.scm \
+ %D%/tests/vnstat.scm \
%D%/tests/web.scm
INSTALLER_MODULES = \
diff --git a/gnu/tests/vnstat.scm b/gnu/tests/vnstat.scm
new file mode 100644
index 0000000000..d1be98e342
--- /dev/null
+++ b/gnu/tests/vnstat.scm
@@ -0,0 +1,159 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2023 Bruno Victal <mirai@makinata.eu>.
+;;;
+;;; 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 vnstat)
+ #:use-module (gnu tests)
+ #:use-module ((gnu packages networking) #:select (socat vnstat))
+ #:use-module (gnu services)
+ #:use-module (gnu services networking)
+ #:use-module (gnu services monitoring)
+ #:use-module (gnu system)
+ #:use-module (gnu system vm)
+ #:use-module (guix gexp)
+ #:use-module (ice-9 format)
+ #:export (%test-vnstat))
+
+
+(define (run-vnstat-test)
+ "Run tests in a vm which has vnstat running."
+
+ (define vnstat-config
+ (vnstat-configuration
+ (max-bandwidth 0)
+ (time-sync-wait 0)
+ (bandwidth-detection-interval 0)))
+
+ (define inetd-service-entry-config
+ (inetd-entry
+ (name "discard")
+ (socket-type 'stream)
+ (protocol "tcp")
+ (wait? #t)
+ (user "nobody")))
+
+ (define os
+ (marionette-operating-system
+ (simple-operating-system
+ (service dhcp-client-service-type)
+ (service vnstat-service-type
+ vnstat-config)
+ (service inetd-service-type
+ (inetd-configuration
+ (entries
+ (list inetd-service-entry-config)))))
+ #:imported-modules '((gnu services herd))))
+
+ (define forwarded-port 9999)
+
+ (define vm
+ (let* ((inetd-service-name "discard")
+ (inetd-service-proto
+ (inetd-entry-protocol inetd-service-entry-config))
+ (guest-port
+ (servent:port (getservbyname inetd-service-name
+ inetd-service-proto))))
+ (virtual-machine
+ (operating-system os)
+ (port-forwardings `((,forwarded-port . ,guest-port))))))
+
+ ;; The test duration is inconsistent, at times a test may complete under
+ ;; 2 minutes and at times it may take up to 5 minutes.
+ (define test-timeout (* 60 5))
+
+ (define test
+ (with-imported-modules '((gnu build marionette))
+ #~(begin
+ (use-modules (gnu build marionette)
+ (srfi srfi-64))
+
+ (let ((marionette (make-marionette (list #$vm)))
+ (pid-file #$(vnstat-configuration-pid-file vnstat-config)))
+
+ (test-runner-current (system-test-runner #$output))
+ (test-begin "vnstat")
+
+ (test-assert "service is running"
+ (marionette-eval
+ '(begin
+ (use-modules (gnu services herd))
+ (start-service 'vnstatd))
+ marionette))
+
+ (test-assert "vnstatd ready"
+ (wait-for-file pid-file marionette))
+
+ ;; Pump garbage into the 'discard' inetd service within the vm.
+ (let* ((socat #$(file-append socat "/bin/socat"))
+ (dest-addr #$(format #f "TCP4:localhost:~d"
+ forwarded-port))
+ (args `("socat" "-u" "/dev/zero" ,dest-addr))
+ ;; XXX: Guile bug (22/03/2023, Guile 3.0.9)
+ ;; Fixed in main: <https://issues.guix.gnu.org/61073>
+ ;; FIXME: re-add #:output (%make-void-port "w") below on
+ ;; next Guile release.
+ (garbage-pump-pid
+ (spawn socat args)))
+ (test-group-with-cleanup "Logging"
+ ;; To aid debugging, this test returns #t on success
+ ;; and either #f or 'timed-out otherwise.
+ (test-eq "vnstatd is logging"
+ #t
+ (marionette-eval
+ '(begin
+ (use-modules (ice-9 popen)
+ (ice-9 match)
+ (sxml simple)
+ (sxml xpath))
+
+ (define selector
+ (let ((xpath '(vnstat interface traffic total)))
+ (compose (node-pos 1) (sxpath xpath))))
+
+ (let loop ((i 0))
+ (let* ((vnstat #$(file-append vnstat "/bin/vnstat"))
+ (query-cmd (format #f "~a --xml" vnstat))
+ (proc (compose selector xml->sxml))
+ (result
+ (call-with-port
+ (open-input-pipe query-cmd) proc)))
+ (match result
+ ;; Counter still warming up.
+ ((('total ('rx "0") ('tx "0")))
+ (sleep 1)
+ (if (< i #$test-timeout)
+ (loop (+ i 1))
+ 'timed-out))
+ ;; Count of bytes on iface was non-zero.
+ ((('total ('rx rx) ('tx tx)))
+ #t)
+ ;; Unknown data encountered, perhaps the
+ ;; data format changed?
+ (_ #f)))))
+ marionette))
+ ;; Cleanup: shutdown garbage pump.
+ (kill garbage-pump-pid SIGTERM)))
+
+ (test-end)))))
+
+ (gexp->derivation "vnstat-test" test))
+
+(define %test-vnstat
+ (system-test
+ (name "vnstat")
+ (description "Basic tests for vnstat service.")
+ (value (run-vnstat-test))))
--
2.39.2
prev parent reply other threads:[~2023-05-05 0:21 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-13 20:07 [bug#60788] [PATCH] services: Add vnstat-service-type Bruno Victal
2023-01-14 21:06 ` [bug#60788] [PATCH v2] " Bruno Victal
2023-01-16 18:42 ` [bug#60788] [PATCH] " Maxim Cournoyer
2023-01-16 19:31 ` Bruno Victal
2023-01-16 19:56 ` Maxim Cournoyer
2023-01-18 0:34 ` [bug#60788] [PATCH v2] " Bruno Victal
2023-01-18 0:37 ` [bug#60788] [PATCH v2] services: vnstat: Use least-authority-wrapper Bruno Victal
2023-02-02 14:21 ` [bug#60788] [PATCH v3] services: Add vnstat-service-type Bruno Victal
2023-02-07 14:25 ` [bug#60788] [PATCH v4] " Bruno Victal
2023-02-09 3:34 ` [bug#60788] [PATCH] " Maxim Cournoyer
2023-02-09 4:19 ` Bruno Victal
2023-02-09 13:31 ` Maxim Cournoyer
2023-02-10 13:15 ` [bug#60788] [PATCH v5] " Bruno Victal
2023-02-10 14:07 ` Maxim Cournoyer
2023-02-10 14:14 ` [bug#60788] [PATCH v6] " Bruno Victal
2023-03-22 16:15 ` [bug#60788] [PATCH v7] " Bruno Victal
2023-04-03 14:14 ` [bug#60788] [PATCH v8] " Bruno Victal
2023-04-04 13:08 ` [bug#60788] [PATCH v9] " Bruno Victal
2023-04-07 15:22 ` [bug#60788] [PATCH] " Ludovic Courtès
2023-04-07 20:04 ` Maxim Cournoyer
2023-04-20 10:03 ` [bug#60788] Policy for system tests? Ludovic Courtès
2023-04-08 12:40 ` [bug#60788] [PATCH] services: Add vnstat-service-type Bruno Victal
2023-04-20 10:09 ` Ludovic Courtès
2023-05-05 0:18 ` [bug#60788] [PATCH v10 1/3] " Bruno Victal
2023-05-11 14:33 ` bug#60788: " Ludovic Courtès
2023-05-05 0:18 ` [bug#60788] [PATCH v10 2/3] services: inetd: Export accessors Bruno Victal
2023-05-05 0:18 ` Bruno Victal [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2b1c8fa1c767cb2bcdec87109402fc42be17753d.1683245610.git.mirai@makinata.eu \
--to=mirai@makinata.eu \
--cc=60788@debbugs.gnu.org \
--cc=ludo@gnu.org \
--cc=maxim.cournoyer@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).