size.scm 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2015, 2016, 2017 Ludovic Courtès <ludo@gnu.org>
  3. ;;;
  4. ;;; This file is part of GNU Guix.
  5. ;;;
  6. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  7. ;;; under the terms of the GNU General Public License as published by
  8. ;;; the Free Software Foundation; either version 3 of the License, or (at
  9. ;;; your option) any later version.
  10. ;;;
  11. ;;; GNU Guix is distributed in the hope that it will be useful, but
  12. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;;; GNU General Public License for more details.
  15. ;;;
  16. ;;; You should have received a copy of the GNU General Public License
  17. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  18. (define-module (test-size)
  19. #:use-module (guix store)
  20. #:use-module (guix monads)
  21. #:use-module (guix packages)
  22. #:use-module (guix derivations)
  23. #:use-module (guix gexp)
  24. #:use-module (guix tests)
  25. #:use-module (guix scripts size)
  26. #:use-module (gnu packages)
  27. #:use-module (gnu packages bootstrap)
  28. #:use-module (ice-9 match)
  29. #:use-module (srfi srfi-1)
  30. #:use-module (srfi srfi-64))
  31. (define %store
  32. (open-connection-for-tests))
  33. (define-syntax-rule (test-assertm name exp)
  34. (test-assert name
  35. (run-with-store %store exp
  36. #:guile-for-build (%guile-for-build))))
  37. (test-begin "size")
  38. (test-assertm "store-profile"
  39. (mlet* %store-monad ((file1 (gexp->derivation "file1"
  40. #~(symlink #$%bootstrap-guile
  41. #$output)))
  42. (file2 (text-file* "file2"
  43. "the file => " file1)))
  44. (define (matching-profile item)
  45. (lambda (profile)
  46. (string=? item (profile-file profile))))
  47. (mbegin %store-monad
  48. (built-derivations (list file2))
  49. (mlet %store-monad ((profiles (store-profile
  50. (list (derivation->output-path file2))))
  51. (bash (interned-file
  52. (search-bootstrap-binary
  53. "bash" (%current-system)) "bash"
  54. #:recursive? #t))
  55. (guile (package->derivation %bootstrap-guile)))
  56. (define (lookup-profile item)
  57. (find (matching-profile (if (derivation? item)
  58. (derivation->output-path item)
  59. item))
  60. profiles))
  61. (letrec-syntax ((match* (syntax-rules (=>)
  62. ((_ ((drv => profile) rest ...) body)
  63. (match (lookup-profile drv)
  64. ((? profile? profile)
  65. (match* (rest ...) body))))
  66. ((_ () body)
  67. body))))
  68. ;; Make sure we get all three profiles with sensible values.
  69. (return (and (= (length profiles) 4)
  70. (match* ((file1 => profile1)
  71. (file2 => profile2)
  72. (guile => profile3)
  73. (bash => profile4)) ;dependency of GUILE
  74. (and (> (profile-closure-size profile2) 0)
  75. (= (profile-closure-size profile2)
  76. (+ (profile-self-size profile1)
  77. (profile-self-size profile2)
  78. (profile-self-size profile3)
  79. (profile-self-size profile4))))))))))))
  80. (test-assertm "store-profile with multiple items"
  81. (mlet* %store-monad ((file1 (gexp->derivation "file1"
  82. #~(symlink #$%bootstrap-guile
  83. #$output)))
  84. (file2 (text-file* "file2"
  85. "the file => " file1)))
  86. (mbegin %store-monad
  87. (built-derivations (list file2))
  88. (mlet %store-monad ((profiles (store-profile
  89. (list (derivation->output-path file2)
  90. (derivation->output-path file1))))
  91. (reference (store-profile
  92. (list (derivation->output-path file2)))))
  93. (return (and (= (length profiles) 4)
  94. (lset= equal? profiles reference)))))))
  95. (test-end "size")
  96. ;;; Local Variables:
  97. ;;; eval: (put 'match* 'scheme-indent-function 1)
  98. ;;; End: