aboutsummaryrefslogtreecommitdiff
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2017 Peter Mikkelsen <petermikkelsen10@gmail.com>
;;; Copyright © 2022 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 audio)
  #:use-module (gnu tests)
  #:use-module (gnu system)
  #:use-module (gnu system vm)
  #:use-module (gnu services)
  #:use-module (gnu services audio)
  #:use-module (gnu services networking)
  #:use-module (gnu packages mpd)
  #:use-module (guix gexp)
  #:export (%test-mpd
            %test-mympd))

(define %mpd-os
  (simple-operating-system
   (service mpd-service-type)))

(define (run-mpd-test)
  "Run tests in %mpd-os, which has mpd running."
  (define os
    (marionette-operating-system
     %mpd-os
     #:imported-modules '((gnu services herd))))

  (define vm
    (virtual-machine os))

  (define test
    (with-imported-modules '((gnu build marionette))
      #~(begin
          (use-modules (srfi srfi-64)
                       (gnu build marionette))
          (define marionette
            (make-marionette (list #$vm)))

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

          (test-assert "service is running"
            (marionette-eval
             '(begin
                (use-modules (gnu services herd))
                (start-service 'mpd))
             marionette))

          (test-assert "mpd listening"
            ;; Wait until mpd is actually listening before spawning 'mpc'.
            (wait-for-tcp-port 6600 marionette))

          (test-equal "mpc connect"
            0
            (marionette-eval
             '(system* #$(file-append mpd-mpc "/bin/mpc"))
             marionette))

          (test-end))))
  (gexp->derivation "mpd-test" test))

(define %test-mpd
  (system-test
   (name "mpd")
   (description "Test that the mpd can run and be connected to.")
   (value (run-mpd-test))))

(define (run-mympd-test)
  (define os (marionette-operating-system
              (simple-operating-system (service dhcp-client-service-type)
                                       (service mympd-service-type))
              #:imported-modules '((gnu services herd))))

  (define vm
    (virtual-machine
     (operating-system os)
     (port-forwardings '((8080 . 80)))))

  (define test
    (with-imported-modules '((gnu build marionette))
      #~(begin
          (use-modules (srfi srfi-64)
                       (srfi srfi-8)
                       (web client)
                       (web response)
                       (gnu build marionette))

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

          (test-runner-current (system-test-runner #$output))
          (test-begin "mympd")
          (test-assert "service is running"
            (marionette-eval '(begin
                                (use-modules (gnu services herd))

                                (start-service 'mympd))
                             marionette))

          (test-assert "HTTP port ready"
            (wait-for-tcp-port 80 marionette))

          (test-equal "http-head"
            200
            (receive (x _) (http-head "http://localhost:8080") (response-code x)))

          (test-end))))
  (gexp->derivation "mympd-test" test))

(define %test-mympd
  (system-test
   (name "mympd")
   (description "Connect to a running myMPD service.")
   (value (run-mympd-test))))
d generation and switch back. guix package -p "$profile" --switch-generation=2 test "`readlink_base "$profile"`" = "$profile-2-link" guix package -p "$profile" --switch-generation=-1 test "`readlink_base "$profile"`" = "$profile-1-link" # Move to the empty profile. for i in `seq 1 3` do guix package --bootstrap --roll-back -p "$profile" test ! -f "$profile/bin" test ! -f "$profile/lib" test "`readlink_base "$profile"`" = "$profile-0-link" done # Test that '--list-generations' does not output the zeroth generation. test -z "`guix package -p "$profile" -l 0`" # Reinstall after roll-back to the empty profile. guix package --bootstrap -p "$profile" -e "$boot_make" test "`readlink_base "$profile"`" = "$profile-1-link" test -x "$profile/bin/guile" && test ! -x "$profile/bin/make" # Check that the first generation is the current one. test "`guix package -p "$profile" -l 1 | cut -f3 | head -n1`" = "(current)" # Roll-back to generation 0, and install---all at once. guix package --bootstrap -p "$profile" --roll-back -i guile-bootstrap test "`readlink_base "$profile"`" = "$profile-1-link" test -x "$profile/bin/guile" && test ! -x "$profile/bin/make" # Install Make. guix package --bootstrap -p "$profile" -e "$boot_make" test "`readlink_base "$profile"`" = "$profile-2-link" test -x "$profile/bin/guile" && test -x "$profile/bin/make" grep "`guix build -e "$boot_make"`" "$profile/manifest" # Make a "hole" in the list of generations, and make sure we can # roll back and switch "over" it. rm "$profile-1-link" guix package --bootstrap -p "$profile" --roll-back test "`readlink_base "$profile"`" = "$profile-0-link" guix package -p "$profile" --switch-generation=+1 test "`readlink_base "$profile"`" = "$profile-2-link" # Make sure LIBRARY_PATH gets listed by `--search-paths'. guix package --bootstrap -p "$profile" -i guile-bootstrap -i gcc-bootstrap guix package -p "$profile" --search-paths | grep LIBRARY_PATH # Roll back so we can delete #3 below. guix package -p "$profile" --switch-generation=2 # Delete the third generation and check that it was actually deleted. guix package -p "$profile" --delete-generations=3 test -z "`guix package -p "$profile" -l 3`" # Search path of combined profiles. 'LIBRARY_PATH' should show up only in the # combination, not in the individual profiles. rm "$profile" guix package --bootstrap -p "$profile" -i guile-bootstrap guix package --bootstrap -p "$profile_alt" -i gcc-bootstrap guix package -p "$profile" --search-paths | grep LIBRARY_PATH && false guix package -p "$profile" -p "$profile_alt" --search-paths \ | grep "LIBRARY_PATH.*$profile/lib.$profile_alt/lib" # Simulate an upgrade and make sure the package order is preserved. cat > "$module_dir/new.scm" <<EOF (define-module (new) #:use-module (guix) #:use-module (gnu packages bootstrap)) (define-public new-guile (package (inherit %bootstrap-guile) (version (string-append "42." (getenv "V_MINOR"))))) (define-public new-gcc (package (inherit %bootstrap-gcc) (version (string-append "77." (getenv "V_MINOR"))))) EOF guix package --bootstrap -p "$profile" -i gcc-bootstrap installed="`guix package -p "$profile" -I | cut -f1`" # Dry-run upgrade. Make sure no new generation is created when things are # already in store and '-n' is used: <https://issues.guix.gnu.org/53267>. V_MINOR=0 export V_MINOR profile_before="$(readlink "$profile")" guix package -p "$profile" --bootstrap -L "$module_dir" -u # build the profile guix package -p "$profile" --roll-back guix package -p "$profile" --bootstrap -L "$module_dir" -u . -n # check '-n' test "$(readlink "$profile")" = "$profile_before" for i in 1 2 do V_MINOR="$i" export V_MINOR guix package -p "$profile" --bootstrap -L "$module_dir" -u . post_upgrade="`guix package -p "$profile" -I | cut -f1`" test "$post_upgrade" = "$installed" done # # Try with the default profile. # XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}" export XDG_CACHE_HOME HOME="$PWD/t-home-$$" export HOME mkdir -p "$HOME" # Get the canonical directory name so that 'guix package' recognizes it. HOME="`cd $HOME; pwd -P`" guix package --bootstrap -e "$boot_make" test -f "$HOME/.guix-profile/bin/make" guix package --bootstrap --roll-back test ! -f "$HOME/.guix-profile/bin/make"