aboutsummaryrefslogtreecommitdiff
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2015, 2016, 2017 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 (test-size)
  #:use-module (guix store)
  #:use-module (guix monads)
  #:use-module (guix packages)
  #:use-module (guix derivations)
  #:use-module (guix gexp)
  #:use-module (guix tests)
  #:use-module (guix scripts size)
  #:use-module (gnu packages)
  #:use-module (gnu packages bootstrap)
  #:use-module (ice-9 match)
  #:use-module (srfi srfi-1)
  #:use-module (srfi srfi-64))


(test-begin "size")

(test-assertm "store-profile"
  (mlet* %store-monad ((file1 (gexp->derivation "file1"
                                                #~(symlink #$%bootstrap-guile
                                                           #$output)))
                       (file2 (text-file* "file2"
                                          "the file => " file1)))
    (define (matching-profile item)
      (lambda (profile)
        (string=? item (profile-file profile))))

    (mbegin %store-monad
      (built-derivations (list file2))
      (mlet %store-monad ((profiles (store-profile
                                     (list (derivation->output-path file2))))
                          (bash     (interned-file
                                     (search-bootstrap-binary
                                      "bash" (%current-system)) "bash"
                                      #:recursive? #t))
                          (guile    (package->derivation %bootstrap-guile)))
        (define (lookup-profile item)
          (find (matching-profile (if (derivation? item)
                                      (derivation->output-path item)
                                      item))
                profiles))

        (letrec-syntax ((match* (syntax-rules (=>)
                                  ((_ ((drv => profile) rest ...) body)
                                   (match (lookup-profile drv)
                                     ((? profile? profile)
                                      (match* (rest ...) body))))
                                  ((_ () body)
                                   body))))
          ;; Make sure we get all three profiles with sensible values.
          (return (and (= (length profiles) 4)
                       (match* ((file1 => profile1)
                                (file2 => profile2)
                                (guile => profile3)
                                (bash  => profile4)) ;dependency of GUILE
                         (and (> (profile-closure-size profile2) 0)
                              (= (profile-closure-size profile2)
                                 (+ (profile-self-size profile1)
                                    (profile-self-size profile2)
                                    (profile-self-size profile3)
                                    (profile-self-size profile4))))))))))))

(test-assertm "store-profile with multiple items"
  (mlet* %store-monad ((file1 (gexp->derivation "file1"
                                                #~(symlink #$%bootstrap-guile
                                                           #$output)))
                       (file2 (text-file* "file2"
                                          "the file => " file1)))
    (mbegin %store-monad
      (built-derivations (list file2))
      (mlet %store-monad ((profiles  (store-profile
                                      (list (derivation->output-path file2)
                                            (derivation->output-path file1))))
                          (reference (store-profile
                                      (list (derivation->output-path file2)))))
        (return (and (= (length profiles) 4)
                     (lset= equal? profiles reference)))))))

(test-end "size")

;;; Local Variables:
;;; eval: (put 'match* 'scheme-indent-function 1)
;;; End:
tle='2018-01-15 23:29:34 +0100'>2018-01-15services: bitlbee: Add test....Ludovic Courtès 2017-12-29tests: networking: Add tests for Open vSwitch....Marius Bakke 2017-12-19tests: Adjust php-fpm test to new nginx API....Ludovic Courtès 2017-12-18services: nginx: Replace 'http-port' and 'https-port' with 'listen'....Clément Lassieur 2017-12-12gnu: services: Add php-fpm....nee 2017-12-11services: web: Remove default certificate and key files for nginx....Christopher Baines 2017-12-06gnu, doc, tests: Use ‘bootloader-configuration’ everywhere....Tobias Geerinckx-Rice 2017-11-28tests: Add 'git-http' test....Ludovic Courtès 2017-11-28tests: cgit: Add a file to the test repository....Ludovic Courtès 2017-11-26tests: messaging: Enable Prosody DIGEST-MD5 auth mechanism....Clément Lassieur 2017-11-15tests: install: Increase target-size....Oleg Pykhalov 2017-11-01tests: ssh: Make sure we can run executables from PATH....Marius Bakke 2017-10-30tests: install: Estimate the installation system disk size....Hartmut Goebel 2017-10-08tests: databases: Add a simple test for MySQL....Christopher Baines 2017-10-06services: Add MongoDB....Christopher Baines 2017-10-03gnu: services: Add cgit....Oleg Pykhalov 2017-09-26tests: install: Switch to modifying the gc-root-service-type....Ludovic Courtès 2017-09-26tests: mcron: Adjust use of 'wait-for-file'....Ludovic Courtès 2017-09-23gnu: Add rsync service....Oleg Pykhalov 2017-09-08tests: Fix incorrect use of 'file-append'....Ludovic Courtès 2017-09-08gnu: elogind: Use itself as the cgroup controller....Ludovic Courtès 2017-09-08marionette: 'wait-for-file' can be passed a read procedure....Ludovic Courtès 2017-09-06tests: Add test for installing from an ISO Image....Christopher Baines 2017-08-28services: user-processes: Reap child processes....Ludovic Courtès 2017-08-26Merge branch 'core-updates'Marius Bakke 2017-08-23gnu: bootloader: Deprecate "device" field in favor of "target"....Andy Wingo 2017-08-23tests: Add 'libvirt-service-type' test....Christopher Baines 2017-08-21Merge branch 'master' into core-updatesMarius Bakke 2017-08-15gnu: Fix memcached service startup....Christopher Baines 2017-08-15Merge branch 'master' into core-updatesMark H Weaver 2017-08-13gnu: Add mpd service....Peter Mikkelsen 2017-08-01Merge branch 'master' into core-updatesMarius Bakke 2017-07-30services: Add memcached....Christopher Baines