test 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © `(nth 5 (decode-time))` `user-full-name` <`user-mail-address`>
  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 (gnu tests `(file-name-base (buffer-name))`)
  19. #:use-module (gnu services)
  20. #:use-module (gnu system vm)
  21. #:use-module (gnu system)
  22. #:use-module (gnu tests)
  23. #:use-module (guix gexp)
  24. #:export (%test-`(file-name-base (buffer-name))`))
  25. ;;; Commentary:
  26. ;;;
  27. ;;; This module provides a test definition for the SERVICE_NAME
  28. ;;;
  29. ;;; Code:
  30. (define* (run-`(file-name-base (buffer-name))`-test name test-os)
  31. "Run tests in %`(upcase (file-name-base (buffer-name)))`-OS, which has `(file-name-base (buffer-name))` running."
  32. (define os
  33. (marionette-operating-system
  34. test-os
  35. #:imported-modules '((gnu services herd))))
  36. (define vm
  37. (virtual-machine
  38. (operating-system os)
  39. (port-forwardings '((8080 . 80)))
  40. (memory-size 1024)))
  41. (define test
  42. (with-imported-modules '((gnu build marionette))
  43. #~(begin
  44. (use-modules (srfi srfi-11)
  45. (srfi srfi-64)
  46. (gnu build marionette)
  47. (web client)
  48. (web response)
  49. (ice-9 popen)
  50. (ice-9 rdelim))
  51. (define marionette
  52. (make-marionette (list #$vm)))
  53. (mkdir #$output)
  54. (chdir #$output)
  55. (test-begin #$name)
  56. ;; XXX: Shepherd reads the config file *before* binding its control
  57. ;; socket, so /var/run/shepherd/socket might not exist yet when the
  58. ;; 'marionette' service is started.
  59. (test-assert "shepherd socket ready"
  60. (marionette-eval
  61. \`(begin
  62. (use-modules (gnu services herd))
  63. (let loop ((i 10))
  64. (cond ((file-exists? (%shepherd-socket-file))
  65. #t)
  66. ((> i 0)
  67. (sleep 1)
  68. (loop (- i 1)))
  69. (else
  70. 'failure))))
  71. marionette))
  72. (test-end)
  73. (exit (= (test-runner-fail-count (test-runner-current)) 0)))))
  74. (gexp->derivation (string-append name "-test") test))
  75. (define %`(file-name-base (buffer-name))`-os
  76. ;; Return operating system under test.
  77. (let ((base-os
  78. (simple-operating-system
  79. (service dhcp-client-service-type)
  80. (service `(file-name-base (buffer-name))`-service-type))))
  81. (operating-system
  82. (inherit base-os)
  83. ;; (packages (operating-system-packages base-os))
  84. )))
  85. (define %test-`(file-name-base (buffer-name))`
  86. (system-test
  87. (name "`(file-name-base (buffer-name))`")
  88. (description "Connect to a running `(capitalize (file-name-base (buffer-name)))`")
  89. (value (run-`(file-name-base (buffer-name))`-test name %`(file-name-base (buffer-name))`-os))))
  90. ;;; `(buffer-name)` ends here