run-system-tests.scm 3.3 KB

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