aboutsummaryrefslogtreecommitdiff
;;; 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")
kages/python-xyz.scm, gnu/packages/python.scm, gnu/packages/qt.scm, gnu/packages/ruby.scm, gnu/packages/rust.scm, gnu/packages/scheme.scm, gnu/packages/serialization.scm, gnu/packages/shells.scm, gnu/packages/ssh.scm, gnu/packages/suckless.scm, gnu/packages/tbb.scm, gnu/packages/telephony.scm, gnu/packages/text-editors.scm, gnu/packages/textutils.scm, gnu/packages/time.scm, gnu/packages/tls.scm, gnu/packages/tor.scm, gnu/packages/version-control.scm, gnu/packages/video.scm, gnu/packages/vim.scm, gnu/packages/web.scm, gnu/packages/wm.scm, gnu/packages/xdisorg.scm, gnu/packages/xfce.scm, gnu/packages/xml.scm, gnu/packages/xorg.scm, gnu/services/certbot.scm, gnu/services/desktop.scm, gnu/services/version-control.scm, gnu/services/web.scm, guix/import/hackage.scm, guix/licenses.scm: Likewise. Signed-off-by: Efraim Flashner <efraim@flashner.co.il> 2020-05-11gnu: git-annex: Add support for v4 of S3 support.Efraim Flashner * gnu/packages/haskell-apps.scm (git-annex)[source]: Add patch. * gnu/packages/patches/git-annex-S3v4.patch: New file. * gnu/local.mk (dist_patch_DATA): Register it. 2020-05-02gnu: git-annex: Update to 8.20200501.Kyle Meyer * gnu/packages/haskell-apps.scm (git-annex): Update to 8.20200501. Signed-off-by: 宋文武 <iyzsong@member.fsf.org> 2020-04-09gnu: shellcheck: Update homepage.Jack Hill * gnu/packages/haskell-apps.scm (shellcheck)[homepage]: Update URL. Signed-off-by: Tobias Geerinckx-Rice <me@tobias.gr> 2020-04-01gnu: git-annex: Update to 8.20200330.Kyle Meyer * gnu/packages/haskell-apps.scm (git-annex): Update to 8.20200330. Signed-off-by: Tobias Geerinckx-Rice <me@tobias.gr> 2020-03-29gnu: Add apply-refact.Brian Leung * gnu/packages/haskell-apps.scm (apply-refact): New variable. Signed-off-by: Marius Bakke <mbakke@fastmail.com> 2020-03-29gnu: Move the deprecated 'ghc-stylish-haskell' closer to its replacement.Marius Bakke Inheritance across modules can cause unbound variable errors because of cyclic dependencies between the modules. * gnu/packages/haskell-xyz.scm (ghc-stylish-haskell): Move from here ... * gnu/packages/haskell-apps.scm (ghc-stylish-haskell): ... to here. 2020-03-21gnu: stylish-haskell: Update description.John Soo * gnu/packages/haskell-apps.scm (stylish-haskell): Update description. Signed-off-by: Marius Bakke <mbakke@fastmail.com> 2020-03-15gnu: Add ghcid.Alexandru-Sergiu Marton * gnu/packages/haskell-apps.scm (ghcid): New variable. Signed-off-by: Leo Famulari <leo@famulari.name> 2020-03-10gnu: git-annex: Update to 8.20200309.Kyle Meyer * gnu/packages/haskell-apps.scm (git-annex): Update to 8.20200309. Signed-off-by: Efraim Flashner <efraim@flashner.co.il> 2020-03-07gnu: raincat: Update home page.Tobias Geerinckx-Rice * gnu/packages/haskell-apps.scm (raincat)[home-page]: Update. 2020-02-27gnu: git-annex: Update to 8.20200226.Kyle Meyer * gnu/packages/haskell-apps.scm (git-annex): Update to 8.20200226. Signed-off-by: Jakub Kądziołka <kuba@kadziolka.net> 2020-02-20gnu: corrode: Use git-file-name.Jakub Kądziołka * gnu/packages/haskell-apps.scm (corrode): Use git-file-name. 2020-02-20gnu: git-annex: Update to 7.20200219.Kyle Meyer * gnu/packages/haskell-apps.scm (git-annex): Update to 7.20200219. Signed-off-by: Leo Famulari <leo@famulari.name> 2020-02-17gnu: hlint: Update home page.Tobias Geerinckx-Rice * gnu/packages/haskell-apps.scm (hlint)[home-page]: Use source repository. 2020-02-04gnu: git-annex: Update to 7.20200202.7.Kyle Meyer * gnu/packages/haskell-apps.scm (git-annex): Update to 7.20200202.7. Signed-off-by: Efraim Flashner <efraim@flashner.co.il>