system-tests.scm 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2016, 2018, 2019, 2020 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. (use-modules (gnu tests)
  19. (gnu packages package-management)
  20. (guix monads)
  21. (guix store)
  22. ((gnu ci) #:select (channel-source->package))
  23. ((guix git-download) #:select (git-predicate))
  24. ((guix utils) #:select (current-source-directory))
  25. (git)
  26. (ice-9 match))
  27. (define (source-commit directory)
  28. "Return the commit of the head of DIRECTORY or #f if it could not be
  29. determined."
  30. (let ((repository #f))
  31. (catch 'git-error
  32. (lambda ()
  33. (set! repository (repository-open directory))
  34. (let* ((head (repository-head repository))
  35. (target (reference-target head))
  36. (commit (oid->string target)))
  37. (repository-close! repository)
  38. commit))
  39. (lambda _
  40. (when repository
  41. (repository-close! repository))
  42. #f))))
  43. (define-syntax mparameterize
  44. (syntax-rules ()
  45. "This form implements dynamic scoping, similar to 'parameterize', but in a
  46. monadic context."
  47. ((_ monad ((parameter value) rest ...) body ...)
  48. (let ((old-value (parameter)))
  49. (mbegin monad
  50. ;; XXX: Non-local exits are not correctly handled.
  51. (return (parameter value))
  52. (mlet monad ((result (mparameterize monad (rest ...) body ...)))
  53. (parameter old-value)
  54. (return result)))))
  55. ((_ monad () body ...)
  56. (mbegin monad body ...))))
  57. (define (tests-for-current-guix source commit)
  58. "Return a list of tests for perform, using Guix built from SOURCE, a channel
  59. instance."
  60. ;; Honor the 'TESTS' environment variable so that one can select a subset
  61. ;; of tests to run in the usual way:
  62. ;;
  63. ;; make check-system TESTS=installed-os
  64. (let ((guix (channel-source->package source #:commit commit)))
  65. (map (lambda (test)
  66. (system-test
  67. (inherit test)
  68. (value (mparameterize %store-monad ((current-guix-package guix))
  69. (system-test-value test)))))
  70. (match (getenv "TESTS")
  71. (#f
  72. (all-system-tests))
  73. ((= string-tokenize (tests ...))
  74. (filter (lambda (test)
  75. (member (system-test-name test) tests))
  76. (all-system-tests)))))))
  77. (define (system-test->manifest-entry test)
  78. "Return a manifest entry for TEST, a system test."
  79. (manifest-entry
  80. (name (string-append "test." (system-test-name test)))
  81. (version "0")
  82. (item test)))
  83. (define (system-test-manifest)
  84. "Return a manifest containing all the system tests, or all those selected by
  85. the 'TESTS' environment variable."
  86. (define source
  87. (string-append (current-source-directory) "/.."))
  88. (define commit
  89. ;; Fetch the current commit ID so we can potentially build the same
  90. ;; derivation as ci.guix.gnu.org.
  91. (source-commit source))
  92. ;; Intern SOURCE so that 'build-from-source' in (guix channels) sees
  93. ;; "fresh" file names and thus doesn't find itself loading .go files
  94. ;; from ~/.cache/guile when it loads 'build-aux/build-self.scm'.
  95. (let* ((source (local-file source
  96. (if commit
  97. (string-append "guix-"
  98. (string-take commit 7))
  99. "guix-source")
  100. #:recursive? #t
  101. #:select?
  102. (or (git-predicate source)
  103. (const #t))))
  104. (tests (tests-for-current-guix source commit)))
  105. (format (current-error-port) "Selected ~a system tests...~%"
  106. (length tests))
  107. (manifest (map system-test->manifest-entry tests))))
  108. ;; Return the manifest.
  109. (system-test-manifest)