system-tests.scm 3.9 KB

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