run-system-tests.scm 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2016, 2018, 2019 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 (run-system-tests)
  19. #:use-module (gnu tests)
  20. #:use-module (guix store)
  21. #:use-module ((guix status) #:select (with-status-verbosity))
  22. #:use-module (guix monads)
  23. #:use-module (guix derivations)
  24. #:use-module (guix ui)
  25. #:use-module (srfi srfi-1)
  26. #:use-module (srfi srfi-34)
  27. #:use-module (ice-9 match)
  28. #:export (run-system-tests))
  29. (define (built-derivations* drv)
  30. (lambda (store)
  31. (guard (c ((store-protocol-error? c)
  32. (values #f store)))
  33. (values (build-derivations store drv) store))))
  34. (define (filterm mproc lst) ;XXX: move to (guix monads)
  35. (with-monad %store-monad
  36. (>>= (foldm %store-monad
  37. (lambda (item result)
  38. (mlet %store-monad ((keep? (mproc item)))
  39. (return (if keep?
  40. (cons item result)
  41. result))))
  42. '()
  43. lst)
  44. (lift1 reverse %store-monad))))
  45. (define (run-system-tests . args)
  46. (define tests
  47. ;; Honor the 'TESTS' environment variable so that one can select a subset
  48. ;; of tests to run in the usual way:
  49. ;;
  50. ;; make check-system TESTS=installed-os
  51. (match (getenv "TESTS")
  52. (#f
  53. (all-system-tests))
  54. ((= string-tokenize (tests ...))
  55. (filter (lambda (test)
  56. (member (system-test-name test) tests))
  57. (all-system-tests)))))
  58. (format (current-error-port) "Running ~a system tests...~%"
  59. (length tests))
  60. (with-store store
  61. (with-status-verbosity 2
  62. (run-with-store store
  63. (mlet* %store-monad ((drv (mapm %store-monad system-test-value tests))
  64. (out -> (map derivation->output-path drv)))
  65. (mbegin %store-monad
  66. (show-what-to-build* drv)
  67. (set-build-options* #:keep-going? #t #:keep-failed? #t
  68. #:print-build-trace #t
  69. #:print-extended-build-trace? #t
  70. #:fallback? #t)
  71. (built-derivations* drv)
  72. (mlet %store-monad ((valid (filterm (store-lift valid-path?)
  73. out))
  74. (failed (filterm (store-lift
  75. (negate valid-path?))
  76. out)))
  77. (format #t "TOTAL: ~a\n" (length drv))
  78. (for-each (lambda (item)
  79. (format #t "PASS: ~a~%" item))
  80. valid)
  81. (for-each (lambda (item)
  82. (format #t "FAIL: ~a~%" item))
  83. failed)
  84. (exit (null? failed)))))))))