aboutsummaryrefslogtreecommitdiff
path: root/tests/processes.scm
blob: ba518f2d9e3ee2491e16259820beaf14e0743014 (about) (plain)
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
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2018 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2019 Mathieu Othacehe <m.othacehe@gmail.com>
;;;
;;; 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 (test-processes)
  #:use-module (guix scripts processes)
  #:use-module (guix store)
  #:use-module (guix derivations)
  #:use-module (guix packages)
  #:use-module (guix gexp)
  #:use-module ((guix utils) #:select (call-with-temporary-directory))
  #:use-module (gnu packages bootstrap)
  #:use-module (guix tests)
  #:use-module (srfi srfi-1)
  #:use-module (srfi srfi-64)
  #:use-module (rnrs bytevectors)
  #:use-module (rnrs io ports)
  #:use-module (ice-9 match)
  #:use-module (ice-9 threads))

;; When using --system argument, binfmt-misc mechanism may be used. In that
;; case, (guix script processes) won't work because:
;;
;; * ARGV0 is qemu-user and not guix-daemon.
;; * Guix-daemon won't be able to stuff client PID in ARGV1 of forked
;;   processes.
;;
;; See: https://lists.gnu.org/archive/html/bug-guix/2019-12/msg00017.html.
;;
;; If we detect that we are running with binfmt emulation, all the following
;; tests must be skipped.

(define (binfmt-misc?)
  (let ((pid (getpid))
        (cmdline (call-with-input-file "/proc/self/cmdline" get-string-all)))
    (match (primitive-fork)
      (0 (dynamic-wind
           (const #t)
           (lambda ()
             (exit
              (not (equal?
                    (call-with-input-file (format #f "/proc/~a/cmdline" pid)
                      get-string-all)
                    cmdline))))
           (const #t)))
      (x (zero? (cdr (waitpid x)))))))

(define-syntax-rule (test-assert* description exp)
  (begin
    (when (binfmt-misc?)
      (test-skip 1))
    (test-assert description exp)))

(test-begin "processes")

(test-assert* "not a client"
  (not (find (lambda (session)
               (= (getpid)
                  (process-id (daemon-session-client session))))
             (daemon-sessions))))

(test-assert* "client"
  (with-store store
    (let* ((session (find (lambda (session)
                            (= (getpid)
                               (process-id (daemon-session-client session))))
                          (daemon-sessions)))
           (daemon  (daemon-session-process session)))
      (and (kill (process-id daemon) 0)
           (string-suffix? "guix-daemon" (first (process-command daemon)))))))

(test-assert* "client + lock"
  (with-store store
    (call-with-temporary-directory
     (lambda (directory)
       (let* ((token1  (string-append directory "/token1"))
              (token2  (string-append directory "/token2"))
              (exp     #~(begin #$(random-text)
                                (mkdir #$token1)
                                (let loop ()
                                  (unless (file-exists? #$token2)
                                    (sleep 1)
                                    (loop)))
                                (mkdir #$output)))
              (guile   (package-derivation store %bootstrap-guile))
              (drv     (run-with-store store
                         (gexp->derivation "foo" exp
                                           #:guile-for-build guile)))
              (thread  (call-with-new-thread
                        (lambda ()
                          (build-derivations store (list drv)))))
              (_       (let loop ()
                         (unless (file-exists? token1)
                           (usleep 200)
                           (loop))))
              (session (find (lambda (session)
                               (= (getpid)
                                  (process-id (daemon-session-client session))))
                             (daemon-sessions)))
              (locks   (daemon-session-locks-held (pk 'session session))))
         (call-with-output-file token2 (const #t))
         (equal? (list (string-append (derivation->output-path drv) ".lock"))
                 locks))))))

(test-end "processes")
38e66dfc05ea4a018418edaf19'>Update e-mail for Theodoros Foradis.Theodoros Foradis * .mailmap: Add entry. * gnu/packages/aspell.scm: Replace theodoros.for@openmailbox.org with current address. * gnu/packages/compression.scm: Likewise. * gnu/packages/electronics.scm: Likewise. * gnu/packages/engineering.scm: Likewise. * gnu/packages/fpga.scm: Likewise. * gnu/packages/graphviz.scm: Likewise. * gnu/packages/guile.scm: Likewise. * gnu/packages/libusb.scm: Likewise. * gnu/packages/maths.scm: Likewise. * gnu/packages/messaging.scm: Likewise. * gnu/packages/uml.scm: Likewise. * gnu/packages/wxwidgets.scm: Likewise. Signed-off-by: Ludovic Courtès <ludo@gnu.org> 2017-08-29Update e-mail for Kei Kebreau.Kei Kebreau * .mailmap: Map kei@openmailbox.org to current address. * gnu/local.mk: Replace kei@openmailbox.org to current address. * gnu/packages/backup.scm: Likewise. * gnu/packages/calendar.scm: Likewise. * gnu/packages/check.scm: Likewise. * gnu/packages/compression.scm: Likewise. * gnu/packages/documentation.scm: Likewise. * gnu/packages/emacs.scm: Likewise. * gnu/packages/fltk.scm: Likewise. * gnu/packages/freedesktop.scm: Likewise. * gnu/packages/game-development.scm: Likewise. * gnu/packages/games.scm: Likewise. * gnu/packages/gnome.scm: Likewise. * gnu/packages/gnustep.scm: Likewise. * gnu/packages/gtk.scm: Likewise. * gnu/packages/hexedit.scm: Likewise. * gnu/packages/image.scm: Likewise. * gnu/packages/maths.scm: Likewise. * gnu/packages/music.scm: Likewise. * gnu/packages/xfce.scm: Likewise. * gnu/packages/python.scm: Likewise. * gnu/packages/tcl.scm: Likewise. * gnu/packages/textutils.scm: Likewise. * gnu/packages/video.scm: Likewise. * gnu/packages/w3m.scm: Likewise. * gnu/packages/web.scm: Likewise. * gnu/packages/web-browsers.scm: Likewise. * gnu/packages/patches/wmfire-update-for-new-gdk-versions.patch: Likewise. 2017-08-13mailmap: fix entries for ng0.ng0 Signed-off-by: Kei Kebreau <kei@openmailbox.org> 2017-06-16mailmap: Adjust entries for ng0.ng0 Signed-off-by: Alex Kost <alezost@gmail.com> 2017-06-03.mailmap: Add another alias for ng0.ng0 Signed-off-by: Marius Bakke <mbakke@fastmail.com> 2017-05-23mailmap: Update entries for Adriano PelusoAdriano Peluso * .mailmap: Add new entry for Adriano Peluso Signed-off-by: Leo Famulari <leo@famulari.name> 2017-05-22mailmap: Add an entry for Mathieu Othacehe.Mathieu Othacehe This avoids duplicated entries with Othacehe in uppercase. 2017-04-20mailmap: Update entries for ng0.ng0 * .mailmap: Add new address for ng0 and map all existing commits to it. Signed-off-by: Tobias Geerinckx-Rice <me@tobias.gr> 2017-01-27Update .mailmap entries for ng0.ng0 * .mailmap: Update entries for ng0. Signed-off-by: Tobias Geerinckx-Rice <me@tobias.gr> 2017-01-01Update .mailmap.Alex Kost * .mailmap: Add new entries for Alex Sassmannshausen, Ben Woodcroft, Daniel Pimentel, David Hashe, George Clemmer, Ivan Vilata i Balaguer, Jeff Mickey, John J. Foerch, Marek Benc, Pjotr Prins, Raoul Jean Pierre Bonnal, Rene Saavedra, 宋文武, Stefan Reichör, Thomas Danckaert and Vincent Legoll. 2016-12-20mailmap: Add alias for Marius Bakke.Marius Bakke * .mailmap: Map m.bakke@warwick.ac.uk to current address. 2016-11-26mailmap: Associate all commits by ng0 with ng0.ng0 Signed-off-by: Leo Famulari <leo@famulari.name> 2016-10-11Update e-mail address for ng0.ng0 * .mailmap: Update entries for ng0. 2016-10-05Update e-mail address for ng0.ng0 * .mailmap: Add new entries for ng0. 2016-07-15Update e-mail address for Tobias Geerinckx-Rice.Andreas Enge * .mailmap: Add Tobias Geerinckx-Rice. * gnu/packages/disk.scm: Replace "tobias.geerinckx.rice@gmail.com" with "me@tobias.gr". * gnu/packages/linux.scm: Likewise. * gnu/packages/networking.scm: Likewise. Co-authored-by: Tobias Geerinckx-Rice <me@tobias.gr> 2016-07-03Update name for ng0.ng0 Signed-off-by: Ludovic Courtès <ludo@gnu.org> 2016-05-19Update name for Kei Kebreau.Kei Kebreau * .mailmap: Add Kei Kebreau. * gnu/local.mk: Replace "Kei Yamashita" with "Kei Kebreau". * gnu/packages/calendar.scm: Likewise. * gnu/packages/dillo.scm: Likewise. * gnu/packages/fltk.scm: Likewise. * gnu/packages/game-development.scm: Likewise. * gnu/packages/games.scm: Likewise. * gnu/packages/gnome.scm: Likewise. * gnu/packages/gtk.scm: Likewise. * gnu/packages/music.scm: Likewise. * gnu/packages/xfce.scm: Likewise. Signed-off-by: Alex Kost <alezost@gmail.com> 2016-05-04Update .mailmap.Alex Kost * .mailmap: Add new entries for Danny Milosavljevic, Nils Gillmann and Raymond Nicholson. 2016-03-24Update .mailmap.Alex Kost * .mailmap: Add new entries for Al McElrath, Alírio Eyng, Andreas Enge, Ben Woodcroft, David Thompson, Leo Famulari, Mathieu Lirzin, Nils Gillmann, Raimon Grau. 2015-08-11Add new entries to .mailmap.Alex Kost * .mailmap: Add new lines for Andy Wingo and Eric Dvorsak. 2015-07-04Add '.mailmap'.Alex Kost * .mailmap: New file.