unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
blob cdcd00d0574f3d0e96c02ef3f1311839f36e01af 7514 bytes (raw)
name: gnu/tests/telephony.scm 	 # note: path name is non-authoritative(*)

  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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
 
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2021 Maxim Cournoyer <maxim.cournoyer@gnu.org>.
;;;
;;; 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 telephony)
  #:use-module (gnu)
  #:use-module (gnu packages guile)
  #:use-module (gnu tests)
  #:use-module (gnu system vm)
  #:use-module (gnu services)
  #:use-module (gnu services dbus)
  #:use-module (gnu services ssh)
  #:use-module (gnu services telephony)
  #:use-module (guix gexp)
  #:use-module (guix modules)
  #:export (%test-jami-daemon
            %test-jami-daemon-provisioning))

;;;
;;; Jami daemon.
;;;

(define define-with-retries (@@ (gnu services telephony) define-with-retries))

(include "data/jami-dummy-account.dat") ;defines %jami-account-content-sexp

(define %dummy-jami-account
  ;; A Jami account archive is a gzipped JSON file.
  (computed-file
   "dummy-jami-account.gz"
   (with-extensions (list guile-json-4 guile-zlib)
     #~(begin
         (use-modules (json) (zlib))
         (let ((port (open-output-file #$output)))
           (call-with-gzip-output-port port
             (lambda (port)
               (scm->json '#$%jami-account-content-sexp port))))))))

(define* (make-jami-daemon-os #:key provisioning?)
  (simple-operating-system
   (service jami-daemon-service-type
            (if provisioning?
                (jami-daemon-configuration
                 (account-archives (list %dummy-jami-account)))
                (jami-daemon-configuration)))
   (service dbus-root-service-type)
   (service openssh-service-type        ;for debugging
            (openssh-configuration
             (permit-root-login 'without-password)))))

(define %jami-daemon-os
  (make-jami-daemon-os))

(define %jami-daemon-os-provisioning
  (make-jami-daemon-os #:provisioning? #t))

(define* (run-jami-daemon-test #:key provisioning?)
  "Run tests in %JAMI-DAEMON-OS.  When PROVISIONING? is true, test the
accounts provisioning feature of the service."
  (define os (marionette-operating-system
              (if provisioning?
                  %jami-daemon-os-provisioning
                  %jami-daemon-os)
              #:imported-modules '((gnu services herd)
                                   (guix combinators))))
  (define vm (virtual-machine
              (operating-system os)
              (memory-size 512)))

  (define test
    (with-imported-modules '((gnu build marionette))
      #~(begin
          (use-modules (rnrs base)
                       (srfi srfi-11)
                       (srfi srfi-64)
                       (gnu build marionette))

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

          (mkdir #$output)
          (chdir #$output)

          (test-begin "jami-daemon")

          (test-assert "service running"
            (marionette-eval
             '(begin
                (use-modules (gnu services herd))
                (match (start-service 'jami-daemon)
                  (#f #f)
                  (('service response-parts ...)
                   (match (assq-ref response-parts 'running)
                     ((pid) (number? pid))))))
             marionette))

          (test-assert "service can be stopped"
            (marionette-eval
             '(begin
                (use-modules (gnu services herd)
                             (rnrs base))
                #$define-with-retries
                (setenv "PATH" "/run/current-system/profile/bin")
                (let ((pid (match (start-service 'jami-daemon)
                             (#f #f)
                             (('service response-parts ...)
                              (match (assq-ref response-parts 'running)
                                ((pid) pid))))))

                  (assert (number? pid))

                  (match (stop-service 'jami-daemon)
                    (services           ;a list of service symbols
                     (member 'jami-daemon services)))
                  ;; Sometimes, the process still appear in pgrep, even
                  ;; though we are using waitpid after sending it SIGTERM
                  ;; in the service; use retries.
                  (with-retries
                   19 1
                   (not (zero? (status:exit-val
                                (system* "pgrep" "dring")))))))
             marionette))

          (test-assert "service can be restarted"
            (marionette-eval
             '(begin
                (use-modules (gnu services herd)
                             (rnrs base))
                ;; Start and retrieve the current PID.
                (define pid (match (start-service 'jami-daemon)
                              (#f #f)
                              (('service response-parts ...)
                               (match (assq-ref response-parts 'running)
                                 ((pid) pid)))))
                (assert (number? pid))

                ;; Restart the service.
                (restart-service 'jami-daemon)

                (define new-pid (match (start-service 'jami-daemon)
                                  (#f #f)
                                  (('service response-parts ...)
                                   (match (assq-ref response-parts 'running)
                                     ((pid) pid)))))
                (assert (number? new-pid))

                (not (eq? pid new-pid)))
             marionette))

          (unless #$provisioning? (test-skip 1))
          (test-assert "jami accounts provisioning"
            (marionette-eval
             '(begin
                (use-modules (gnu services herd))

                #$define-with-retries

                (setenv "PATH" "/run/current-system/profile/bin")
                ;; The imported account takes some time to appear in the
                ;; account files; retry for up to about 10 s.
                (with-retries
                 20 1
                 (zero? (status:exit-val
                         (system* "grep" "-r"
                                  #$(assoc-ref %jami-account-content-sexp
                                               "Account.username")
                                  "/var/lib/jami/.local/share/jami/")))))
             marionette))

          (test-end)
          (exit (= (test-runner-fail-count (test-runner-current)) 0)))))

  (gexp->derivation (if provisioning?
                        "jami-daemon-provisioning-test"
                        "jami-daemon-test")
                    test))

(define %test-jami-daemon
  (system-test
   (name "jami-daemon")
   (description "Basic tests for the jami-daemon service.")
   (value (run-jami-daemon-test))))

(define %test-jami-daemon-provisioning
  (system-test
   (name "jami-daemon-provisioning")
   (description "Provisioning test for the jami-daemon service.")
   (value (run-jami-daemon-test #:provisioning? #t))))

debug log:

solving cdcd00d057 ...
found cdcd00d057 in https://yhetil.org/guix-patches/20210417200617.18182-1-maxim.cournoyer@gmail.com/

applying [1/1] https://yhetil.org/guix-patches/20210417200617.18182-1-maxim.cournoyer@gmail.com/
diff --git a/gnu/tests/telephony.scm b/gnu/tests/telephony.scm
new file mode 100644
index 0000000000..cdcd00d057

Checking patch gnu/tests/telephony.scm...
Applied patch gnu/tests/telephony.scm cleanly.

index at:
100644 cdcd00d0574f3d0e96c02ef3f1311839f36e01af	gnu/tests/telephony.scm

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

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).