aboutsummaryrefslogtreecommitdiff
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2019, 2021 Ludovic Courtès <ludo@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 singularity)
  #:use-module (gnu tests)
  #:use-module (gnu system)
  #:use-module (gnu system vm)
  #:use-module (gnu system shadow)
  #:use-module (gnu services)
  #:use-module (gnu services docker)
  #:use-module (gnu packages bash)
  #:use-module (gnu packages guile)
  #:use-module (gnu packages linux)               ;singularity
  #:use-module (guix gexp)
  #:use-module (guix store)
  #:use-module (guix grafts)
  #:use-module (guix monads)
  #:use-module (guix packages)
  #:use-module (guix profiles)
  #:use-module (guix scripts pack)
  #:export (%test-singularity))

(define %singularity-os
  (simple-operating-system
   (service singularity-service-type)
   (simple-service 'guest-account
                   account-service-type
                   (list (user-account (name "guest") (uid 1000) (group "guest"))
                         (user-group (name "guest") (id 1000))))))

(define (run-singularity-test image)
  "Load IMAGE, a Squashfs image, as a Singularity image and run it inside
%SINGULARITY-OS."
  (define os
    (marionette-operating-system %singularity-os))

  (define singularity-exec
    #~(begin
        (use-modules (ice-9 popen) (rnrs io ports))

        (let* ((pipe (open-pipe* OPEN_READ
                                 #$(file-append singularity
                                                "/bin/singularity")
                                 "exec" #$image "/bin/guile"
                                 "-c" "(display \"hello, world\")"))
               (str  (get-string-all pipe))
               (status (close-pipe pipe)))
          (and (zero? status)
               (string=? str "hello, world")))))

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

          (define marionette
            (make-marionette (list #$(virtual-machine os))))

          (test-runner-current (system-test-runner #$output))
          (test-begin "singularity")

          (test-assert "singularity exec /bin/guile (as root)"
            (marionette-eval '#$singularity-exec
                             marionette))

          (test-equal "singularity exec /bin/guile (unprivileged)"
            0
            (marionette-eval
             `(begin
                (use-modules (ice-9 match))

                (match (primitive-fork)
                  (0
                   (dynamic-wind
                     (const #f)
                     (lambda ()
                       (setgid 1000)
                       (setuid 1000)
                       (execl #$(program-file "singularity-exec-test"
                                              #~(exit #$singularity-exec))
                              "test"))
                     (lambda ()
                       (primitive-exit 127))))
                  (pid
                   (cdr (waitpid pid)))))
             marionette))

          (test-equal "singularity run"           ;test the entry point
            42
            (marionette-eval
             `(status:exit-val
               (system* #$(file-append singularity "/bin/singularity")
                        "run" #$image "-c" "(exit 42)"))
             marionette))

          ;; FIXME: Singularity 2.x doesn't directly honor
          ;; /.singularity.d/env/*.sh.  Instead, you have to load those files
          ;; manually, which we don't do.  Remove 'test-skip' call once we've
          ;; switch to Singularity 3.x.
          (test-skip 1)
          (test-equal "singularity run, with environment"
            0
            (marionette-eval
             ;; Check whether GUILE_LOAD_PATH is properly set, allowing us to
             ;; find the (json) module.
             `(status:exit-val
               (system* #$(file-append singularity "/bin/singularity")
                        "--debug" "run" #$image "-c" "(use-modules (json))"))
             marionette))

          (test-end))))

  (gexp->derivation "singularity-test" test))

(define (build-tarball&run-singularity-test)
  (mlet* %store-monad
      ((_        (set-grafting #f))
       (guile    (set-guile-for-build (default-guile)))
       ;; 'singularity exec' insists on having /bin/sh in the image.
       (profile  (profile-derivation (packages->manifest
                                      (list bash-minimal
                                            guile-2.2 guile-json-3))
                                     #:hooks '()
                                     #:locales? #f))
       (tarball  (squashfs-image "singularity-pack" profile
                                 #:entry-point "bin/guile"
                                 #:symlinks '(("/bin" -> "bin")))))
    (run-singularity-test tarball)))

(define %test-singularity
  (system-test
   (name "singularity")
   (description "Test Singularity container of Guix.")
   (value (build-tarball&run-singularity-test))))
tstrap'. (libmesode): Remove 'arguments'. (libstrophe): Likewise. * gnu/packages/microcom.scm (microcom): Likewise. * gnu/packages/networking.scm (libnet): Remove 'bootstrap. * gnu/packages/onc-rpc.scm (libnsl): Remove 'arguments'. * gnu/packages/package-management.scm (guix): Replace 'bootstrap. * gnu/packages/sawfish.scm (librep): Remove 'arguments'. * gnu/packages/version-control.scm (findnewest): Likewise. * gnu/packages/video.scm (liba52, handbrake, motion): Replace 'bootstrap. * gnu/packages/web.scm (fcgiwrap): Remove #:phases. (tidy): Replace 'bootstrap. (gumbo-parser): Remove #:phases. * gnu/packages/wget.scm (wget2): Replace 'bootstrap. * gnu/packages/wm.scm (i3lock-color): Remove #:phases. * gnu/packages/xdisorg.scm (xclip): Likewise. * gnu/packages/xml.scm (libxls): Replace 'bootstrap'. * gnu/packages/xorg.scm (xf86-video-freedreno) (xf86-video-intel): Remove #:phases. * gnu/packages/zile.scm (zile-on-guile): Replace 'bootstrap. Ludovic Courtès 2018-03-07gnu: c-reduce: Use HTTPS home page....* gnu/packages/debug.scm (c-reduce)[home-page]: Use HTTPS. Tobias Geerinckx-Rice 2018-03-07gnu: c-reduce: Update to 2.6.0....* gnu/packages/debug.scm (c-reduce): Update to 2.6.0. Tobias Geerinckx-Rice 2018-03-02gnu: delta: Remove redundant code....* gnu/packages/debug.scm (delta)[arguments]: Remove unneeded MKDIR-P calls. Tobias Geerinckx-Rice 2018-02-22gnu: american-fuzzy-lop: Change custom qemu input....* gnu/packages/debug.scm (american-fuzzy-lop)[inputs]: Custom-qemu now inherits from private qemu-minimal-2.10. * gnu/packages/bootloaders.scm (qemu-minimal-2.10): Add note to move variable to gnu/packages/debug.scm when no longer needed in bootloaders.scm. Efraim Flashner 2018-01-16gnu: american-fuzzy-lop: Update to 2.52b....* gnu/packages/debug.scm (american-fuzzy-lop): Update to 2.52b. [inputs]: custom-qemu now inherits from qemu-minimal. (qemu-2.3.0): Remove variable. Efraim Flashner 2017-09-20gnu: Use 'modify-phases' syntax....* gnu/packages/admin.scm (mingetty, clusterssh, wpa-supplicant-minimal, wpa-supplicant, wakelan, acpica, tree, direvent, dstat)[arguments]: Use 'modify-phases' syntax. * gnu/packages/algebra.scm (arb)[arguments]: Likewise. * gnu/packages/apr.scm (apr-util)[arguments]: Likewise. * gnu/packages/audio.scm (clalsadrv, fluidsynth, faad2, lv2-mda-piano, lv2-mda-epiano, timidity++, vamp, soundtouch, portaudio, rsound, zita-convolver, zita-alsa-pcmi)[arguments]: Likewise. * gnu/packages/backup.scm (rdup, btar)[arguments]: Likewise. * gnu/packages/bioinformatics.scm (bedops, bwa, crossmap, express, flexbar, grit, hisat, ngs-sdk, subread)[arguments]: Likewise. * gnu/packages/bittorrent.scm (transmission)[arguments]: Likewise. * gnu/packages/cdrom.scm (cd-discid)[arguments]: Likewise. * gnu/packages/compression.scm (sharutils)[arguments]: Likewise. * gnu/packages/conky.scm (conky)[arguments]: Likewise. * gnu/packages/databases.scm (bdb, bdb-5.3)[arguments]: Likewise. * gnu/packages/debug.scm (delta, c-reduce)[arguments]: Likewise. * gnu/packages/display-managers.scm (slim)[arguments]: Likewise. * gnu/packages/dns.scm (dnsmasq)[arguments]: Likewise. * gnu/packages/emacs.scm (geiser, emacs-wget, bbdb)[arguments]: Likewise. * gnu/packages/engineering.scm (pcb)[arguments]: Likewise. * gnu/packages/firmware.scm (ath9k-htc-firmware)[arguments]: Likewise. * gnu/packages/flashing-tools.scm (flashrom)[arguments]: Likewise. * gnu/packages/fltk.scm (fltk)[arguments]: Likewise. * gnu/packages/freedesktop.scm (python-pyxdg)[arguments]: Likewise. * gnu/packages/gd.scm (perl-gd)[arguments]: Likewise. * gnu/packages/gkrellm.scm (gkrellm)[arguments]: Likewise. * gnu/packages/glib.scm (glibmm)[arguments]: Likewise. * gnu/packages/gl.scm (glew)[arguments]: Likewise. * gnu/packages/gnome.scm (icon-naming-utils, orbit2, libbonobo, gnome-vfs, libgnome, libbonoboui, goffice-0.8, dconf)[arguments]: Likewise. * gnu/packages/gprolog.scm (gprolog)[arguments]: Likewise. * gnu/packages/gps.scm (gpscorrelate)[arguments]: Likewise. * gnu/packages/graphics.scm (agg)[arguments]: Likewise. * gnu/packages/gtk.scm (ganv, girara, gtksourceview-2, guile-present, python2-pycairo)[arguments]: Likewise. * gnu/packages/guile.scm (guile-1.8)[arguments]: Likewise. * gnu/packages/guile-wm.scm (guile-wm)[arguments]: Likewise. * gnu/packages/hugs.scm (hugs)[arguments]: Likewise. * gnu/packages/hurd.scm (gnumach-headers, hurd-headers, hurd-minimal) [arguments]: Likewise. * gnu/packages/image-viewers.scm (feh, sxiv)[arguments]: Likewise. * gnu/packages/libcanberra.scm (libcanberra)[arguments]: Likewise. * gnu/packages/linux.scm (bridge-utils, iw, fuse, unionfs-fuse/static, lm-sensors, i2c-tools, xsensors, perf, mdadm, libaio, module-init-tools) [arguments]: Likewise. * gnu/packages/lisp.scm (ccl)[arguments]: Likewise. * gnu/packages/lout.scm (lout)[arguments]: Likewise. * gnu/packages/lua.scm (luajit)[arguments]: Likewise. * gnu/packages/machine-learning.scm (shogun)[arguments]: Likewise. * gnu/packages/mail.scm (exim)[arguments]: Likewise. * gnu/packages/man.scm (man-pages, txt2man)[arguments]: Likewise. * gnu/packages/maths.scm (lapack, superlu-dist, openlibm, openspecfun) [arguments]: Likewise. * gnu/packages/messaging.scm (bitlbee)[arguments]: Likewise. * gnu/packages/mp3.scm (libmad, id3lib, mp3info)[arguments]: Likewise. * gnu/packages/music.scm (solfege)[arguments]: Likewise. * gnu/packages/noweb.scm (noweb)[arguments]: Likewise. * gnu/packages/patchutils.scm (patchutils, quilt, colordiff)[arguments]: Likewise. * gnu/packages/pdf.scm (xpdf, zathura-cb, zathura-ps, zathura-djvu, zathura-pdf-poppler, zathura, podofo, fbida)[arguments]: Likewise. * gnu/packages/perl.scm (perl-file-list, perl-test-harness)[arguments]: Likewise. * gnu/packages/photo.scm (gphoto2)[arguments]: Likewise. * gnu/packages/popt.scm (popt)[arguments]: Likewise. * gnu/packages/pretty-print.scm (source-highlight, astyle)[arguments]: Likewise. * gnu/packages/pumpio.scm (pumpa)[arguments]: Likewise. * gnu/packages/python.scm (python-passlib, python-pycrypto, python2-empy, python-sqlalchemy, python-docopt)[arguments]: Likewise. * gnu/packages/rdf.scm (lrdf)[arguments]: Likewise. * gnu/packages/regex.scm (tre)[arguments]: Likewise. * gnu/packages/rrdtool.scm (rrdtool)[arguments]: Likewise. * gnu/packages/ruby.scm (ruby-2.1, ruby-1.8)[arguments]: Likewise. * gnu/packages/sawfish.scm (sawfish)[arguments]: Likewise. * gnu/packages/scheme.scm (racket)[arguments]: Likewise. * gnu/packages/sdl.scm (guile-sdl)[arguments]: Likewise. * gnu/packages/serveez.scm (serveez)[arguments]: Likewise. * gnu/packages/skribilo.scm (skribilo)[arguments]: Likewise. * gnu/packages/smalltalk.scm (smalltalk)[arguments]: Likewise. * gnu/packages/suckless.scm (dmenu, slock)[arguments]: Likewise. * gnu/packages/tcl.scm (expect)[arguments]: Likewise. * gnu/packages/telephony.scm (commoncpp)[arguments]: Likewise. * gnu/packages/textutils.scm (recode, libgtextutils)[arguments]: Likewise. * gnu/packages/time.scm (time)[arguments]: Likewise. * gnu/packages/tor.scm (privoxy)[arguments]: Likewise. * gnu/packages/uucp.scm (uucp)[arguments]: Likewise. * gnu/packages/video.scm (libdvdnav-4)[arguments]: Likewise. * gnu/packages/web-browsers.scm (lynx)[arguments]: Likewise. * gnu/packages/web.scm (tinyproxy)[arguments]: Likewise. * gnu/packages/wicd.scm (wicd)[arguments]: Likewise. * gnu/packages/wm.scm (bspwm)[arguments]: Likewise. * gnu/packages/xdisorg.scm (sxhkd, xcape)[arguments]: Likewise. * gnu/packages/xfce.scm (xfconf)[arguments]: Likewise. * gnu/packages/xfig.scm (transfig)[arguments]: Likewise. * gnu/packages/xorg.scm (imake)[arguments]: Likewise. Kei Kebreau 2017-09-04gnu: Put autoconf-related phases immediately after the 'unpack phase....* gnu/packages/audio.scm (audacity, rtmidi)[arguments]: Correct phases accordingly. * gnu/packages/bioinformatics.scm (mash, seek, vsearch, emboss, htslib-for-sambamba)[arguments]: Likewise. * gnu/packages/ci.scm (cuirass)[arguments]: Likewise. * gnu/packages/compression.scm (minizip, xdelta)[arguments]: Likewise. * gnu/packages/cpp.scm (libzen)[arguments]: Likewise. * gnu/packages/crypto.scm (opendht)[arguments]: Likewise. * gnu/packages/databases.scm (4store, mdbtools)[arguments]: Likewise. * gnu/packages/debug.scm (stress-make)[arguments]: Likewise. * gnu/packages/dns.scm (dnscrypt-proxy, dnscrypt-wrapper)[arguments]: Likewise. * gnu/packages/emacs.scm (emacs-pdf-tools)[arguments]: Likewise. * gnu/packages/embedded.scm (libjaylink, openocd)[arguments]: Likewise. * gnu/packages/engineering.scm (gerbv)[arguments]: Likewise. * gnu/packages/erlang.scm (erlang)[arguments]: Likewise. * gnu/packages/ftp.scm (weex)[arguments]: Likewise. * gnu/packages/gnome.scm (dia)[arguments]: Likewise. * gnu/packages/gnunet.scm (gnurl, guile-gnunet)[arguments]: Likewise. * gnu/packages/gtk.scm (guile-rsvg, graphene)[arguments]: Likewise. * gnu/packages/guile.scm (guildhall, guile-ics, guile-sqlite3)[arguments]: Likewise. * gnu/packages/ibus.scm (ibus-libpinyin)[arguments]: Likewise. * gnu/packages/irc.scm (weechat)[arguments]: Likewise. * gnu/packages/java.scm (classpath-devel)[arguments]: Likewise. * gnu/packages/libreoffice.scm (libetonyek)[arguments]: Likewise. * gnu/packages/libusb.scm (hidapi)[arguments]: Likewise. * gnu/packages/linux.scm (gpm)[arguments]: Likewise. * gnu/packages/logging.scm (glog)[arguments]: Likewise. * gnu/packages/machine-learning.scm (ghmm)[arguments]: Likewise. * gnu/packages/mail.scm (dovecot-trees, dovecot-libsodium-plugin, esmtp) [arguments]: Likewise. * gnu/packages/messaging.scm (freetalk, libmesode, libstrophe)[arguments]: Likewise. * gnu/packages/microcom.scm (microcom)[arguments]: Likewise. * gnu/packages/ocaml.scm (ocaml-ssl)[arguments]: Likewise. * gnu/packages/parallel.scm (slurm)[arguments]: Likewise. * gnu/packages/pdf.scm (libharu)[arguments]: Likewise. * gnu/packages/samba.scm (cifs-utils)[arguments]: Likewise. * gnu/packages/serialization.scm (msgpack)[arguments]: Likewise. * gnu/packages/shells.scm (scsh)[arguments]: Likewise. * gnu/packages/telephony.scm (libiax2)[arguments]: Likewise. * gnu/packages/textutils.scm (dotconf)[arguments]: Likewise. * gnu/packages/version-control.scm (findnewest)[arguments]: Likewise. * gnu/packages/video.scm (libmediainfo, mediainfo)[arguments]: Likewise. Kei Kebreau 2017-08-17gnu: american-fuzzy-lop: Update to 2.49b....* gnu/packages/debug.scm (american-fuzzy-lop): Update to 2.49b. Efraim Flashner 2017-08-17gnu: american-fuzzy-lop: Add support for non-Intel architectures....* gnu/packages/debug.scm (americal-fuzzy-lop): Add qemu target for non-Intel targets. [arguments]: On non-Intel systems, add phase to disable non-Intel architecture warning and remove incompatible binaries. Efraim Flashner 2017-08-09gnu: stress-make: Patch default shell....* gnu/packages/debug.scm (stress-make)[arguments]: Add 'set-default-shell phase. Eric Bavier 2017-07-15gnu: Rename (gnu packages qemu) to (gnu packages virtualization)....* gnu/packages/qemu.scm: Rename this ... * gnu/packages/virtualization.scm: ... to this. * gnu/local.mk (GNU_SYSTEM_MODULES), gnu/packages/bootloaders.scm, gnu/packages/debug.scm, gnu/packages/gnome.scm, gnu/system/vm.scm, gnu/tests/install.scm: Adjust accordingly. 宋文武 2017-03-15gnu: Use INSTALL-FILE where appropriate....* gnu/packages/admin.scm (wpa-supplicant-minimal): Substitute the simpler INSTALL-FILE for COPY-FILE when invoked with redundant arguments. * gnu/packages/bioinformatics.scm (couger, aragorn, express-beta-diversity, edirect, fasttree, rsem, samtools-0.1): Likewise. * gnu/packages/code.scm (withershins): Likewise. * gnu/packages/conky.scm (conky): Likewise. * gnu/packages/debug.scm (delta, american-fuzzy-lop): Likewise. * gnu/packages/emacs.scm (emacs-mit-scheme-doc): Likewise. * gnu/packages/engineering.scm (librecad): Likewise. Tobias Geerinckx-Rice 2017-03-15gnu: stress-make: Fix description....* gnu/packages/debug.scm (stress-make)[description]: Fix typo. Avoid ambiguous use of ‘in order’. Tobias Geerinckx-Rice 2016-11-29gnu: Add zzuf...* gnu/packages/debug.scm (zzuf): New variable. John Darrington 2016-09-09gnu: c-reduce: Upgrade to 2.5.0....* gnu/packages/debug.scm (c-reduce): Upgrade to 2.5.0. [inputs]: Remove delta and perl-benchmark-timer. Add perl-term-readkey. [arguments]: Adjust wrapper libraries. Eric Bavier 2016-09-06gnu: Fix pre-2.7.0 qemu builds....This is a follow-up to 43bec6d0. * gnu/packages/debug.scm (qemu-2.3.0), gnu/packages/grub.scm (qemu-for-tests)[arguments]: Remove the 'disable-test-qga phase. Efraim Flashner 2016-08-13gnu: Add stress-make....* gnu/packages/debug.scm (stress-make): New variable. Eric Bavier