;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2018 Julien Lepiller ;;; Copyright © 2018, 2019 Tobias Geerinckx-Rice ;;; Copyright © 2019 Dan Frumin ;;; Copyright © 2020 Brett Gilio ;;; Copyright © 2020 Björn Höfling ;;; Copyright © 2020 raingloom ;;; Copyright © 2020 Robin Green ;;; ;;; 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 . (define-module (gnu packages coq) #:use-module (gnu packages) #:use-module (gnu packages autotools) #:use-module (gnu packages base) #:use-module (gnu packages bison) #:use-module (gnu packages boost) #:use-module (gnu packages emacs) #:use-module (gnu packages flex) #:use-module (gnu packages gawk) #:use-module (gnu packages multiprecision) #:use-module (gnu packages ocaml) #:use-module (gnu packages perl) #:use-module (gnu packages python) #:use-module (gnu packages rsync) #:use-module (gnu packages texinfo) #:use-module (guix build-system gnu) #:use-module (guix build-system ocaml) #:use-module (guix download) #:use-module (guix git-download) #:use-module ((guix licenses) #:prefix license:) #:use-module (guix packages) #:use-module (guix utils) #:use-modul
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2017, 2018 Clément Lassieur <clement@lassieur.org>
;;; Copyright © 2017-2018, 2021-2022 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2018 Efraim Flashner <efraim@flashner.co.il>
;;;
;;; 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 messaging)
  #:use-module (gnu tests)
  #:use-module (gnu system)
  #:use-module (gnu system vm)
  #:use-module (gnu services)
  #:use-module (gnu services messaging)
  #:use-module (gnu services networking)
  #:use-module (gnu packages messaging)
  #:use-module (guix gexp)
  #:use-module (guix store)
  #:use-module (guix modules)
  #:export (%test-prosody
            %test-bitlbee
            %test-quassel))

(define (run-xmpp-test name xmpp-service pid-file create-account)
  "Run a test of an OS running XMPP-SERVICE, which writes its PID to PID-FILE."
  (define os
    (marionette-operating-system
     (simple-operating-system (service dhcp-client-service-type)
                              xmpp-service)
     #:imported-modules '((gnu services herd))))

  (define port 15222)

  (define vm
    (virtual-machine
     (operating-system os)
     (port-forwardings `((,port . 5222)))))

  (define username "alice")
  (define server "localhost")
  (define jid (string-append username "@" server))
  (define password "correct horse battery staple")
  (define message "hello world")
  (define witness "/tmp/freetalk-witness")

  (define script.ft
    (scheme-file
     "script.ft"
     #~(begin
         (define (handle-received-message time from nickname message)
           (define (touch file-name)
             (call-with-output-file file-name (const #t)))
           (when (equal? message #$message)
             (touch #$witness)))
         (add-hook! ft-message-receive-hook handle-received-message)

         (ft-set-jid! #$jid)
         (ft-set-password! #$password)
         (ft-set-server! #$server)
         (ft-set-port! #$port)
         (ft-set-sslconn! #f)
         (ft-connect-blocking)
         (ft-send-message #$jid #$message)

         (ft-set-daemon)
         (ft-main-loop))))

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

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

          (define (host-wait-for-file file)
            ;; Wait until FILE exists in the host.
            (let loop ((i 60))
              (cond ((file-exists? file)
                     #t)
                    ((> i 0)
                     (begin
                       (sleep 1))
                     (loop (- i 1)))
                    (else
                     (error "file didn't show up" file)))))

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

          ;; Wait for XMPP service to be up and running.
          (test-assert "service running"
            (marionette-eval
             '(begin
                (use-modules (gnu services herd))
                (start-service 'xmpp-daemon))
             marionette))

          ;; Check XMPP service's PID.
          (test-assert "service process id"
            (let ((pid (number->string (wait-for-file #$pid-file
                                                      marionette))))
              (marionette-eval `(file-exists? (string-append "/proc/" ,pid))
                               marionette)))

          ;; Alice sends an XMPP message to herself, with Freetalk.
          (test-assert "client-to-server communication"
            (let ((freetalk-bin (string-append #$freetalk "/bin/freetalk")))
              (marionette-eval '(system* #$create-account #$jid #$password)
                               marionette)
              ;; Freetalk requires write access to $HOME.
              (setenv "HOME" "/tmp")
              (system* freetalk-bin "-s" #$script.ft)
              (host-wait-for-file #$witness)))

          (test-end))))

  (gexp->derivation name test))

(define %create-prosody-account
  (program-file
   "create-account"
   #~(begin
       (use-modules (ice-9 match))
       (match (command-line)
         ((command jid password)
          (let ((password-input (format #f "\"~a~%~a\"" password password))
                (prosodyctl #$(file-append prosody "/bin/prosodyctl")))
            (system (string-join
                     `("echo" ,password-input "|" ,prosodyctl "adduser" ,jid)
                     " "))))))))

(define %test-prosody
  (let* ((config (prosody-configuration
                  (insecure-sasl-mechanisms '())
                  (virtualhosts
                   (list
                    (virtualhost-configuration
                     (domain "localhost")))))))
    (system-test
     (name "prosody")
     (description "Connect to a running Prosody daemon.")
     (value (run-xmpp-test name
                           (service prosody-service-type config)
                           (prosody-configuration-pidfile config)
                           %create-prosody-account)))))


;;;
;;; BitlBee.
;;;

(define (run-bitlbee-test)
  (define os
    (marionette-operating-system
     (simple-operating-system (service dhcp-client-service-type)
                              (service bitlbee-service-type
                                       (bitlbee-configuration
                                        (interface "0.0.0.0"))))
     #:imported-modules (source-module-closure
                         '((gnu services herd)))))

  (define vm
    (virtual-machine
     (operating-system os)
     (port-forwardings `((6667 . 6667)))))

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

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

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

          (test-assert "service started"
            (marionette-eval
             '(begin
                (use-modules (gnu services herd))
                (start-service 'bitlbee))
             marionette))

          (test-assert "connect"
            (let* ((address (make-socket-address AF_INET INADDR_LOOPBACK
                                                 6667))
                   (sock    (socket AF_INET SOCK_STREAM 0)))
              (connect sock address)
              ;; See <https://tools.ietf.org/html/rfc1459>.
              (->bool (string-contains (pk 'message (read-line sock))
                                       "BitlBee"))))

          (test-end))))

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

(define %test-bitlbee
  (system-test
   (name "bitlbee")
   (description "Connect to a BitlBee IRC server.")
   (value (run-bitlbee-test))))

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

  (define vm
    (virtual-machine
      (operating-system os)
      (port-forwardings `((4242 . 4242)))))

  (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 "quassel")

          (test-assert "service started"
            (marionette-eval
             '(begin
                (use-modules (gnu services herd))
                (start-service 'quassel))
             marionette))

          (test-assert "certificate file"
            (marionette-eval
              '(file-exists? "/var/lib/quassel/quasselCert.pem")
              marionette))

          (test-end))))

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

(define %test-quassel
  (system-test
   (name "quassel")
   (description "Connect to a quassel IRC server.")
   (value (run-quassel-test))))
("coq" ,coq) ("camlp5" ,camlp5) ("bison" ,bison) ("flex" ,flex))) (inputs `(("gmp" ,gmp) ("mpfr" ,mpfr) ("boost" ,boost))) (propagated-inputs `(("coq-flocq" ,coq-flocq))) (arguments `(#:configure-flags (list (string-append "--libdir=" (assoc-ref %outputs "out") "/lib/coq/user-contrib/Gappa")) #:phases (modify-phases %standard-phases (add-before 'configure 'fix-remake (lambda _ (substitute* "remake.cpp" (("/bin/sh") (which "sh"))) #t)) (replace 'build (lambda _ (invoke "./remake"))) ;; FIXME: Figure out why failures occur, and re-enable check phase. (delete 'check) ;; (replace 'check ;; (lambda _ (invoke "./remake" "check"))) (replace 'install (lambda _ (invoke "./remake" "install")))))) (home-page "https://gappa.gforge.inria.fr/") (synopsis "Verify and formally prove properties on numerical programs") (description "Gappa is a tool intended to help verifying and formally proving properties on numerical programs dealing with floating-point or fixed-point arithmetic. It has been used to write robust floating-point filters for CGAL and it is used to certify elementary functions in CRlibm. While Gappa is intended to be used directly, it can also act as a backend prover for the Why3 software verification plateform or as an automatic tactic for the Coq proof assistant.") (license (list license:gpl2+ license:cecill))));either gpl2+ or cecill (define-public coq-mathcomp (package (name "coq-mathcomp") (version "1.11.0") (source (origin (method git-fetch) (uri (git-reference (url "https://github.com/math-comp/math-comp") (commit (string-append "mathcomp-" version)))) (file-name (git-file-name name version)) (sha256 (base32 "1axywpa1jcpnidd86irpd1gdbbg2sfbwc652675xisq5wnmfmf6f")))) (build-system gnu-build-system) (native-inputs `(("ocaml" ,ocaml) ("which" ,which) ("coq" ,coq))) (arguments `(#:tests? #f ; No tests. #:phases (modify-phases %standard-phases (delete 'configure) (add-before 'build 'chdir (lambda _ (chdir "mathcomp") #t)) (replace 'install (lambda* (#:key outputs #:allow-other-keys) (invoke "make" "-f" "Makefile.coq" (string-append "COQLIB=" (assoc-ref outputs "out") "/lib/coq/") "install")))))) (home-page "https://math-comp.github.io/") (synopsis "Mathematical Components for Coq") (description "Mathematical Components for Coq has its origins in the formal proof of the Four Colour Theorem. Since then it has grown to cover many areas of mathematics and has been used for large scale projects like the formal proof of the Odd Order Theorem. The library is written using the Ssreflect proof language that is an integral part of the distribution.") (license license:cecill-b))) (define-public coq-coquelicot (package (name "coq-coquelicot") (version "3.1.0") (source (origin (method git-fetch) (uri (git-reference (url "https://gitlab.inria.fr/coquelicot/coquelicot.git") (commit (string-append "coquelicot-" version)))) (file-name (git-file-name name version)) (sha256 (base32 "0mz3pxan1237fr5fi79c66y7b9z7bmi0sc45kwrmkczsjm5462jm")))) (build-system gnu-build-system) (native-inputs `(("autoconf" ,autoconf) ("automake" ,automake) ("ocaml" ,ocaml) ("which" ,which) ("coq" ,coq))) (propagated-inputs `(("mathcomp" ,coq-mathcomp))) (arguments `(#:configure-flags (list (string-append "--libdir=" (assoc-ref %outputs "out") "/lib/coq/user-contrib/Coquelicot")) #:phases (modify-phases %standard-phases (add-before 'configure 'fix-remake (lambda _ (substitute* "remake.cpp" (("/bin/sh") (which "sh"))) #t)) (replace 'build (lambda _ (invoke "./remake"))) (replace 'check (lambda _ (invoke "./remake" "check"))) (replace 'install (lambda _ (invoke "./remake" "install")))))) (home-page "http://coquelicot.saclay.inria.fr") (synopsis "Coq library for Reals") (description "Coquelicot is an easier way of writing formulas and theorem statements, achieved by relying on total functions in place of dependent types for limits, derivatives, integrals, power series, and so on. To help with the proof process, the library comes with a comprehensive set of theorems that cover not only these notions, but also some extensions such as parametric integrals, two-dimensional differentiability, asymptotic behaviors. It also offers some automations for performing differentiability proofs. Moreover, Coquelicot is a conservative extension of Coq's standard library and provides correspondence theorems between the two libraries.") (license license:lgpl3+))) (define-public coq-bignums (package (name "coq-bignums") (version "8.11.0") (source (origin (method git-fetch) (uri (git-reference (url "https://github.com/coq/bignums") (commit (string-append "V" version)))) (file-name (git-file-name name version)) (sha256 (base32 "1xcd7c7qlvs0narfba6px34zq0mz8rffnhxw0kzhhg6i4iw115dp")))) (build-system gnu-build-system) (native-inputs `(("ocaml" ,ocaml) ("coq" ,coq))) (inputs `(("camlp5" ,camlp5))) (arguments `(#:tests? #f ; No test target. #:make-flags (list (string-append "COQLIBINSTALL=" (assoc-ref %outputs "out") "/lib/coq/user-contrib")) #:phases (modify-phases %standard-phases (delete 'configure)))) (home-page "https://github.com/coq/bignums") (synopsis "Coq library for arbitrary large numbers") (description "Bignums is a coq library of arbitrary large numbers. It provides BigN, BigZ, BigQ that used to be part of Coq standard library.") (license license:lgpl2.1+))) (define-public coq-interval (package (name "coq-interval") (version "4.0.0") (source (origin (method git-fetch) (uri (git-reference (url "https://gitlab.inria.fr/coqinterval/interval.git") (commit (string-append "interval-" version)))) (file-name (git-file-name name version)) (sha256 (base32 "01iz6qmnsm6b9s1vmdjs79vjx9xgwzn5rwyjp6bvs8hg3zlmhpip")))) (build-system gnu-build-system) (native-inputs `(("autoconf" ,autoconf) ("automake" ,automake) ("ocaml" ,ocaml) ("which" ,which) ("coq" ,coq))) (propagated-inputs `(("flocq" ,coq-flocq) ("bignums" ,coq-bignums) ("coquelicot" ,coq-coquelicot) ("mathcomp" ,coq-mathcomp))) (arguments `(#:configure-flags (list (string-append "--libdir=" (assoc-ref %outputs "out") "/lib/coq/user-contrib/Gappa")) #:phases (modify-phases %standard-phases (add-before 'configure 'fix-remake (lambda _ (substitute* "remake.cpp" (("/bin/sh") (which "sh"))) #t)) (replace 'build (lambda _ (invoke "./remake"))) (replace 'check (lambda _ (invoke "./remake" "check"))) (replace 'install (lambda _ (invoke "./remake" "install")))))) (home-page "http://coq-interval.gforge.inria.fr/") (synopsis "Coq tactics to simplify inequality proofs") (description "Interval provides vernacular files containing tactics for simplifying the proofs of inequalities on expressions of real numbers for the Coq proof assistant.") (license license:cecill-c))) (define-public coq-autosubst ;; Latest commit on that branch, where work on supporting coq 8.6 and ;; more recent versions of coq happen. (let ((branch "coq86-devel") (commit "fa6ef30664511ffa659cbcf3c962715cbee03572")) (package (name "coq-autosubst") (version (git-version "1" branch commit)) (source (origin (method git-fetch) (uri (git-reference (url "git://github.com/uds-psl/autosubst") (commit commit))) (file-name (git-file-name name version)) (sha256 (base32 "1cl0bp96bk6lplbl7n5c703vd3gvbs5mvf2qrf8q333kkqd7jqq4")))) (build-system gnu-build-system) (arguments `(#:tests? #f #:phases (modify-phases %standard-phases (delete 'configure) (replace 'install (lambda* (#:key outputs #:allow-other-keys) (setenv "COQLIB" (string-append (assoc-ref outputs "out") "/lib/coq/")) (invoke "make" (string-append "COQLIB=" (assoc-ref outputs "out") "/lib/coq/") "install")))))) (native-inputs `(("coq" ,coq))) (home-page "https://www.ps.uni-saarland.de/autosubst/") (synopsis "Coq library for parallel de Bruijn substitutions") (description "Formalizing syntactic theories with variable binders is not easy. Autosubst is a library for the Coq proof assistant to automate this process. Given an inductive definition of syntactic objects in de Bruijn representation augmented with binding annotations, Autosubst synthesizes the parallel substitution operation and automatically proves the basic lemmas about substitutions. This library contains an automation tactic that solves equations involving terms and substitutions. This makes the usage of substitution lemmas unnecessary. The tactic is based on our current work on a decision procedure for the equational theory of an extension of the sigma-calculus by Abadi et al. The library is completely written in Coq and uses Ltac to synthesize the substitution operation.") (license license:bsd-3)))) (define-public coq-equations (package (name "coq-equations") (version "1.2.3") (source (origin (method git-fetch) (uri (git-reference (url "https://github.com/mattam82/Coq-Equations") (commit (string-append "v" version "-8.11")))) (file-name (git-file-name name version)) (sha256 (base32 "1srxz1rws8jsh7402g2x2vcqgjbbsr64dxxj5d2zs48pmhb20csf")))) (build-system gnu-build-system) (native-inputs `(("ocaml" ,ocaml) ("coq" ,coq) ("camlp5" ,camlp5))) (arguments `(#:test-target "test-suite" #:phases (modify-phases %standard-phases (replace 'configure (lambda* (#:key outputs #:allow-other-keys) (invoke "sh" "./configure.sh"))) (replace 'install (lambda* (#:key outputs #:allow-other-keys) (invoke "make" (string-append "COQLIB=" (assoc-ref outputs "out") "/lib/coq/") "install")))))) (home-page "https://mattam82.github.io/Coq-Equations/") (synopsis "Function definition plugin for Coq") (description "Equations provides a notation for writing programs by dependent pattern-matching and (well-founded) recursion in Coq. It compiles everything down to eliminators for inductive types, equality and accessibility, providing a definitional extension to the Coq kernel.") (license license:lgpl2.1))) (define-public coq-stdpp (package (name "coq-stdpp") (version "1.4.0") (synopsis "Alternative Coq standard library std++") (source (origin (method git-fetch) (uri (git-reference (url "https://gitlab.mpi-sws.org/iris/stdpp.git") (commit (string-append "coq-stdpp-" version)))) (file-name (git-file-name name version)) (sha256 (base32 "1m6c7ibwc99jd4cv14v3r327spnfvdf3x2mnq51f9rz99rffk68r")))) (build-system gnu-build-system) (inputs `(("coq" ,coq))) (arguments `(#:tests? #f ; Tests are executed during build phase. #:phases (modify-phases %standard-phases (delete 'configure) (replace 'install (lambda* (#:key outputs #:allow-other-keys) (invoke "make" (string-append "COQLIB=" (assoc-ref outputs "out") "/lib/coq/") "install")))))) (description "This project contains an extended \"Standard Library\" for Coq called coq-std++. The key features are: @itemize @item Great number of definitions and lemmas for common data structures such as lists, finite maps, finite sets, and finite multisets. @item Type classes for common notations (like ∅, ∪, and Haskell-style monad notations) so that these can be overloaded for different data structures. @item It uses type classes to keep track of common properties of types, like it having decidable equality or being countable or finite. @item Most data structures are represented in canonical ways so that Leibniz equality can be used as much as possible (for example, for maps we have m1 = m2 iff ∀ i, m1 !! i = m2 !! i). On top of that, the library provides setoid instances for most types and operations. @item Various tactics for common tasks, like an ssreflect inspired done tactic for finishing trivial goals, a simple breadth-first solver naive_solver, an equality simplifier simplify_eq, a solver solve_proper for proving compatibility of functions with respect to relations, and a solver set_solver for goals involving set operations. @item The library is dependency- and axiom-free. @end itemize") (home-page "https://gitlab.mpi-sws.org/iris/stdpp") (license license:bsd-3)))